diff --git a/.travis.yml b/.travis.yml index 14d30ed3c..e1ae023fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,9 @@ env: CHANNEL=major - VERSION=1.6.1.10 CHANNEL=minor + # Check how the upgrade behaves with the latest PrestaShop + - VERSION=latest + CHANNEL=minor cache: directories: @@ -34,8 +37,10 @@ script: # Back office -> HTTP code 200 expected - bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/admin-dev/index.php)" == "200" ]' - # Rollback - - docker exec -u www-data -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-rollback.php --dir="admin-dev" --backup=`docker exec -ti prestashop_autoupgrade bash -c "ls -td -- /var/www/html/admin-dev/autoupgrade/backup/*/ | head -n 1 | cut -d'/' -f8 | tr -d '\n'"` + # Rollback (only when expect a completed upgrade) + - if [ $VERSION != "latest" ]; then + docker exec -u www-data -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-rollback.php --dir="admin-dev" --backup=`docker exec -ti prestashop_autoupgrade bash -c "ls -td -- /var/www/html/admin-dev/autoupgrade/backup/*/ | head -n 1 | cut -d'/' -f8 | tr -d '\n'"`; + fi # Front office -> HTTP code 200 expected (no maintenance) - bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/index.php)" == "200" ]' # Back office -> HTTP code 200 expected diff --git a/AdminSelfUpgrade.gif b/AdminSelfUpgrade.gif index 981356908..98d0bc84a 100755 Binary files a/AdminSelfUpgrade.gif and b/AdminSelfUpgrade.gif differ diff --git a/AdminSelfUpgrade.php b/AdminSelfUpgrade.php index 83a12bbc0..30fdee806 100755 --- a/AdminSelfUpgrade.php +++ b/AdminSelfUpgrade.php @@ -19,11 +19,11 @@ * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * -* @author PrestaShop SA -* @copyright 2007-2016 PrestaShop SA -* @version Release: $Revision: 11834 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA +* @author PrestaShop SA +* @copyright 2007-2016 PrestaShop SA +* @version Release: $Revision: 11834 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA */ use PrestaShop\Module\AutoUpgrade\AjaxResponse; @@ -55,11 +55,11 @@ class AdminSelfUpgrade extends AdminController /** * Initialized in initPath(). */ - public $autoupgradePath = null; - public $downloadPath = null; - public $backupPath = null; - public $latestPath = null; - public $tmpPath = null; + public $autoupgradePath; + public $downloadPath; + public $backupPath; + public $latestPath; + public $tmpPath; /** * autoupgradeDir. @@ -71,18 +71,18 @@ class AdminSelfUpgrade extends AdminController public $prodRootDir = ''; public $adminDir = ''; - public $keepImages = null; - public $updateDefaultTheme = null; - public $changeToDefaultTheme = null; - public $keepMails = null; - public $manualMode = null; - public $deactivateCustomModule = null; + public $keepImages; + public $updateDefaultTheme; + public $changeToDefaultTheme; + public $keepMails; + public $manualMode; + public $deactivateCustomModule; public static $classes14 = array('Cache', 'CacheFS', 'CarrierModule', 'Db', 'FrontController', 'Helper', 'ImportModule', - 'MCached', 'Module', 'ModuleGraph', 'ModuleGraphEngine', 'ModuleGrid', 'ModuleGridEngine', - 'MySQL', 'Order', 'OrderDetail', 'OrderDiscount', 'OrderHistory', 'OrderMessage', 'OrderReturn', - 'OrderReturnState', 'OrderSlip', 'OrderState', 'PDF', 'RangePrice', 'RangeWeight', 'StockMvt', - 'StockMvtReason', 'SubDomain', 'Shop', 'Tax', 'TaxRule', 'TaxRulesGroup', 'WebserviceKey', 'WebserviceRequest', '', ); + 'MCached', 'Module', 'ModuleGraph', 'ModuleGraphEngine', 'ModuleGrid', 'ModuleGridEngine', + 'MySQL', 'Order', 'OrderDetail', 'OrderDiscount', 'OrderHistory', 'OrderMessage', 'OrderReturn', + 'OrderReturnState', 'OrderSlip', 'OrderState', 'PDF', 'RangePrice', 'RangeWeight', 'StockMvt', + 'StockMvtReason', 'SubDomain', 'Shop', 'Tax', 'TaxRule', 'TaxRulesGroup', 'WebserviceKey', 'WebserviceRequest', '', ); public static $maxBackupFileSize = 15728640; // 15 Mo @@ -213,7 +213,7 @@ public function init() ); // If you have defined this somewhere, you know what you do - /* load options from configuration if we're not in ajax mode */ + // load options from configuration if we're not in ajax mode if (!$this->ajax) { $upgrader = $this->upgradeContainer->getUpgrader(); $this->upgradeContainer->getCookie()->create( @@ -356,7 +356,7 @@ public function postProcess() public function display() { - /* Make sure the user has configured the upgrade options, or set default values */ + // Make sure the user has configured the upgrade options, or set default values $configuration_keys = array( 'PS_AUTOUP_UPDATE_DEFAULT_THEME' => 1, 'PS_AUTOUP_CHANGE_DEFAULT_THEME' => 0, @@ -428,6 +428,6 @@ public function display() */ public function trans($id, array $parameters = array(), $domain = null, $locale = null) { - return (new \PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator(get_class()))->trans($id, $parameters, $domain, $locale); + return (new \PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator(__CLASS__))->trans($id, $parameters, $domain, $locale); } } diff --git a/ajax-upgradetabconfig.php b/ajax-upgradetabconfig.php index cf5ade991..1e6c2bfa2 100644 --- a/ajax-upgradetabconfig.php +++ b/ajax-upgradetabconfig.php @@ -40,7 +40,7 @@ */ function autoupgrade_init_container($callerFilePath) { - if (php_sapi_name() === 'cli') { + if (PHP_SAPI === 'cli') { $_POST['dir'] = getopt('', array('dir:'))['dir']; } diff --git a/autoupgrade.php b/autoupgrade.php index 439c1d18b..a751e89a6 100644 --- a/autoupgrade.php +++ b/autoupgrade.php @@ -31,7 +31,7 @@ public function __construct() $this->name = 'autoupgrade'; $this->tab = 'administration'; $this->author = 'PrestaShop'; - $this->version = '4.5.1'; + $this->version = '4.6.0'; $this->need_instance = 1; $this->bootstrap = true; @@ -57,6 +57,7 @@ public function install() { if (50600 > PHP_VERSION_ID) { $this->_errors[] = $this->trans('This version of 1-click upgrade requires PHP 5.6 to work properly. Please upgrade your server configuration.', array(), 'Modules.Autoupgrade.Admin'); + return false; } @@ -64,7 +65,7 @@ public function install() return false; } - /* Before creating a new tab "AdminSelfUpgrade" we need to remove any existing "AdminUpgrade" tab (present in v1.4.4.0 and v1.4.4.1) */ + // Before creating a new tab "AdminSelfUpgrade" we need to remove any existing "AdminUpgrade" tab (present in v1.4.4.0 and v1.4.4.1) if ($id_tab = Tab::getIdFromClassName('AdminUpgrade')) { $tab = new Tab((int) $id_tab); if (!$tab->delete()) { @@ -72,7 +73,7 @@ public function install() } } - /* If the "AdminSelfUpgrade" tab does not exist yet, create it */ + // If the "AdminSelfUpgrade" tab does not exist yet, create it if (!$id_tab = Tab::getIdFromClassName('AdminSelfUpgrade')) { $tab = new Tab(); $tab->class_name = 'AdminSelfUpgrade'; @@ -91,35 +92,35 @@ public function install() $tab = new Tab((int) $id_tab); } - /* Update the "AdminSelfUpgrade" tab id in database or exit */ + // Update the "AdminSelfUpgrade" tab id in database or exit if (Validate::isLoadedObject($tab)) { Configuration::updateValue('PS_AUTOUPDATE_MODULE_IDTAB', (int) $tab->id); } else { return $this->_abortInstall($this->trans('Unable to load the "AdminSelfUpgrade" tab', array(), 'Modules.Autoupgrade.Admin')); } - /* Check that the 1-click upgrade working directory is existing or create it */ + // Check that the 1-click upgrade working directory is existing or create it $autoupgrade_dir = _PS_ADMIN_DIR_ . DIRECTORY_SEPARATOR . 'autoupgrade'; if (!file_exists($autoupgrade_dir) && !@mkdir($autoupgrade_dir)) { return $this->_abortInstall($this->trans('Unable to create the directory "%s"', array($autoupgrade_dir), 'Modules.Autoupgrade.Admin')); } - /* Make sure that the 1-click upgrade working directory is writeable */ + // Make sure that the 1-click upgrade working directory is writeable if (!is_writable($autoupgrade_dir)) { return $this->_abortInstall($this->trans('Unable to write in the directory "%s"', array($autoupgrade_dir), 'Modules.Autoupgrade.Admin')); } - /* If a previous version of ajax-upgradetab.php exists, delete it */ + // If a previous version of ajax-upgradetab.php exists, delete it if (file_exists($autoupgrade_dir . DIRECTORY_SEPARATOR . 'ajax-upgradetab.php')) { @unlink($autoupgrade_dir . DIRECTORY_SEPARATOR . 'ajax-upgradetab.php'); } - /* Then, try to copy the newest version from the module's directory */ + // Then, try to copy the newest version from the module's directory if (!@copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ajax-upgradetab.php', $autoupgrade_dir . DIRECTORY_SEPARATOR . 'ajax-upgradetab.php')) { return $this->_abortInstall($this->trans('Unable to copy ajax-upgradetab.php in %s', array($autoupgrade_dir), 'Modules.Autoupgrade.Admin')); } - /* Make sure that the XML config directory exists */ + // Make sure that the XML config directory exists if (!file_exists(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'xml') && !@mkdir(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'xml', 0775)) { return $this->_abortInstall($this->trans('Unable to create the directory "%s"', array(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'xml'), 'Modules.Autoupgrade.Admin')); @@ -127,7 +128,7 @@ public function install() @chmod(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'xml', 0775); } - /* Create a dummy index.php file in the XML config directory to avoid directory listing */ + // Create a dummy index.php file in the XML config directory to avoid directory listing if (!file_exists(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'index.php') && (file_exists(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'index.php') && !@copy(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'index.php', _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'xml' . DIRECTORY_SEPARATOR . 'index.php'))) { @@ -139,13 +140,13 @@ public function install() public function uninstall() { - /* Delete the 1-click upgrade Back-office tab */ + // Delete the 1-click upgrade Back-office tab if ($id_tab = Tab::getIdFromClassName('AdminSelfUpgrade')) { $tab = new Tab((int) $id_tab); $tab->delete(); } - /* Remove the 1-click upgrade working directory */ + // Remove the 1-click upgrade working directory self::_removeDirectory(_PS_ADMIN_DIR_ . DIRECTORY_SEPARATOR . 'autoupgrade'); return parent::uninstall(); @@ -203,7 +204,8 @@ public function trans($id, array $parameters = array(), $domain = null, $locale { require_once _PS_ROOT_DIR_ . '/modules/autoupgrade/classes/UpgradeTools/Translator.php'; - $translator = new \PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator(get_class()); + $translator = new \PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator(__CLASS__); + return $translator->trans($id, $parameters, $domain, $locale); } } diff --git a/classes/AjaxResponse.php b/classes/AjaxResponse.php index a3aa79a21..71bf23023 100644 --- a/classes/AjaxResponse.php +++ b/classes/AjaxResponse.php @@ -123,9 +123,7 @@ public function getJson() return json_encode($this->getResponse()); } - /* - * GETTERS - */ + // GETTERS public function getError() { @@ -157,9 +155,7 @@ public function getUpgradeConfiguration() return $this->upgradeConfiguration; } - /* - * SETTERS - */ + // SETTERS public function setError($error) { diff --git a/classes/BackupFinder.php b/classes/BackupFinder.php index 42b1292cf..cad8dde6b 100644 --- a/classes/BackupFinder.php +++ b/classes/BackupFinder.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade; class BackupFinder diff --git a/classes/ChannelInfo.php b/classes/ChannelInfo.php index cd615cc13..1b1fb1fe3 100644 --- a/classes/ChannelInfo.php +++ b/classes/ChannelInfo.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; diff --git a/classes/ConfigurationTest.php b/classes/ConfigurationTest.php index d4cc9302b..0147b81c6 100755 --- a/classes/ConfigurationTest.php +++ b/classes/ConfigurationTest.php @@ -48,7 +48,7 @@ public static function run($ptr, $arg = 0) // Misc functions public static function test_phpversion() { - return version_compare(substr(phpversion(), 0, 3), '5.4', '>='); + return version_compare(substr(PHP_VERSION, 0, 3), '5.4', '>='); } public static function test_mysql_support() diff --git a/classes/Log/LegacyLogger.php b/classes/Log/LegacyLogger.php index 7ff2772d5..479180220 100644 --- a/classes/Log/LegacyLogger.php +++ b/classes/Log/LegacyLogger.php @@ -40,7 +40,7 @@ class LegacyLogger extends Logger /** * @var resource|null|false File descriptor of the log file */ - protected $fd = null; + protected $fd; public function __construct($fileName = null) { diff --git a/classes/Parameters/UpgradeConfiguration.php b/classes/Parameters/UpgradeConfiguration.php index c2ddd7313..f2d40b71a 100644 --- a/classes/Parameters/UpgradeConfiguration.php +++ b/classes/Parameters/UpgradeConfiguration.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade\Parameters; use Doctrine\Common\Collections\ArrayCollection; diff --git a/classes/PrestashopConfiguration.php b/classes/PrestashopConfiguration.php index 566fec8b2..ffb1f53f9 100644 --- a/classes/PrestashopConfiguration.php +++ b/classes/PrestashopConfiguration.php @@ -33,7 +33,7 @@ class PrestashopConfiguration { // Variables used for cache - private $moduleVersion = null; + private $moduleVersion; private $allowed_array = array(); // Variables from main class @@ -68,7 +68,7 @@ public function getCompliancyResults() 'shop_deactivated' => (!Configuration::get('PS_SHOP_ENABLE') || (isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], array('127.0.0.1', 'localhost')))), 'cache_deactivated' => !(defined('_PS_CACHE_ENABLED_') && _PS_CACHE_ENABLED_), 'module_version_ok' => $this->checkAutoupgradeLastVersion($this->getUpgrader()->autoupgrade_last_version), - )); + )); } return $this->allowed_array; @@ -79,7 +79,7 @@ public function getCompliancyResults() */ public function getModuleVersion() { - if (!is_null($this->moduleVersion)) { + if (null !== $this->moduleVersion) { return $this->moduleVersion; } @@ -104,6 +104,7 @@ public function getPrestaShopVersion() $files = array( $this->psRootDir . '/config/settings.inc.php', $this->psRootDir . '/config/autoload.php', + $this->psRootDir . '/app/AppKernel.php', ); foreach ($files as $file) { $version = $this->findPrestaShopVersionInFile(file_get_contents($file)); @@ -153,10 +154,16 @@ protected function getRootWritableDetails() public function findPrestaShopVersionInFile($content) { $matches = array(); + // Example: define('_PS_VERSION_', '1.7.3.4'); if (1 === preg_match("/define\([\"']_PS_VERSION_[\"'], [\"'](?[0-9.]+)[\"']\)/", $content, $matches)) { return $matches['version']; } + // Example: const VERSION = '1.7.6.0'; + if (1 === preg_match("/const VERSION = [\"'](?[0-9.]+)[\"'];/", $content, $matches)) { + return $matches['version']; + } + return false; } } diff --git a/classes/State.php b/classes/State.php index fcec2e2df..f1551c6f7 100644 --- a/classes/State.php +++ b/classes/State.php @@ -33,17 +33,17 @@ class State { private $install_version; // Destination version of PrestaShop - private $backupName = null; - private $backupFilesFilename = null; - private $backupDbFilename = null; - private $restoreName = null; - private $restoreFilesFilename = null; + private $backupName; + private $backupFilesFilename; + private $backupDbFilename; + private $restoreName; + private $restoreFilesFilename; private $restoreDbFilenames = array(); // STEP BackupDb - private $backup_lines = null; - private $backup_loop_limit = null; - private $backup_table = null; + private $backup_lines; + private $backup_loop_limit; + private $backup_table; /** * Int during BackupDb, allowing the script to increent the number of different file names @@ -58,15 +58,15 @@ class State * * @var array|null File containing sample files to be deleted */ - private $removeList = null; + private $removeList; /** * @var string|null File containing files to be upgraded */ - private $fileToUpgrade = null; + private $fileToUpgrade; /** * @var string|null File containing modules to be upgraded */ - private $modulesToUpgrade = null; + private $modulesToUpgrade; /** * installedLanguagesIso is an array of iso_code of each installed languages. @@ -155,9 +155,7 @@ function ($v) { return $v['iso_code']; }, $this->setBackupName($backupName); } - /* - * GETTERS - */ + // GETTERS public function getInstallVersion() { return $this->install_version; @@ -233,9 +231,7 @@ public function getWarningExists() return $this->warning_exists; } - /* - * SETTERS - */ + // SETTERS public function setInstallVersion($install_version) { $this->install_version = $install_version; diff --git a/classes/TaskRunner/AbstractTask.php b/classes/TaskRunner/AbstractTask.php index c01de1879..11c4b2227 100644 --- a/classes/TaskRunner/AbstractTask.php +++ b/classes/TaskRunner/AbstractTask.php @@ -103,7 +103,7 @@ public function getResponse() private function checkTaskMayRun() { - /* PrestaShop demo mode */ + // PrestaShop demo mode if (defined('_PS_MODE_DEMO_') && _PS_MODE_DEMO_) { return; } diff --git a/classes/TaskRunner/Miscellaneous/UpdateConfig.php b/classes/TaskRunner/Miscellaneous/UpdateConfig.php index 2cc68da89..1e762435f 100644 --- a/classes/TaskRunner/Miscellaneous/UpdateConfig.php +++ b/classes/TaskRunner/Miscellaneous/UpdateConfig.php @@ -51,7 +51,7 @@ public function run() $config['channel'] = $request['channel']; $config['archive.filename'] = Upgrader::DEFAULT_FILENAME; } - if (isset($request['private_release_link']) && isset($request['private_release_md5'])) { + if (isset($request['private_release_link'], $request['private_release_md5'])) { $config['channel'] = 'private'; $config['private_release_link'] = $request['private_release_link']; $config['private_release_md5'] = $request['private_release_md5']; diff --git a/classes/TaskRunner/Rollback/RestoreDb.php b/classes/TaskRunner/Rollback/RestoreDb.php index c23c039bf..ee08898d5 100644 --- a/classes/TaskRunner/Rollback/RestoreDb.php +++ b/classes/TaskRunner/Rollback/RestoreDb.php @@ -147,7 +147,7 @@ public function run() } } - // @todo : error if listQuery is not an array (that can happen if toRestoreQueryList is empty for example) + /** @todo : error if listQuery is not an array (that can happen if toRestoreQueryList is empty for example) */ $time_elapsed = time() - $startTime; if (is_array($listQuery) && count($listQuery) > 0) { $this->container->getDb()->execute('SET SESSION sql_mode = \'\''); diff --git a/classes/TaskRunner/Upgrade/BackupDb.php b/classes/TaskRunner/Upgrade/BackupDb.php index dbd92b778..5ee251d50 100644 --- a/classes/TaskRunner/Upgrade/BackupDb.php +++ b/classes/TaskRunner/Upgrade/BackupDb.php @@ -66,10 +66,10 @@ public function run() $ignore_stats_table = array(); if (!$psBackupAll) { $ignore_stats_table = array(_DB_PREFIX_ . 'connections', - _DB_PREFIX_ . 'connections_page', - _DB_PREFIX_ . 'connections_source', - _DB_PREFIX_ . 'guest', - _DB_PREFIX_ . 'statssearch', ); + _DB_PREFIX_ . 'connections_page', + _DB_PREFIX_ . 'connections_source', + _DB_PREFIX_ . 'guest', + _DB_PREFIX_ . 'statssearch', ); } // INIT LOOP @@ -91,7 +91,7 @@ public function run() // MAIN BACKUP LOOP // $written = 0; do { - if (!is_null($this->container->getState()->getBackupTable())) { + if (null !== $this->container->getState()->getBackupTable()) { // only insert (schema already done) $table = $this->container->getState()->getBackupTable(); $lines = $this->container->getState()->getBackupLines(); @@ -159,8 +159,8 @@ public function run() $schema = $this->container->getDb()->executeS('SHOW CREATE TABLE `' . $table . '`', true, false); if (count($schema) != 1 || - !((isset($schema[0]['Table']) && isset($schema[0]['Create Table'])) - || (isset($schema[0]['View']) && isset($schema[0]['Create View'])))) { + !(isset($schema[0]['Table'], $schema[0]['Create Table']) + || isset($schema[0]['View'], $schema[0]['Create View']))) { fclose($fp); if (file_exists($backupfile)) { unlink($backupfile); diff --git a/classes/TaskRunner/Upgrade/BackupFiles.php b/classes/TaskRunner/Upgrade/BackupFiles.php index fbb268d5c..1c753130b 100644 --- a/classes/TaskRunner/Upgrade/BackupFiles.php +++ b/classes/TaskRunner/Upgrade/BackupFiles.php @@ -55,7 +55,7 @@ public function run() } if (!$this->container->getFileConfigurationStorage()->exists(UpgradeFileNames::FILES_TO_BACKUP_LIST)) { - // @todo : only add files and dir listed in "originalPrestashopVersion" list + /** @todo : only add files and dir listed in "originalPrestashopVersion" list */ $filesToBackup = $this->container->getFilesystemAdapter()->listFilesInDir($this->container->getProperty(UpgradeContainer::PS_ROOT_PATH), 'backup', false); $this->container->getFileConfigurationStorage()->save($filesToBackup, UpgradeFileNames::FILES_TO_BACKUP_LIST); if (count($filesToBackup)) { diff --git a/classes/TaskRunner/Upgrade/CleanDatabase.php b/classes/TaskRunner/Upgrade/CleanDatabase.php index c4c326775..aae284f16 100644 --- a/classes/TaskRunner/Upgrade/CleanDatabase.php +++ b/classes/TaskRunner/Upgrade/CleanDatabase.php @@ -36,7 +36,7 @@ class CleanDatabase extends AbstractTask { public function run() { - /* Clean tabs order */ + // Clean tabs order foreach ($this->container->getDb()->ExecuteS('SELECT DISTINCT id_parent FROM ' . _DB_PREFIX_ . 'tab') as $parent) { $i = 1; foreach ($this->container->getDb()->ExecuteS('SELECT id_tab FROM ' . _DB_PREFIX_ . 'tab WHERE id_parent = ' . (int) $parent['id_parent'] . ' ORDER BY IF(class_name IN ("AdminHome", "AdminDashboard"), 1, 2), position ASC') as $child) { diff --git a/classes/TaskRunner/Upgrade/UpgradeComplete.php b/classes/TaskRunner/Upgrade/UpgradeComplete.php index b02f5fe69..e049173ea 100644 --- a/classes/TaskRunner/Upgrade/UpgradeComplete.php +++ b/classes/TaskRunner/Upgrade/UpgradeComplete.php @@ -30,7 +30,6 @@ use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask; use PrestaShop\Module\AutoUpgrade\UpgradeTools\FilesystemAdapter; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; - use Configuration; /** diff --git a/classes/TaskRunner/Upgrade/UpgradeDb.php b/classes/TaskRunner/Upgrade/UpgradeDb.php index 19ce73dfa..f2bd1d848 100644 --- a/classes/TaskRunner/Upgrade/UpgradeDb.php +++ b/classes/TaskRunner/Upgrade/UpgradeDb.php @@ -54,6 +54,7 @@ public function run() $this->logger->info($this->translator->trans('Database upgraded. Now upgrading your Addons modules...', array(), 'Modules.Autoupgrade.Admin')); $this->container->getSymfonyAdapter()->clearMigrationCache(); + return true; } diff --git a/classes/TaskRunner/Upgrade/UpgradeFiles.php b/classes/TaskRunner/Upgrade/UpgradeFiles.php index 5a86965d5..dc0e74059 100644 --- a/classes/TaskRunner/Upgrade/UpgradeFiles.php +++ b/classes/TaskRunner/Upgrade/UpgradeFiles.php @@ -38,9 +38,7 @@ class UpgradeFiles extends AbstractTask public function run() { - /* - * The first call must init the list of files be upgraded - */ + // The first call must init the list of files be upgraded if (!$this->container->getFileConfigurationStorage()->exists(UpgradeFileNames::FILES_TO_UPGRADE_LIST)) { return $this->warmUp(); } @@ -151,7 +149,7 @@ public function upgradeThisFile($file) } if (is_dir($orig)) { // if $dest is not a directory (that can happen), just remove that file - if (!is_dir($dest) and file_exists($dest)) { + if (!is_dir($dest) && file_exists($dest)) { unlink($dest); $this->logger->debug($this->translator->trans('[WARNING] File %1$s has been deleted.', array($file), 'Modules.Autoupgrade.Admin')); } diff --git a/classes/TaskRunner/Upgrade/UpgradeNow.php b/classes/TaskRunner/Upgrade/UpgradeNow.php index fa3d4412d..ad09d8223 100644 --- a/classes/TaskRunner/Upgrade/UpgradeNow.php +++ b/classes/TaskRunner/Upgrade/UpgradeNow.php @@ -53,6 +53,12 @@ public function run() $upgrader->checkPSVersion(false, array('minor')); } + if ($upgrader->isLastVersion()) { + $this->next = ''; + $this->logger->info($this->translator->trans('You already have the %s version.', array($upgrader->version_name), 'Modules.Autoupgrade.Admin')); + return; + } + switch ($channel) { case 'directory': // if channel directory is chosen, we assume it's "ready for use" (samples already removed for example) diff --git a/classes/Tools14.php b/classes/Tools14.php index d9b0ffd2b..cafdbbe12 100755 --- a/classes/Tools14.php +++ b/classes/Tools14.php @@ -76,7 +76,7 @@ public static function redirect($url, $baseUri = __PS_BASE_URI__) $baseUri = ''; } - if (isset($_SERVER['HTTP_REFERER']) and ($url == $_SERVER['HTTP_REFERER'])) { + if (isset($_SERVER['HTTP_REFERER']) && ($url == $_SERVER['HTTP_REFERER'])) { header('Location: ' . $_SERVER['HTTP_REFERER']); } else { header('Location: ' . $baseUri . $url); @@ -127,7 +127,7 @@ public static function redirectAdmin($url) */ public static function getProtocol($use_ssl = null) { - return !is_null($use_ssl) && $use_ssl ? 'https://' : 'http://'; + return null !== $use_ssl && $use_ssl ? 'https://' : 'http://'; } /** @@ -206,7 +206,7 @@ public static function getShopDomainSsl($http = false, $entities = false) */ public static function getServerName() { - if (isset($_SERVER['HTTP_X_FORWARDED_SERVER']) and $_SERVER['HTTP_X_FORWARDED_SERVER']) { + if (isset($_SERVER['HTTP_X_FORWARDED_SERVER']) && $_SERVER['HTTP_X_FORWARDED_SERVER']) { return $_SERVER['HTTP_X_FORWARDED_SERVER']; } @@ -221,7 +221,7 @@ public static function getServerName() public static function getRemoteAddr() { // This condition is necessary when using CDN, don't remove it. - if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) and $_SERVER['HTTP_X_FORWARDED_FOR'] and (!isset($_SERVER['REMOTE_ADDR']) or preg_match('/^127\..*/i', trim($_SERVER['REMOTE_ADDR'])) or preg_match('/^172\.16.*/i', trim($_SERVER['REMOTE_ADDR'])) or preg_match('/^192\.168\.*/i', trim($_SERVER['REMOTE_ADDR'])) or preg_match('/^10\..*/i', trim($_SERVER['REMOTE_ADDR'])))) { + if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] && (!isset($_SERVER['REMOTE_ADDR']) || preg_match('/^127\..*/i', trim($_SERVER['REMOTE_ADDR'])) || preg_match('/^172\.16.*/i', trim($_SERVER['REMOTE_ADDR'])) || preg_match('/^192\.168\.*/i', trim($_SERVER['REMOTE_ADDR'])) || preg_match('/^10\..*/i', trim($_SERVER['REMOTE_ADDR'])))) { if (strpos($_SERVER['HTTP_X_FORWARDED_FOR'], ',')) { $ips = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); @@ -293,7 +293,7 @@ public static function secureReferrer($referrer) */ public static function getValue($key, $defaultValue = false) { - if (!isset($key) or empty($key) or !is_string($key)) { + if (!isset($key) || empty($key) || !is_string($key)) { return false; } $ret = (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : $defaultValue)); @@ -307,7 +307,7 @@ public static function getValue($key, $defaultValue = false) public static function getIsset($key) { - if (!isset($key) or empty($key) or !is_string($key)) { + if (!isset($key) || empty($key) || !is_string($key)) { return false; } @@ -326,13 +326,13 @@ public static function setCookieLanguage() /* If language does not exist or is disabled, erase it */ if ($cookie->id_lang) { $lang = new Language((int) $cookie->id_lang); - if (!Validate::isLoadedObject($lang) or !$lang->active) { + if (!Validate::isLoadedObject($lang) || !$lang->active) { $cookie->id_lang = null; } } /* Automatically detect language if not already defined */ - if (!$cookie->id_lang and isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { + if (!$cookie->id_lang && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $array = explode(',', self::strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE'])); if (self::strlen($array[0]) > 2) { $tab = explode('-', $array[0]); @@ -342,14 +342,14 @@ public static function setCookieLanguage() } if (Validate::isLanguageIsoCode($string)) { $lang = new Language((int) (Language::getIdByIso($string))); - if (Validate::isLoadedObject($lang) and $lang->active) { + if (Validate::isLoadedObject($lang) && $lang->active) { $cookie->id_lang = (int) ($lang->id); } } } /* If language file not present, you must use default language file */ - if (!$cookie->id_lang or !Validate::isUnsignedId($cookie->id_lang)) { + if (!$cookie->id_lang || !Validate::isUnsignedId($cookie->id_lang)) { $cookie->id_lang = (int) (Configuration::get('PS_LANG_DEFAULT')); } @@ -366,7 +366,7 @@ public static function switchLanguage() { global $cookie; - if ($id_lang = (int) (self::getValue('id_lang')) and Validate::isUnsignedId($id_lang)) { + if ($id_lang = (int) (self::getValue('id_lang')) && Validate::isUnsignedId($id_lang)) { $cookie->id_lang = $id_lang; } } @@ -381,9 +381,9 @@ public static function setCurrency() global $cookie; if (self::isSubmit('SubmitCurrency')) { - if (isset($_POST['id_currency']) and is_numeric($_POST['id_currency'])) { + if (isset($_POST['id_currency']) && is_numeric($_POST['id_currency'])) { $currency = Currency::getCurrencyInstance((int) ($_POST['id_currency'])); - if (is_object($currency) and $currency->id and !$currency->deleted) { + if (is_object($currency) && $currency->id && !$currency->deleted) { $cookie->id_currency = (int) ($currency->id); } } @@ -391,12 +391,12 @@ public static function setCurrency() if ((int) $cookie->id_currency) { $currency = Currency::getCurrencyInstance((int) $cookie->id_currency); - if (is_object($currency) and (int) $currency->id and (int) $currency->deleted != 1 and $currency->active) { + if (is_object($currency) && (int) $currency->id && (int) $currency->deleted != 1 && $currency->active) { return $currency; } } $currency = Currency::getCurrencyInstance((int) (Configuration::get('PS_CURRENCY_DEFAULT'))); - if (is_object($currency) and $currency->id) { + if (is_object($currency) && $currency->id) { $cookie->id_currency = (int) ($currency->id); } @@ -523,10 +523,10 @@ public static function dateFormat($params, &$smarty) */ public static function displayDate($date, $id_lang, $full = false, $separator = '-') { - if (!$date or !($time = strtotime($date))) { + if (!$date || !($time = strtotime($date))) { return $date; } - if (!Validate::isDate($date) or !Validate::isBool($full)) { + if (!Validate::isDate($date) || !Validate::isBool($full)) { die(self::displayError('Invalid date')); } @@ -618,17 +618,17 @@ public static function displayError($string = 'Fatal error', $htmlentities = tru return $string; global $_ERRORS, $cookie; - $iso = strtolower(Language::getIsoById((is_object($cookie) and $cookie->id_lang) ? (int) $cookie->id_lang : (int) Configuration::get('PS_LANG_DEFAULT'))); + $iso = strtolower(Language::getIsoById((is_object($cookie) && $cookie->id_lang) ? (int) $cookie->id_lang : (int) Configuration::get('PS_LANG_DEFAULT'))); @include_once _PS_TRANSLATIONS_DIR_ . $iso . '/errors.php'; - if (defined('_PS_MODE_DEV_') and _PS_MODE_DEV_ and $string == 'Fatal error') { + if (defined('_PS_MODE_DEV_') && _PS_MODE_DEV_ && $string == 'Fatal error') { return '
' . print_r(debug_backtrace(), true) . '
'; } if (!is_array($_ERRORS)) { return str_replace('"', '"', $string); } $key = md5(str_replace('\'', '\\\'', $string)); - $str = (isset($_ERRORS) and is_array($_ERRORS) and key_exists($key, $_ERRORS)) ? ($htmlentities ? htmlentities($_ERRORS[$key], ENT_COMPAT, 'UTF-8') : $_ERRORS[$key]) : $string; + $str = (isset($_ERRORS) && is_array($_ERRORS) && key_exists($key, $_ERRORS)) ? ($htmlentities ? htmlentities($_ERRORS[$key], ENT_COMPAT, 'UTF-8') : $_ERRORS[$key]) : $string; return str_replace('"', '"', stripslashes($str)); } @@ -681,8 +681,8 @@ public static function p($object) public static function isSubmit($submit) { return - isset($_POST[$submit]) or isset($_POST[$submit . '_x']) or isset($_POST[$submit . '_y']) - or isset($_GET[$submit]) or isset($_GET[$submit . '_x']) or isset($_GET[$submit . '_y']) + isset($_POST[$submit]) || isset($_POST[$submit . '_x']) || isset($_POST[$submit . '_y']) + || isset($_GET[$submit]) || isset($_GET[$submit . '_x']) || isset($_GET[$submit . '_y']) ; } @@ -697,7 +697,7 @@ public static function getMetaTags($id_lang, $page_name) { global $maintenance; - if (!(isset($maintenance) and (!in_array(self::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))))) { + if (!(isset($maintenance) && (!in_array(self::getRemoteAddr(), explode(',', Configuration::get('PS_MAINTENANCE_IP')))))) { /* Products specifics meta tags */ if ($id_product = self::getValue('id_product')) { $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' @@ -818,9 +818,9 @@ public static function getHomeMetaTags($id_lang, $page_name) { /* Metas-tags */ $metas = Meta::getMetaByPage($page_name, $id_lang); - $ret['meta_title'] = (isset($metas['title']) and $metas['title']) ? $metas['title'] . ' - ' . Configuration::get('PS_SHOP_NAME') : Configuration::get('PS_SHOP_NAME'); - $ret['meta_description'] = (isset($metas['description']) and $metas['description']) ? $metas['description'] : ''; - $ret['meta_keywords'] = (isset($metas['keywords']) and $metas['keywords']) ? $metas['keywords'] : ''; + $ret['meta_title'] = (isset($metas['title']) && $metas['title']) ? $metas['title'] . ' - ' . Configuration::get('PS_SHOP_NAME') : Configuration::get('PS_SHOP_NAME'); + $ret['meta_description'] = (isset($metas['description']) && $metas['description']) ? $metas['description'] : ''; + $ret['meta_keywords'] = (isset($metas['keywords']) && $metas['keywords']) ? $metas['keywords'] : ''; return $ret; } @@ -926,10 +926,10 @@ public static function getPath($id_category, $path = '', $linkOntheLastItem = fa $nCategories = (int) sizeof($categories); foreach ($categories as $category) { $fullPath .= - (($n < $nCategories or $linkOntheLastItem) ? '' : '') . + (($n < $nCategories || $linkOntheLastItem) ? '' : '') . htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8') . - (($n < $nCategories or $linkOntheLastItem) ? '' : '') . - (($n++ != $nCategories or !empty($path)) ? '' . $pipe . '' : ''); + (($n < $nCategories || $linkOntheLastItem) ? '' : '') . + (($n++ != $nCategories || !empty($path)) ? '' . $pipe . '' : ''); } return $fullPath . $path; @@ -1023,13 +1023,13 @@ public static function getOrdersTotal() public static function historyc_l($key, $translations) { global $cookie; - if (!$translations or !is_array($translations)) { + if (!$translations || !is_array($translations)) { die(self::displayError()); } $iso = strtoupper(Language::getIsoById($cookie->id_lang)); $lang = key_exists($iso, $translations) ? $translations[$iso] : false; - return ($lang and is_array($lang) and key_exists($key, $lang)) ? stripslashes($lang[$key]) : $key; + return ($lang && is_array($lang) && key_exists($key, $lang)) ? stripslashes($lang[$key]) : $key; } /** @@ -1264,7 +1264,7 @@ public static function ucfirst($str) public static function orderbyPrice(&$array, $orderWay) { foreach ($array as &$row) { - $row['price_tmp'] = Product::getPriceStatic($row['id_product'], true, ((isset($row['id_product_attribute']) and !empty($row['id_product_attribute'])) ? (int) ($row['id_product_attribute']) : null), 2); + $row['price_tmp'] = Product::getPriceStatic($row['id_product'], true, ((isset($row['id_product_attribute']) && !empty($row['id_product_attribute'])) ? (int) ($row['id_product_attribute']) : null), 2); } if (strtolower($orderWay) == 'desc') { uasort($array, 'cmpPriceDesc'); @@ -1287,7 +1287,7 @@ public static function iconv($from, $to, $string) public static function isEmpty($field) { - return $field === '' or $field === null; + return $field === '' || $field === null; } /** @@ -1398,7 +1398,7 @@ public static function shouldUseFopen($url) public static function file_get_contents($url, $use_include_path = false, $stream_context = null, $curl_timeout = 5) { - if (!extension_loaded('openssl') and strpos('https://', $url) === true) { + if (!extension_loaded('openssl') && strpos('https://', $url) === true) { $url = str_replace('https', 'http', $url); } if ($stream_context == null && preg_match('/^https?:\/\//', $url)) { @@ -1878,7 +1878,7 @@ public static function getMediaServer($filename) } } - if (self::$_cache_nb_media_servers and ($id_media_server = (abs(crc32($filename)) % self::$_cache_nb_media_servers + 1))) { + if (self::$_cache_nb_media_servers && ($id_media_server = (abs(crc32($filename)) % self::$_cache_nb_media_servers + 1))) { return constant('_MEDIA_SERVER_' . $id_media_server . '_'); } @@ -1945,7 +1945,7 @@ public static function generateHtaccess($path, $rewrite_settings, $cache_control $tab['RewriteRule']['content']['^content/category/([0-9]+)\-([a-zA-Z0-9-]*)'] = 'cms.php?id_cms_category=$1 [QSA,L]'; // Compatibility with the old URLs - if (!Configuration::get('PS_INSTALL_VERSION') or version_compare(Configuration::get('PS_INSTALL_VERSION'), '1.4.0.7') == -1) { + if (!Configuration::get('PS_INSTALL_VERSION') || version_compare(Configuration::get('PS_INSTALL_VERSION'), '1.4.0.7') == -1) { // This is a nasty copy/paste of the previous links, but with "lang-en" instead of "en" // Do not update it when you add something in the one at the top, it's only for the old links $tab['RewriteRule']['content']['^lang-([a-z]{2})/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html'] = 'product.php?id_product=$3&isolang=$1 [QSA,L]'; @@ -1961,7 +1961,7 @@ public static function generateHtaccess($path, $rewrite_settings, $cache_control if ($multilang) { foreach (Language::getLanguages() as $language) { foreach (Meta::getMetasByIdLang($language['id_lang']) as $key => $meta) { - if (!empty($meta['url_rewrite']) and Validate::isLinkRewrite($meta['url_rewrite'])) { + if (!empty($meta['url_rewrite']) && Validate::isLinkRewrite($meta['url_rewrite'])) { $tab['RewriteRule']['content']['^' . $language['iso_code'] . '/' . $meta['url_rewrite'] . '$'] = $meta['page'] . '.php?isolang=' . $language['iso_code'] . ' [QSA,L]'; } elseif (array_key_exists($key, $default_meta) && $default_meta[$key]['url_rewrite'] != '') { $tab['RewriteRule']['content']['^' . $language['iso_code'] . '/' . $default_meta[$key]['url_rewrite'] . '$'] = $default_meta[$key]['page'] . '.php?isolang=' . $language['iso_code'] . ' [QSA,L]'; @@ -2111,7 +2111,7 @@ public static function enableCache($level = 1) if (!Configuration::get('PS_SMARTY_CACHE')) { return; } - if ($smarty->force_compile == 0 and $smarty->caching == $level) { + if ($smarty->force_compile == 0 && $smarty->caching == $level) { return; } self::$_forceCompile = (int) ($smarty->force_compile); @@ -2136,7 +2136,7 @@ public static function isCallable($function) { $disabled = explode(',', ini_get('disable_functions')); - return !in_array($function, $disabled) and is_callable($function); + return !in_array($function, $disabled) && is_callable($function); } public static function pRegexp($s, $delim) @@ -2249,7 +2249,7 @@ public static function ZipExtract($fromFile, $toDir) } if (class_exists('ZipArchive', false)) { $zip = new ZipArchive(); - if ($zip->open($fromFile) === true and $zip->extractTo($toDir) and $zip->close()) { + if ($zip->open($fromFile) === true && $zip->extractTo($toDir) && $zip->close()) { return true; } @@ -2291,14 +2291,14 @@ public static function getProductsOrder($type, $value = null, $prefix = false) } } - $value = (is_null($value) || $value === false || $value === '') ? (int) Configuration::get('PS_PRODUCTS_ORDER_BY') : $value; + $value = (null === $value || $value === false || $value === '') ? (int) Configuration::get('PS_PRODUCTS_ORDER_BY') : $value; $list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity'); return $orderByPrefix . ((isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'position')); break; case 'way': - $value = (is_null($value) || $value === false || $value === '') ? (int) Configuration::get('PS_PRODUCTS_ORDER_WAY') : $value; + $value = (null === $value || $value === false || $value === '') ? (int) Configuration::get('PS_PRODUCTS_ORDER_WAY') : $value; $list = array(0 => 'asc', 1 => 'desc'); return (isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'asc'); @@ -2450,7 +2450,7 @@ public static function nl2br($str) */ public static function copy($source, $destination, $stream_context = null) { - if (is_null($stream_context) && !preg_match('/^https?:\/\//', $source)) { + if (null === $stream_context && !preg_match('/^https?:\/\//', $source)) { return @copy($source, $destination); } diff --git a/classes/Twig/Block/ChannelInfoBlock.php b/classes/Twig/Block/ChannelInfoBlock.php index cbdc6fce8..0491ae598 100644 --- a/classes/Twig/Block/ChannelInfoBlock.php +++ b/classes/Twig/Block/ChannelInfoBlock.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade\Twig\Block; use PrestaShop\Module\AutoUpgrade\ChannelInfo; diff --git a/classes/Twig/Block/RollbackForm.php b/classes/Twig/Block/RollbackForm.php index aeee76d0e..29c0226a6 100644 --- a/classes/Twig/Block/RollbackForm.php +++ b/classes/Twig/Block/RollbackForm.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade\Twig\Block; use PrestaShop\Module\AutoUpgrade\BackupFinder; diff --git a/classes/Twig/Block/UpgradeButtonBlock.php b/classes/Twig/Block/UpgradeButtonBlock.php index 8f4e7d593..84c9c2dbc 100644 --- a/classes/Twig/Block/UpgradeButtonBlock.php +++ b/classes/Twig/Block/UpgradeButtonBlock.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade\Twig\Block; use Configuration; diff --git a/classes/Twig/Block/UpgradeChecklist.php b/classes/Twig/Block/UpgradeChecklist.php index 76813d6c5..2735be5da 100644 --- a/classes/Twig/Block/UpgradeChecklist.php +++ b/classes/Twig/Block/UpgradeChecklist.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade\Twig\Block; use PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck; diff --git a/classes/Twig/Form/BackupOptionsForm.php b/classes/Twig/Form/BackupOptionsForm.php index 0e74382e9..f7b5c66e5 100644 --- a/classes/Twig/Form/BackupOptionsForm.php +++ b/classes/Twig/Form/BackupOptionsForm.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade\Twig\Form; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator; diff --git a/classes/Twig/Form/FormRenderer.php b/classes/Twig/Form/FormRenderer.php index 9bf87b6de..d1b0656a2 100644 --- a/classes/Twig/Form/FormRenderer.php +++ b/classes/Twig/Form/FormRenderer.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade\Twig\Form; use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeConfiguration; @@ -71,7 +70,7 @@ public function render($name, $fields, $tabname, $size, $icon) . '
'; } - /* Display the appropriate input type for each field */ + // Display the appropriate input type for each field switch ($field['type']) { case 'disabled': $html .= $field['disabled']; diff --git a/classes/Twig/Form/UpgradeOptionsForm.php b/classes/Twig/Form/UpgradeOptionsForm.php index 2f4a8cd9a..652f2036e 100644 --- a/classes/Twig/Form/UpgradeOptionsForm.php +++ b/classes/Twig/Form/UpgradeOptionsForm.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade\Twig\Form; use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator; diff --git a/classes/UpgradePage.php b/classes/UpgradePage.php index 29f8197b3..1f1e129b7 100644 --- a/classes/UpgradePage.php +++ b/classes/UpgradePage.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade; use PrestaShop\Module\AutoUpgrade\Twig\Block\RollbackForm; @@ -258,7 +257,7 @@ private function getUpgradeOptionsForm() $formRenderer = new FormRenderer($this->config, $this->twig, $this->translator); return (new UpgradeOptionsForm($this->translator, $formRenderer)) - ->render(); + ->render(); } /** @@ -268,7 +267,7 @@ private function getErrorMessage() { $translator = $this->translator; - /* PrestaShop demo mode */ + // PrestaShop demo mode if (defined('_PS_MODE_DEMO_') && _PS_MODE_DEMO_) { return array( 'message' => $translator->trans('This functionality has been disabled.', array(), self::TRANSLATION_DOMAIN), diff --git a/classes/UpgradeSelfCheck.php b/classes/UpgradeSelfCheck.php index 4c494b720..f531a51dd 100644 --- a/classes/UpgradeSelfCheck.php +++ b/classes/UpgradeSelfCheck.php @@ -24,7 +24,6 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade; use Configuration; @@ -234,8 +233,7 @@ public function isOkForUpgrade() && $this->isShopDeactivated() && $this->isCacheDisabled() && $this->isModuleVersionLatest() - && $this->isPrestaShopReady() - ; + && $this->isPrestaShopReady(); } /** @@ -278,8 +276,7 @@ private function checkShopIsDeactivated() { return !Configuration::get('PS_SHOP_ENABLE') - || (isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], array('127.0.0.1', 'localhost'))) - ; + || (isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], array('127.0.0.1', 'localhost'))); } /** diff --git a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php index 9f74366fc..17b10414c 100644 --- a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php +++ b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php @@ -113,13 +113,13 @@ protected function initConstants() // 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) < 512) - || is_numeric($memory_limit) and (intval($memory_limit) < 131072)) + && ((substr($memory_limit, -1) == 'M' && substr($memory_limit, 0, -1) < 512) + || is_numeric($memory_limit) && ((int) $memory_limit < 131072)) ) { @ini_set('memory_limit', '512M'); } - /* Redefine REQUEST_URI if empty (on some webservers...) */ + // 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']; @@ -164,7 +164,7 @@ protected function initConstants() } // if _PS_ROOT_DIR_ is defined, use it instead of "guessing" the module dir. - if (defined('_PS_ROOT_DIR_') and !defined('_PS_MODULE_DIR_')) { + if (defined('_PS_ROOT_DIR_') && !defined('_PS_MODULE_DIR_')) { define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/modules/'); } elseif (!defined('_PS_MODULE_DIR_')) { define('_PS_MODULE_DIR_', INSTALL_PATH . '/../modules/'); @@ -335,7 +335,7 @@ protected function runQuery($upgrade_file, $query) if (empty($query)) { return; } - /* If php code have to be executed */ + // If php code have to be executed if (strpos($query, '/* PHP:') !== false) { return $this->runPhpQuery($upgrade_file, $query); } @@ -344,7 +344,7 @@ protected function runQuery($upgrade_file, $query) protected function runPhpQuery($upgrade_file, $query) { - /* Parsing php code */ + // Parsing php code $pos = strpos($query, '/* PHP:') + strlen('/* PHP:'); $phpString = substr($query, $pos, strlen($query) - $pos - strlen(' */;')); $php = explode('::', $phpString); @@ -360,7 +360,7 @@ protected function runPhpQuery($upgrade_file, $query) // reset phpRes to a null value $phpRes = null; - /* Call a simple function */ + // Call a simple function if (strpos($phpString, '::') === false) { $func_name = str_replace($pattern[0], '', $php[0]); @@ -372,7 +372,7 @@ protected function runPhpQuery($upgrade_file, $query) $phpRes = call_user_func_array($func_name, $parameters); } } - /* Or an object method */ + // Or an object method else { $func_name = array($php[0], str_replace($pattern[0], '', $php[1])); $this->logger->error('[ERROR] ' . $upgrade_file . ' PHP - Object Method call is forbidden (' . $php[0] . '::' . str_replace($pattern[0], '', $php[1]) . ')'); @@ -515,7 +515,7 @@ protected function generateHtaccess() 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')) { + if (!class_exists('Tools2', false) && class_exists('ToolsCore')) { eval('class Tools2 extends ToolsCore{}'); } @@ -535,105 +535,105 @@ protected function generateHtaccess() 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')) { + if (!class_exists('ObjectModel', false) && 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')) { + if (!class_exists('Configuration', false) && 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')) { + if (!class_exists('Cache', false) && 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')) { + if (!class_exists('PrestaShopCollection', false) && 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')) { + if (!class_exists('ShopUrl', false) && 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')) { + if (!class_exists('Shop', false) && 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')) { + if (!class_exists('Translate', false) && 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')) { + if (!class_exists('Module', false) && 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')) { + if (!class_exists('Validate', false) && 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')) { + if (!class_exists('Language', false) && 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')) { + if (!class_exists('Tab', false) && 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')) { + if (!class_exists('Dispatcher', false) && 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')) { + if (!class_exists('Hook', false) && 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')) { + if (!class_exists('Context', false) && 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')) { + if (!class_exists('Group', false) && class_exists('GroupCore')) { eval('class Group extends GroupCore{}'); } diff --git a/classes/UpgradeTools/FilesystemAdapter.php b/classes/UpgradeTools/FilesystemAdapter.php index 8dab5faa4..f00aca9a1 100644 --- a/classes/UpgradeTools/FilesystemAdapter.php +++ b/classes/UpgradeTools/FilesystemAdapter.php @@ -227,7 +227,7 @@ public function isFileSkipped($file, $fullpath, $way = 'backup', $temporaryWorks } foreach ($ignoreList as $path) { - $path = str_replace(DIRECTORY_SEPARATOR.'admin', DIRECTORY_SEPARATOR.$this->adminSubDir, $path); + $path = str_replace(DIRECTORY_SEPARATOR . 'admin', DIRECTORY_SEPARATOR . $this->adminSubDir, $path); if ($fullpath === $rootpath . $path) { return true; } diff --git a/classes/UpgradeTools/ModuleAdapter.php b/classes/UpgradeTools/ModuleAdapter.php index 00dd9c9ee..36b606ad9 100644 --- a/classes/UpgradeTools/ModuleAdapter.php +++ b/classes/UpgradeTools/ModuleAdapter.php @@ -45,7 +45,7 @@ class ModuleAdapter private $zipAction; // Cached instance - private $moduleDataUpdater = null; + private $moduleDataUpdater; public function __construct($db, $translator, $modulesPath, $tempPath, $upgradeVersion, ZipAction $zipAction) { diff --git a/classes/UpgradeTools/Translator.php b/classes/UpgradeTools/Translator.php index 288453023..e17b0ff32 100644 --- a/classes/UpgradeTools/Translator.php +++ b/classes/UpgradeTools/Translator.php @@ -37,11 +37,11 @@ public function __construct($caller) } /** - * Translate a string to the current language - * + * Translate a string to the current language. + * * This methods has the same signature as the 1.7 trans method, but only relies * on the module translation files. - * + * * @param string $id Original text * @param array $parameters Parameters to apply * @param string $domain Unused diff --git a/classes/Upgrader.php b/classes/Upgrader.php index 42f21d5fe..846bd1752 100755 --- a/classes/Upgrader.php +++ b/classes/Upgrader.php @@ -24,7 +24,6 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ - namespace PrestaShop\Module\AutoUpgrade; use Symfony\Component\Filesystem\Filesystem; @@ -50,7 +49,7 @@ class Upgrader public $version_name; public $version_num; - public $version_is_modified = null; + public $version_is_modified; /** * @var string contains hte url where to download the file */ @@ -124,7 +123,7 @@ public function isLastVersion() $this->checkPSVersion(); } - return $this->need_upgrade; + return !$this->need_upgrade; } /** @@ -272,11 +271,11 @@ public function getApiAddons($xml_localfile, $postData, $refresh = false) // Make the request $opts = array( 'http' => array( - 'method' => 'POST', - 'content' => $postData, - 'header' => 'Content-type: application/x-www-form-urlencoded', - 'timeout' => 10, - ), ); + 'method' => 'POST', + 'content' => $postData, + 'header' => 'Content-type: application/x-www-form-urlencoded', + 'timeout' => 10, + ), ); $context = stream_context_create($opts); $xml = false; foreach ($protocolsList as $protocol => $port) { @@ -405,8 +404,11 @@ public function md5FileAsArray($node, $dir = '/') foreach ($node as $key => $child) { if (is_object($child) && $child->getName() == 'dir') { $dir = (string) $child['name']; - // $current_path = $dir.(string)$child['name']; - // @todo : something else than array pop ? + /** + * $current_path = $dir.(string)$child['name'];. + * + * @todo : something else than array pop ? + */ $dir_content = $this->md5FileAsArray($child, $dir); $array[$dir] = $dir_content; } elseif (is_object($child) && $child->getName() == 'md5file') { diff --git a/classes/pclzip.lib.php b/classes/pclzip.lib.php index 582a817c9..8a05f979f 100755 --- a/classes/pclzip.lib.php +++ b/classes/pclzip.lib.php @@ -4595,7 +4595,7 @@ public function privDeleteByRule(&$p_result_list, &$p_options) if ((strlen($v_header_list[$v_nb_extracted]['stored_filename']) > strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) && (substr($v_header_list[$v_nb_extracted]['stored_filename'], 0, strlen($p_options[PCLZIP_OPT_BY_NAME][$j])) == $p_options[PCLZIP_OPT_BY_NAME][$j])) { $v_found = true; - } elseif ((($v_header_list[$v_nb_extracted]['external'] & 0x00000010) == 0x00000010) /* Indicates a folder */ + } elseif ((($v_header_list[$v_nb_extracted]['external'] & 0x00000010) == 0x00000010) // Indicates a folder && ($v_header_list[$v_nb_extracted]['stored_filename'] . '/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { $v_found = true; } diff --git a/cli-rollback.php b/cli-rollback.php index bcd4ce242..efdbd886e 100644 --- a/cli-rollback.php +++ b/cli-rollback.php @@ -25,7 +25,7 @@ * International Registered Trademark & Property of PrestaShop SA */ -if (php_sapi_name() !== 'cli') { +if (PHP_SAPI !== 'cli') { echo 'This script must be called from CLI'; exit(1); } diff --git a/cli-upgrade.php b/cli-upgrade.php index 027d8e82f..2ab08e220 100644 --- a/cli-upgrade.php +++ b/cli-upgrade.php @@ -25,7 +25,7 @@ * International Registered Trademark & Property of PrestaShop SA */ -if (php_sapi_name() !== 'cli') { +if (PHP_SAPI !== 'cli') { echo 'This script must be called from CLI'; exit(1); } diff --git a/config.xml b/config.xml index e34721430..26f7b961e 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ autoupgrade - + diff --git a/docker-compose.yml b/docker-compose.yml index 3a9de4f4c..a7d8a8f85 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,28 +1,28 @@ version: '2' services: - mysql: - image: mysql:5.7 - ports: - - "3306" - environment: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: psreference - reference-release: - container_name: prestashop_autoupgrade - image: prestashop/prestashop:${VERSION} - volumes: - - ./:/var/www/html/modules/autoupgrade - environment: - DB_SERVER: mysql - DB_PASSWD: root - DB_NAME: psreference - PS_DOMAIN: localhost:8001 - PS_INSTALL_AUTO: 1 - PS_ERASE_DB: 1 - PS_FOLDER_ADMIN: admin-dev - PS_FOLDER_INSTALL: install-dev - depends_on: - - mysql - ports: - - "8001:80" + mysql: + image: mysql:5.7 + ports: + - '3306' + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: psreference + reference-release: + container_name: prestashop_autoupgrade + image: prestashop/prestashop:${VERSION} + volumes: + - ./:/var/www/html/modules/autoupgrade + environment: + DB_SERVER: mysql + DB_PASSWD: root + DB_NAME: psreference + PS_DOMAIN: localhost:8001 + PS_INSTALL_AUTO: 1 + PS_ERASE_DB: 1 + PS_FOLDER_ADMIN: admin-dev + PS_FOLDER_INSTALL: install-dev + depends_on: + - mysql + ports: + - '8001:80' diff --git a/functions.php b/functions.php index 705ec6f75..dd5985853 100755 --- a/functions.php +++ b/functions.php @@ -1,28 +1,28 @@ -* @copyright 2007-2016 PrestaShop SA -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ + * 2007-2016 PrestaShop. + * + * NOTICE OF LICENSE + * + * This source file is subject to the Open Software License (OSL 3.0) + * that is bundled with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://opensource.org/licenses/osl-3.0.php + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@prestashop.com so we can send you a copy immediately. + * + * DISCLAIMER + * + * Do not edit or add to this file if you wish to upgrade PrestaShop to newer + * versions in the future. If you wish to customize PrestaShop for your + * needs please refer to http://www.prestashop.com for more information. + * + * @author PrestaShop SA + * @copyright 2007-2016 PrestaShop SA + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ /** * Generate a new settings file, only transmitted parameters are updated. @@ -34,18 +34,18 @@ function rewriteSettingsFile($baseUrls = null, $theme = null, $arrayDB = null) { $defines = array(); - $defines['__PS_BASE_URI__'] = ($baseUrls and $baseUrls['__PS_BASE_URI__']) ? $baseUrls['__PS_BASE_URI__'] : __PS_BASE_URI__; - $defines['_MEDIA_SERVER_1_'] = ($baseUrls and isset($baseUrls['_MEDIA_SERVER_1_'])) ? $baseUrls['_MEDIA_SERVER_1_'] : _MEDIA_SERVER_1_; + $defines['__PS_BASE_URI__'] = ($baseUrls && $baseUrls['__PS_BASE_URI__']) ? $baseUrls['__PS_BASE_URI__'] : __PS_BASE_URI__; + $defines['_MEDIA_SERVER_1_'] = ($baseUrls && isset($baseUrls['_MEDIA_SERVER_1_'])) ? $baseUrls['_MEDIA_SERVER_1_'] : _MEDIA_SERVER_1_; $defines['_PS_CACHING_SYSTEM_'] = _PS_CACHING_SYSTEM_; $defines['_PS_CACHE_ENABLED_'] = _PS_CACHE_ENABLED_; $defines['_THEME_NAME_'] = $theme ? $theme : _THEME_NAME_; - $defines['_DB_NAME_'] = (($arrayDB and isset($arrayDB['_DB_NAME_'])) ? $arrayDB['_DB_NAME_'] : _DB_NAME_); - $defines['_MYSQL_ENGINE_'] = (($arrayDB and isset($arrayDB['_MYSQL_ENGINE_'])) ? $arrayDB['_MYSQL_ENGINE_'] : _MYSQL_ENGINE_); - $defines['_DB_SERVER_'] = (($arrayDB and isset($arrayDB['_DB_SERVER_'])) ? $arrayDB['_DB_SERVER_'] : _DB_SERVER_); - $defines['_DB_USER_'] = (($arrayDB and isset($arrayDB['_DB_USER_'])) ? $arrayDB['_DB_USER_'] : _DB_USER_); - $defines['_DB_PREFIX_'] = (($arrayDB and isset($arrayDB['_DB_PREFIX_'])) ? $arrayDB['_DB_PREFIX_'] : _DB_PREFIX_); - $defines['_DB_PASSWD_'] = (($arrayDB and isset($arrayDB['_DB_PASSWD_'])) ? $arrayDB['_DB_PASSWD_'] : _DB_PASSWD_); - $defines['_DB_TYPE_'] = (($arrayDB and isset($arrayDB['_DB_TYPE_'])) ? $arrayDB['_DB_TYPE_'] : _DB_TYPE_); + $defines['_DB_NAME_'] = (($arrayDB && isset($arrayDB['_DB_NAME_'])) ? $arrayDB['_DB_NAME_'] : _DB_NAME_); + $defines['_MYSQL_ENGINE_'] = (($arrayDB && isset($arrayDB['_MYSQL_ENGINE_'])) ? $arrayDB['_MYSQL_ENGINE_'] : _MYSQL_ENGINE_); + $defines['_DB_SERVER_'] = (($arrayDB && isset($arrayDB['_DB_SERVER_'])) ? $arrayDB['_DB_SERVER_'] : _DB_SERVER_); + $defines['_DB_USER_'] = (($arrayDB && isset($arrayDB['_DB_USER_'])) ? $arrayDB['_DB_USER_'] : _DB_USER_); + $defines['_DB_PREFIX_'] = (($arrayDB && isset($arrayDB['_DB_PREFIX_'])) ? $arrayDB['_DB_PREFIX_'] : _DB_PREFIX_); + $defines['_DB_PASSWD_'] = (($arrayDB && isset($arrayDB['_DB_PASSWD_'])) ? $arrayDB['_DB_PASSWD_'] : _DB_PASSWD_); + $defines['_DB_TYPE_'] = (($arrayDB && isset($arrayDB['_DB_TYPE_'])) ? $arrayDB['_DB_TYPE_'] : _DB_TYPE_); $defines['_COOKIE_KEY_'] = addslashes(_COOKIE_KEY_); $defines['_COOKIE_IV_'] = addslashes(_COOKIE_IV_); if (defined('_RIJNDAEL_KEY_')) { @@ -97,19 +97,19 @@ function getPath($urlBase, $id_category, $path = '', $highlight = '', $categoryT global $cookie; if ($categoryType == 'catalog') { - $category = Db::getInstance()->getRow(' - SELECT id_category, level_depth, nleft, nright - FROM ' . _DB_PREFIX_ . 'category - WHERE id_category = ' . (int) $id_category); + $category = Db::getInstance()->getRow(' + SELECT id_category, level_depth, nleft, nright + FROM ' . _DB_PREFIX_ . 'category + WHERE id_category = ' . (int) $id_category); if (isset($category['id_category'])) { - $categories = Db::getInstance()->ExecuteS(' - SELECT c.id_category, cl.name, cl.link_rewrite - FROM ' . _DB_PREFIX_ . 'category c - LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category) - WHERE c.nleft <= ' . (int) $category['nleft'] . ' AND c.nright >= ' . (int) $category['nright'] . ' AND cl.id_lang = ' . (int) ($cookie->id_lang) . ' - ORDER BY c.level_depth ASC - LIMIT ' . (int) ($category['level_depth'] + 1)); + $categories = Db::getInstance()->ExecuteS(' + SELECT c.id_category, cl.name, cl.link_rewrite + FROM ' . _DB_PREFIX_ . 'category c + LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category) + WHERE c.nleft <= ' . (int) $category['nleft'] . ' AND c.nright >= ' . (int) $category['nright'] . ' AND cl.id_lang = ' . (int) ($cookie->id_lang) . ' + ORDER BY c.level_depth ASC + LIMIT ' . (int) ($category['level_depth'] + 1)); $fullPath = ''; $n = 1; @@ -120,7 +120,7 @@ function getPath($urlBase, $id_category, $path = '', $highlight = '', $categoryT ($n < $nCategories ? '' : '') . (!empty($highlight) ? str_ireplace($highlight, '' . htmlentities($highlight, ENT_NOQUOTES, 'UTF-8') . '', $category['name']) : $category['name']) . ($n < $nCategories ? '' : '') . - (($n++ != $nCategories or !empty($path)) ? ' > ' : ''); + (($n++ != $nCategories || !empty($path)) ? ' > ' : ''); } return $fullPath . $path; @@ -132,14 +132,14 @@ function getPath($urlBase, $id_category, $path = '', $highlight = '', $categoryT } $name = ($highlight != null) ? str_ireplace($highlight, '' . $highlight . '', CMSCategory::hideCMSCategoryPosition($category->name)) : CMSCategory::hideCMSCategoryPosition($category->name); - $edit = ' - Modify '; + $edit = ' + Modify '; if ($category->id == 1) { - $edit = ' - Home '; + $edit = ' + Home '; } - $path = $edit . ' - ' . $name . ' > ' . $path; + $path = $edit . ' + ' . $name . ' > ' . $path; if ($category->id == 1) { return substr($path, 0, strlen($path) - 3); } @@ -202,13 +202,13 @@ function checkingTab($tab) return false; } - if ($row['module'] and file_exists(_PS_MODULE_DIR_ . '/' . $row['module'] . '/' . $tab . '.php')) { + if ($row['module'] && file_exists(_PS_MODULE_DIR_ . '/' . $row['module'] . '/' . $tab . '.php')) { include_once _PS_MODULE_DIR_ . '/' . $row['module'] . '/' . $tab . '.php'; } elseif (file_exists(PS_ADMIN_DIR . '/tabs/' . $tab . '.php')) { include_once PS_ADMIN_DIR . '/tabs/' . $tab . '.php'; } - if (!class_exists($tab, false) or !$row['id_tab']) { + if (!class_exists($tab, false) || !$row['id_tab']) { echo Tools14::displayError('Tab file cannot be found.'); return false; @@ -281,7 +281,7 @@ function checkTabRights($id_tab) * @param string $childrenKey index for children, in case $flattenChildren was set to * false. Defaults to "@children" * - * @return array the resulting array. + * @return array the resulting array */ function simpleXMLToArray($xml, $flattenValues = true, $flattenAttributes = true, $flattenChildren = true, $valueKey = '@value', $attributesKey = '@attributes', $childrenKey = '@children') { diff --git a/logo.gif b/logo.gif index 981356908..98d0bc84a 100755 Binary files a/logo.gif and b/logo.gif differ diff --git a/logo.png b/logo.png index a60bdcbcc..d7df3dd78 100644 Binary files a/logo.png and b/logo.png differ diff --git a/tests/CookieTest.php b/tests/CookieTest.php index afd2e0a95..175622695 100644 --- a/tests/CookieTest.php +++ b/tests/CookieTest.php @@ -33,7 +33,7 @@ class CookieTest extends TestCase private $cookie; - public function setUp() + protected function setUp() { parent::setUp(); $this->cookie = new Cookie('admin', sys_get_temp_dir()); diff --git a/tests/CoreUpgraderTest.php b/tests/CoreUpgraderTest.php index 5858272c0..d4d32573c 100644 --- a/tests/CoreUpgraderTest.php +++ b/tests/CoreUpgraderTest.php @@ -38,8 +38,8 @@ protected function setUp() parent::setUp(); $stub = $this->getMockBuilder(UpgradeContainer::class) - ->disableOriginalConstructor() - ->getMock(); + ->disableOriginalConstructor() + ->getMock(); $this->coreUpgrader = new CoreUpgrader17($stub, new LegacyLogger()); } diff --git a/tests/ErrorHandlerTest.php b/tests/ErrorHandlerTest.php index 7f603c2cc..0722e2059 100644 --- a/tests/ErrorHandlerTest.php +++ b/tests/ErrorHandlerTest.php @@ -53,7 +53,7 @@ public function testCheckExceptionAndContent() $this->errorHandler->exceptionHandler($exception); $errors = $this->logger->getErrors(); - $this->assertEquals(1, count($errors)); + $this->assertCount(1, $errors); $this->assertContains('[INTERNAL] ' . __FILE__ . ' line ' . $line . ' - Exception: ERMAGHERD', end($errors)); } @@ -62,9 +62,9 @@ public function testWarningInErrorHandler() $line = __LINE__; $this->errorHandler->errorHandler(E_WARNING, 'Trololo', __FILE__, $line); $msgs = $this->logger->getInfos(); - $this->assertEquals(0, count($this->logger->getErrors())); - $this->assertEquals(1, count($msgs)); - $this->assertEquals(end($msgs), '[INTERNAL] ' . __FILE__ . ' line ' . $line . ' - Trololo'); + $this->assertCount(0, $this->logger->getErrors()); + $this->assertCount(1, $msgs); + $this->assertSame(end($msgs), '[INTERNAL] ' . __FILE__ . ' line ' . $line . ' - Trololo'); } /** diff --git a/tests/FilesystemAdapterTest.php b/tests/FilesystemAdapterTest.php index 8f15f98ba..ffd192123 100644 --- a/tests/FilesystemAdapterTest.php +++ b/tests/FilesystemAdapterTest.php @@ -46,8 +46,7 @@ protected function setUp() */ public function testFileIsIgnored($file, $fullpath, $process) { - $this->assertSame( - true, + $this->assertTrue( $this->filesystemAdapter->isFileSkipped( $file, $this->container->getProperty(UpgradeContainer::PS_ROOT_PATH) . $fullpath, @@ -62,11 +61,10 @@ public function testFileIsIgnored($file, $fullpath, $process) */ public function testFileFromReleaseIsIgnored($file, $fullpath, $process) { - $this->assertSame( - true, + $this->assertTrue( $this->filesystemAdapter->isFileSkipped( $file, - $this->container->getProperty(UpgradeContainer::LATEST_PATH).$fullpath, + $this->container->getProperty(UpgradeContainer::LATEST_PATH) . $fullpath, $process, $this->container->getProperty(UpgradeContainer::LATEST_PATH) )); @@ -77,8 +75,7 @@ public function testFileFromReleaseIsIgnored($file, $fullpath, $process) */ public function testFileIsNotIgnored($file, $fullpath, $process) { - $this->assertSame( - false, + $this->assertFalse( $this->filesystemAdapter->isFileSkipped( $file, $this->container->getProperty(UpgradeContainer::PS_ROOT_PATH) . $fullpath, @@ -125,7 +122,7 @@ public function testRandomFolderIsNotAPrestashopRelease() public function testTempFolderIsAPrestashopRelease() { // Create temp folder and fill it with the needed files - $folder = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'PSA' . rand(100, 2000); + $folder = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'PSA' . mt_rand(100, 2000); $this->fillFolderWithPsAssets($folder); $this->assertTrue( @@ -139,7 +136,7 @@ public function testTempFolderIsAPrestashopRelease() public function testTempFolderIsNotAPrestashopReleaseAfterChanges() { // Create temp folder and fill it with the needed files - $folder = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'PSA' . rand(100, 2000); + $folder = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'PSA' . mt_rand(100, 2000); $this->fillFolderWithPsAssets($folder); rmdir($folder . DIRECTORY_SEPARATOR . 'classes'); touch($folder . DIRECTORY_SEPARATOR . 'classes'); diff --git a/tests/LegacyLoggerTest.php b/tests/LegacyLoggerTest.php index 9bacd0f70..c7dfb13a3 100644 --- a/tests/LegacyLoggerTest.php +++ b/tests/LegacyLoggerTest.php @@ -46,7 +46,7 @@ public function testSeveralLastInfoAreRegistered() $this->assertSame('Good bye', $logger->getLastInfo()); $infos = $logger->getInfos(); $this->assertSame('Hello', end($infos)); - $this->assertSame(1, count($infos)); + $this->assertCount(1, $infos); } public function testErrorIsRegistered() @@ -55,8 +55,8 @@ public function testErrorIsRegistered() $logger->log(LegacyLogger::CRITICAL, 'Ach!!!'); $errors = $logger->getErrors(); - $this->assertSame(1, count($errors)); - $this->assertSame(0, count($logger->getInfos())); + $this->assertCount(1, $errors); + $this->assertCount(0, $logger->getInfos()); $this->assertSame('Ach!!!', end($errors)); } @@ -66,8 +66,8 @@ public function testMessageIsRegistered() $logger->log(LegacyLogger::DEBUG, 'Some stuff happened'); $messages = $logger->getInfos(); - $this->assertSame(1, count($messages)); - $this->assertSame(0, count($logger->getErrors())); + $this->assertCount(1, $messages); + $this->assertCount(0, $logger->getErrors()); $this->assertSame('Some stuff happened', end($messages)); } } diff --git a/tests/PrestaShopConfigurationTest.php b/tests/PrestaShopConfigurationTest.php index db72fe7ee..847172edc 100644 --- a/tests/PrestaShopConfigurationTest.php +++ b/tests/PrestaShopConfigurationTest.php @@ -51,4 +51,18 @@ public function testPrestaShopVersionInFile() $this->assertSame('1.6.1.18', $class->findPrestaShopVersionInFile($content)); } + + /** + * From PrestaShop 1.7.5.0, the version is stored in the class AppKernel + */ + public function testPrestaShopVersionInAppKernel() + { + $class = new PrestashopConfiguration(__DIR__, __DIR__); + $this->assertSame( + '1.7.6.0', + $class->findPrestaShopVersionInFile( + file_get_contents(__DIR__.'/fixtures/AppKernelExample.php.txt') + ) + ); + } } diff --git a/tests/TranslatorTest.php b/tests/TranslatorTest.php index 3c2a5d894..7b899fecb 100644 --- a/tests/TranslatorTest.php +++ b/tests/TranslatorTest.php @@ -37,7 +37,7 @@ class TranslatorTest extends TestCase protected function setUp() { parent::setUp(); - $this->translator = new Translator(get_class()); + $this->translator = new Translator(__CLASS__); } /** diff --git a/tests/UpgradeContainerTest.php b/tests/UpgradeContainerTest.php index c2096b061..006010753 100644 --- a/tests/UpgradeContainerTest.php +++ b/tests/UpgradeContainerTest.php @@ -55,7 +55,7 @@ public function objectsToInstanciateProvider() array('getCookie', PrestaShop\Module\AutoUpgrade\Cookie::class), array('getFileConfigurationStorage', PrestaShop\Module\AutoUpgrade\Parameters\FileConfigurationStorage::class), array('getFileFilter', \PrestaShop\Module\AutoUpgrade\UpgradeTools\FileFilter::class), -// array('getUpgrader', \PrestaShop\Module\AutoUpgrade\Upgrader::class), + // array('getUpgrader', \PrestaShop\Module\AutoUpgrade\Upgrader::class), array('getFilesystemAdapter', PrestaShop\Module\AutoUpgrade\UpgradeTools\FilesystemAdapter::class), array('getLogger', PrestaShop\Module\AutoUpgrade\Log\LegacyLogger::class), array('getModuleAdapter', PrestaShop\Module\AutoUpgrade\UpgradeTools\ModuleAdapter::class), diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index c5ac32e76..c68015059 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -7,9 +7,25 @@ services: SELENIUM_HOST: selenium-chrome URL: prestashop-web depends_on: - - "prestashop" - - "selenium-chrome" - command: ["/tmp/wait-for-it.sh", "--timeout=200", "--strict", "prestashop:80", "--", "/tmp/node_modules/mocha/bin/mocha /tmp/test/campaigns/high/13_installation", "--URL=prestashop-web", "--SELENIUM=selenium-chrome", "--DIR=/home/seluser/Downloads/", "--DB_SERVER=db", "--DB_USER=root", "--DB_PASSWD=admin", "--RCTARGET=/tmp/", "--RCLINK=http://localhost/prestashop_1.7.3.0-RC1.zip"] + - 'prestashop' + - 'selenium-chrome' + command: + [ + '/tmp/wait-for-it.sh', + '--timeout=200', + '--strict', + 'prestashop:80', + '--', + '/tmp/node_modules/mocha/bin/mocha /tmp/test/campaigns/high/13_installation', + '--URL=prestashop-web', + '--SELENIUM=selenium-chrome', + '--DIR=/home/seluser/Downloads/', + '--DB_SERVER=db', + '--DB_USER=root', + '--DB_PASSWD=admin', + '--RCTARGET=/tmp/', + '--RCLINK=http://localhost/prestashop_1.7.3.0-RC1.zip', + ] volumes: - ./screenshots/:/home/test/screenshots/ - downloads:/home/seluser/Downloads @@ -26,25 +42,33 @@ services: PS_FOLDER_ADMIN: admin-dev PS_FOLDER_INSTALL: install-dev depends_on: - - "db" - command: ["/tmp/wait-for-it.sh", "--timeout=60", "--strict", "db:3306", "--", "/tmp/docker_run.sh"] + - 'db' + command: + [ + '/tmp/wait-for-it.sh', + '--timeout=60', + '--strict', + 'db:3306', + '--', + '/tmp/docker_run.sh', + ] ports: - - 8002:80 + - 8002:80 networks: default: - aliases: - - prestashop-web + aliases: + - prestashop-web selenium-chrome: image: selenium/standalone-chrome ports: - 4444:4444 volumes: - - downloads:/home/seluser/Downloads + - downloads:/home/seluser/Downloads networks: default: - aliases: - - selenium-chrome + aliases: + - selenium-chrome db: image: mysql @@ -54,8 +78,7 @@ services: - default volumes: - downloads: + downloads: networks: default: - diff --git a/tests/fixtures/AppKernelExample.php.txt b/tests/fixtures/AppKernelExample.php.txt new file mode 100644 index 000000000..5a57c8658 --- /dev/null +++ b/tests/fixtures/AppKernelExample.php.txt @@ -0,0 +1,244 @@ + + * @copyright 2007-2018 PrestaShop SA + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +use Doctrine\DBAL\DriverManager; +use PrestaShopBundle\Kernel\ModuleRepository; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Kernel; + +class AppKernel extends Kernel +{ + const VERSION = '1.7.6.0'; + const MAJOR_VERSION_STRING = '1.7'; + const MAJOR_VERSION = 17; + const MINOR_VERSION = 6; + const RELEASE_VERSION = 0; + + /** + * @{inheritdoc} + */ + public function registerBundles() + { + $bundles = array( + new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + new Symfony\Bundle\SecurityBundle\SecurityBundle(), + new Symfony\Bundle\TwigBundle\TwigBundle(), + new Symfony\Bundle\MonologBundle\MonologBundle(), + new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), + new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + // PrestaShop Core bundle + new PrestaShopBundle\PrestaShopBundle(), + // PrestaShop Translation parser + new PrestaShop\TranslationToolsBundle\TranslationToolsBundle(), + // REST API consumer + new Csa\Bundle\GuzzleBundle\CsaGuzzleBundle(), + new League\Tactician\Bundle\TacticianBundle(), + ); + + if (in_array($this->getEnvironment(), array('dev', 'test'), true)) { + $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); + $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); + $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); + } + + if ('dev' === $this->getEnvironment()) { + $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle(); + } + + /* Will not work until PrestaShop is installed */ + if ($this->parametersFileExists()) { + try { + $this->enableComposerAutoloaderOnModules($this->getActiveModules()); + } catch (\Exception $e) { + } + } + + return $bundles; + } + + /** + * @{inheritdoc} + */ + protected function getKernelParameters() + { + $kernelParameters = parent::getKernelParameters(); + + $activeModules = array(); + + /* Will not work until PrestaShop is installed */ + if ($this->parametersFileExists()) { + try { + $this->getConnection()->connect(); + $activeModules = $this->getActiveModules(); + } catch (\Exception $e) { + } + } + + return array_merge( + $kernelParameters, + array('kernel.active_modules' => $activeModules) + ); + } + + /** + * @{inheritdoc} + */ + public function getRootDir() + { + return __DIR__; + } + + /** + * @{inheritdoc} + */ + public function getCacheDir() + { + return dirname(__DIR__).'/var/cache/'.$this->getEnvironment(); + } + + /** + * @{inheritdoc} + */ + public function getLogDir() + { + return dirname(__DIR__).'/var/logs'; + } + + /** + * @{inheritdoc} + * @throws \Exception + */ + public function registerContainerConfiguration(LoaderInterface $loader) + { + $loader->load(function (ContainerBuilder $container) { + $container->setParameter('container.autowiring.strict_mode', true); + $container->setParameter('container.dumper.inline_class_loader', false); + $container->addObjectResource($this); + }); + + $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); + } + + /** + * Return all active modules. + * + * @return array list of modules names. + * @throws \Doctrine\DBAL\DBALException + */ + private function getActiveModules() + { + $databasePrefix = $this->getParameters()['database_prefix']; + + $modulesRepository = new ModuleRepository( + $this->getConnection(), + $databasePrefix + ); + + return $modulesRepository->getActiveModules(); + } + + /** + * @return array The root parameters of PrestaShop. + */ + private function getParameters() + { + if ($this->parametersFileExists()) { + $config = require $this->getParametersFile(); + + return $config['parameters']; + } + + return array(); + } + + /** + * @var bool + * @return bool + */ + private function parametersFileExists() + { + return file_exists($this->getParametersFile()); + } + + /** + * @return string file path to PrestaShop configuration parameters. + */ + private function getParametersFile() + { + return $this->getRootDir().'/config/parameters.php'; + } + + /** + * @return \Doctrine\DBAL\Connection + * @throws \Doctrine\DBAL\DBALException + */ + private function getConnection() + { + $parameters = $this->getParameters(); + + return DriverManager::getConnection(array( + 'dbname' => $parameters['database_name'], + 'user' => $parameters['database_user'], + 'password' => $parameters['database_password'], + 'host' => $parameters['database_host'], + 'port' => $parameters['database_port'], + 'charset' => 'utf8', + 'driver' => 'pdo_mysql', + )); + } + + /** + * Enable auto loading of module Composer autoloader if needed. + * Need to be done as earlier as possible in application lifecycle. + * + * @param array $modules the list of modules + */ + private function enableComposerAutoloaderOnModules($modules) + { + foreach ($modules as $module) { + $autoloader = __DIR__.'/../modules/'.$module.'/vendor/autoload.php'; + + if (file_exists($autoloader)) { + include_once $autoloader; + } + } + } + + /** + * Gets the application root dir. + * Override Kernel due to the fact that we remove the composer.json in + * downloaded package. More we are not a framework and the root directory + * should always be the parent of this file. + * + * @return string The project root dir + */ + public function getProjectDir() + { + return realpath(__DIR__ . '/..'); + } +} diff --git a/tests/testCliProcess.php b/tests/testCliProcess.php index c481dc20c..affb74986 100644 --- a/tests/testCliProcess.php +++ b/tests/testCliProcess.php @@ -57,9 +57,9 @@ function displayHelp() testCliProcess.php [Options] ------------------ Options ---help Display this message. +--help Display this message. ---admin-dir Tells where the admin directory is. +--dir Tells where the admin directory is. [UPGRADE] --channel Selects what upgrade to run (minor, major etc.)