Hello everyone,
I’m new to Modx and need your help.
I am developing a news portal and I’m using Articles. I need to import data from the old site (it was a custom cms) and add the old news items as articles. I managed to create some xml files (one for each news category) that include the content I need for Modx. I created a snippet to add the items to the database, but when I run it I got the following error:
fatal error: Uncaught Error: Call to undefined method SimpleXMLElement::getTimestamp() in …\core\cache\includes\elements\modsnippet\95.include.cache.php on line 34
the snippet code:
<?php
if (!defined('MODX_CORE_PATH')) {
define('MODX_CORE_PATH', '../core/');
}
if (!defined('MODX_CONFIG_KEY')) {
define('MODX_CONFIG_KEY', 'config');
}
require_once( MODX_CORE_PATH . 'model/modx/modx.class.php');
$modx = new modX();
$modx->initialize('mgr');
$source = $scriptProperties['source'];
$parent = $scriptProperties['parent'];
if (empty($source)) {
$modx->log(modX::LOG_LEVEL_DEBUG,'[xmlparser] Empty source adress passed, aborting.');
return '';
} else {
$xml = simplexml_load_file($source) or die("Error: Cannot create object");
// print_r ($xml);
foreach ($xml->children() as $row) {
// print_r ($row);
$pagetitle = $row->pagetitle;
$longtitle = "long title";
$descr = "description";
$template = 8;
$published = 1;
$searchable = 1;
$content = $row->content;
$date = $row->publishedon;
$publishedon = $date->getTimestamp();
$path = 'uploads/news/' . $row->imgpath;
$doc->set('parent', $parent);
$doc->set('pagetitle', $pagetitle);
$doc->set('longtitle', $longtitle);
$doc->set('alias',$alias);
$doc->set('description', $descr);
$doc->set('template',$template);
$doc->set('published',$published);
$doc->set('publishedon',$publishedon);
$doc->set('searchable', $searchable);
$doc->setContent($content);
$doc->save();
$doc_id = $doc->get('id');
$tv = $modx->getObject('modTemplateVar',array('name'=>'mainImg'));
$tv->setValue($doc_id, $path);
$tv->save();
}
}
and the call:
[[!ImportDB? &source=
[[!++site_url]]assets/exports/parapolitika.xml&parent=
46]]
Any idea on what I’m doing wrong?
Thank you!