* This script is intended to be launched in command line only (mostly via a System Crontab) */ // Load Prestashop environnement require dirname(__FILE__) . '/../../config/config.inc.php'; if (!defined('_PS_VERSION_')) { exit; } // Allow only running from CLI or with a token parameter if (!Tools::isPHPCLI()) { if (Tools::getValue(Configuration::get('AUTOZIP_TOKEN_NAME')) !== Configuration::get('AUTOZIP_TOKEN_KEY')) { header('HTTP/1.0 403 Forbidden'); die('This script is intended to be launched in command line or with the right token'); } } // Load Config require_once _PS_MODULE_DIR_ . 'autozip/classes/AutoZipConfig.php'; require_once _PS_MODULE_DIR_ . 'autozip/classes/AutoZipCron.php'; AutoZipCron::checkCommonPrerequisities(); foreach (AutoZipConfig::getAllStatic() as $autozip) { try { $download_function_name = $autozip->source_type . 'Download'; $last_version = AutoZipCron::$download_function_name($autozip); AutoZipCron::generateZip($autozip, $last_version); if ($last_version) { AutoZipCron::UpdateVersionNumber($autozip, $last_version); } $autozip->updateZipDate(); } catch (Exception $e) { echo "\n" . 'Error processing autozip "' . $autozip->zip_basename . ' - ' . $autozip->source_url . '" : ' . "\n" . $e->getMessage(); } }
/** * updateVersionNumber * * @param AutoZipConfig $autozip * @param type $version_number */ public static function updateVersionNumber(AutoZipConfig $autozip, $version_number) { if (!($id_feature = (int) Configuration::get('AUTOZIP_ID_FEATURE'))) { return; } $id_products = $autozip->getRelatedProductsIds(); $id_langs = Language::getLanguages(false, false, true); foreach ($id_products as $id_product) { //Check if value already exists $id_feature_value = Db::getInstance()->getValue('SELECT DISTINCT fv.id_feature_value ' . 'FROM ' . _DB_PREFIX_ . 'feature_value fv, ' . _DB_PREFIX_ . 'feature_value_lang fvl ' . 'WHERE fv.id_feature_value = fvl.id_feature_value ' . 'AND fv.id_feature=' . (int) $id_feature . ' ' . 'AND fvl.value="' . $version_number . '" ' . 'AND fv.custom=1'); // if not create if (!$id_feature_value) { $row = array('id_feature' => (int) $id_feature, 'custom' => true); Db::getInstance()->insert('feature_value', $row); $id_feature_value = Db::getInstance()->Insert_ID(); // The version number will be stored in any language available foreach ($id_langs as $id_lang) { $row = array('id_feature_value' => (int) $id_feature_value, 'id_lang' => (int) $id_lang, 'value' => pSQL($version_number)); Db::getInstance()->insert('feature_value_lang', $row); } } // Completly recreate the link between the product & feature/value, in any case, to keep unicity Db::getInstance()->delete('feature_product', 'id_feature=' . (int) $id_feature . ' AND id_product=' . (int) $id_product['id_product']); $row = array('id_feature' => (int) $id_feature, 'id_product' => (int) $id_product['id_product'], 'id_feature_value' => (int) $id_feature_value); Db::getInstance()->insert('feature_product', $row, false, false, Db::REPLACE); } }