From c0224d4958f12eb29e8ff8a33b0badad0d6af4e6 Mon Sep 17 00:00:00 2001 From: rMalie Date: Fri, 16 Sep 2011 15:02:29 +0000 Subject: [PATCH] // Merge -> revision 8624 --- classes/SpecificPrice.php | 89 ++++++++++++------------ classes/Upgrader.php | 63 +++++++++++++++++ install-dev/xml/checkConfig.php | 3 +- modules/autoupgrade/AdminSelfUpgrade.php | 66 +++++++++++++++++- modules/autoupgrade/Upgrader.php | 64 +++++++++++++++++ modules/autoupgrade/jquery.xml2json.js | 1 + modules/blocklayered/blocklayered.php | 82 +++++++++++----------- 7 files changed, 281 insertions(+), 87 deletions(-) create mode 100755 modules/autoupgrade/jquery.xml2json.js diff --git a/classes/SpecificPrice.php b/classes/SpecificPrice.php index 259f28773..224d9949a 100644 --- a/classes/SpecificPrice.php +++ b/classes/SpecificPrice.php @@ -52,14 +52,14 @@ class SpecificPriceCore extends ObjectModel public function getFields() { $this->validateFields(); - $fields['id_product'] = (int)($this->id_product); - $fields['id_shop'] = (int)($this->id_shop); - $fields['id_currency'] = (int)($this->id_currency); - $fields['id_country'] = (int)($this->id_country); - $fields['id_group'] = (int)($this->id_group); - $fields['price'] = (float)($this->price); - $fields['from_quantity'] = (int)($this->from_quantity); - $fields['reduction'] = (float)($this->reduction); + $fields['id_product'] = (int)$this->id_product; + $fields['id_shop'] = (int)$this->id_shop; + $fields['id_currency'] = (int)$this->id_currency; + $fields['id_country'] = (int)$this->id_country; + $fields['id_group'] = (int)$this->id_group; + $fields['price'] = (float)$this->price; + $fields['from_quantity'] = (int)$this->from_quantity; + $fields['reduction'] = (float)$this->reduction; $fields['reduction_type'] = pSQL($this->reduction_type); $fields['from'] = pSQL($this->from); $fields['to'] = pSQL($this->to); @@ -68,17 +68,16 @@ class SpecificPriceCore extends ObjectModel public static function getByProductId($id_product) { - return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' - SELECT * - FROM `'._DB_PREFIX_.'specific_price` - WHERE `id_product` = '.(int)$id_product); + return Db::getInstance()->ExecuteS(' + SELECT * FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product + ); } public static function getIdsByProductId($id_product) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' - SELECT `id_specific_price` - FROM `'._DB_PREFIX_.'specific_price` + SELECT `id_specific_price` + FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product); } @@ -91,7 +90,7 @@ class SpecificPriceCore extends ObjectModel $select .= ' IF (\''.$now.'\' >= `from` AND \''.$now.'\' <= `to`, '.pow(2, 0).', 0) + '; $priority = SpecificPrice::getPriority($id_product); - foreach (array_reverse($priority) AS $k => $field) + foreach (array_reverse($priority) as $k => $field) $select .= ' IF (`'.$field.'` = '.(int)(${$field}).', '.pow(2, $k + 1).', 0) + '; return rtrim($select, ' +').') AS `score`'; @@ -121,7 +120,7 @@ class SpecificPriceCore extends ObjectModel { if (!self::isFeatureActive()) return array(); - + /* ** The date is not taken into account for the cache, but this is for the better because it keeps the consistency for the whole script. ** The price must not change between the top and the bottom of the page @@ -146,7 +145,7 @@ class SpecificPriceCore extends ObjectModel AND (`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`) ) - ORDER BY `from_quantity` DESC, `score` DESC, `from_quantity` DESC'); + ORDER BY `from_quantity` DESC, `score` DESC'); } return self::$_specificPriceCache[$key]; } @@ -186,17 +185,17 @@ class SpecificPriceCore extends ObjectModel { if (!self::isFeatureActive()) return array(); - + $now = date('Y-m-d H:i:s'); $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT *, '.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).' FROM `'._DB_PREFIX_.'specific_price` - WHERE `id_product` IN(0, '.(int)($id_product).') AND - `id_shop` IN(0, '.(int)($id_shop).') AND - `id_currency` IN(0, '.(int)($id_currency).') AND - `id_country` IN(0, '.(int)($id_country).') AND - `id_group` IN(0, '.(int)($id_group).') + WHERE `id_product` IN(0, '.(int)$id_product.') AND + `id_shop` IN(0, '.(int)$id_shop.') AND + `id_currency` IN(0, '.(int)$id_currency.') AND + `id_country` IN(0, '.(int)$id_country.') AND + `id_group` IN(0, '.(int)$id_group.') AND ( (`from` = \'0000-00-00 00:00:00\' OR \''.$now.'\' >= `from`) @@ -207,16 +206,16 @@ class SpecificPriceCore extends ObjectModel '); $targeted_prices = array(); - $last_quantity = NULL; + $last_quantity = null; foreach($res as $specific_price) { if (!isset($last_quantity)) - $last_quantity = $specific_price['from_quantity']; + $last_quantity = $specific_price['from_quantity']; else if ($last_quantity == $specific_price['from_quantity']) break; - $last_quantity = $specific_price['from_quantity']; + $last_quantity = $specific_price['from_quantity']; if ($specific_price['from_quantity'] > 1) $targeted_prices[] = $specific_price; } @@ -228,25 +227,25 @@ class SpecificPriceCore extends ObjectModel { if (!self::isFeatureActive()) return array(); - + $now = date('Y-m-d H:i:s'); return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT *, '.self::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group).' FROM `'._DB_PREFIX_.'specific_price` - WHERE `id_product` IN(0, '.(int)($id_product).') AND - `id_shop` IN(0, '.(int)($id_shop).') AND - `id_currency` IN(0, '.(int)($id_currency).') AND - `id_country` IN(0, '.(int)($id_country).') AND - `id_group` IN(0, '.(int)($id_group).') AND - `from_quantity` >= '.(int)($quantity).' + WHERE `id_product` IN(0, '.(int)$id_product.') AND + `id_shop` IN(0, '.(int)$id_shop.') AND + `id_currency` IN(0, '.(int)$id_currency.') AND + `id_country` IN(0, '.(int)$id_country.') AND + `id_group` IN(0, '.(int)$id_group.') AND + `from_quantity` >= '.(int)$quantity.' AND ( (`from` = \'0000-00-00 00:00:00\' OR \''.$now.'\' >= `from`) AND (`to` = \'0000-00-00 00:00:00\' OR \''.$now.'\' <= `to`) ) - ORDER BY `score` DESC, `from_quantity` DESC + ORDER BY `from_quantity` DESC, `score` DESC '); } @@ -254,14 +253,14 @@ class SpecificPriceCore extends ObjectModel { if (!self::isFeatureActive()) return array(); - + $resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT `id_product` FROM `'._DB_PREFIX_.'specific_price` - WHERE `id_shop` IN(0, '.(int)($id_shop).') AND - `id_currency` IN(0, '.(int)($id_currency).') AND - `id_country` IN(0, '.(int)($id_country).') AND - `id_group` IN(0, '.(int)($id_group).') AND + WHERE `id_shop` IN(0, '.(int)$id_shop.') AND + `id_currency` IN(0, '.(int)$id_currency.') AND + `id_country` IN(0, '.(int)$id_country.') AND + `id_group` IN(0, '.(int)$id_group.') AND `from_quantity` = 1 AND ( (`from` = \'0000-00-00 00:00:00\' OR \''.$beginning.'\' >= `from`) @@ -273,22 +272,22 @@ class SpecificPriceCore extends ObjectModel ', false); $ids_product = array(); while ($row = DB::getInstance()->nextRow($resource)) - $ids_product[] = (int)($row['id_product']); + $ids_product[] = (int)$row['id_product']; return $ids_product; } public static function deleteByProductId($id_product) { - return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)($id_product)); + return Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'specific_price` WHERE `id_product` = '.(int)$id_product); } public function duplicate($id_product = false) { if ($id_product) - $this->id_product = (int)($id_product); + $this->id_product = (int)$id_product; return $this->add(); } - + /** * This method is allow to know if a feature is used or active * @since 1.5.0.1 @@ -298,10 +297,10 @@ class SpecificPriceCore extends ObjectModel { if (self::$feature_active === null) self::$feature_active = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT COUNT(*) + SELECT COUNT(*) FROM `'._DB_PREFIX_.'specific_price` '); return self::$feature_active; - } + } } diff --git a/classes/Upgrader.php b/classes/Upgrader.php index 96790abbe..66d28fb78 100644 --- a/classes/Upgrader.php +++ b/classes/Upgrader.php @@ -28,6 +28,7 @@ class UpgraderCore{ const DEFAULT_CHECK_VERSION_DELAY_HOURS = 24; public $rss_version_link = 'http://www.prestashop.com/xml/version.xml'; + public $rss_md5file_link_dir = 'http://www.prestashop.com/xml/md5/'; /** * link contains hte url where to download the file * @@ -35,6 +36,9 @@ class UpgraderCore{ */ private $needUpgrade = false; private $noRefresh = false; + private $changedFiles = array(); + private $missingFiles = array(); + private $versionIsModified = false; public $version_name; public $version_num; @@ -154,4 +158,63 @@ class UpgraderCore{ return false; } + public function getChangedFilesList() + { + $checksum = simplexml_load_file($this->rss_md5file_link_dir._PS_VERSION_.'.xml'); + if ($checksum === false) + throw new Exception('No checksum xml file for your Prestashop version'); + $this->browseXmlAndCompare($checksum); + + return $this->changedFiles; +} + protected function addChangedFile($path) + { + $this->versionIsModified = true; + $this->changedFiles[] = $path; + } + + protected function addMissingFile($path) + { + $this->versionIsModified = true; + $this->missingFiles[] = $path; + } + + protected function browseXmlAndCompare($node, &$currentPath = array(), $level = 0) + { + foreach ($node as $key => $child) + { + if (is_object($child) && $child->getName() != 'md5file') + { + $level += 1; + $currentPath[$level] = $child->getName(); + $this->browseXmlAndCompare($child, $currentPath, $level); + $level -= 1; + } + else + { + $path = ''; + for ($i=1;$i<=$level;$i++) + $path .= $currentPath[$i].'/'; + $path .= (string)$child->attributes()->name; + $path = str_replace('ps_root_dir',_PS_ROOT_DIR_,$path); + if(!file_exists($path)) + $this->addMissingFile($path); + else if (!$this->compareChecksum($path, (string)$child->attributes()->sum)) + $this->addChangedFile($path); + } + } + } + + protected function compareChecksum($path, $originalSum) + { + if (md5_file($path) == $originalSum) + return true; + return false; + } + + public function isAuthenticPrestashopVersion() + { + return !$this->versionIsModified; + } + } diff --git a/install-dev/xml/checkConfig.php b/install-dev/xml/checkConfig.php index a086d3354..ee3e3d9c5 100644 --- a/install-dev/xml/checkConfig.php +++ b/install-dev/xml/checkConfig.php @@ -26,7 +26,8 @@ */ header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé -include_once(INSTALL_PATH.'/../classes/ConfigurationTest.php'); +if (!class_exists('ConfigurationTest',false)) + require_once(INSTALL_PATH.'/../classes/ConfigurationTest.php'); // Functions list to test with 'test_system' $funcs = array('fopen', 'fclose', 'fread', 'fwrite', 'rename', 'file_exists', 'unlink', 'rmdir', 'mkdir', 'getcwd', 'chdir', 'chmod'); diff --git a/modules/autoupgrade/AdminSelfUpgrade.php b/modules/autoupgrade/AdminSelfUpgrade.php index 049556f11..105e2ff83 100644 --- a/modules/autoupgrade/AdminSelfUpgrade.php +++ b/modules/autoupgrade/AdminSelfUpgrade.php @@ -457,7 +457,19 @@ $this->standalone = true; $this->nextDesc = $this->l('Upgrade process done. Congratulations ! You can now reactive your shop.'); $this->next = ''; } + public function ajaxProcessCheckFilesVersion() + { + if ($testOrigCore = $this->upgrader->isAuthenticPrestashopVersion() !== false) + $this->nextParams['status'] = 'ok'; + else + $this->nextParams['status'] = 'nok'; + $changedFileList = $this->upgrader->getChangedFilesList(); + + // echo ' '. + $this->nextParams['msg'] = ($testOrigCore?$this->l('Core files are ok'):sprintf($this->l('%s core files have been modified'), sizeof($changedFileList))); + $this->nextParams['result'] = $changedFileList; + } public function ajaxProcessUpgradeNow() { $this->nextDesc = $this->l('Starting upgrade ...'); @@ -1570,7 +1582,11 @@ txtError[37] = "'.$this->l('The config/defines.inc.php file was not found. Where $configurationDone = '../img/admin/disabled.gif'; echo ''.$this->l('Options chosen').' : '.' '.($testConfigDone?$this->l('autoupgrade configuration ok'):$this->l('Please configure autoupgrade options')).'

'; - echo ''.$this->l('Modify your options').''; + echo ''.$this->l('PrestaShop Original version').' : '.' + + '; + + echo '

'.$this->l('Modify your options').'

'; echo ''; echo '
'; @@ -1687,6 +1703,8 @@ echo ''; .button-autoupgrade {-moz-border-bottom-colors: none;-moz-border-image: none;-moz-border-left-colors: none;-moz-border-right-colors: none;-moz-border-top-colors: none;border-color: #FFF6D3 #DFD5AF #DFD5AF #FFF6D3;border-right: 1px solid #DFD5AF;border-style: solid;border-width: 1px;color: #268CCD;font-size: medium;padding: 5px;} .processing {border:2px outset grey;margin-top:1px;overflow: auto;} #dbResultCheck{ padding-left:20px;} +#checkPrestaShopFilesVersion{margin-bottom:20px;} +#changedList ul{list-style-type:circle} '; $this->displayWarning($this->l('This function is experimental. It\'s highly recommended to make a backup of your files and database before starting the upgrade process.')); @@ -1882,8 +1900,8 @@ function afterUpgradeDb() { // console.info("inside afterUpgradeDb"); // console.log(resGlobal); - } + function afterUpgradeComplete() { $("#pleaseWait").hide(); @@ -2093,6 +2111,50 @@ function handleError(res) } } '; +// ajax to check md5 files +$js.= '$(document).ready(function(){ + $.ajax({ + type:"POST", + url : "'.($this->standalone? __PS_BASE_URI__ . trim($this->adminDir,DIRECTORY_SEPARATOR).'/autoupgrade/ajax-upgradetab.php' : str_replace('index','ajax-tab',$currentIndex)).'", + async: true, + data : { + dir:"'.trim($this->adminDir,DIRECTORY_SEPARATOR).'", + token : "'.$this->token.'", + tab : "'.get_class($this).'", + action : "checkFilesVersion", + params : {} + }, + success : function(res,textStatus,jqXHR) + { + res = $.parseJSON(res); + answer = res.nextParams; + $("#checkPrestaShopFilesVersion").html(""+answer.msg+" "); + $("#checkPrestaShopFilesVersion").append("'.$this->l('See or hide the list').'
"); + + $("#checkPrestaShopFilesVersion").append("
"); + + $("#changedList").html("