CLI Script for Object Import

Skip to end of metadata
Go to start of metadata

The following script is a cli script from a pimcore plugin, which imports pimcore objects. It can be executed from the directory where it is located like this:

 /usr/local/zend/bin/php import.php -f
Please exchange the path "/usr/local/zend/bin/php" with the path to your php binary

Source Code for import.php:

<?php

include(dirname(__FILE__) . "/../../../pimcore/cli/startup.php");

//this is optional, memory limit could be increased further (pimcore default is 1024M)
ini_set('memory_limit', '1024M');
ini_set("max_execution_time", "-1");

//execute in admin mode
define("PIMCORE_ADMIN", true);

//some command line options for my importer
try {
    $opts = new Zend_Console_Getopt(array(
                'force|f' => "force update of all objects"
    ));
    $opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
    echo $e->getUsageMessage();
    exit;
}


$overwrite = $opts->getOption('force');
$importerConfig = new Zend_Config_Xml(dirname(__FILE__) . "/../config/import.xml");


try {
    //do the import job
    $importer = new Myplugin_Importer($importerConfig,$overwrite);
    $importer->init();
    $importer->doImport();
    echo "\ndone with import\n";
    
} catch (Exception $e) {
    p_r($e);
}

For the import logic, which in this case is capsuled in "Myplugin_Importer" please refer to the import snippet in External System Interaction and the hints towards object field getters and setters in the pages about the different object fields.

Note
Don't forget to call the garbage collector if you're importing a huge amount of objects.
Read more ... 
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.