/** * ends the upgrade process * * @return void */ public function ajaxProcessUpgradeComplete() { if (version_compare($this->install_version, '1.5.4.0', '>=')) { // Upgrade languages if (!defined('_PS_TOOL_DIR_')) { define('_PS_TOOL_DIR_', _PS_ROOT_DIR_ . '/tools/'); } if (!defined('_PS_TRANSLATIONS_DIR_')) { define('_PS_TRANSLATIONS_DIR_', _PS_ROOT_DIR_ . '/translations/'); } if (!defined('_PS_MODULES_DIR_')) { define('_PS_MODULES_DIR_', _PS_ROOT_DIR_ . '/modules/'); } if (!defined('_PS_MAILS_DIR_')) { define('_PS_MAILS_DIR_', _PS_ROOT_DIR_ . '/mails/'); } $langs = Db::getInstance()->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'lang WHERE active=1'); require_once _PS_TOOL_DIR_ . 'tar/Archive_Tar.php'; foreach ($langs as $lang) { $lang_pack = Tools14::jsonDecode(Tools::file_get_contents('http' . (extension_loaded('openssl') ? 's' : '') . '://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . $this->install_version . '&iso_lang=' . $lang['iso_code'])); if (!$lang_pack) { continue; } elseif ($content = Tools14::file_get_contents('http' . (extension_loaded('openssl') ? 's' : '') . '://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $lang['iso_code'] . '.gzip')) { $file = _PS_TRANSLATIONS_DIR_ . $lang['iso_code'] . '.gzip'; if ((bool) @file_put_contents($file, $content)) { $gz = new Archive_Tar($file, true); $files_list = $gz->listContent(); if (!$this->keepMails) { foreach ($files_list as $i => $file) { if (preg_match('/^mails\\/' . $lang['iso_code'] . '\\/.*/', $file['filename'])) { unset($files_list[$i]); } } foreach ($files_list as $file) { if (isset($file['filename']) && is_string($file['filename'])) { $files_listing[] = $file['filename']; } } if (is_array($files_listing) && !$gz->extractList($files_listing, _PS_TRANSLATIONS_DIR_ . '../', '')) { continue; } } elseif (!$gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) { continue; } } } } // Remove class_index Autoload cache @unlink(_PS_ROOT_DIR_ . '/cache/class_index.php'); } if (!$this->warning_exists) { $this->next_desc = $this->l('Upgrade process done. Congratulations ! You can now reactive your shop.'); } else { $this->next_desc = $this->l('Upgrade process done, but some warnings has been found. Please restore your shop.'); } $this->next = ''; $conf_clear = Db::getInstance()->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'configuration` WHERE `name` = \'PS_UPGRADE_CLEAR_CACHE\' '); if (!$conf_clear) { //set this value to 1 after upgrade process to Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES (\'PS_UPGRADE_CLEAR_CACHE\', 1, NOW(), NOW())'); } else { Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'configuration` SET value=1 WHERE name=\'PS_UPGRADE_CLEAR_CACHE\' '); } }
/** * ends the upgrade process * * @return void */ public function ajaxProcessUpgradeComplete() { if (version_compare($this->install_version, '1.5.4.0', '>=')) { // Upgrade languages if (!defined('_PS_TOOL_DIR_')) { define('_PS_TOOL_DIR_', _PS_ROOT_DIR_ . '/tools/'); } if (!defined('_PS_TRANSLATIONS_DIR_')) { define('_PS_TRANSLATIONS_DIR_', _PS_ROOT_DIR_ . '/translations/'); } if (!defined('_PS_MODULES_DIR_')) { define('_PS_MODULES_DIR_', _PS_ROOT_DIR_ . '/modules/'); } if (!defined('_PS_MAILS_DIR_')) { define('_PS_MAILS_DIR_', _PS_ROOT_DIR_ . '/mails/'); } $langs = Db::getInstance()->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'lang` WHERE `active` = 1'); require_once _PS_TOOL_DIR_ . 'tar/Archive_Tar.php'; if (is_array($langs)) { foreach ($langs as $lang) { $lang_pack = Tools14::jsonDecode(Tools::file_get_contents('http' . (extension_loaded('openssl') ? 's' : '') . '://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . $this->install_version . '&iso_lang=' . $lang['iso_code'])); if (!$lang_pack) { continue; } elseif ($content = Tools14::file_get_contents('http' . (extension_loaded('openssl') ? 's' : '') . '://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $lang['iso_code'] . '.gzip')) { $file = _PS_TRANSLATIONS_DIR_ . $lang['iso_code'] . '.gzip'; if ((bool) file_put_contents($file, $content)) { $gz = new Archive_Tar($file, true); $files_list = $gz->listContent(); if (!$this->keepMails) { foreach ($files_list as $i => $file) { if (preg_match('/^mails\\/' . $lang['iso_code'] . '\\/.*/', $file['filename'])) { unset($files_list[$i]); } } foreach ($files_list as $file) { if (isset($file['filename']) && is_string($file['filename'])) { $files_listing[] = $file['filename']; } } if (is_array($files_listing) && !$gz->extractList($files_listing, _PS_TRANSLATIONS_DIR_ . '../', '')) { continue; } } elseif (!$gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false)) { continue; } } } } } // Remove class_index Autoload cache if (file_exists(_PS_ROOT_DIR_ . '/cache/class_index.php')) { unlink(_PS_ROOT_DIR_ . '/cache/class_index.php'); } } if (!$this->warning_exists) { $this->next_desc = $this->l('Upgrade process done. Congratulations ! You can now reactive your shop.'); } else { $this->next_desc = $this->l('Upgrade process done, but some warnings has been found.'); } $this->next = ''; if ($this->getConfig('channel') != 'archive' && file_exists($this->getFilePath()) && unlink($this->getFilePath())) { $this->nextQuickInfo[] = sprintf('%s removed', $this->getFilePath()); } elseif (is_file($this->getFilePath())) { $this->nextQuickInfo[] = '<strong>' . sprintf('Please remove %s by ftp', $this->getFilePath()) . '</strong>'; } if ($this->getConfig('channel') != 'directory' && file_exists($this->latestRootDir) && self::deleteDirectory($this->latestRootDir)) { $this->nextQuickInfo[] = sprintf('%s removed', $this->latestRootDir); } elseif (is_dir($this->latestRootDir)) { $this->nextQuickInfo[] = '<strong>' . sprintf('Please remove %s by ftp', $this->latestRootDir) . '</strong>'; } }
/** * This function now replaces doUpgrade.php or upgrade.php * * @return void */ public function doUpgrade() { // Initialize // setting the memory limit to 128M only if current is lower $memory_limit = ini_get('memory_limit'); if (substr($memory_limit, -1) != 'G' && ((substr($memory_limit, -1) == 'M' and substr($memory_limit, 0, -1) < 128) || is_numeric($memory_limit) and intval($memory_limit) < 131072)) { @ini_set('memory_limit', '128M'); } /* Redefine REQUEST_URI if empty (on some webservers...) */ if (!isset($_SERVER['REQUEST_URI']) || empty($_SERVER['REQUEST_URI'])) { if (!isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['SCRIPT_FILENAME'])) { $_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_FILENAME']; } if (isset($_SERVER['SCRIPT_NAME'])) { if (basename($_SERVER['SCRIPT_NAME']) == 'index.php' && empty($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'] = dirname($_SERVER['SCRIPT_NAME']) . '/'; } else { $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; } } } } $_SERVER['REQUEST_URI'] = str_replace('//', '/', $_SERVER['REQUEST_URI']); define('INSTALL_VERSION', $this->install_version); // 1.4 define('INSTALL_PATH', realpath($this->latestRootDir . DIRECTORY_SEPARATOR . 'install')); // 1.5 ... define('_PS_INSTALL_PATH_', INSTALL_PATH . DIRECTORY_SEPARATOR); // 1.6 if (!defined('_PS_CORE_DIR_')) { define('_PS_CORE_DIR_', _PS_ROOT_DIR_); } define('PS_INSTALLATION_IN_PROGRESS', true); define('SETTINGS_FILE', $this->prodRootDir . '/config/settings.inc.php'); define('DEFINES_FILE', $this->prodRootDir . '/config/defines.inc.php'); define('INSTALLER__PS_BASE_URI', substr($_SERVER['REQUEST_URI'], 0, -1 * (strlen($_SERVER['REQUEST_URI']) - strrpos($_SERVER['REQUEST_URI'], '/')) - strlen(substr(dirname($_SERVER['REQUEST_URI']), strrpos(dirname($_SERVER['REQUEST_URI']), '/') + 1)))); // define('INSTALLER__PS_BASE_URI_ABSOLUTE', 'http://'.ToolsInstall::getHttpHost(false, true).INSTALLER__PS_BASE_URI); // XML Header // header('Content-Type: text/xml'); $filePrefix = 'PREFIX_'; $engineType = 'ENGINE_TYPE'; $mysqlEngine = defined('_MYSQL_ENGINE_') ? _MYSQL_ENGINE_ : 'MyISAM'; if (function_exists('date_default_timezone_set')) { date_default_timezone_set('Europe/Paris'); } // if _PS_ROOT_DIR_ is defined, use it instead of "guessing" the module dir. if (defined('_PS_ROOT_DIR_') and !defined('_PS_MODULE_DIR_')) { define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/'); } else { if (!defined('_PS_MODULE_DIR_')) { define('_PS_MODULE_DIR_', INSTALL_PATH . '/../modules/'); } } $upgrade_dir_php = 'upgrade/php'; if (!file_exists(INSTALL_PATH . DIRECTORY_SEPARATOR . $upgrade_dir_php)) { $upgrade_dir_php = 'php'; if (!file_exists(INSTALL_PATH . DIRECTORY_SEPARATOR . $upgrade_dir_php)) { $this->next = 'error'; $this->next_desc = $this->l('/install/upgrade/php directory is missing in archive or directory'); $this->nextQuickInfo[] = '/install/upgrade/php directory is missing in archive or directory'; $this->nextErrors[] = '/install/upgrade/php directory is missing in archive or directory.'; return false; } } define('_PS_INSTALLER_PHP_UPGRADE_DIR_', INSTALL_PATH . DIRECTORY_SEPARATOR . $upgrade_dir_php . DIRECTORY_SEPARATOR); //old version detection global $oldversion, $logger; $oldversion = false; if (file_exists(SETTINGS_FILE)) { include_once SETTINGS_FILE; // include_once(DEFINES_FILE); $oldversion = _PS_VERSION_; } else { $this->next = 'error'; $this->nextQuickInfo[] = $this->l('The config/settings.inc.php file was not found.'); $this->nextErrors[] = $this->l('The config/settings.inc.php file was not found.'); return false; } if (!defined('__PS_BASE_URI__')) { define('__PS_BASE_URI__', realpath(dirname($_SERVER['SCRIPT_NAME'])) . '/../../'); } if (!defined('_THEMES_DIR_')) { define('_THEMES_DIR_', __PS_BASE_URI__ . 'themes/'); } $oldversion = _PS_VERSION_; $versionCompare = version_compare(INSTALL_VERSION, $oldversion); if ($versionCompare == '-1') { $this->next = 'error'; $this->nextQuickInfo[] = sprintf($this->l('Current version: %1$s. Version to install: %2$s.'), $oldversion, INSTALL_VERSION); $this->nextErrors[] = sprintf($this->l('Current version: %1$s. Version to install: %2$s'), $oldversion, INSTALL_VERSION); $this->nextQuickInfo[] = $this->l('[ERROR] Version to install is too old.'); $this->nextErrors[] = $this->l('[ERROR] Version to install is too old.'); return false; } elseif ($versionCompare == 0) { $this->next = 'error'; $this->nextQuickInfo[] = $this->l(sprintf('You already have the %s version.', INSTALL_VERSION)); $this->nextErrors[] = $this->l(sprintf('You already have the %s version.', INSTALL_VERSION)); return false; } elseif ($versionCompare === false) { $this->next = 'error'; $this->nextQuickInfo[] = $this->l('There is no older version. Did you delete or rename the config/settings.inc.php file?'); $this->nextErrors[] = $this->l('There is no older version. Did you delete or rename the config/settings.inc.php file?'); return false; } //check DB access $this->db; error_reporting(E_ALL); $resultDB = Db::checkConnection(_DB_SERVER_, _DB_USER_, _DB_PASSWD_, _DB_NAME_); if ($resultDB !== 0) { // $logger->logError('Invalid database configuration.'); $this->next = 'error'; $this->nextQuickInfo[] = $this->l('Invalid database configuration'); $this->nextErrors[] = $this->l('Invalid database configuration'); return false; } //custom sql file creation $upgradeFiles = array(); $upgrade_dir_sql = INSTALL_PATH . '/upgrade/sql'; // if 1.4; if (!file_exists($upgrade_dir_sql)) { $upgrade_dir_sql = INSTALL_PATH . '/sql/upgrade'; } if (!file_exists($upgrade_dir_sql)) { $this->next = 'error'; $this->next_desc = $this->l('Unable to find upgrade directory in the installation path.'); return false; } if ($handle = opendir($upgrade_dir_sql)) { while (false !== ($file = readdir($handle))) { if ($file != '.' and $file != '..') { $upgradeFiles[] = str_replace(".sql", "", $file); } } closedir($handle); } if (empty($upgradeFiles)) { $this->next = 'error'; $this->nextQuickInfo[] = sprintf($this->l('Cannot find the SQL upgrade files. Please check that the %s folder is not empty.'), $upgrade_dir_sql); $this->nextErrors[] = sprintf($this->l('Cannot find the SQL upgrade files. Please check that the %s folder is not empty.'), $upgrade_dir_sql); // fail 31 return false; } natcasesort($upgradeFiles); $neededUpgradeFiles = array(); $arrayVersion = explode('.', $oldversion); $versionNumbers = count($arrayVersion); if ($versionNumbers != 4) { $arrayVersion = array_pad($arrayVersion, 4, '0'); } $oldversion = implode('.', $arrayVersion); foreach ($upgradeFiles as $version) { if (version_compare($version, $oldversion) == 1 && version_compare(INSTALL_VERSION, $version) != -1) { $neededUpgradeFiles[] = $version; } } if (strpos(INSTALL_VERSION, '.') === false) { $this->nextQuickInfo[] = sprintf($this->l('%s is not a valid version number.'), INSTALL_VERSION); $this->nextErrors[] = sprintf($this->l('%s is not a valid version number.'), INSTALL_VERSION); return false; } $sqlContentVersion = array(); if ($this->deactivateCustomModule) { require_once _PS_INSTALLER_PHP_UPGRADE_DIR_ . 'deactivate_custom_modules.php'; deactivate_custom_modules(); } if (version_compare(INSTALL_VERSION, '1.5.6.1', '=')) { $filename = _PS_INSTALLER_PHP_UPGRADE_DIR_ . 'migrate_orders.php'; $content = file_get_contents($filename); $str_old[] = '$values_order_detail = array();'; $str_old[] = '$values_order = array();'; $str_old[] = '$col_order_detail = array();'; $content = str_replace($str_old, '', $content); file_put_contents($filename, $content); } foreach ($neededUpgradeFiles as $version) { $file = $upgrade_dir_sql . DIRECTORY_SEPARATOR . $version . '.sql'; if (!file_exists($file)) { $this->next = 'error'; $this->nextQuickInfo[] = sprintf($this->l('Error while loading SQL upgrade file "%s.sql".'), $version); $this->nextErrors[] = sprintf($this->l('Error while loading SQL upgrade file "%s.sql".'), $version); return false; $logger->logError('Error while loading SQL upgrade file.'); } if (!($sqlContent = file_get_contents($file) . "\n")) { $this->next = 'error'; $this->nextQuickInfo[] = $this->l(sprintf('Error while loading SQL upgrade file %s.', $version)); $this->nextErrors[] = $this->l(sprintf('Error while loading sql SQL file %s.', $version)); return false; $logger->logError(sprintf('Error while loading sql upgrade file %s.', $version)); } $sqlContent = str_replace(array($filePrefix, $engineType), array(_DB_PREFIX_, $mysqlEngine), $sqlContent); $sqlContent = preg_split("/;\\s*[\r\n]+/", $sqlContent); $sqlContentVersion[$version] = $sqlContent; } //sql file execution global $requests, $warningExist; $requests = ''; $warningExist = false; // Configuration::loadConfiguration(); $request = ''; foreach ($sqlContentVersion as $upgrade_file => $sqlContent) { foreach ($sqlContent as $query) { $query = trim($query); if (!empty($query)) { /* If php code have to be executed */ if (strpos($query, '/* PHP:') !== false) { /* Parsing php code */ $pos = strpos($query, '/* PHP:') + strlen('/* PHP:'); $phpString = substr($query, $pos, strlen($query) - $pos - strlen(' */;')); $php = explode('::', $phpString); preg_match('/\\((.*)\\)/', $phpString, $pattern); $paramsString = trim($pattern[0], '()'); preg_match_all('/([^,]+),? ?/', $paramsString, $parameters); if (isset($parameters[1])) { $parameters = $parameters[1]; } else { $parameters = array(); } if (is_array($parameters)) { foreach ($parameters as &$parameter) { $parameter = str_replace('\'', '', $parameter); } } // reset phpRes to a null value $phpRes = null; /* Call a simple function */ if (strpos($phpString, '::') === false) { $func_name = str_replace($pattern[0], '', $php[0]); if (version_compare(INSTALL_VERSION, '1.5.5.0', '=') && $func_name == 'fix_download_product_feature_active') { continue; } if (!file_exists(_PS_INSTALLER_PHP_UPGRADE_DIR_ . strtolower($func_name) . '.php')) { $this->nextQuickInfo[] = '<div class="upgradeDbError">[ERROR] ' . $upgrade_file . ' PHP - missing file ' . $query . '</div>'; $this->nextErrors[] = '[ERROR] ' . $upgrade_file . ' PHP - missing file ' . $query; $warningExist = true; } else { require_once _PS_INSTALLER_PHP_UPGRADE_DIR_ . strtolower($func_name) . '.php'; $phpRes = call_user_func_array($func_name, $parameters); } } else { $func_name = array($php[0], str_replace($pattern[0], '', $php[1])); $this->nextQuickInfo[] = '<div class="upgradeDbError">[ERROR] ' . $upgrade_file . ' PHP - Object Method call is forbidden ( ' . $php[0] . '::' . str_replace($pattern[0], '', $php[1]) . ')</div>'; $this->nextErrors[] = '[ERROR] ' . $upgrade_file . ' PHP - Object Method call is forbidden (' . $php[0] . '::' . str_replace($pattern[0], '', $php[1]) . ')'; $warningExist = true; } if (isset($phpRes) && (is_array($phpRes) && !empty($phpRes['error'])) || $phpRes === false) { // $this->next = 'error'; $this->nextQuickInfo[] = ' <div class="upgradeDbError"> [ERROR] PHP ' . $upgrade_file . ' ' . $query . "\n" . ' ' . (empty($phpRes['error']) ? '' : $phpRes['error'] . "\n") . ' ' . (empty($phpRes['msg']) ? '' : ' - ' . $phpRes['msg'] . "\n") . ' </div>'; $this->nextErrors[] = ' [ERROR] PHP ' . $upgrade_file . ' ' . $query . "\n" . ' ' . (empty($phpRes['error']) ? '' : $phpRes['error'] . "\n") . ' ' . (empty($phpRes['msg']) ? '' : ' - ' . $phpRes['msg'] . "\n"); $warningExist = true; } else { $this->nextQuickInfo[] = '<div class="upgradeDbOk">[OK] PHP ' . $upgrade_file . ' : ' . $query . '</div>'; } if (isset($phpRes)) { unset($phpRes); } } else { if (strstr($query, 'CREATE TABLE') !== false) { $pattern = '/CREATE TABLE.*[`]*' . _DB_PREFIX_ . '([^`]*)[`]*\\s\\(/'; preg_match($pattern, $query, $matches); if (isset($matches[1]) && $matches[1]) { $drop = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . $matches[1] . '`;'; $result = $this->db->execute($drop, false); if ($result) { $this->nextQuickInfo[] = '<div class="upgradeDbOk">' . sprintf($this->l('[DROP] SQL %s table has been dropped.'), '`' . _DB_PREFIX_ . $matches[1] . '`') . '</div>'; } } } $result = $this->db->execute($query, false); if (!$result) { $error = $this->db->getMsgError(); $error_number = $this->db->getNumberError(); $this->nextQuickInfo[] = ' <div class="upgradeDbError"> [WARNING] SQL ' . $upgrade_file . ' ' . $error_number . ' in ' . $query . ': ' . $error . '</div>'; $duplicates = array('1050', '1054', '1060', '1061', '1062', '1091'); if (!in_array($error_number, $duplicates)) { $this->nextErrors[] = 'SQL ' . $upgrade_file . ' ' . $error_number . ' in ' . $query . ': ' . $error; $warningExist = true; } } else { $this->nextQuickInfo[] = '<div class="upgradeDbOk">[OK] SQL ' . $upgrade_file . ' ' . $query . '</div>'; } } if (isset($query)) { unset($query); } } } } if ($this->next == 'error') { $this->next_desc = $this->l('An error happened during the database upgrade.'); return false; } $this->nextQuickInfo[] = $this->l('Database upgrade OK'); // no error ! # At this point, database upgrade is over. # Now we need to add all previous missing settings items, and reset cache and compile directories $this->writeNewSettings(); // Settings updated, compile and cache directories must be emptied $arrayToClean[] = $this->prodRootDir . '/tools/smarty/cache/'; $arrayToClean[] = $this->prodRootDir . '/tools/smarty/compile/'; $arrayToClean[] = $this->prodRootDir . '/tools/smarty_v2/cache/'; $arrayToClean[] = $this->prodRootDir . '/tools/smarty_v2/compile/'; if (version_compare(INSTALL_VERSION, '1.5.0.0', '>')) { $arrayToClean[] = $this->prodRootDir . '/cache/smarty/cache/'; $arrayToClean[] = $this->prodRootDir . '/cache/smarty/compile/'; } foreach ($arrayToClean as $dir) { if (!file_exists($dir)) { $this->nextQuickInfo[] = sprintf($this->l('[SKIP] directory "%s" does not exist and cannot be emptied.'), str_replace($this->prodRootDir, '', $dir)); continue; } else { foreach (scandir($dir) as $file) { if ($file[0] != '.' && $file != 'index.php' && $file != '.htaccess') { if (is_file($dir . $file)) { unlink($dir . $file); } elseif (is_dir($dir . $file . DIRECTORY_SEPARATOR)) { self::deleteDirectory($dir . $file . DIRECTORY_SEPARATOR); } $this->nextQuickInfo[] = sprintf($this->l('[CLEANING CACHE] File %s removed'), $file); } } } } if (version_compare(INSTALL_VERSION, '1.5.0.0', '>')) { Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'configuration` SET `name` = \'PS_LEGACY_IMAGES\' WHERE name LIKE \'0\' AND `value` = 1'); Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'configuration` SET `value` = 0 WHERE `name` LIKE \'PS_LEGACY_IMAGES\''); if (Db::getInstance()->getValue('SELECT COUNT(id_product_download) FROM `' . _DB_PREFIX_ . 'product_download` WHERE `active` = 1') > 0) { Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'configuration` SET `value` = 1 WHERE `name` LIKE \'PS_VIRTUAL_PROD_FEATURE_ACTIVE\''); } if (defined('_THEME_NAME_') && $this->updateDefaultTheme && preg_match('#(default|prestashop|default-boostrap)$#', _THEME_NAME_)) { $separator = addslashes(DIRECTORY_SEPARATOR); $file = _PS_ROOT_DIR_ . $separator . 'themes' . $separator . _THEME_NAME_ . $separator . 'cache' . $separator; if (file_exists($file)) { foreach (scandir($file) as $cache) { if ($cache[0] != '.' && $cache != 'index.php' && $cache != '.htaccess' && file_exists($file . $cache) && !is_dir($file . $cache)) { if (file_exists($dir . $cache)) { unlink($file . $cache); } } } } } if (version_compare(_PS_VERSION_, '1.5.0.0', '<=')) { $dir = _PS_ROOT_DIR_ . '/controllers/'; if (file_exists($dir)) { foreach (scandir($dir) as $file) { if (!is_dir($file) && $file[0] != '.' && $file != 'index.php' && $file != '.htaccess') { if (file_exists($dir . basename(str_replace('.php', '', $file) . '.php'))) { unlink($dir . basename($file)); } } } } $dir = _PS_ROOT_DIR_ . '/classes/'; foreach (self::$classes14 as $class) { if (file_exists($dir . basename($class) . '.php')) { unlink($dir . basename($class) . '.php'); } } $dir = _PS_ADMIN_DIR_ . '/tabs/'; if (file_exists($dir)) { foreach (scandir($dir) as $file) { if (!is_dir($file) && $file[0] != '.' && $file != 'index.php' && $file != '.htaccess') { if (file_exists($dir . basename(str_replace('.php', '', $file) . '.php'))) { unlink($dir . basename($file)); } } } } } if (version_compare($this->install_version, '1.5.4.0', '>=')) { // Upgrade languages if (!defined('_PS_TOOL_DIR_')) { define('_PS_TOOL_DIR_', _PS_ROOT_DIR_ . '/tools/'); } if (!defined('_PS_TRANSLATIONS_DIR_')) { define('_PS_TRANSLATIONS_DIR_', _PS_ROOT_DIR_ . '/translations/'); } if (!defined('_PS_MODULES_DIR_')) { define('_PS_MODULES_DIR_', _PS_ROOT_DIR_ . '/modules/'); } if (!defined('_PS_MAILS_DIR_')) { define('_PS_MAILS_DIR_', _PS_ROOT_DIR_ . '/mails/'); } $langs = Db::getInstance()->executeS('SELECT * FROM `' . _DB_PREFIX_ . 'lang` WHERE `active` = 1'); require_once _PS_TOOL_DIR_ . 'tar/Archive_Tar.php'; if (is_array($langs)) { foreach ($langs as $lang) { $lang_pack = Tools14::jsonDecode(Tools14::file_get_contents('http' . (extension_loaded('openssl') ? 's' : '') . '://www.prestashop.com/download/lang_packs/get_language_pack.php?version=' . $this->install_version . '&iso_lang=' . $lang['iso_code'])); if (!$lang_pack) { continue; } elseif ($content = Tools14::file_get_contents('http' . (extension_loaded('openssl') ? 's' : '') . '://translations.prestashop.com/download/lang_packs/gzip/' . $lang_pack->version . '/' . $lang['iso_code'] . '.gzip')) { $file = _PS_TRANSLATIONS_DIR_ . $lang['iso_code'] . '.gzip'; if ((bool) file_put_contents($file, $content)) { $gz = new Archive_Tar($file, true); $files_list = $gz->listContent(); if (!$this->keepMails) { $files_listing = array(); foreach ($files_list as $i => $file) { if (preg_match('/^mails\\/' . $lang['iso_code'] . '\\/.*/', $file['filename'])) { unset($files_list[$i]); } } foreach ($files_list as $file) { if (isset($file['filename']) && is_string($file['filename'])) { $files_listing[] = $file['filename']; } } if (is_array($files_listing)) { $gz->extractList($files_listing, _PS_TRANSLATIONS_DIR_ . '../', ''); } } else { $gz->extract(_PS_TRANSLATIONS_DIR_ . '../', false); } } } } } } if (version_compare($this->install_version, '1.6.0.0', '>')) { if (version_compare($this->install_version, '1.6.1.0', '>=')) { require_once _PS_ROOT_DIR_ . '/Core/Foundation/Database/Core_Foundation_Database_EntityInterface.php'; } if (file_exists(_PS_ROOT_DIR_ . '/classes/Tools.php')) { require_once _PS_ROOT_DIR_ . '/classes/Tools.php'; } if (!class_exists('Tools2', false) and class_exists('ToolsCore')) { eval('class Tools2 extends ToolsCore{}'); } if (class_exists('Tools2') && method_exists('Tools2', 'generateHtaccess')) { $url_rewrite = (bool) Db::getInstance()->getvalue('SELECT `value` FROM `' . _DB_PREFIX_ . 'configuration` WHERE name=\'PS_REWRITING_SETTINGS\''); if (!defined('_MEDIA_SERVER_1_')) { define('_MEDIA_SERVER_1_', ''); } if (!defined('_MEDIA_SERVER_2_')) { define('_MEDIA_SERVER_2_', ''); } if (!defined('_MEDIA_SERVER_3_')) { define('_MEDIA_SERVER_3_', ''); } if (!defined('_PS_USE_SQL_SLAVE_')) { define('_PS_USE_SQL_SLAVE_', false); } if (file_exists(_PS_ROOT_DIR_ . '/classes/ObjectModel.php')) { require_once _PS_ROOT_DIR_ . '/classes/ObjectModel.php'; } if (!class_exists('ObjectModel', false) and class_exists('ObjectModelCore')) { eval('abstract class ObjectModel extends ObjectModelCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/Configuration.php')) { require_once _PS_ROOT_DIR_ . '/classes/Configuration.php'; } if (!class_exists('Configuration', false) and class_exists('ConfigurationCore')) { eval('class Configuration extends ConfigurationCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/cache/Cache.php')) { require_once _PS_ROOT_DIR_ . '/classes/cache/Cache.php'; } if (!class_exists('Cache', false) and class_exists('CacheCore')) { eval('abstract class Cache extends CacheCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/PrestaShopCollection.php')) { require_once _PS_ROOT_DIR_ . '/classes/PrestaShopCollection.php'; } if (!class_exists('PrestaShopCollection', false) and class_exists('PrestaShopCollectionCore')) { eval('class PrestaShopCollection extends PrestaShopCollectionCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/shop/ShopUrl.php')) { require_once _PS_ROOT_DIR_ . '/classes/shop/ShopUrl.php'; } if (!class_exists('ShopUrl', false) and class_exists('ShopUrlCore')) { eval('class ShopUrl extends ShopUrlCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/shop/Shop.php')) { require_once _PS_ROOT_DIR_ . '/classes/shop/Shop.php'; } if (!class_exists('Shop', false) and class_exists('ShopCore')) { eval('class Shop extends ShopCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/Translate.php')) { require_once _PS_ROOT_DIR_ . '/classes/Translate.php'; } if (!class_exists('Translate', false) and class_exists('TranslateCore')) { eval('class Translate extends TranslateCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/module/Module.php')) { require_once _PS_ROOT_DIR_ . '/classes/module/Module.php'; } if (!class_exists('Module', false) and class_exists('ModuleCore')) { eval('class Module extends ModuleCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/Validate.php')) { require_once _PS_ROOT_DIR_ . '/classes/Validate.php'; } if (!class_exists('Validate', false) and class_exists('ValidateCore')) { eval('class Validate extends ValidateCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/Language.php')) { require_once _PS_ROOT_DIR_ . '/classes/Language.php'; } if (!class_exists('Language', false) and class_exists('LanguageCore')) { eval('class Language extends LanguageCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/Tab.php')) { require_once _PS_ROOT_DIR_ . '/classes/Tab.php'; } if (!class_exists('Tab', false) and class_exists('TabCore')) { eval('class Tab extends TabCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/Dispatcher.php')) { require_once _PS_ROOT_DIR_ . '/classes/Dispatcher.php'; } if (!class_exists('Dispatcher', false) and class_exists('DispatcherCore')) { eval('class Dispatcher extends DispatcherCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/Hook.php')) { require_once _PS_ROOT_DIR_ . '/classes/Hook.php'; } if (!class_exists('Hook', false) and class_exists('HookCore')) { eval('class Hook extends HookCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/Context.php')) { require_once _PS_ROOT_DIR_ . '/classes/Context.php'; } if (!class_exists('Context', false) and class_exists('ContextCore')) { eval('class Context extends ContextCore{}'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/Group.php')) { require_once _PS_ROOT_DIR_ . '/classes/Group.php'; } if (!class_exists('Group', false) and class_exists('GroupCore')) { eval('class Group extends GroupCore{}'); } Tools2::generateHtaccess(null, $url_rewrite); } } if (version_compare($this->install_version, '1.6.0.2', '>')) { $path = $this->adminDir . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'controllers' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'header.tpl'; if (file_exists($path)) { unlink($path); } } } if (file_exists(_PS_ROOT_DIR_ . '/cache/class_index.php')) { unlink(_PS_ROOT_DIR_ . '/cache/class_index.php'); } // Clear XML files if (file_exists(_PS_ROOT_DIR_ . '/config/xml/blog-fr.xml')) { unlink(_PS_ROOT_DIR_ . '/config/xml/blog-fr.xml'); } if (file_exists(_PS_ROOT_DIR_ . '/config/xml/default_country_modules_list.xml')) { unlink(_PS_ROOT_DIR_ . '/config/xml/default_country_modules_list.xml'); } if (file_exists(_PS_ROOT_DIR_ . '/config/xml/modules_list.xml')) { unlink(_PS_ROOT_DIR_ . '/config/xml/modules_list.xml'); } if (file_exists(_PS_ROOT_DIR_ . '/config/xml/modules_native_addons.xml')) { unlink(_PS_ROOT_DIR_ . '/config/xml/modules_native_addons.xml'); } if (file_exists(_PS_ROOT_DIR_ . '/config/xml/must_have_modules_list.xml')) { unlink(_PS_ROOT_DIR_ . '/config/xml/must_have_modules_list.xml'); } if (file_exists(_PS_ROOT_DIR_ . '/config/xml/tab_modules_list.xml')) { unlink(_PS_ROOT_DIR_ . '/config/xml/tab_modules_list.xml'); } if (file_exists(_PS_ROOT_DIR_ . '/config/xml/trusted_modules_list.xml')) { unlink(_PS_ROOT_DIR_ . '/config/xml/trusted_modules_list.xml'); } if (file_exists(_PS_ROOT_DIR_ . '/config/xml/untrusted_modules_list.xml')) { unlink(_PS_ROOT_DIR_ . '/config/xml/untrusted_modules_list.xml'); } if ($this->deactivateCustomModule) { $exist = Db::getInstance()->getValue('SELECT `id_configuration` FROM `' . _DB_PREFIX_ . 'configuration` WHERE `name` LIKE \'PS_DISABLE_OVERRIDES\''); if ($exist) { Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'configuration` SET value = 1 WHERE `name` LIKE \'PS_DISABLE_OVERRIDES\''); } else { Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'configuration` (name, value, date_add, date_upd) VALUES ("PS_DISABLE_OVERRIDES", 1, NOW(), NOW())'); } if (file_exists(_PS_ROOT_DIR_ . '/classes/PrestaShopAutoload.php')) { require_once _PS_ROOT_DIR_ . '/classes/PrestaShopAutoload.php'; } if (version_compare($this->install_version, '1.6.0.0', '>') && class_exists('PrestaShopAutoload') && method_exists('PrestaShopAutoload', 'generateIndex')) { PrestaShopAutoload::getInstance()->_include_override_path = false; PrestaShopAutoload::getInstance()->generateIndex(); } } if ($this->changeToDefaultTheme) { if (version_compare(INSTALL_VERSION, '1.6.0.0', '>')) { Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'shop` SET id_theme = (SELECT id_theme FROM `' . _DB_PREFIX_ . 'theme` WHERE name LIKE \'default-bootstrap\')'); Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'theme` WHERE name LIKE \'default\' OR name LIKE \'prestashop\''); } elseif (version_compare(INSTALL_VERSION, '1.5.0.0', '>')) { Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'shop` SET id_theme = (SELECT id_theme FROM `' . _DB_PREFIX_ . 'theme` WHERE name LIKE \'default\')'); Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'theme` WHERE name LIKE \'prestashop\''); } } // delete cache filesystem if activated if (defined('_PS_CACHE_ENABLED_') && _PS_CACHE_ENABLED_) { $depth = (int) $this->db->getValue('SELECT value FROM ' . _DB_PREFIX_ . 'configuration WHERE name = "PS_CACHEFS_DIRECTORY_DEPTH"'); if ($depth) { if (!defined('_PS_CACHEFS_DIRECTORY_')) { define('_PS_CACHEFS_DIRECTORY_', $this->prodRootDir . '/cache/cachefs/'); } self::deleteDirectory(_PS_CACHEFS_DIRECTORY_, false); if (class_exists('CacheFs', false)) { self::createCacheFsDirectories((int) $depth); } } } $this->db->execute('UPDATE `' . _DB_PREFIX_ . 'configuration` SET value="0" WHERE name = "PS_HIDE_OPTIMIZATION_TIS"', false); $this->db->execute('UPDATE `' . _DB_PREFIX_ . 'configuration` SET value="1" WHERE name = "PS_NEED_REBUILD_INDEX"', false); $this->db->execute('UPDATE `' . _DB_PREFIX_ . 'configuration` SET value="' . INSTALL_VERSION . '" WHERE name = "PS_VERSION_DB"', false); if ($warningExist) { $this->warning_exists = true; $this->nextQuickInfo[] = $this->l('Warning detected during upgrade.'); $this->nextErrors[] = $this->l('Warning detected during upgrade.'); $this->next_desc = $this->l('Warning detected during upgrade.'); } else { $this->next_desc = $this->l('Database upgrade completed'); } return true; }