Find the Exponential Software extensions you want
| UNIX name | Owner | Status |
|---|---|---|
| apliaexportimport | eZ Publish Legacy | stable |
| Version | Compatible with |
|---|---|
| N/A | N/A |
Lets you import any XML/HTML to ez content objects, meaning import and export of data in ez.
Tested on:
Aplia Export Import contains two routines. These are completely seprated, and does not nessecary need to be used together. Export is only for exporting eZ classes to html. Import can import any html to EZ objects.
Useful for converting some old installations content into a newer installation.
Exports all attributes on a contentclass but some edge cases you should know:
Export contains a folder with images and a XML file that can be imported with the import routine.
Imports XML file with both HTML and attributes to eZ. A config handler is created per structure of the xml file you want to import.
A Configuration file must be created, see the "IMPORTING DATA" section.
Here i want to export all "news_article" content objects. Don't worry, images inline and files in xml fields will also be added to the export..
php extension/apliaexportimport/bin/php/exportcontentclass.php news_article
Importing requires you to create a simple php file, it can be created in the EZ ROOT directory. The extension comes with a sample php config file. See "CONFIG FILE"
section for all the options for the config file.
See extension/apliaexportimport/import.config.sample.php its pretty straight forward.
Run this command to import after you have customized the config file for your contentclass!
php extension/apliaexportimport/bin/php/importcontentclass.php extension/apliaexportimport/import.config.sample.php export_news_article export_news_article/export.xml
Sample below:
Hello
<FONT size=2>
<P><IMG src="http://www.ewqwqwd.no/nettavis/bilder/eqw.jpg"
align=left>wdqwe ewqewqJahr.</P></FONT>
Hello 2
<FONT size=2>
<P><IMG src="http://www.ew.no/nettavis/bilder/ewweq.jpg"
align=left>wdqwe ewqewqJahr.</P></FONT>
Hello 3
<FONT size=2>
<P><IMG src="http://www.qw.no/nettavis/bilder/ewq.jpg"
align=left>wdqwe ewqewqJahr.</P></FONT>
php extension/apliaexportimport/bin/php/importcontentclass.php [Relative path to config.php file] [Relative path to the export archive, where images and files are found] [Relative path to the xml file is located]
Config file can be quite advanced based on the XML you are importing. Here is a sample config containing some of the options.
This config file in short:
Here is a custom exported XML (not from the exportcontentclass.php):
eqwwe med rom for eqw
dqwd dqwdqw qwd qwdqwd qw
<FONT size=2>
<P><IMG src="http://www.ewqwqwd.no/nettavis/bilder/Hernes3.jpg"
align=left>wdqwe ewqewqJahr.</P></FONT>
ewqqwe fag
eqw.ewqwqe@ewq.no
2003-09-05 00:00:00
2003-09-05
05-09-03
We can then create a config file like this:
'filter_before_xml' => function ($xml) {
return str_replace(' },
'image_resolver' => function ($image_parent_node) {
return function ($imageUrl) {
$imageLocation = null;
// here we can DL the image by $imageUrl.. but we already have all images in a folder so not needed..
if (strstr($imageUrl, 'http://www.hia.no/nettavis')) {
$imageLocation = str_ireplace('http://www.hia.no/nettavis', eZSys::rootDir(). '/webarkiv/', $imageUrl);
}
return $imageLocation;
};
},
'remove_tag_handlers' => array(
'a' => array(
function (Crawler $node) {
if (
stripos($node->attr('href'), 'http://wedontwantthishost') === 0 ||
stripos($node->attr('href'), 'http://neitherthis') === 0
) {
return false;
} else {
return true;
}
}
)
),
'creator_user' => 'admin',
'create_images_inside_node' => 8339,
'create_imported_nodes_inside_node' => 8339,
// Mapping is based on how the XML file is and the content class.
'mapping' => array(
'contentclass' => 'news_article',
'fields' => array(
'title' => 'heading', // <-- no call back, no filtering needed. just set the attribute of the xml field.
'body' => function ($xmlNode, ApliaCliImporter $apliaCliImporter) {
return $apliaCliImporter->htmlParser->parse((string)$xmlNode->content);
},
'intro' => function ($xmlNode) {
return ApliaHtmlToXmlFieldParser::stringToXMLField((string)$xmlNode->ingress);
},
'author' => function ($xmlNode) {
$email = (string)$xmlNode->epost;
if ($email) {
$e = explode('@', $email);
if ($e[0]) {
$ps = explode('.', $e[0]);
if (count($ps)) {
$name = '';
foreach($ps as $p) {
$name .= ucfirst($p) . ' ';
}
return "$name|$email|-1";
}
}
}
}
),
'publishTimeResolver' => function ($xmlNode) {
$publish_time = strtotime((string)$xmlNode->publishDate);
return $publish_time;
},
'modificationTimeResolver' => function ($xmlNode) {
$mod_time = strtotime((string)$xmlNode->endretdato);
return $mod_time;
}
)
);
Sometimes you see that you need to run the import script again, add a custom ignore handler to the config script:
'skip_node_handler' => function ($xmlNode, $settings) {
$title = $xmlNode->title;
$founds = eZContentObjectTreeNode::subTreeByNodeID(
array(
'ClassFilterType', 'include',
'ClassFilterArray', array($settings['mapping']['contentclass']),
'Depth'=>1,
'Limit' => 1,
'Limitation' => array(),
'AttributeFilter' => array('and',array($settings['mapping']['contentclass'] . '/title', '=', $title))
), $settings['create_imported_nodes_inside_node']);
if ($founds) {
return "Object with that name ($title) already exist..";
}
return false;
},
This will: