1,
502 => 7,
503 => 9,
505 => 8,
506 => 11,
1002 => 12,
1004 => 13,
1007 => 14,
1022 => 15,
1027 => 16,
1028 => 17
);
const LEGACYTABLE = 'legacyblog';
const BLOGTABLE = 'blog';
public function __construct()
{
$this->table = WBClass::create('WBDatasource_Table');
$this->scan = WBClass::create('WBMarkup_Scanner');
$this->hdlXinha = WBClass::create('WBMarkup_Handler_Xml2Xinha');
$this->hdlXml = WBClass::create('WBMarkup_Handler_Xinha2Xml');
$this->hdlHtml = WBClass::create('WBMarkup_Handler_Xml2Html');
}
public function setTable($src)
{
$conf = $this->table->getTableInfo(self::BLOGTABLE);
$conf['created'] = null;
$conf['changed'] = null;
$this->table->setTables(array(self::BLOGTABLE => $conf));
$conf['table'] = $src;
$conf['delete'] = null;
// $conf['order'] = null;
$conf['limit'] = null;
$this->table->setTables(array(self::LEGACYTABLE=> $conf));
}
public function transformBlog()
{
$ids = $this->table->getIds(self::LEGACYTABLE);
//$ids = array($ids[951]);
foreach ($ids as $id) {
$this->transformRecord($id);
}
}
public function transformRecord($id)
{
// load legacy XML
$data = $this->table->get(self::LEGACYTABLE, $id);
$data = $data[0];
$search = array(
'ä' => 'ä',
'ö' => 'ö',
'ü' => 'ü',
'€' => '€',
'ß' => 'ß',
'Ä' => 'Ä',
'Ö' => 'Ö',
'Ãœ' => 'Ü',
'Â' => '',
);
$data['title'] = str_replace(array_keys($search), array_values($search), $data['title']);
$data['body'] = str_replace(array_keys($search), array_values($search), $data['body']);
// transform to current XML
$this->scan->setHandler($this->hdlXinha);
$this->scan->scan($data['body']);
$xinha = $this->hdlXinha->getParsedContent();
$this->scan->setHandler($this->hdlXml);
$this->scan->scan($xinha);
$data['body'] = $this->hdlXml->getParsedContent();
// save XML
$uPrimary = $this->table->getIdentifier('user');
$new = array();
$keys = array(
$uPrimary,
$this->table->getIdentifier('blogcategory'),
'created',
'changed',
'title',
'body'
);
foreach ($keys as $key) {
$new[$key] = $data[$key];
}
if (isset($this->user[$new[$uPrimary]])) {
$new[$uPrimary] = $this->user[$new[$uPrimary]];
}
$id = $this->table->save(self::BLOGTABLE, '__new', $new);
echo $id . ' ' . $new['title'] . '
';
flush();
//echo $new['title'] . '
' . htmlspecialchars($new['body']) . "\n"; // echo '
' . var_export($new, true) . "\n"; return $id; } protected function displayHtml($data) { $this->scan->setHandler($this->hdlHtml); $this->scan->scan($data['body']); $html = $this->hdlXml->getParsedContent(); } } $lb = new LegaxyBlog(); $lb->setTable('lena.lenablog'); $lb->transformBlog(); ?>