Skip to content

Instantly share code, notes, and snippets.

@ameenross
Created July 15, 2014 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ameenross/91b85beb45f1ff0a23c6 to your computer and use it in GitHub Desktop.
Save ameenross/91b85beb45f1ff0a23c6 to your computer and use it in GitHub Desktop.
Magento CLI import script
#!/usr/bin/php
<?php
/**
* @file
* Based on http://www.magentocommerce.com/boards/viewthread/113901/P30/#t277875
*
* @todo
* - fix importing
* - fix logging
*/
// Disallow running via web server.
if (PHP_SAPI != 'cli') {
ob_clean();
header('HTTP/1.0 403 Forbidden');
print '<h1>You are forbidden from accessing this resource.</h1>';
exit();
}
$script = basename(__FILE__);
$usage_example = "Usage: {$script} profile_id\n";
// Syntax check of first argument: profile_id.
if (!isset($argv[1]) || !is_numeric($argv[1]) || (int) $argv[1] != $argv[1]) {
exit($usage_example);
}
else {
$profile_id = $argv[1];
}
// Log file used to report results.
$logfile = 'dataflow_cli.log';
// Load the main Magento file.
require './app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
// Instantiate a session for the "root" user.
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);
Mage::getSingleton('admin/session')->setUser($userModel);
// Load the dataflow profile.
$profile = Mage::getModel('dataflow/profile');
$profile->load($profile_id);
if (!$profile->getId()) {
exit("Profile with id #{$profile_id} does not exist.");
}
Mage::log("$direction {$profile_id} started.");
//Mage::register('current_convert_profile', $profile);
// Run the dataflow profile.
$profile->run();
$recordCount = 0;
$batchModel = Mage::getSingleton('dataflow/batch');
// Reporting.
$direction = ucwords($profile->getDirection());
$success = "{$direction} with id #{$batchModel->getId()} completed succesfully.\n";
Mage::log($success);
print $success;
@ameenross
Copy link
Author

This script was based on a script originally written for Magento 1.4. Exports are tested and work properly on 1.5, but importing doesn't seem to work. Later versions not tested.

@ameenross
Copy link
Author

From the looks of it, imports only setup a batch system which splits the import up into chunks. Those chunks still need to be run separately. Stackoverflow has a way to do that, but I don't like the fact it's actually using curl (thus the webserver) for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment