DataObjects/Cms_page.php
[Pman.Cms] / Import / old.php
1 <?php
2 /**
3  * this is to convert akbkhome old stuff into db.
4  * 
5  */
6 require_once 'Pman.php';
7
8 class Pman_Cms_Import_old extends Pman
9 {
10     function getAuth ()
11     {
12         return true;
13     }
14     
15     
16     function get($base = '',  $opts = array())
17     {
18         //$this->convertblog();
19         DB_DataObject::debugLevel(1);
20         $this->convertDir();
21         die("DONE");
22     }
23     var $bdir = '/home/svn/svn_wikidata';
24     function convertDir($din='')
25     {
26         $d = empty($din) ? $this->bdir : $this->bdir.'/'.$din;
27         
28         foreach(scandir($d) as $f) {
29             if (!strlen($f) || $f[0] =='.') {
30                 continue;
31             }
32             $ff = $d.'/'.$f;
33             
34             if (is_dir($ff)) {
35                 $this->convertDir(substr($ff,strlen($this->bdir)+1));
36                 continue;
37             }
38             if (!preg_match('/\.html$/', $f)) {
39                 // skip images at present.
40                 continue;
41             }
42             $p = DB_DataObject::factory('Page');
43             $p->published = strtotime('Y-m-d H:i:s', filemtime($ff));
44             $p->title = preg_replace('/\.html$/', '', $f);
45             if (!$p->find(true)) {
46                 $p->insert();
47             }
48             $p->contents = file_get_contents($ff);
49             $p->update();
50              
51             
52         }
53         // how the old site was structured.
54         //a) directories with .img == images...
55         // only bother with HTML files..
56         
57         
58     }
59     
60     
61     
62     function convertblog()
63     {
64         
65         $d = DB_DataObject::factory('Category');
66         $d->query('
67             SELECT * FROM serendipity.category
68         ');
69         $ar = array();
70         while( $d->fetch() ) {
71             $ar[] = clone($d);
72         }
73         // categoryid | category_name | category_description                 | authorid |
74         //| short_name  
75         //| title   
76         
77         DB_DataObject::debugLevel(1);
78         $cmap = array();
79         foreach($ar as $b) {
80             $c = DB_DataObject::factory('Category'); 
81             if ($c->get('short_name', $b->category_name)) {
82                 $cmap[$b->categoryid] = $c->id;
83             } else {
84                 $c = DB_DataObject::factory('Category'); 
85                 $c->setFrom(array(
86                     'short_name' => $b->category_name,
87                     'title' => $b->category_description,
88                 ));
89                 $c->insert();
90                 $cmap[$b->categoryid] = $c->id;
91                 $d = DB_DataObject::factory('Page');
92                 
93                 
94                 
95             }
96             
97             
98         }
99         
100         
101         // import blog data..
102         //DB_DataObject::debugLevel(1);
103         $d = DB_DataObject::factory('Page');
104         $d->query('
105             SELECT * FROM serendipity.entries
106         ');
107         $ar = array();
108         while( $d->fetch() ) {
109             $ar[] = clone($d);
110         }
111         
112         $a = DB_DataObject::factory('core_person');
113         $a->get('email', 'alan@akbkhome.com');
114         
115         
116         //echo '<PRE>'. htmlspecialchars(print_R($ar,true));
117         foreach($ar as $b) {
118             
119                 
120             $d = DB_DataObject::factory('Page');
121             $d->published = strtotime('Y-m-d H:i:s', $b->timestamp);
122             $d->title = $b->title;
123             if (!$d->find(true)) {
124                 $d->insert();
125             }
126             $d->setFrom($b->toArray());
127             // mappings..
128             $d->setFrom(array(
129                 'contents' => $b->body,
130                 'comments_no' => $b->comments,
131                 'trackbacks_no' => $b->trackbacks,
132                 'has_extended' => $b->exflag,
133                 'contents' => $b->body,
134                 'author_id' =>  $a->id,
135                 'author_name' => $a->name,
136                 'category_id' => $cmap[$b->categoryid],
137                 'published' => strtotime('Y-m-d H:i:s', $b->timestamp),
138                 'created' => strtotime('Y-m-d H:i:s', $b->timestamp),
139                 'updated' => strtotime('Y-m-d H:i:s', $b->timestamp),
140                 'replaces_id' => $b->isdraft ? -1 : 0,
141                 
142                 
143             ));
144             $d->update();
145             
146             
147         }
148         
149         exit;
150         
151         
152         
153         /*
154 id = 129
155 shortname = 130
156 category_id = 129
157 title = 130
158 contents = 194
159 visible = 145
160 extended = 194
161 trackbacks_no = 129
162 comments_no = 129
163 has_extended = 129
164 author_id = 129
165 author_name = 130
166 updated = 142
167 created = 142
168 published = 142
169 page_link = 130
170 parent_id = 129
171 in_rss = 129
172 replaces_id = 129
173 */
174         
175         
176     }
177     
178     
179 }