Last active
September 28, 2017 10:54
-
-
Save pepijnblom/343af9572f3862c183ff36313f72f843 to your computer and use it in GitHub Desktop.
Call Xtento crons from the commandline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// place file in your magento public root | |
// call like so: php cron_xtento.php --module=xtento_orderexport --profile=MODULE_PROFILE_ID | |
// it should be easy to extend this for all other modules by adding the name to the array | |
require_once 'app/Mage.php'; | |
umask(0); | |
/* not Mage::run(); */ | |
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); | |
$options = getopt('', ['module:', 'profile:']); | |
$allowedModules = [ | |
'xtento_orderexport', | |
'xtento_productexport' | |
]; | |
$module = isset($options['module']) && !empty($options['module']) && in_array($options['module'], $allowedModules) ? $options['module'] : ''; | |
$profileId = isset($options['profile']) && !empty($options['profile']) && is_numeric($options['profile']) && $options['profile'] > 0 ? $options['profile'] : 0; | |
if (!empty($module) && !empty($profileId)) { | |
$method = strpos($module, 'export') !== false ? 'export' : 'import'; | |
$profile = Mage::getModel($module . '/profile')->load($profileId); | |
if ($profile && $profile->getId()) { | |
$model = Mage::getModel($module . '/' . $method, ['profile' => $profile]); | |
$observer = Mage::getModel($module . '/observer_cronjob'); | |
$filters = $observer->addProfileFilters($profile); | |
$cronMethod = 'cron' . ucfirst($method); | |
if(method_exists($model, $cronMethod)) { | |
$model->$cronMethod($filters); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment