diff --git a/admin-dev/tabs/AdminFeatures.php b/admin-dev/tabs/AdminFeatures.php index 9e4852df8..cfda801a5 100644 --- a/admin-dev/tabs/AdminFeatures.php +++ b/admin-dev/tabs/AdminFeatures.php @@ -170,7 +170,7 @@ class AdminFeatures extends AdminTab echo ''; } echo ' - '.Module::hookExec('featureForm', array('id_attribute_group' => $obj->id)).' + '.Module::hookExec('featureForm', array('id_feature' => $obj->id)).'
diff --git a/admin-dev/tabs/AdminGenerator.php b/admin-dev/tabs/AdminGenerator.php index e018e2c1b..12d8d083e 100644 --- a/admin-dev/tabs/AdminGenerator.php +++ b/admin-dev/tabs/AdminGenerator.php @@ -131,13 +131,13 @@ class AdminGenerator extends AdminTab { // PS Comments fwrite($writeFd, "# robots.txt automaticaly generated by PrestaShop e-commerce open-source solution\n"); - fwrite($writeFd, "# http://www.prestashop.com - http://www.prestashop.com/forums\n\n"); + fwrite($writeFd, "# http://www.prestashop.com - http://www.prestashop.com/forums\n"); fwrite($writeFd, "# This file is to prevent the crawling and indexing of certain parts\n"); fwrite($writeFd, "# of your site by web crawlers and spiders run by sites like Yahoo!\n"); fwrite($writeFd, "# and Google. By telling these \"robots\" where not to go on your site,\n"); - fwrite($writeFd, "# you save bandwidth and server resources.\n\n"); + fwrite($writeFd, "# you save bandwidth and server resources.\n"); fwrite($writeFd, "# For more information about the robots.txt standard, see:\n"); - fwrite($writeFd, "# http://www.robotstxt.org/wc/robots.html\n\n"); + fwrite($writeFd, "# http://www.robotstxt.org/wc/robots.html\n"); //GoogleBot specific fwrite($writeFd, "# GoogleBot specific\n"); @@ -146,7 +146,7 @@ class AdminGenerator extends AdminTab fwrite($writeFd, 'Disallow: '.__PS_BASE_URI__.$GB."\n"); // User-Agent - fwrite($writeFd, "# All bots\n\n"); + fwrite($writeFd, "# All bots\n"); fwrite($writeFd, "User-agent: *\n"); // Directories @@ -193,4 +193,4 @@ class AdminGenerator extends AdminTab return $tab; } -} \ No newline at end of file +} diff --git a/admin-dev/tabs/AdminImages.php b/admin-dev/tabs/AdminImages.php index 1ba072551..8fce7381e 100644 --- a/admin-dev/tabs/AdminImages.php +++ b/admin-dev/tabs/AdminImages.php @@ -443,8 +443,16 @@ class AdminImages extends AdminTab

'.$this->l('Move images').'

'. $this->l('A new storage system for product images is now used by PrestaShop. It offers better performance if your shop has a very large number of products.').'
'. '
'; + if (file_exists(_PS_PROD_IMG_DIR_.'duplicates/')) + { + echo '
'; + $this->displayWarning($this->l('Duplicate images were found when moving the product images. It is probably caused by unused demonstration images. Please make sure that the folder '). + _PS_PROD_IMG_DIR_.'duplicates/'. + $this->l(' only contains demonstration images then delete this folder.')); + echo '
'; + } if($safe_mode) - echo $this->displayWarning('PrestaShop has detected that your server configuration is not compatible with the new storage system (directive "safe_mode" is activated). You should continue to use the actual system.'); + $this->displayWarning($this->l('PrestaShop has detected that your server configuration is not compatible with the new storage system (directive "safe_mode" is activated). You should continue to use the actual system.')); else echo '
diff --git a/admin-dev/tabs/AdminPPreferences.php b/admin-dev/tabs/AdminPPreferences.php index d21ec1f88..18598ff96 100644 --- a/admin-dev/tabs/AdminPPreferences.php +++ b/admin-dev/tabs/AdminPPreferences.php @@ -71,7 +71,7 @@ class AdminPPreferences extends AdminPreferences 'PS_PRODUCT_PICTURE_WIDTH' => array('title' => $this->l('Product pictures width:'), 'desc' => $this->l('The maximum width of pictures uploadable by customers'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), 'PS_PRODUCT_PICTURE_HEIGHT' => array('title' => $this->l('Product pictures height:'), 'desc' => $this->l('The maximum height of pictures uploadable by customers'), 'validation' => 'isUnsignedId', 'required' => true, 'cast' => 'intval', 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL), 'PS_LEGACY_IMAGES' => array('title' => $this->l('Use the legacy image filesystem:'), 'desc' => $this->l('This should be set to yes unless you successfully moved images in Preferences > Images tab'), 'validation' => 'isBool', 'cast' => 'intval', 'required' => true, 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL), - 'PS_QTY_DISCOUNT_ON_COMBINATION' => array('title' => $this->l('Quantity discounts based on:'), 'desc' => $this->l('The way of calculate quantity discounts'), 'cast' => 'intval', 'show' => true, 'required' => true, 'type' => 'radio', 'validation' => 'isBool', 'choices' => array(0 => $this->l('Products'), 1 => $this->l('Combinations'))) + 'PS_QTY_DISCOUNT_ON_COMBINATION' => array('title' => $this->l('Quantity discounts based on:'), 'desc' => $this->l('How to calculate quantity discounts'), 'cast' => 'intval', 'show' => true, 'required' => true, 'type' => 'radio', 'validation' => 'isBool', 'choices' => array(0 => $this->l('Products'), 1 => $this->l('Combinations'))) ), ), ); diff --git a/admin-dev/tabs/AdminUpgrade.php b/admin-dev/tabs/AdminUpgrade.php index 77ed6fc3b..7116eaabd 100755 --- a/admin-dev/tabs/AdminUpgrade.php +++ b/admin-dev/tabs/AdminUpgrade.php @@ -1573,9 +1573,17 @@ echo ''; $tokenModule = Tools::getAdminToken('AdminModules'.(int)(Tab::getIdFromClassName('AdminModules')).(int)$cookie->id_employee); $tokenAdminTabs = Tools::getAdminToken('AdminTabs'.(int)(Tab::getIdFromClassName('AdminTabs')).(int)$cookie->id_employee); $tokenAdminTools = Tools::getAdminToken('AdminTools'.(int)(Tab::getIdFromClassName('AdminTools')).(int)$cookie->id_employee); + if (!$idTab = Tab::getIdFromClassName('AdminSelfUpgrade')) + { echo '

' .$this->l('Activate the module').'

'; + } + else{ + $tokenSelfUpgrade = Tools::getAdminToken('AdminSelfUpgrade'.(int)(Tab::getIdFromClassName('AdminSelfUpgrade')).(int)$cookie->id_employee); + echo ' ' + .$this->l('Use the autoupgrade module').'

'; + } echo '
'; if (!is_array($warn)) - $str_output .= ''.$warn; + { + if (file_exists(__PS_BASE_URI__.'img/admin/warn2.png')) + $str_output .= ''; + else + $str_output .= ''; + + + $str_output .= $warn; + } else { $str_output .= 'X'. (count($warn) > 1 ? $this->l('There are') : $this->l('There is')).' '.count($warn).' '.(count($warn) > 1 ? $this->l('warnings') : $this->l('warning')) @@ -2141,5 +2152,112 @@ abstract class AdminSelfTab '. $this->l('Click here if you want to modify the main shop domain name').''); } + /* + * from 1.4 AdminPreferences + */ + protected function _postConfig($fields) + { + global $currentIndex, $smarty; + + $languages = Language::getLanguages(false); + if (function_exists('Tools','clearCache')) + Tools::clearCache($smarty); + + /* Check required fields */ + foreach ($fields AS $field => $values) + if (isset($values['required']) AND $values['required']) + if (isset($values['type']) AND $values['type'] == 'textLang') + { + foreach ($languages as $language) + if (($value = Tools::getValue($field.'_'.$language['id_lang'])) == false AND (string)$value != '0') + $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is required.'); +} + elseif (($value = Tools::getValue($field)) == false AND (string)$value != '0') + $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is required.'); + + /* Check fields validity */ + foreach ($fields AS $field => $values) + if (isset($values['type']) AND $values['type'] == 'textLang') + { + foreach ($languages as $language) + if (Tools::getValue($field.'_'.$language['id_lang']) AND isset($values['validation'])) + if (!Validate::$values['validation'](Tools::getValue($field.'_'.$language['id_lang']))) + $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is invalid.'); + } + elseif (Tools::getValue($field) AND isset($values['validation'])) + if (!Validate::$values['validation'](Tools::getValue($field))) + $this->_errors[] = Tools::displayError('field').' '.$values['title'].' '.Tools::displayError('is invalid.'); + + /* Default value if null */ + foreach ($fields AS $field => $values) + if (!Tools::getValue($field) AND isset($values['default'])) + $_POST[$field] = $values['default']; + + /* Save process */ + if (!sizeof($this->_errors)) + { + if (Tools::isSubmit('submitAppearanceconfiguration')) + { + if (isset($_FILES['PS_LOGO']['tmp_name']) AND $_FILES['PS_LOGO']['tmp_name']) + { + if ($error = checkImage($_FILES['PS_LOGO'], 300000)) + $this->_errors[] = $error; + if (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($_FILES['PS_LOGO']['tmp_name'], $tmpName)) + return false; + elseif (!@imageResize($tmpName, _PS_IMG_DIR_.'logo.jpg')) + $this->_errors[] = 'an error occurred during logo copy'; + unlink($tmpName); + } + if (isset($_FILES['PS_LOGO_MAIL']['tmp_name']) AND $_FILES['PS_LOGO_MAIL']['tmp_name']) + { + if ($error = checkImage($_FILES['PS_LOGO_MAIL'], 300000)) + $this->_errors[] = $error; + if (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_MAIL') OR !move_uploaded_file($_FILES['PS_LOGO_MAIL']['tmp_name'], $tmpName)) + return false; + elseif (!@imageResize($tmpName, _PS_IMG_DIR_.'logo_mail.jpg')) + $this->_errors[] = 'an error occurred during logo copy'; + unlink($tmpName); + } + if (isset($_FILES['PS_LOGO_INVOICE']['tmp_name']) AND $_FILES['PS_LOGO_INVOICE']['tmp_name']) + { + if ($error = checkImage($_FILES['PS_LOGO_INVOICE'], 300000)) + $this->_errors[] = $error; + if (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_INVOICE') OR !move_uploaded_file($_FILES['PS_LOGO_INVOICE']['tmp_name'], $tmpName)) + return false; + elseif (!@imageResize($tmpName, _PS_IMG_DIR_.'logo_invoice.jpg')) + $this->_errors[] = 'an error occurred during logo copy'; + unlink($tmpName); + } + if (isset($_FILES['PS_STORES_ICON']['tmp_name']) AND $_FILES['PS_STORES_ICON']['tmp_name']) + { + if ($error = checkImage($_FILES['PS_STORES_ICON'], 300000)) + $this->_errors[] = $error; + if (!$tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS_STORES_ICON') OR !move_uploaded_file($_FILES['PS_STORES_ICON']['tmp_name'], $tmpName)) + return false; + elseif (!@imageResize($tmpName, _PS_IMG_DIR_.'logo_stores.gif')) + $this->_errors[] = 'an error occurred during logo copy'; + unlink($tmpName); + } + $this->uploadIco('PS_FAVICON', _PS_IMG_DIR_.'favicon.ico'); + } + + /* Update settings in database */ + if (!sizeof($this->_errors)) + { + foreach ($fields AS $field => $values) + { + unset($val); + if (isset($values['type']) AND $values['type'] == 'textLang') + foreach ($languages as $language) + $val[$language['id_lang']] = isset($values['cast']) ? $values['cast'](Tools::getValue($field.'_'.$language['id_lang'])) : Tools::getValue($field.'_'.$language['id_lang']); + else + $val = isset($values['cast']) ? $values['cast'](Tools::getValue($field)) : Tools::getValue($field); + + Configuration::updateValue($field, $val); + } + Tools::redirectAdmin($currentIndex.'&conf=6'.'&token='.$this->token); + } + } + } } diff --git a/modules/autoupgrade/AdminSelfUpgrade.gif b/modules/autoupgrade/AdminSelfUpgrade.gif new file mode 100644 index 000000000..981356908 Binary files /dev/null and b/modules/autoupgrade/AdminSelfUpgrade.gif differ diff --git a/modules/autoupgrade/AdminSelfUpgrade.php b/modules/autoupgrade/AdminSelfUpgrade.php index 448783608..fc32ef3ea 100644 --- a/modules/autoupgrade/AdminSelfUpgrade.php +++ b/modules/autoupgrade/AdminSelfUpgrade.php @@ -31,6 +31,9 @@ if(!defined('_PS_USE_SQL_SLAVE_')) if(empty($_POST['action']) OR !in_array($_POST['action'],array('upgradeDb'))) { + if(!defined('_PS_CACHE_ENABLED_')) + define('_PS_CACHE_ENABLED_',false); + if(!defined('PS_ORDER_PROCESS_STANDARD')) define('PS_ORDER_PROCESS_STANDARD',true); if(!defined('PS_ORDER_PROCESS_OPC')) @@ -40,24 +43,22 @@ if(empty($_POST['action']) OR !in_array($_POST['action'],array('upgradeDb'))) } require_once(dirname(__FILE__).'/AdminSelfTab.php'); require_once(dirname(__FILE__).'/SelfModule.php'); - if(file_exists(_PS_ROOT_DIR_.'/classes/Upgrader.php')) - { + +// Add Upgrader class + if(!version_compare(_PS_VERSION_,'1.4.5.0','<') AND file_exists(_PS_ROOT_DIR_.'/classes/Upgrader.php')) require_once(_PS_ROOT_DIR_.'/classes/Upgrader.php'); - } else require_once(dirname(__FILE__).'/Upgrader.php'); if(!class_exists('Upgrader',false)) { if(file_exists(_PS_ROOT_DIR_.'/override/classes/Upgrader.php')) - { require_once(_PS_ROOT_DIR_.'/override/classes/Upgrader.php'); - } else - { eval('class Upgrader extends UpgraderCore{}'); } - } + + require_once(dirname(__FILE__).'/Tools14.php'); if(!class_exists('Tools',false)) @@ -68,6 +69,9 @@ class AdminSelfUpgrade extends AdminSelfTab public $nextResponseType = 'json'; // json, xml public $next = 'N/A'; + public $upgrader = null; + public $standalone = true; + /** * set to false if the current step is a loop * @@ -111,8 +115,8 @@ class AdminSelfUpgrade extends AdminSelfTab public $rootWritable = false; public $svnDir = 'svn'; public $destDownloadFilename = 'prestashop.zip'; - public $toUpgradeFileList = array(); - public $backupFileList = array(); + public $toUpgradeFileList = 'filesToUpgrade.list'; + public $toBackupFileList = 'filesToBackup.list'; public $sampleFileList = array(); private $backupIgnoreFiles = array(); private $backupIgnoreAbsoluteFiles = array(); @@ -165,7 +169,7 @@ class AdminSelfUpgrade extends AdminSelfTab global $cookie; $id_employee = $cookie->id_employee; - $cookiePath = __PS_BASE_URI__.str_replace($this->prodRootDir,'',trim($this->adminDir,'/')); + $cookiePath = __PS_BASE_URI__.str_replace($this->prodRootDir,'',trim($this->adminDir,DIRECTORY_SEPARATOR)); setcookie('id_employee', $id_employee, time()+3600, $cookiePath); setcookie('id_tab', $this->id, time()+3600, $cookiePath); setcookie('autoupgrade', $this->encrypt($id_employee), time()+3600, $cookiePath); @@ -221,7 +225,7 @@ class AdminSelfUpgrade extends AdminSelfTab private function _setFields() { $this->_fieldsAutoUpgrade['PS_AUTOUP_DONT_SAVE_IMAGES'] = array( - 'title' => $this->l('Don\'t save images'), 'cast' => 'intval', 'validation' => 'isBool', + 'title' => $this->l('Also save images'), 'cast' => 'intval', 'validation' => 'isBool', 'type' => 'bool', 'desc'=>$this->l('You can exclude the image directory from backup if you already saved it by another method (not recommended)'), ); @@ -259,6 +263,7 @@ class AdminSelfUpgrade extends AdminSelfTab { $allowed = (ConfigurationTest::test_fopen() && $this->rootWritable); $allowed &= !Configuration::get('PS_SHOP_ENABLE'); + $allowed &= (Configuration::get('PS_AUTOUP_KEEP_TRAD') !== false); return $allowed; } @@ -272,7 +277,7 @@ class AdminSelfUpgrade extends AdminSelfTab $allowed = (ConfigurationTest::test_fopen() && $this->rootWritable); if (!defined('_PS_MODE_DEV_') OR !_PS_MODE_DEV_) - $allowed &= $this->upgrader->autoupgrade; + $allowed &= $this->upgrader->autoupgrade_module; return $allowed; } @@ -289,8 +294,11 @@ class AdminSelfUpgrade extends AdminSelfTab $this->prodRootDir = _PS_ROOT_DIR_; $this->adminDir = _PS_ADMIN_DIR_; + // from $_POST or $_GET + $this->action = empty($_REQUEST['action'])?null:$_REQUEST['action']; + $this->currentParams = empty($_REQUEST['params'])?null:$_REQUEST['params']; // test writable recursively - if(version_compare(_PS_VERSION_,'1.4.4.0','<')) + if(version_compare(_PS_VERSION_,'1.4.5.0','<')) { require_once('ConfigurationTest.php'); if(!class_exists('ConfigurationTest', false) AND class_exists('ConfigurationTestCore')) @@ -299,25 +307,28 @@ class AdminSelfUpgrade extends AdminSelfTab if (ConfigurationTest::test_dir($this->prodRootDir,true)) $this->rootWritable = true; + if (!in_array($this->action,array('upgradeFile', 'upgradeDb', 'upgradeComplete','rollback','restoreFiles','restoreDb'))) + { // checkPSVersion will be not - $this->upgrader = new Upgrader(true); + $this->upgrader = new Upgrader(); $this->upgrader->checkPSVersion(); - if (version_compare(_PS_VERSION_,'1.4.4.0','<') OR $this->upgrader->need_standalone) + $this->currentParams['install_version'] = $this->upgrader->version_num; + + if ($this->upgrader->autoupgrade_module) $this->standalone = true; else $this->standalone = false; +$this->standalone = true; + } // If you have defined this somewhere, you know what you do if (defined('_PS_ALLOW_UPGRADE_UNSTABLE_') AND _PS_ALLOW_UPGRADE_UNSTABLE_ AND function_exists('svn_checkout')) { - if(version_compare(_PS_VERSION_,'1.4.4.0','<') OR class_exists('Configuration',false)) + if(version_compare(_PS_VERSION_,'1.4.5.0','<') OR class_exists('Configuration',false)) $this->useSvn = Configuration::get('PS_AUTOUP_USE_SVN'); } else $this->useSvn = false; - // from $_POST or $_GET - $this->action = empty($_REQUEST['action'])?null:$_REQUEST['action']; - $this->currentParams = empty($_REQUEST['params'])?null:$_REQUEST['params']; // If not exists in this sessions, "create" // session handling : from current to next params @@ -327,6 +338,18 @@ class AdminSelfUpgrade extends AdminSelfTab if (isset($this->currentParams['filesToUpgrade'])) $this->nextParams['filesToUpgrade'] = $this->currentParams['filesToUpgrade']; + // set autoupgradePath, to be used in backupFiles and backupDb config values + $this->autoupgradePath = $this->adminDir.DIRECTORY_SEPARATOR.$this->autoupgradeDir; + + if (!file_exists($this->autoupgradePath)) + if (!@mkdir($this->autoupgradePath,0777)) + $this->_errors[] = Tools::displayError(sprintf($this->l('unable to create directory %s'),$this->autoupgradePath)); + + $latest = $this->autoupgradePath.DIRECTORY_SEPARATOR.'latest'; + if (!file_exists($latest)) + if (!@mkdir($latest,0777)) + $this->_errors[] = Tools::displayError(sprintf($this->l('unable to create directory %s'),$latest)); + if (class_exists('Configuration',false)) { $time = time(); @@ -351,26 +374,16 @@ class AdminSelfUpgrade extends AdminSelfTab // backupFilesFilename should never etc. $this->backupFilesFilename = $this->currentParams['backupFilesFilename']; } - $this->autoupgradePath = $this->adminDir.DIRECTORY_SEPARATOR.$this->autoupgradeDir; - - if (!file_exists($this->autoupgradePath)) - if (!@mkdir($this->autoupgradePath,0777)) - $this->_errors[] = Tools::displayError(sprintf($this->l('unable to create directory %s'),$this->autoupgradePath)); - - $latest = $this->autoupgradePath.DIRECTORY_SEPARATOR.'latest'; - if (!file_exists($latest)) - if (!@mkdir($latest,0777)) - $this->_errors[] = Tools::displayError(sprintf($this->l('unable to create directory %s'),$latest)); $this->latestRootDir = $latest.DIRECTORY_SEPARATOR.'prestashop'; $this->adminDir = str_replace($this->prodRootDir,'',$this->adminDir); - // @TODO future option + // @TODO future option "install in test dir" // $this->testRootDir = $this->autoupgradePath.DIRECTORY_SEPARATOR.'test'; /* option */ if (class_exists('Configuration',false)) { - $this->dontBackupImages = Configuration::get('PS_AUTOUP_DONT_SAVE_IMAGES'); + $this->dontBackupImages = !Configuration::get('PS_AUTOUP_DONT_SAVE_IMAGES'); $this->keepDefaultTheme = Configuration::get('PS_AUTOUP_KEEP_DEFAULT_THEME'); $this->keepTrad = Configuration::get('PS_AUTOUP_KEEP_TRAD'); $this->manualMode = Configuration::get('PS_AUTOUP_MANUAL_MODE'); @@ -382,7 +395,7 @@ class AdminSelfUpgrade extends AdminSelfTab $this->keepDefaultTheme = $this->currentParams['keepDefaultTheme']; $this->keepTrad = $this->currentParams['keepTrad']; $this->manualMode = $this->currentParams['manualMode']; - $this->desactivateCustomModule = $this->current['desactivateCustomModule']; + $this->desactivateCustomModule = $this->currentParams['desactivateCustomModule']; } // We can add any file or directory in the exclude dir : theses files will be not removed or overwritten // @TODO cache should be ignored recursively, but we have to reconstruct it after upgrade @@ -398,6 +411,7 @@ class AdminSelfUpgrade extends AdminSelfTab $this->excludeFilesFromUpgrade[] = '.svn'; $this->excludeFilesFromUpgrade[] = 'install'; $this->excludeFilesFromUpgrade[] = 'settings.inc.php'; + // this will exclude autoupgrade dir from admin, and autoupgrade from modules $this->excludeFilesFromUpgrade[] = 'autoupgrade'; $this->backupIgnoreFiles[] = '.'; $this->backupIgnoreFiles[] = '..'; @@ -493,7 +507,7 @@ class AdminSelfUpgrade extends AdminSelfTab } public function ajaxProcessUnzip(){ - if(version_compare(_PS_VERSION_,'1.4.4.0','<') + if(version_compare(_PS_VERSION_,'1.4.5.0','<') AND !class_exists('Tools',false) ) require_once('Tools.php'); @@ -556,9 +570,12 @@ class AdminSelfUpgrade extends AdminSelfTab public function _listBackupFiles($dir) { + static $list = array(); $allFiles = scandir($dir); foreach ($allFiles as $file) { + if ($file[0] != '.') + { $fullPath = $dir.DIRECTORY_SEPARATOR.$file; if (!$this->_skipFile($file, $fullPath,'backup')) @@ -566,16 +583,18 @@ class AdminSelfUpgrade extends AdminSelfTab if (is_dir($fullPath)) $this->_listBackupFiles($fullPath); else - $this->backupFileList[] = $fullPath; + $list[] = $fullPath; } else - $this->backupIgnoreFiles[] = $fullPath; - + $list[] = $fullPath; } } + file_put_contents($this->autoupgradePath.DIRECTORY_SEPARATOR.$this->toBackupFileList,serialize($list)); + } public function _listFilesToUpgrade($dir) { + static $list = array(); $allFiles = scandir($dir); foreach ($allFiles as $file) { @@ -583,20 +602,15 @@ class AdminSelfUpgrade extends AdminSelfTab if (!$this->_skipFile($file, $fullPath, "upgrade")) { + $list[] = $fullPath; + // if is_dir, we will create it :) if (is_dir($fullPath)) - { - // if is_dir, we will create it :)e it :) - $this->toUpgradeFileList[] = $fullPath; if (strpos($dir.DIRECTORY_SEPARATOR.$file, 'install') === false) - { $this->_listFilesToUpgrade($fullPath); } } - else - $this->toUpgradeFileList[] = $fullPath; - } - } + file_put_contents($this->autoupgradePath.DIRECTORY_SEPARATOR.$this->toUpgradeFileList,serialize($list)); $this->nextParams['filesToUpgrade'] = $this->toUpgradeFileList; } @@ -615,9 +629,9 @@ class AdminSelfUpgrade extends AdminSelfTab // @TODO : // foreach files in latest, copy $this->next = 'upgradeFiles'; - if (!is_array($this->nextParams['filesToUpgrade'])) + $filesToUpgrade = @unserialize(file_get_contents($this->nextParams['filesToUpgrade'])); + if (!is_array($filesToUpgrade)) { - error($this->nextParams); $this->next = 'error'; $this->nextDesc = $this->l('filesToUpgrade is not an array'); $this->nextQuickInfo[] = $this->l('filesToUpgrade is not an array'); @@ -627,29 +641,31 @@ class AdminSelfUpgrade extends AdminSelfTab // @TODO : does not upgrade files in modules, translations if they have not a correct md5 (or crc32, or whatever) from previous version for ($i=0;$inextParams['filesToUpgrade'])<=0) + if (sizeof($filesToUpgrade)<=0) { $this->next = 'upgradeDb'; + unlink($this->nextParams['filesToUpgrade']); $this->nextDesc = $this->l('All files upgraded. Now upgrading database'); $this->nextResponseType = 'xml'; break; } - //$file = array_shift($this->nextParams['filesToUpgrade']); - $file = array_shift($this->nextParams['filesToUpgrade']); + $file = array_shift($filesToUpgrade); if (!$this->upgradeThisFile($file)) { // put the file back to the begin of the list - $totalFiles = array_unshift($this->nextParams['filesToUpgrade'],$file); + $totalFiles = array_unshift($filesToUpgrade,$file); $this->next = 'error'; $this->nextQuickInfo[] = sprintf($this->l('error when trying to upgrade %s'),$file); break; } else{ + $this->nextQuickInfo[] = sprintf($this->l('copied %1$s. %2$s files left to upgrade.'),$file, sizeof($filesToUpgrade)); // @TODO : maybe put several files at the same times ? - $this->nextDesc = sprintf($this->l('%2$s files left to upgrade.'),$file,sizeof($this->nextParams['filesToUpgrade'])); + $this->nextDesc = sprintf($this->l('%2$s files left to upgrade.'),$file,sizeof($filesToUpgrade)); } } + file_put_contents($this->nextParams['filesToUpgrade'],serialize($filesToUpgrade)); } /** @@ -692,10 +708,14 @@ class AdminSelfUpgrade extends AdminSelfTab /////////////////////// // Copy from model.php /////////////////////// + if (!is_object($this->upgrader)) + $this->upgrader = new Upgrader(); + $upgrader = $this->upgrader; + $upgrader->checkPSVersion(); - define('INSTALL_VERSION', $upgrader->version_num); + define('INSTALL_VERSION', $this->currentParams['install_version']); // now the install dir to use is in a subdirectory of the admin dir define('INSTALL_PATH', realpath($this->latestRootDir.DIRECTORY_SEPARATOR.'install')); @@ -733,14 +753,12 @@ class AdminSelfUpgrade extends AdminSelfTab // 2) confirm config is correct (r/w rights) // install/model.php?method=checkConfig&firsttime=0 // later - // 3) save current activated modules in nextParams, or don't desactivate them ? // @TODO // 4) upgrade // install/model.php?_=1309193641470&method=doUpgrade&customModule=desactivate if (!empty($this->currentParams['desactivateCustomModule'])) $_GET['customModule'] = 'desactivate'; - if (!$this->_modelDoUpgrade()) { $this->next = 'error'; @@ -775,13 +793,14 @@ class AdminSelfUpgrade extends AdminSelfTab if (is_dir($file)) { + // if $dest is not a directory (that can happen), just remove that file + if (!is_dir($dest) AND file_exists($dest)) + unlink($dest); + if (!file_exists($dest)) { if (@mkdir($dest)) - { - $this->nextQuickInfo[] = sprintf($this->l('created dir %2$s. %3$s files left to upgrade.'),$file, $dest, sizeof($this->nextParams['filesToUpgrade'])); return true; - } else { $this->next = 'error'; @@ -791,18 +810,13 @@ class AdminSelfUpgrade extends AdminSelfTab } } else - { // directory already exists return true; } - } else { if (copy($file,$dest)) - { - $this->nextQuickInfo[] = sprintf($this->l('copied %1$s in %2$s. %3$s files left to upgrade.'),$file, $dest, sizeof($this->nextParams['filesToUpgrade'])); return true; - } else { $this->next = 'error'; @@ -824,7 +838,7 @@ class AdminSelfUpgrade extends AdminSelfTab { $this->next = 'restoreFiles'; $this->status = 'ok'; - $this->nextDesc = $this->l('Files restored, now restoring database.'); + $this->nextDesc = $this->l('Restoring files...'); } else { @@ -832,7 +846,7 @@ class AdminSelfUpgrade extends AdminSelfTab { $this->next = 'restoreDb'; $this->status = 'ok'; - $this->nextDesc = $this->l('Database restored'); + $this->nextDesc = $this->l('restoring Database ...'); } else { @@ -841,6 +855,9 @@ class AdminSelfUpgrade extends AdminSelfTab // all theses cases are handled by the method ajaxRequestRollback() $this->next = ''; // next is empty : nothing next :) $this->status = 'ok'; + if (isset($this->currentParams['firstTime'])) + $this->nextDesc = $this->l('Nothing has to be restored'); + else $this->nextDesc = $this->l('All your site is restored... '); } } @@ -866,19 +883,18 @@ class AdminSelfUpgrade extends AdminSelfTab $filepath = $this->backupFilesFilename; $destExtract = $this->prodRootDir; + if (self::ZipExtract($filepath, $destExtract)) { - // once it's restored, delete the file ! - unlink($this->backupFilesFilename); - Configuration::updateValue('UPGRADER_BACKUPFILES_FILENAME', ''); - if (!empty($this->backupDbFilename)) + // once it's restored, do not delete the archive file. This has to be done manually + if (!empty($this->backupDbFilename) AND file_exists($this->backupDbFilename) ) { $this->nextDesc = $this->l('Files restored. No database backup found. Restoration done.'); - $this->next = ''; + $this->next = 'rollback'; } else { - $this->nextDesc = $this->l('Files restored.'); + $this->nextDesc = $this->l('Files restored. No database backup found. Restoration done.'); $this->next = 'rollback'; } return true; @@ -906,6 +922,8 @@ class AdminSelfUpgrade extends AdminSelfTab */ public function ajaxProcessRestoreDb() { + $this->_loadDbRelatedClasses(); + $exts = explode('.', $this->backupDbFilename); $fileext = $exts[count($exts)-1]; $requests = array(); @@ -947,12 +965,12 @@ class AdminSelfUpgrade extends AdminSelfTab // This way we avoid extra blank lines // option s (PCRE_DOTALL) added // @TODO need to check if a ";" in description could block that (I suppose it can at the end of a line) - preg_match_all('/.*;[\n]\+/s', $content, $requests); + preg_match_all('/(.*;)[\n\r]+/Usm', $content, $requests); /* @TODO maybe improve regex pattern ... */ $db = Db::getInstance(); - if (count($requests)>0) + if (count($requests[0])>0) { - foreach ($requests as $request) + foreach ($requests[1] as $request) if (!empty($request)) if (!$db->Execute($request)) $this->nextQuickInfo[] = $db->getMsgError(); @@ -968,8 +986,9 @@ class AdminSelfUpgrade extends AdminSelfTab $this->nextDesc = 'Database restore done.'; } - public function ajaxProcessBackupDb() + private function _loadDbRelatedClasses() { + // Manual inclusion of all classes used if(!class_exists('ObjectModel',false)) { require_once(_PS_ROOT_DIR_.'/classes/ObjectModel.php'); @@ -983,12 +1002,6 @@ class AdminSelfUpgrade extends AdminSelfTab if(!class_exists('Language',false)) eval('Class Language extends LanguageCore{}'); } - if(!class_exists('Validate',false)) - { - require_once(_PS_ROOT_DIR_.'/classes/Validate.php'); - if(!class_exists('Validate',false)) - eval('Class Validate extends ValidateCore{}'); - } if(!class_exists('Db',false)) { require_once(_PS_ROOT_DIR_.'/classes/Db.php'); @@ -1001,6 +1014,13 @@ class AdminSelfUpgrade extends AdminSelfTab if(!class_exists('MySQL',false)) eval('Class MySQL extends MySQLCore{}'); } + + if(!class_exists('Validate',false)) + { + require_once(_PS_ROOT_DIR_.'/classes/Validate.php'); + if(!class_exists('Validate',false)) + eval('Class Validate extends ValidateCore{}'); + } if(!class_exists('Configuration',false)) { require_once(_PS_ROOT_DIR_.'/classes/Configuration.php'); @@ -1021,6 +1041,11 @@ class AdminSelfUpgrade extends AdminSelfTab define('_PS_MAGIC_QUOTES_GPC_', get_magic_quotes_gpc()); if(!defined('_PS_MYSQL_REAL_ESCAPE_STRING_')) define('_PS_MYSQL_REAL_ESCAPE_STRING_', function_exists('mysql_real_escape_string')); + Configuration::loadConfiguration(); + } + public function ajaxProcessBackupDb() + { + $this->_loadDbRelatedClasses(); $backup = new Backup(); // for backup db, use autoupgrade directory @@ -1050,8 +1075,8 @@ class AdminSelfUpgrade extends AdminSelfTab if (!isset($this->nextParams['filesForBackup'])) { $list = $this->_listBackupFiles($this->prodRootDir); - $this->nextQuickInfo[] = sprintf($this->l('%s Files to backup.'), sizeof($this->backupFileList)); - $this->nextParams['filesForBackup'] = $this->backupFileList; + $this->nextQuickInfo[] = sprintf($this->l('%s Files to backup.'), sizeof($this->toBackupFileList)); + $this->nextParams['filesForBackup'] = $this->toBackupFileList; // delete old backup, create new if (file_exists($this->backupFilesFilename)) @@ -1059,12 +1084,13 @@ class AdminSelfUpgrade extends AdminSelfTab $this->nextQuickInfo[] = sprintf($this->l('backup files initialized in %s'), $this->backupFilesFilename); } + $filesToBackup = unserialize(file_get_contents($this->toBackupFileList)); ///////////////////// $this->next = 'backupFiles'; // @TODO : display % instead of this - $this->nextDesc = sprintf($this->l('Backup files in progress. %s files left'), sizeof($this->nextParams['filesForBackup'])); - if (is_array($this->nextParams['filesForBackup'])) + $this->nextDesc = sprintf($this->l('Backup files in progress. %s files left'), sizeof($filesToBackup)); + if (is_array($filesToBackup)) { // @TODO later // 1) calculate crc32 of next file @@ -1089,7 +1115,7 @@ class AdminSelfUpgrade extends AdminSelfTab // @TODO min(self::$loopBackupFiles, sizeof()) for($i=0;$inextParams['filesForBackup'])<=0) + if (sizeof($filesToBackup)<=0) { $this->stepok = true; $this->status = 'ok'; @@ -1099,11 +1125,11 @@ class AdminSelfUpgrade extends AdminSelfTab break; } // filesForBackup already contains all the correct files - $file = array_shift($this->nextParams['filesForBackup']); - $archiveFilename = str_replace($this->prodRootDir,'',$file); + $file = array_shift($filesToBackup); + $archiveFilename = ltrim(str_replace($this->prodRootDir,'',$file),DIRECTORY_SEPARATOR); // @TODO : maybe put several files at the same times ? if ($zip->addFile($file,$archiveFilename)) - $this->nextQuickInfo[] = sprintf($this->l('%1$s added to archive. %2$s left.'),$file, sizeof($this->nextParams['filesForBackup'])); + $this->nextQuickInfo[] = sprintf($this->l('%1$s added to archive. %2$s left.'),$file, sizeof($filesToBackup)); else { // if an error occur, it's more safe to delete the corrupted backup @@ -1115,6 +1141,7 @@ class AdminSelfUpgrade extends AdminSelfTab } } $zip->close(); + file_put_contents($this->autoupgradePath.DIRECTORY_SEPARATOR.$this->toBackupFileList,serialize($filesToBackup)); return true; } else{ @@ -1157,7 +1184,6 @@ class AdminSelfUpgrade extends AdminSelfTab public function ajaxProcessRemoveSamples(){ $this->stepDone = false; - // @TODO : list exaustive list of files to remove : // all images from img dir exept admin ? // all images like logo, favicon, ?. // all custom image from modules ? @@ -1306,8 +1332,8 @@ class AdminSelfUpgrade extends AdminSelfTab { if(!$this->standalone) { - if (version_compare(_PS_VERSION_,'1.4.4.0','<') AND false) - $this->_errors[] = Tools::displayError('This class depends of several files modified in 1.4.4.0 version and should not be used in an older version'); + if (version_compare(_PS_VERSION_,'1.4.5.0','<') AND false) + $this->_errors[] = Tools::displayError('This class depends of several files modified in 1.4.5.0 version and should not be used in an older version'); } parent::displayConf(); @@ -1336,7 +1362,7 @@ class AdminSelfUpgrade extends AdminSelfTab } } - if ($this->apacheModExists('mod_evasive')) + if ($this->apacheModExists('evasive')) sleep(1); } /** @@ -1357,9 +1383,11 @@ class AdminSelfUpgrade extends AdminSelfTab // we need strpos (example can be evasive20 foreach($apacheModuleList as $module) - if (strpos($name, $module)!==false) + { + if (strpos($module, $name)!==false) return true; } + } else{ // If apache_get_modules does not exists, // one solution should be parsing httpd.conf, @@ -1377,7 +1405,7 @@ class AdminSelfUpgrade extends AdminSelfTab private function _getJsErrorMsgs() { - $INSTALL_VERSION = $this->upgrader->version_num; + $INSTALL_VERSION = $this->currentParams['install_version']; $ret = ' var txtError = new Array(); txtError[0] = "'.$this->l('Required field').'"; @@ -1501,11 +1529,11 @@ txtError[37] = "'.$this->l('The config/defines.inc.php file was not found. Where $srcExecTime = '../img/admin/warning.gif'; echo ''.$this->l('PHP time limit').' : '.''.($max_exec_time == 0?$this->l('disabled'):$max_exec_time.' '.$this->l('seconds')).'

'; - if ($this->rootWritable) - $srcRootWritable = '../img/admin/enabled.gif'; + if (($testConfigDone = Configuration::get('PS_AUTOUP_DONT_SAVE_IMAGES')) !== false) + $configurationDone = '../img/admin/enabled.gif'; else - $srcRootWritable = '../img/admin/disabled.gif'; - echo ''.$this->l('Root directory').' : '.' '.($this->rootWritable?$this->l('writable recursively'):$this->l('not writable recursively')).'.

'; + $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 ''; @@ -1556,7 +1584,7 @@ txtError[37] = "'.$this->l('The config/defines.inc.php file was not found. Where - if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_) + if (defined('_PS_MODE_DEV_') AND _PS_MODE_DEV_ AND $this->manualMode) { echo '
'; echo '
'.$this->l('Step').''; @@ -1623,6 +1651,7 @@ echo ''; #upgradeNow {-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;} .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;} '; $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.')); @@ -1716,6 +1745,7 @@ function addQuickInfo(arrQuickInfo){ $js .= ' var firstTimeParams = '.$this->buildAjaxResult().'; firstTimeParams = firstTimeParams.nextParams; +firstTimeParams.firstTime = "1"; $(document).ready(function(){ $(".upgradestep").click(function(e) @@ -1757,7 +1787,7 @@ function parseXMLResult(xmlRet) $("#dbCreateResultCheck") .hide("slow"); - // difference with the original function + // as xml is only after upgradeDb, the next step is always upgradeComplete ret = {next:"upgradeComplete",nextParams:{typeResult:"json"},status:"ok"}; } @@ -1812,12 +1842,14 @@ function afterBackupFiles() } function doAjaxRequest(action, nextParams){ + // myNext, used when json is not available but response is correct + myNext = nextParams; req = $.ajax({ type:"POST", - url : "'.($this->standalone? __PS_BASE_URI__ . trim($this->adminDir,'/').'/autoupgrade/ajax-upgradetab.php' : str_replace('index','ajax-tab',$currentIndex)).'", + 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,'/').'", + dir:"'.trim($this->adminDir,DIRECTORY_SEPARATOR).'", ajaxMode : "1", token : "'.$this->token.'", tab : "'.get_class($this).'", @@ -1912,8 +1944,6 @@ function doAjaxRequest(action, nextParams){ */ function prepareNextButton(button_selector, nextParams) { -// myNext; - myNext = nextParams; $(button_selector).unbind(); $(button_selector).click(function(e){ e.preventDefault(); diff --git a/modules/autoupgrade/Backup.php b/modules/autoupgrade/Backup.php index 2254cfeb7..36de581ca 100644 --- a/modules/autoupgrade/Backup.php +++ b/modules/autoupgrade/Backup.php @@ -49,6 +49,7 @@ class BackupCore if ($filename) $this->id = $this->getRealBackupPath($filename); + Configuration::loadConfiguration(); $psBackupAll = Configuration::get('PS_BACKUP_ALL'); $psBackupDropTable = Configuration::get('PS_BACKUP_DROP_TABLE'); $this->psBackupAll = $psBackupAll !== false ? $psBackupAll : true; diff --git a/modules/autoupgrade/Upgrader.php b/modules/autoupgrade/Upgrader.php index ce87ff54a..c3c000581 100644 --- a/modules/autoupgrade/Upgrader.php +++ b/modules/autoupgrade/Upgrader.php @@ -40,6 +40,7 @@ class UpgraderCore{ public $version_num; public $link; public $autoupgrade; + public $autoupgrade_module; public $changelog; public $md5; @@ -95,7 +96,10 @@ class UpgraderCore{ { if (empty($this->link)) { + if (class_exists('Configuration')) $lastCheck = Configuration::get('PS_LAST_VERSION_CHECK'); + else + $lastCheck = 0; // if we use the autoupgrade process, we will never refresh it // except if no check has been done before if ($force OR ($lastCheck < time() - (3600 * Upgrader::DEFAULT_CHECK_VERSION_DELAY_HOURS)) ) @@ -103,12 +107,14 @@ class UpgraderCore{ libxml_set_streams_context(stream_context_create(array('http' => array('timeout' => 3)))); if ($feed = @simplexml_load_file($this->rss_version_link)) { + $this->version_name = (string)$feed->version->name; $this->version_num = (string)$feed->version->num; $this->link = (string)$feed->download->link; $this->md5 = (string)$feed->download->md5; $this->changelog = (string)$feed->download->changelog; $this->autoupgrade = (int)$feed->autoupgrade; + $this->autoupgrade_module = (int)$feed->autoupgrade_module; $this->desc = (string)$feed->desc ; $configLastVersion = array( 'name' => $this->version_name, @@ -116,13 +122,17 @@ class UpgraderCore{ 'link' => $this->link, 'md5' => $this->md5, 'autoupgrade' => $this->autoupgrade, + 'autoupgrade_module' => $this->autoupgrade_module, 'changelog' => $this->changelog, 'desc' => $this->desc ); + if (class_exists('Configuration')) + { Configuration::updateValue('PS_LAST_VERSION',serialize($configLastVersion)); Configuration::updateValue('PS_LAST_VERSION_CHECK',time()); } } + } else { $lastVersionCheck = @unserialize(Configuration::get('PS_LAST_VERSION')); @@ -130,6 +140,7 @@ class UpgraderCore{ $this->version_num = $lastVersionCheck['num']; $this->link = $lastVersionCheck['link']; $this->autoupgrade = $lastVersionCheck['autoupgrade']; + $this->autoupgrade_module = $lastVersionCheck['autoupgrade_module']; $this->md5 = $lastVersionCheck['md5']; $this->desc = $lastVersionCheck['desc']; $this->changelog = $lastVersionCheck['changelog']; diff --git a/modules/autoupgrade/ajax-upgradetab.php b/modules/autoupgrade/ajax-upgradetab.php index e83960b50..e0be1d26a 100644 --- a/modules/autoupgrade/ajax-upgradetab.php +++ b/modules/autoupgrade/ajax-upgradetab.php @@ -28,19 +28,22 @@ if($_POST['action'] == 'upgradeDb') require_once(dirname(__FILE__).'/../../config/config.inc.php'); -// require('Tools.php'); -// require('../../config/config.autoupgrade.inc.php'); +// ajax-upgrade-tab is located in admin/autoupgrade directory if(!defined('_PS_ROOT_DIR_')) - define('_PS_ROOT_DIR_', dirname(__FILE__).'/../../'); + define('_PS_ROOT_DIR_', realpath(dirname(__FILE__).'/../../')); require_once(_PS_ROOT_DIR_.'/config/settings.inc.php'); if(!defined('_PS_MODULE_DIR_')) - define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ .'modules/'); + define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ .'/modules/'); + define('AUTOUPGRADE_MODULE_DIR', _PS_MODULE_DIR_.'autoupgrade/'); require_once(AUTOUPGRADE_MODULE_DIR.'functions.php'); if(!defined('_PS_USE_SQL_SLAVE_')) define('_PS_USE_SQL_SLAVE_',0); // dir = admin-dev -define('_PS_ADMIN_DIR_', _PS_ROOT_DIR_.'/'.$_POST['dir']); +if ( _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$_POST['dir'] !== realpath(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$_POST['dir'])) + die('not allowed'); + +define('_PS_ADMIN_DIR_', _PS_ROOT_DIR_.DIRECTORY_SEPARATOR.$_POST['dir']); define('PS_ADMIN_DIR', _PS_ADMIN_DIR_); // Retro-compatibility //require(_PS_ADMIN_DIR_.'/functions.php'); include(AUTOUPGRADE_MODULE_DIR.'init.php'); diff --git a/modules/autoupgrade/autoupgrade.php b/modules/autoupgrade/autoupgrade.php index 861d42d49..bc83318bb 100644 --- a/modules/autoupgrade/autoupgrade.php +++ b/modules/autoupgrade/autoupgrade.php @@ -26,14 +26,9 @@ class Autoupgrade extends Module } function install() { - $autoupgradeCanWork = true; - if (!$autoupgradeCanWork) - return false; $res = true; // before adding AdminSelfUpgrade, we should remove AdminUpgrade - if (version_compare(_PS_VERSION_,'1.4.4.0','==') OR version_compare(_PS_VERSION_,'1.4.4.1','==')) - { $idTab = Tab::getIdFromClassName('AdminUpgrade'); if ($idTab) @@ -41,7 +36,6 @@ class Autoupgrade extends Module $tab = new Tab($idTab); $res &= $tab->delete(); } - } $idTab = Tab::getIdFromClassName('AdminSelfUpgrade'); // Then we add AdminSelfUpgrade only if not exists @@ -55,9 +49,7 @@ class Autoupgrade extends Module $res &= $tab->save(); } else - { $tab = new Tab($idTab); - } Configuration::updateValue('PS_AUTOUPDATE_MODULE_IDTAB',$tab->id); $autoupgradeDir = _PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.'autoupgrade'; @@ -68,6 +60,7 @@ class Autoupgrade extends Module $path = dirname(__FILE__).'/'; $res &= copy($path.'ajax-upgradetab.php',$autoupgradeDir . DIRECTORY_SEPARATOR . 'ajax-upgradetab.php'); + $res &= copy($path.'logo.gif',_PS_ROOT_DIR_. DIRECTORY_SEPARATOR . 'img/t/AdminSelfUpgrade.gif'); if (!$res OR !Tab::getIdFromClassName('AdminSelfUpgrade') @@ -94,6 +87,7 @@ class Autoupgrade extends Module $res = $tab->save(); } + if (file_exists(_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.'autoupgrade'.DIRECTORY_SEPARATOR.'ajax-upgradetab.php')) $res &= @unlink(_PS_ADMIN_DIR_.DIRECTORY_SEPARATOR.'autoupgrade'.DIRECTORY_SEPARATOR.'ajax-upgradetab.php'); if($res OR !parent::uninstall()) return false; diff --git a/modules/autoupgrade/de.php b/modules/autoupgrade/de.php index 03ebff7d2..502a68288 100644 --- a/modules/autoupgrade/de.php +++ b/modules/autoupgrade/de.php @@ -1,56 +1,56 @@ AdminSelfUpgrade_19f823c6453c2b1ffd09cb715214813d'] = 'Pflichtfelder'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_760c4026bc5a0bd5378e6efc3f1370b4'] = 'Zu lang!'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_4f2e28904946a09d8c7f36dd3ee72457'] = 'Die Felder sind unterschiedlich!'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_43b01d1a6c5065545c65f42003b0ab5c'] = 'Falsche Adresse!'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_2e170dfd78c2171a25605ececc0950a4'] = 'Kann E-Mail nicht senden!'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_6deee80e4bdb8894331994116818558e'] = 'Fehler beim Erstellen der Konfigurationsdatei, wenn die Datei /config/ settings.inc.php existiert, geben Sie ihr bitte die offiziellen Schreibrechte, ansonsten erstellen Sie bitte eine Datei settings.inc.php im Konfigurationsverzeichnis (/config/)'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_aa946cb00b1c23ff6553b6f9e05da151'] = 'Die Settings-Datei konnte nicht geschrieben werden, erstellen Sie bitte eine Datei namens settings.inc.php in Ihrem Konfigurationsverzeichnis.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_e930e2474c664a3a7e89ecfb8793694b'] = 'Kann Datei nicht senden!'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_774fc7a0f56391abc5d8856f2436ca07'] = 'Die Integrität der Daten ist nicht bestätigt.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_8fd007bf08e0717537825a3e91cb4fcc'] = 'Kann den Inhalt einer *.sql-Datei nicht lesen.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_c71e825f6873f64b91efc26313614eab'] = 'Kann nicht auf den Inhalt einer *.sql-Datei zugreifen.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_3d5c8f1d29b1a1dc4ea0673122e0d277'] = 'Fehler beim Einfügen in die Datenbank:'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_17e1581d01152347bfaacd153b961379'] = 'Falsches Kennwort (alpha-numerischer String aus mindestens 8 Zeichen)'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_9b9f3b2f8a4dffcad9188c8fc4b468c8'] = 'Eine PrestaShop Datenbank existiert bereits mit diesem Präfix, Sie müssen sie manuell löschen oder das Präfix ändern.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_bc5e1163a15106f9e941a7603124709d'] = 'Dies ist kein gültiger Name.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_a9d82945b8603f0c8807958d7db9a24d'] = 'Dies ist kein gültiges Bild.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_b37eef07b764ea58eec9afe624e20a40'] = 'Fehler beim Erstellen der Datei /config/settings.inc.php.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_3d9f514d46849760ef1b1412e314fd99'] = 'Fehler:'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_504053ab4c6d648edf11624f1bea4bb4'] = 'Diese PrestaShop-Datenbank existiert schon, bitte bestätigen Sie der Datenbank erneut Ihre Kennungen.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_d7a99f61bb284d096ea4f221784af85a'] = 'Bei der Änderung des Bildmaßstabs ist ein Fehler aufgetreten.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_428c933bafbf262d693fbf1c22c03e5d'] = 'Die Datenbank wurde gefunden!'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_76bd190129b7aefb90fdf42f09ec3ec7'] = 'Der Datenbank-Server steht zur Verfügung, aber die Datenbank wurde nicht gefunden'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_045f4b5c3f990e5a26e2837495d68259'] = 'Der Datenbank-Server wurde nicht gefunden, bitte prüfen Sie Ihren Benutzernamen oder den Server-Namen.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_757fc72e8d69106dd2cf9da22cc7adb1'] = 'Beim Senden der E-Mail ist ein Fehler aufgetreten, bitte prüfen Sie Ihre Einstellungen.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_d18ad19290b3bfc3cd0d7badbb6cb6a3'] = 'Kann Bild /img/logo.jpg nicht schreiben. Falls es bereits existiert, löschen Sie es bitte manuell.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_2368e33e3e01d53abb9b60061ab83903'] = 'Die gesendete Datei überschreitet die maximal zulässige Größe.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_a10ef376d9f4c877ac86d8e4350116bf'] = 'Die gesendete Datei überschreitet die maximal zulässige Größe.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_f8fe8cba1625eaf8e5c253b041d57dbd'] = 'Die Datei wurde teilweise gesendet.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_8c9067e52e4440d8a20e74fdc745b0c6'] = 'Es ist keine Datei gesandt worden'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_2384d693d9af53b4727c092af7570a19'] = 'Der temporäre Ordner Ihrer empfangenen Dateisendungen fehlt. Bitte wenden Sie sich an Ihren Systemadministrator.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_f5985b2c059d5cc36968baab7585baba'] = 'Kann die Datei nicht auf die Festplatte schreiben'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_9e54dfe54e03b0010c1fe70bd65cd5e6'] = 'Datei Senden unterbrochen aufgrund falscher Erweiterung'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_32af3a59b50e98d254d6c03c5b320a94'] = 'Kann die Daten aus Ihrer Datenbank nicht in UTF-8 zu konvertieren.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_989a45a4ca01ee222f4370172bf8850d'] = 'Ungültiger Shopname'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_68499acecfba9d3bf0ca8711f300d3ed'] = 'Ihr Vorname enthält ungültige Zeichen'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_2399cf4ca7b49f2706f6e147a32efa78'] = 'Ihr Nachname enthält ungültige Zeichen'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_7d72600fcff52fb3a2d2f73572117311'] = 'Ihr Datenbank-Server unterstützt keinen UTF-8-Zeichensatz.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_5b9bbadcf96f15e7f112c13a9e5f076e'] = 'Diese Datenbank-Engine wird nicht unterstützt, bitte wählen Sie eine andere als MyISAM'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_24b481455c1b72b0c2539e7d516b9582'] = 'Die Datei /img/logo.jpg kann nicht geschrieben werden, bitte ändern Sie die Dateirechte mit CHMOD 755 oder CHMOD 777'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_5746b74663148afffd1350c97d4fcdfe'] = 'Feld Katalog-Modus ungültig'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_dafe44b99256a7783bc37f4f949da373'] = 'Der Installer ist zu alt.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_37ce0f29c7377c827e7247fe5645a782'] = 'Sie besitzen bereits die Version. %s'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_89928a14f2090aec4fd7aff9ea983f95'] = 'Keine frühere Version erkannt. Haben Sie die Datei settings.inc.php aus dem Ordner config gelöscht oder umbenannt?'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_5276a8cbd9e3e467396089b267564f51'] = 'Die Datei config/settings.inc.php wurde nicht gefunden. Haben Sie sie gelöscht oder umbenannt?'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_24784d9e80638781b74c017b33d8ca0c'] = 'Kann eine der SQL-Update-Dateien nicht finden. Bitte stellen Sie sicher, dass der Ordner /install/sql/upgrade nicht leer ist.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_580e4b216e324f675f0237cdb34b6c2d'] = 'Kein Update verfügbar'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_f15e7e7292b0c72894cf45a893e0d497'] = 'Fehler beim Öffnen der SQL-Datei'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_b8286438fbb6c7df9129fadc5316c19f'] = 'Fehler beim Einfügen in die Datenbank'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_229ee8046cafc09ddaf46fb9db710e91'] = 'Leider'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_e805a556799b7cef40e9760c81d99218'] = 'Es sind SQL-Fehler aufgetreten.'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_5627353fd6ac678497af3ece05087068'] = 'Die Datei config/defines.inc.php wurde nicht gefunden. Wo ist sie?'; -$_MODULE['<{autoupgrade}prestashop>AdminSelfUpgrade_783e8e29e6a8c3e22baa58a19420eb4f'] = 'Sekunden'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_19f823c6453c2b1ffd09cb715214813d'] = 'Pflichtfelder'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_760c4026bc5a0bd5378e6efc3f1370b4'] = 'Zu lang!'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_4f2e28904946a09d8c7f36dd3ee72457'] = 'Die Felder sind unterschiedlich!'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_43b01d1a6c5065545c65f42003b0ab5c'] = 'Falsche Adresse!'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_2e170dfd78c2171a25605ececc0950a4'] = 'Kann E-Mail nicht senden!'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_6deee80e4bdb8894331994116818558e'] = 'Fehler beim Erstellen der Konfigurationsdatei, wenn die Datei /config/ settings.inc.php existiert, geben Sie ihr bitte die offiziellen Schreibrechte, ansonsten erstellen Sie bitte eine Datei settings.inc.php im Konfigurationsverzeichnis (/config/)'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_aa946cb00b1c23ff6553b6f9e05da151'] = 'Die Settings-Datei konnte nicht geschrieben werden, erstellen Sie bitte eine Datei namens settings.inc.php in Ihrem Konfigurationsverzeichnis.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_e930e2474c664a3a7e89ecfb8793694b'] = 'Kann Datei nicht senden!'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_774fc7a0f56391abc5d8856f2436ca07'] = 'Die Integrität der Daten ist nicht bestätigt.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_8fd007bf08e0717537825a3e91cb4fcc'] = 'Kann den Inhalt einer *.sql-Datei nicht lesen.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_c71e825f6873f64b91efc26313614eab'] = 'Kann nicht auf den Inhalt einer *.sql-Datei zugreifen.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_3d5c8f1d29b1a1dc4ea0673122e0d277'] = 'Fehler beim Einfügen in die Datenbank:'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_17e1581d01152347bfaacd153b961379'] = 'Falsches Kennwort (alpha-numerischer String aus mindestens 8 Zeichen)'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_9b9f3b2f8a4dffcad9188c8fc4b468c8'] = 'Eine PrestaShop Datenbank existiert bereits mit diesem Präfix, Sie müssen sie manuell löschen oder das Präfix ändern.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_bc5e1163a15106f9e941a7603124709d'] = 'Dies ist kein gültiger Name.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_a9d82945b8603f0c8807958d7db9a24d'] = 'Dies ist kein gültiges Bild.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_b37eef07b764ea58eec9afe624e20a40'] = 'Fehler beim Erstellen der Datei /config/settings.inc.php.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_3d9f514d46849760ef1b1412e314fd99'] = 'Fehler:'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_504053ab4c6d648edf11624f1bea4bb4'] = 'Diese PrestaShop-Datenbank existiert schon, bitte bestätigen Sie der Datenbank erneut Ihre Kennungen.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_d7a99f61bb284d096ea4f221784af85a'] = 'Bei der Änderung des Bildmaßstabs ist ein Fehler aufgetreten.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_428c933bafbf262d693fbf1c22c03e5d'] = 'Die Datenbank wurde gefunden!'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_76bd190129b7aefb90fdf42f09ec3ec7'] = 'Der Datenbank-Server steht zur Verfügung, aber die Datenbank wurde nicht gefunden'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_045f4b5c3f990e5a26e2837495d68259'] = 'Der Datenbank-Server wurde nicht gefunden, bitte prüfen Sie Ihren Benutzernamen oder den Server-Namen.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_757fc72e8d69106dd2cf9da22cc7adb1'] = 'Beim Senden der E-Mail ist ein Fehler aufgetreten, bitte prüfen Sie Ihre Einstellungen.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_d18ad19290b3bfc3cd0d7badbb6cb6a3'] = 'Kann Bild /img/logo.jpg nicht schreiben. Falls es bereits existiert, löschen Sie es bitte manuell.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_2368e33e3e01d53abb9b60061ab83903'] = 'Die gesendete Datei überschreitet die maximal zulässige Größe.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_a10ef376d9f4c877ac86d8e4350116bf'] = 'Die gesendete Datei überschreitet die maximal zulässige Größe.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_f8fe8cba1625eaf8e5c253b041d57dbd'] = 'Die Datei wurde teilweise gesendet.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_8c9067e52e4440d8a20e74fdc745b0c6'] = 'Es ist keine Datei gesandt worden'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_2384d693d9af53b4727c092af7570a19'] = 'Der temporäre Ordner Ihrer empfangenen Dateisendungen fehlt. Bitte wenden Sie sich an Ihren Systemadministrator.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_f5985b2c059d5cc36968baab7585baba'] = 'Kann die Datei nicht auf die Festplatte schreiben'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_9e54dfe54e03b0010c1fe70bd65cd5e6'] = 'Datei Senden unterbrochen aufgrund falscher Erweiterung'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_32af3a59b50e98d254d6c03c5b320a94'] = 'Kann die Daten aus Ihrer Datenbank nicht in UTF-8 zu konvertieren.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_989a45a4ca01ee222f4370172bf8850d'] = 'Ungültiger Shopname'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_68499acecfba9d3bf0ca8711f300d3ed'] = 'Ihr Vorname enthält ungültige Zeichen'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_2399cf4ca7b49f2706f6e147a32efa78'] = 'Ihr Nachname enthält ungültige Zeichen'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_7d72600fcff52fb3a2d2f73572117311'] = 'Ihr Datenbank-Server unterstützt keinen UTF-8-Zeichensatz.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_5b9bbadcf96f15e7f112c13a9e5f076e'] = 'Diese Datenbank-Engine wird nicht unterstützt, bitte wählen Sie eine andere als MyISAM'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_24b481455c1b72b0c2539e7d516b9582'] = 'Die Datei /img/logo.jpg kann nicht geschrieben werden, bitte ändern Sie die Dateirechte mit CHMOD 755 oder CHMOD 777'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_5746b74663148afffd1350c97d4fcdfe'] = 'Feld Katalog-Modus ungültig'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_dafe44b99256a7783bc37f4f949da373'] = 'Der Installer ist zu alt.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_37ce0f29c7377c827e7247fe5645a782'] = 'Sie besitzen bereits die Version. %s'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_89928a14f2090aec4fd7aff9ea983f95'] = 'Keine frühere Version erkannt. Haben Sie die Datei settings.inc.php aus dem Ordner config gelöscht oder umbenannt?'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_5276a8cbd9e3e467396089b267564f51'] = 'Die Datei config/settings.inc.php wurde nicht gefunden. Haben Sie sie gelöscht oder umbenannt?'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_24784d9e80638781b74c017b33d8ca0c'] = 'Kann eine der SQL-Update-Dateien nicht finden. Bitte stellen Sie sicher, dass der Ordner /install/sql/upgrade nicht leer ist.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_580e4b216e324f675f0237cdb34b6c2d'] = 'Kein Update verfügbar'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_f15e7e7292b0c72894cf45a893e0d497'] = 'Fehler beim Öffnen der SQL-Datei'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_b8286438fbb6c7df9129fadc5316c19f'] = 'Fehler beim Einfügen in die Datenbank'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_229ee8046cafc09ddaf46fb9db710e91'] = 'Leider'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_e805a556799b7cef40e9760c81d99218'] = 'Es sind SQL-Fehler aufgetreten.'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_5627353fd6ac678497af3ece05087068'] = 'Die Datei config/defines.inc.php wurde nicht gefunden. Wo ist sie?'; +$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_783e8e29e6a8c3e22baa58a19420eb4f'] = 'Sekunden'; diff --git a/modules/autoupgrade/fr.php b/modules/autoupgrade/fr.php index e52758e9e..f1de5b9bb 100644 --- a/modules/autoupgrade/fr.php +++ b/modules/autoupgrade/fr.php @@ -2,7 +2,6 @@ global $_MODULE; $_MODULE = array(); -$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_875b8a59022d232837491c0fdfacb4ab'] = 'Ne pas sauver les images'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_a8d6c6734da0083021561b23f2fa88cc'] = 'Vous pouvez exclure le dossier image de la sauvegarde si vous l\'avez déjà sauvegardé d\'une autre manière (non recommandé)'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_af98608eaedd4ba7ffd47a0204e84b23'] = 'Conserver le thème \"prestashop\" actuel'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_4ea56ca1a757e426911ff20889c0e93c'] = 'Si vous avez personnalisé le thème par défaut de PrestaShop, vous pouvez le protéger de la mise à niveau (non recommandé)'; @@ -31,12 +30,9 @@ $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_63ded4905ba41ac4bf00373df273 $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_11978affb3b0dbb16c50d571fd05de6d'] = 'erreur lors de la création du répertoire %s'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_1b854285afc1988b6f83414fde5943ab'] = '%1$s copié dans %2$s. encore %3$s fichiers à mettre à jour.'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_0e06ce0972ad338e1d96e8589dc21b9c'] = 'erreur lors de la copie de %1$s vers %2$s'; -$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_0511620a3a1d6036d3fbe47b131d7c4b'] = 'Fichiers restorés. Restauration de la base de données.'; -$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_791403f158965a3e19f8627c7b744126'] = 'Base de données restaurée.'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_5f7f50973696d0a42c1efcc07f7820a0'] = 'Votre site est maintenant restauré.'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_28517b8a291c50d80aa53a078407065b'] = 'Répertoire racine nettoyée.'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_bb71892737d721949538d6e1c4d3d22d'] = 'Fichiers restaurés. Sauvegarde de la base de données non trouvée. Restauration terminée.'; -$_MODULE['<{autoupgrade}prestashop>adminselfupgrade_cb7dce5f6a1934d54c0d3335c7ffe841'] = 'Fichiers restaurés.'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_8efc36d230f76fbfd9e4d758964e9414'] = 'impossible d\'extraire %1$ s dans%2$s.'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_d7624db09c15d46cd37d7709ae05e44b'] = 'aucune sauvegarde trouvée. Il n\'y a rien à restaurer.'; $_MODULE['<{autoupgrade}prestashop>adminselfupgrade_09a362e2dd3800f8fbc55d3446513f65'] = 'Rien à restaurer (aucune requête trouvée)'; diff --git a/modules/blocklayered/blocklayered-ajax-back.php b/modules/blocklayered/blocklayered-ajax-back.php index 9e378e4fc..e69192e7d 100644 --- a/modules/blocklayered/blocklayered-ajax-back.php +++ b/modules/blocklayered/blocklayered-ajax-back.php @@ -28,6 +28,10 @@ /* Getting cookie or logout */ include(dirname(__FILE__).'/../../config/config.inc.php'); require_once(dirname(__FILE__).'/../../init.php'); + +if (substr(Tools::encrypt('blocklayered/index'),0,10) != Tools::getValue('layered_token') || !Module::isInstalled('blocklayered')) + die('Bad token'); + include(dirname(__FILE__).'/blocklayered.php'); /* Clean categoryBox before use */ diff --git a/modules/blocklayered/blocklayered-indexer.php b/modules/blocklayered/blocklayered-indexer.php index 60523382b..4d0dcb9bf 100644 --- a/modules/blocklayered/blocklayered-indexer.php +++ b/modules/blocklayered/blocklayered-indexer.php @@ -5,7 +5,7 @@ include(dirname(__FILE__).'/../../init.php'); include(dirname(__FILE__).'/blocklayered.php'); if (substr(Tools::encrypt('blocklayered/index'),0,10) != Tools::getValue('token') || !Module::isInstalled('blocklayered')) - die; + die('Bad token'); if(Tools::getValue('full')) echo BlockLayered::fullindexProcess((int)Tools::getValue('cursor'), (int)Tools::getValue('ajax'), true); diff --git a/modules/blocklayered/blocklayered-url-indexer.php b/modules/blocklayered/blocklayered-url-indexer.php new file mode 100644 index 000000000..f9cb401a0 --- /dev/null +++ b/modules/blocklayered/blocklayered-url-indexer.php @@ -0,0 +1,11 @@ +indexUrl((int)Tools::getValue('id_category'), (int)Tools::getValue('truncate')); \ No newline at end of file diff --git a/modules/blocklayered/blocklayered.js b/modules/blocklayered/blocklayered.js index 7eb2f2189..325d6d49d 100644 --- a/modules/blocklayered/blocklayered.js +++ b/modules/blocklayered/blocklayered.js @@ -26,6 +26,8 @@ var ajaxQueries = new Array(); var ajaxLoaderOn = 0; +var sliderList = new Array(); +var slidersInit = false; $(document).ready(function() { @@ -54,9 +56,76 @@ $(document).ready(function() } }); paginationButton(); + initLayered(); reloadContent(); }); +function addSlider(type, data, unit) +{ + sliderList.push({ + type: type, + data: data, + unit: unit + }); +} + +function initSliders() +{ + $(sliderList).each(function(i, slider){ + $('#layered_'+slider['type']+'_slider').slider(slider['data']); + $('#layered_'+slider['type']+'_range').html($('#layered_'+slider['type']+'_slider').slider('values', 0)+slider['unit']+ + ' - ' + $('#layered_'+slider['type']+'_slider').slider('values', 1 )+slider['unit']); + }); +} + +function initLayered() +{ + initSliders(); + var params = document.location.toString().split('#'); + params.shift(); + $(params).each(function(it, val) + { + if (val.split('=')[0] == 'price' || val.split('=')[0] == 'weight') + { + $("#layered_"+val.split('=')[0]+"_slider").slider('values', 0, val.split('=')[1].split('_')[0]); + $("#layered_"+val.split('=')[0]+"_slider").slider('values', 1, val.split('=')[1].split('_')[1]); + $("#layered_"+val.split('=')[0]+"_slider").slider('option', 'slide')(0,{values:[val.split('=')[1].split('_')[0], val.split('=')[1].split('_')[1]]}); + } + else + { + $('#'+val.split('=')[0]).click(); + } + }); +} + +function updatelink(link) +{ + baseUrl = link.split('#'); + linkFilterUpdate = baseUrl[0]+getValueSelected(); + return linkFilterUpdate; +} + +function getValueSelected(){ + + var checkboxChecked = ""; + $("#layered_form input:checkbox:checked").each(function(){ + checkboxChecked += '#' + $(this).attr('id')+"="+$(this).val(); + }); + $("#layered_form input:hidden").each(function(){ + checkboxChecked += '#' + $(this).attr('name')+"="+$(this).val(); + }); + $(['price','weight']).each(function(i, filter) { + if ($("#layered_"+filter+"_slider").length) + { + if (typeof($("#layered_"+filter+"_slider").slider('values', 0)) != 'object') + { + checkboxChecked += '#'+filter+'='+$("#layered_"+filter+"_slider").slider('values', 0)+'_'+$("#layered_"+filter+"_slider").slider('values', 1); + } + } + }); + return checkboxChecked; +} + function paginationButton() { $('#pagination li').not('.current, .disabled').each( function () { var nbPage = 0; @@ -82,8 +151,17 @@ function cancelFilter() { $('#enabled_filters a').live('click', function(e) { + if($(this).attr('rel').search(/_slider$/) > 0) + { + $('#'+$(this).attr('rel')).slider("values" , 0, $('#'+$(this).attr('rel')).slider( "option" , 'min' )); + $('#'+$(this).attr('rel')).slider("values" , 1, $('#'+$(this).attr('rel')).slider( "option" , 'max' )); + $('#'+$(this).attr('rel')).slider('option', 'slide')(0,{values:[$('#'+$(this).attr('rel')).slider( "option" , 'min' ), $('#'+$(this).attr('rel')).slider( "option" , 'max' )]}); + } + else + { $('#'+$(this).attr('rel')).attr('checked', false); $('#layered_form input[name='+$(this).attr('rel')+']:hidden').remove(); + } reloadContent(); e.preventDefault(); }); @@ -110,6 +188,7 @@ function openCloseFilter() function reloadContent(params_plus) { + window.location = updatelink( window.location.href); for(i = 0; i < ajaxQueries.length; i++) ajaxQueries[i].abort(); ajaxQueries = new Array(); @@ -157,6 +236,8 @@ function reloadContent(params_plus) $('#layered_block_left').after('
').remove(); $('#tmp_layered_block_left').html(result.filtersBlock).attr('id', 'layered_block_left'); + $('.category-product-count').html(result.categoryCount); + $('#product_list').html(result.productList).html(); $('#product_list').css('opacity', '1'); $('div#pagination').html(result.pagination); @@ -182,6 +263,7 @@ function reloadContent(params_plus) if(typeof(reloadProductComparison) == 'function') { reloadProductComparison(); } + initSliders(); } }); ajaxQueries.push(ajaxQuery); diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index b6334dd63..91cb92594 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -52,7 +52,8 @@ class BlockLayered extends Module if ($result = parent::install() && $this->registerHook('leftColumn') && $this->registerHook('header') && $this->registerHook('footer') && $this->registerHook('categoryAddition') && $this->registerHook('categoryUpdate') && $this->registerHook('attributeGroupForm') && $this->registerHook('afterSaveAttributeGroup') && $this->registerHook('afterDeleteAttributeGroup') && $this->registerHook('featureForm') - && $this->registerHook('afterDeleteFeature') && $this->registerHook('afterSaveFeature') && $this->registerHook('categoryDeletion')) + && $this->registerHook('afterDeleteFeature') && $this->registerHook('afterSaveFeature') && $this->registerHook('categoryDeletion') + && $this->registerHook('afterSaveProduct') && $this->registerHook('productListAssign')) { Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', 0); Configuration::updateValue('PS_LAYERED_SHOW_QTIES', 1); @@ -63,6 +64,7 @@ class BlockLayered extends Module self::_installPriceIndexTable(); self::_installFriendlyUrlTable(); + self::_installIndexableAttributeTable(); return $result; } @@ -73,6 +75,13 @@ class BlockLayered extends Module Configuration::deleteByName('PS_LAYERED_HIDE_0_VALUES'); Configuration::deleteByName('PS_LAYERED_SHOW_QTIES'); + Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'price_static_index'); + Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_friendly_url'); + Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_indexable_attribute_group'); + Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_indexable_feature'); + Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_category'); + Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_filter'); + return parent::uninstall(); } @@ -91,13 +100,14 @@ class BlockLayered extends Module private function _installFriendlyUrlTable() { Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'layered_friendly_url`'); - Db::getInstance()->Execute(' CREATE TABLE `'._DB_PREFIX_.'layered_friendly_url` ( `id_layered_friendly_url` INT NOT NULL AUTO_INCREMENT, `url_key` varchar(32) NOT NULL, `data` varchar(200) NOT NULL, - PRIMARY KEY (`id_layered_friendly_url`)) ENGINE = '._MYSQL_ENGINE_); + `id_lang` INT NOT NULL, + PRIMARY KEY (`id_layered_friendly_url`), + INDEX `id_lang` (`id_lang`)) ENGINE = '._MYSQL_ENGINE_); Db::getInstance()->Execute('CREATE INDEX `url_key` ON `'._DB_PREFIX_.'layered_friendly_url`(url_key(5))'); } @@ -110,6 +120,9 @@ class BlockLayered extends Module `id_attribute_group` INT NOT NULL, `indexable` BOOL NOT NULL DEFAULT 0, PRIMARY KEY (`id_attribute_group`)) ENGINE = '._MYSQL_ENGINE_); + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'layered_indexable_attribute_group` + SELECT id_attribute_group, 1 FROM `'._DB_PREFIX_.'attribute_group`'); Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'layered_indexable_feature`'); Db::getInstance()->Execute(' @@ -117,75 +130,231 @@ class BlockLayered extends Module `id_feature` INT NOT NULL, `indexable` BOOL NOT NULL DEFAULT 0, PRIMARY KEY (`id_feature`)) ENGINE = '._MYSQL_ENGINE_); + Db::getInstance()->Execute(' + INSERT INTO `'._DB_PREFIX_.'layered_indexable_feature` + SELECT id_feature, 1 FROM `'._DB_PREFIX_.'feature`'); } /* * Url indexation */ - static function _indexUrl() + public function indexUrl($idCategory = null, $truncate = true) { + if($truncate) + Db::getInstance()->execute('TRUNCATE '._DB_PREFIX_.'layered_friendly_url'); - $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT id_category FROM '._DB_PREFIX_.'layered_category GROUP BY id_category'); + if(!empty($idCategory)) + $categorySubQuery = ' AND lc.id_category = '.(int)$idCategory; + else + $categorySubQuery = ''; - if(!$categories) + $attributeValues = array(); + $filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT lc.*, id_lang, name, link_rewrite, cl.id_category + FROM '._DB_PREFIX_.'layered_category lc + INNER JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = lc.id_category AND lc.id_category <> 1'.$categorySubQuery.') + ORDER BY position ASC'); + if (!$filters) return; - // We want all attributes of each categories - $attributeValuesByCategory = array(); + foreach ($filters as $filter) + switch ($filter['type']) + { + case 'id_attribute_group': + $attributes = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + SELECT agl.public_name name, a.id_attribute_group id_name, al.name value, a.id_attribute id_value, al.id_lang + FROM '._DB_PREFIX_.'attribute_group ag + INNER JOIN '._DB_PREFIX_.'attribute_group_lang agl ON (agl.id_attribute_group = ag.id_attribute_group) + INNER JOIN '._DB_PREFIX_.'attribute a ON (a.id_attribute_group = ag.id_attribute_group) + INNER JOIN '._DB_PREFIX_.'attribute_lang al ON (al.id_attribute = a.id_attribute) + INNER JOIN '._DB_PREFIX_.'layered_indexable_attribute_group liag ON (liag.id_attribute_group = a.id_attribute_group AND liag.indexable = 1) + WHERE a.id_attribute_group = '.(int)$filter['id_value'].' AND agl.id_lang = al.id_lang AND agl.id_lang = '.(int)$filter['id_lang']); + foreach ($attributes as $attribute) + { + if (!isset($attributeValues[$attribute['id_lang']])) + $attributeValues[$attribute['id_lang']] = array(); + if (!isset($attributeValues[$attribute['id_lang']][$filter['id_category']])) + $attributeValues[$attribute['id_lang']][$filter['id_category']] = array(); + if (!isset($attributeValues[$attribute['id_lang']][$filter['id_category']]['c'.$attribute['id_name']])) + $attributeValues[$attribute['id_lang']][$filter['id_category']]['c'.$attribute['id_name']] = array(); + $attributeValues[$attribute['id_lang']][$filter['id_category']]['c'.$attribute['id_name']][] = array('name' => $attribute['name'], + 'id_name' => 'c'.$attribute['id_name'], 'value' => $attribute['value'], 'id_value' => $attribute['id_value'], + 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); + } + break; + + case 'id_feature': + $features = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + SELECT fl.name name, fl.id_feature id_name, fvl.id_feature_value id_value, fvl.value value, fl.id_lang + FROM '._DB_PREFIX_.'feature_lang fl + INNER JOIN '._DB_PREFIX_.'layered_indexable_feature lif ON (lif.id_feature = fl.id_feature AND indexable = 1) + INNER JOIN '._DB_PREFIX_.'feature_value fv ON (fv.id_feature = fl.id_feature) + INNER JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = fv.id_feature_value) + WHERE fl.id_feature = '.(int)$filter['id_value'].' AND fvl.id_lang = fl.id_lang AND fvl.id_lang = '.(int)$filter['id_lang']); + foreach ($features as $feature) + { + if (!isset($attributeValues[$feature['id_lang']])) + $attributeValues[$feature['id_lang']] = array(); + if (!isset($attributeValues[$feature['id_lang']][$filter['id_category']])) + $attributeValues[$feature['id_lang']][$filter['id_category']] = array(); + if (!isset($attributeValues[$feature['id_lang']][$filter['id_category']]['f'.$feature['id_name']])) + $attributeValues[$feature['id_lang']][$filter['id_category']]['f'.$feature['id_name']] = array(); + $attributeValues[$feature['id_lang']][$filter['id_category']]['f'.$feature['id_name']][] = array('name' => $feature['name'], + 'id_name' => 'f'.$feature['id_name'], 'value' => $feature['value'], 'id_value' => $feature['id_value'], + 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); + } + break; + + case 'category': + $categories = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + SELECT cl.name, cl.id_lang, c.id_category + FROM '._DB_PREFIX_.'category c + INNER JOIN '._DB_PREFIX_.'category_lang cl ON (c.id_category = cl.id_category) + WHERE nleft > (SELECT nleft FROM '._DB_PREFIX_.'category WHERE id_category = 2) + AND nright < (SELECT nright FROM '._DB_PREFIX_.'category WHERE id_category = 2) + '); foreach($categories as $category) { - $attributeValuesByCategory[(int)$category['id_category']] = array(); - $filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT * FROM '._DB_PREFIX_.'layered_category WHERE id_category = '.(int)$category['id_category'].' ORDER BY position ASC'); - if(!$categories) - continue; + if (!isset($attributeValues[$category['id_lang']])) + $attributeValues[$category['id_lang']] = array(); + if (!isset($attributeValues[$category['id_lang']][$filter['id_category']])) + $attributeValues[$category['id_lang']][$filter['id_category']] = array(); + if (!isset($attributeValues[$category['id_lang']][$filter['id_category']]['cat'.$category['id_category']])) + $attributeValues[$category['id_lang']][$filter['id_category']]['cat'.$category['id_category']] = array(); + $attributeValues[$category['id_lang']][$filter['id_category']]['cat'.$category['id_category']][] = array('name' => $this->l('Categories'), + 'id_name' => null, 'value' => $category['name'], 'id_value' => $category['id_category'], + 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']); } + $filter['id_category']; + break; + + case 'manufacturer': + // @TODO + break; + + case 'avaibility': + // @TODO + break; } + + // Foreach langs + foreach ($attributeValues as $id_lang => $tmp1) + { + // Foreach categories + foreach ($tmp1 as $id_category => $tmp2) + { + $cursors = array_fill(0, count($tmp2), 0); + $limits = array(); + $nbName = count($tmp2); + $nbPosibilities = 1; + $tmp2 = array_values($tmp2); + + // fill limits and calculate the number of combination possible + foreach ($tmp2 as $name) + { + $count = count($name)+1; + $limits[] = $count; + $nbPosibilities *= $count; + } + + // Loop all url posibilities + for ($i = 1; $i < $nbPosibilities; $i++) + { + // generate all parameters posibilities + $a = 1; + foreach ($cursors as $position => $cursor) + { + // Get all possible combination (one by group) + // 0 means no combinations selected in the group + $cursors[$position] = (($i / ($a)) % $limits[$position]); + $a *= $limits[$position]; + } + + $link = ''; + $selectedFilters = array('category' => array()); + + // Generate url with selected filters + foreach ($cursors as $position => $cursor) + { + if ($cursor != 0) + { + $link .= '/'.Tools::link_rewrite($tmp2[$position][$cursor-1]['name'].'-'.$tmp2[$position][$cursor-1]['value']); + if (!isset($selectedFilters[$tmp2[$position][$cursor-1]['type']])) + $selectedFilters[$tmp2[$position][$cursor-1]['type']] = array(); + $selectedFilters[$tmp2[$position][$cursor-1]['type']][$tmp2[$position][$cursor-1]['id_value']] = $tmp2[$position][$cursor-1]['id_value']; + } + } + + $urlKey = md5($link); + $idLayeredFriendlyUrl = Db::getInstance()->getValue('SELECT id_layered_friendly_url FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `url_key` = \''.$urlKey.'\''); + if ($idLayeredFriendlyUrl == false) + { + Db::getInstance()->AutoExecute(_DB_PREFIX_.'layered_friendly_url', array('url_key' => $urlKey, 'data' => serialize($selectedFilters), 'id_lang' => $id_lang), 'INSERT'); + $idLayeredFriendlyUrl = Db::getInstance()->Insert_ID(); + } + } + } + } + return 1; + } + + public function hookProductListAssign($params) + { + if (!Configuration::get('PS_LAYERED_INDEXED')) + return; + $params['hookExecuted'] = true; + $params['catProducts'] = array(); + $selectedFilters = $this->getSelectedFilters(); + $this->getProducts($selectedFilters, $params['catProducts'], $params['nbProducts'], $p, $n, $pages_nb, $start, $stop, $range); + } + + public function hookAfterSaveProduct($params) + { + if (!$params['id_product']) + return; + + self::indexProduct((int)$params['id_product']); + } + public function hookAfterSaveFeature($params) { - $idFeature = $params['id_feature']; - - if(!$idFeature) - return; - if(Tools::getValue('layered_indexable') === false) + if (!$params['id_feature'] || Tools::getValue('layered_indexable') === false) return; - Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_feature WHERE id_feature = '.(int)$idFeature); - Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'layered_indexable_feature VALUES ('.(int)$idFeature.', '.(int)Tools::getValue('layered_indexable').')'); + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_feature WHERE id_feature = '.(int)$params['id_feature']); + Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'layered_indexable_feature VALUES ('.(int)$params['id_feature'].', '.(int)Tools::getValue('layered_indexable').')'); } + public function hookAfterDeleteFeature($params) { - $idFeature = $params['id_feature']; - - if(!$idFeature) + if (!$params['id_feature']) return; - Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_feature WHERE id_feature = '.(int)$idFeature); + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_feature WHERE id_feature = '.(int)$params['id_feature']); } public function hookAfterSaveAttributeGroup($params) { - $idAttributeGroup = $params['id_attribute_group']; - - if(!$idAttributeGroup) - return; - if(Tools::getValue('layered_indexable') === false) + if (!$params['id_attribute_group'] || Tools::getValue('layered_indexable') === false) return; - Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$idAttributeGroup); - Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'layered_indexable_attribute_group VALUES ('.(int)$idAttributeGroup.', '.(int)Tools::getValue('layered_indexable').')'); + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$params['id_attribute_group']); + Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'layered_indexable_attribute_group VALUES ('.(int)$params['id_attribute_group'].', '.(int)Tools::getValue('layered_indexable').')'); } + public function hookAfterDeleteAttributeGroup($params) { - $idAttributeGroup = $params['id_attribute_group']; - - if(!$idAttributeGroup) + if (!$params['id_attribute_group']) return; - Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$idAttributeGroup); + + Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$params['id_attribute_group']); } public function hookAttributeGroupForm($params) { - $idAttributeGroup = $params['id_attribute_group']; - $on = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT indexable FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$idAttributeGroup); + $indexable = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT indexable FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$params['id_attribute_group']); + if($indexable === false) + $on = true; + else + $on = (bool)$indexable; return '
@@ -199,12 +368,14 @@ class BlockLayered extends Module public function hookFeatureForm($params) { - $this->registerHook('afterDeleteFeature'); - $this->registerHook('afterSaveFeature'); - $idAttributeGroup = $params['id_attribute_group']; - $on = (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT indexable FROM '._DB_PREFIX_.'layered_indexable_attribute_group WHERE id_attribute_group = '.(int)$idAttributeGroup); + $indexable = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT indexable FROM '._DB_PREFIX_.'layered_indexable_feature WHERE id_feature = '.(int)$params['id_feature']); + if($indexable === false) + $on = true; + else + $on = (bool)$indexable; - return ' + return ' +
@@ -301,7 +472,7 @@ class BlockLayered extends Module WHERE `active` = 1 AND psi.id_product is null ORDER by id_product LIMIT 0,'.(int)$length; - foreach (Db::getInstance()->executeS($query) as $product) + foreach (Db::getInstance()->ExecuteS($query) as $product) self::indexProduct((int)$product['id_product'], ($smart AND $full)); return (int)($cursor + $length); @@ -333,7 +504,7 @@ class BlockLayered extends Module LEFT JOIN `'._DB_PREFIX_.'tax_rule` tr ON (tr.id_tax_rules_group = trg.id_tax_rules_group) LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.id_tax = tr.id_tax AND t.active = 1) WHERE id_product = '.(int)$idProduct.' - GROUP BY id_product;'); + GROUP BY id_product'); $productMinPrices = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT id_shop, id_currency, id_country, id_group, from_quantity @@ -341,6 +512,24 @@ class BlockLayered extends Module WHERE id_product = '.(int)$idProduct); // Get min price + foreach ($currencyList as $currency) + { + $price = Product::priceCalculation(null, (int)$idProduct, null, null, null, null, + $currency['id_currency'], null, null, false, true, false, true, true, + $specificPriceOutput, true); + + if (!isset($maxPrice[$currency['id_currency']])) + $maxPrice[$currency['id_currency']] = 0; + if (!isset($minPrice[$currency['id_currency']])) + $minPrice[$currency['id_currency']] = null; + if ($price > $maxPrice[$currency['id_currency']]) + $maxPrice[$currency['id_currency']] = $price; + if ($price == 0) + continue; + if (is_null($minPrice[$currency['id_currency']]) OR $price < $minPrice[$currency['id_currency']]) + $minPrice[$currency['id_currency']] = $price; + } + foreach ($productMinPrices as $specificPrice) foreach ($currencyList as $currency) { @@ -381,10 +570,13 @@ class BlockLayered extends Module $minPrice[$currency['id_currency']] = $price; } + $values = array(); foreach ($currencyList as $currency) + $values[] = '('.(int)$idProduct.', '.(int)$currency['id_currency'].', '.(int)$minPrice[$currency['id_currency']].', '.(int)$maxPrice[$currency['id_currency']].')'; + Db::getInstance()->Execute(' INSERT INTO `'._DB_PREFIX_.'price_static_index` (id_product, id_currency, price_min, price_max) - VALUES ('.(int)$idProduct.', '.(int)$currency['id_currency'].', '.(int)$minPrice[$currency['id_currency']].', '.(int)$maxPrice[$currency['id_currency']].')'); + VALUES '.implode(',', $values)); } public function hookLeftColumn($params) @@ -399,9 +591,9 @@ class BlockLayered extends Module public function hookHeader($params) { - $id_parent = (int)Tools::getValue('id_category', Tools::getValue('id_category_layered', 1)); - if ($id_parent == 1) + if (Tools::getValue('id_category', Tools::getValue('id_category_layered', 1)) == 1) return; + Tools::addJS(($this->_path).'blocklayered.js'); Tools::addJS(_PS_JS_DIR_.'jquery/jquery-ui-1.8.10.custom.min.js'); Tools::addCSS(_PS_CSS_DIR_.'jquery-ui-1.8.10.custom.css', 'all'); @@ -446,23 +638,20 @@ class BlockLayered extends Module { global $cookie; - $errors = array(); $html = ''; - if (!extension_loaded('curl')) - $html .= '

'.$this->l('You must enable cURL extension on your server if you want to use short link.').'

'; - - if (Tools::isSubmit('submitLayeredCache')) + if (Tools::isSubmit('SubmitFilter')) { - $this->rebuildLayeredStructure(); - $this->rebuildLayeredCache(); + if(!Tools::getValue('layered_tpl_name')) $html .= ' -
- '.$this->l('Layered navigation database was initialized successfully').' +
+ + X + + '.$this->l('Filter template name required (cannot be empty)').'
'; - } - elseif (Tools::isSubmit('SubmitFilter')) + else { if (isset($_POST['id_layered_filter']) AND $_POST['id_layered_filter']) Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)Tools::getValue('id_layered_filter')); @@ -485,6 +674,8 @@ class BlockLayered extends Module Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_category WHERE id_category IN ('.implode(',', $_POST['categoryBox']).')'); $filterValues = array(); + foreach (Tools::getValue('categoryBox') AS $idc) + $filterValues['categories'][] = (int)$idc; $sqlToInsert = 'INSERT INTO '._DB_PREFIX_.'layered_category (id_category, id_value, type, position) VALUES '; foreach ($_POST['categoryBox'] AS $id_category_layered) @@ -494,7 +685,6 @@ class BlockLayered extends Module if (substr($key, 0, 17) == 'layered_selection' AND $value == 'on') { $filterValues[$key] = $value; - $n++; if ($key == 'layered_selection_stock') $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'quantity\','.(int)$n.'),'; @@ -513,11 +703,11 @@ class BlockLayered extends Module elseif (substr($key, 0, 23) == 'layered_selection_feat_') $sqlToInsert .= '('.(int)$id_category_layered.','.(int)str_replace('layered_selection_feat_', '', $key).',\'id_feature\','.(int)$n.'),'; } - $filterValues['categories'] = Tools::getValue('categoryBox'); } + Db::getInstance()->Execute(rtrim($sqlToInsert, ',')); - $valuesToInsert = array('name' => pSQL(Tools::getValue('layered_tpl_name')), 'filters' => pSQL(serialize($filterValues)), 'n_categories' => (int)sizeof($_POST['categoryBox']), 'date_add' => date('Y-m-d H:i:s')); + $valuesToInsert = array('name' => pSQL(Tools::getValue('layered_tpl_name')), 'filters' => pSQL(serialize($filterValues)), 'n_categories' => (int)sizeof($filterValues['categories']), 'date_add' => date('Y-m-d H:i:s')); if (isset($_POST['id_layered_filter']) AND $_POST['id_layered_filter']) $valuesToInsert['id_layered_filter'] = (int)Tools::getValue('id_layered_filter'); @@ -526,10 +716,9 @@ class BlockLayered extends Module echo '
'.$this->l('Your filter').' "'.Tools::getValue('layered_tpl_name').'" '.((isset($_POST['id_layered_filter']) AND $_POST['id_layered_filter']) ? $this->l('was updated successfully.') : $this->l('was added successfully.')).'
'; } } + } elseif (Tools::isSubmit('submitLayeredSettings')) { - if (!sizeof($errors)) - { Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', Tools::getValue('ps_layered_hide_0_values')); Configuration::updateValue('PS_LAYERED_SHOW_QTIES', Tools::getValue('ps_layered_show_qties')); @@ -538,18 +727,6 @@ class BlockLayered extends Module '.$this->l('Settings saved successfully').'
'; } - else - { - $html .= ' -
- '.$this->l('Settings not saved :').'
    '; - foreach ($errors AS $error) - $html .= '
  • '.$error.'
  • '; - $html .= '
-
'; - } - - } elseif (isset($_GET['deleteFilterTemplate'])) { $layeredValues = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' @@ -576,29 +753,102 @@ class BlockLayered extends Module } $html .= ' -

'.$this->l('Layered navigation').'

'; - $html .= ' + + +

'.$this->l('Layered navigation').'

'.$this->l('Indexes and caches').' - - '; + '; + if(!Configuration::get('PS_LAYERED_INDEXED')) $html .= ' '; + + $categoryList = array(); + foreach(Db::getInstance()->ExecuteS('SELECT id_category FROM `'._DB_PREFIX_.'category`') as $category) + if($category['id_category'] != 1) + $categoryList[] = $category['id_category']; + + $html .= ' - '.$this->l('Index all missing products').' + '.$this->l('Index all missing prices').'
- '.$this->l('Re-build entire index').' + '.$this->l('Re-build entire price index').' +
+ '.$this->l('Build url index').'

- '.$this->l('You can set a cron job that will re-build your index using the following URL:').'
'.Tools::getProtocol().Tools::getHttpHost().__PS_BASE_URI__.'modules/blocklayered/blocklayered-indexer.php'.'?token='.substr(Tools::encrypt('blocklayered/index'), 0, 10).'&full=1 + '.$this->l('You can set a cron job that will re-build price index using the following URL:').'
'.Tools::getProtocol().Tools::getHttpHost().__PS_BASE_URI__.'modules/blocklayered/blocklayered-indexer.php'.'?token='.substr(Tools::encrypt('blocklayered/index'), 0, 10).'&full=1 +
+ '.$this->l('You can set a cron job that will re-build url index using the following URL:').'
'.Tools::getProtocol().Tools::getHttpHost().__PS_BASE_URI__.'modules/blocklayered/blocklayered-url-indexer.php'.'?token='.substr(Tools::encrypt('blocklayered/index'), 0, 10).'&truncate=1

- '.$this->l('A full re-index process must be done each time products are modified. A nightly rebuild is recommended.').' + '.$this->l('A nightly rebuild is recommended.').'
-
'; - - $html .= ' +
'.$this->l('Existing filters templates').''; @@ -695,6 +959,7 @@ class BlockLayered extends Module '.$this->l('Build your own filters template').'