From 13f5dd19a7653528e8b1a61ebea804bad4c6278e Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 7 Aug 2018 12:13:55 +0200 Subject: [PATCH 01/18] Implement new abstract class ChainedTasks --- classes/TaskRunner/ChainedTasks.php | 94 +++++++++++++++++++ .../{ => Upgrade}/AllUpgradeTasks.php | 53 ++--------- 2 files changed, 104 insertions(+), 43 deletions(-) create mode 100644 classes/TaskRunner/ChainedTasks.php rename classes/TaskRunner/{ => Upgrade}/AllUpgradeTasks.php (73%) diff --git a/classes/TaskRunner/ChainedTasks.php b/classes/TaskRunner/ChainedTasks.php new file mode 100644 index 000000000..45d01a11b --- /dev/null +++ b/classes/TaskRunner/ChainedTasks.php @@ -0,0 +1,94 @@ + + * @copyright 2007-2018 PrestaShop SA + * @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\TaskRunner; + +use PrestaShop\Module\AutoUpgrade\AjaxResponse; +use PrestaShop\Module\AutoUpgrade\UpgradeTools\TaskRepository; + +/** + * Execute the whole process in a single request, useful in CLI. + */ +abstract class ChainedTasks extends AbstractTask +{ + private $step = self::initialTask; + + public function run() + { + $requireRestart = false; + while ($this->canContinue() && !$requireRestart) { + echo PHP_EOL.'=== Step '.$this->step.PHP_EOL; + $controller = TaskRepository::get($this->step, $this->container); + $controller->init(); + $controller->run(); + + $result = $controller->getResponse(); + $requireRestart = $this->checkIfRestartRequested($result); + $this->error = $result->getError(); + $this->stepDone = $result->getStepDone(); + $this->step = $result->getNext(); + } + + return (int) ($this->error || $this->step === 'error'); + } + + /** + * Customize the execution context with several options + * + * @param array $options + */ + public function setOptions(array $options) + { + } + + /** + * Tell the while loop if it can continue. + * + * @return bool + */ + protected function canContinue() + { + if (empty($this->step)) { + return false; + } + + if ($this->error) { + return false; + } + + return $this->step !== 'error'; + } + + /** + * For some steps, we may require a new request to be made. + * Return true for stopping the process + */ + protected function checkIfRestartRequested(AjaxResponse $response) + { + return false; + } +} diff --git a/classes/TaskRunner/AllUpgradeTasks.php b/classes/TaskRunner/Upgrade/AllUpgradeTasks.php similarity index 73% rename from classes/TaskRunner/AllUpgradeTasks.php rename to classes/TaskRunner/Upgrade/AllUpgradeTasks.php index bf3115626..d0af39a0d 100644 --- a/classes/TaskRunner/AllUpgradeTasks.php +++ b/classes/TaskRunner/Upgrade/AllUpgradeTasks.php @@ -25,40 +25,19 @@ * International Registered Trademark & Property of PrestaShop SA */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner; +namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; use PrestaShop\Module\AutoUpgrade\AjaxResponse; +use PrestaShop\Module\AutoUpgrade\TaskRunner\ChainedTasks; use PrestaShop\Module\AutoUpgrade\UpgradeContainer; -use PrestaShop\Module\AutoUpgrade\UpgradeTools\TaskRepository; /** * Execute the whole upgrade process in a single request. */ -class AllUpgradeTasks extends AbstractTask +class AllUpgradeTasks extends ChainedTasks { const initialTask = 'upgradeNow'; - private $step = self::initialTask; - - public function run() - { - $requireRestart = false; - while ($this->canContinue() && !$requireRestart) { - echo PHP_EOL.'=== Step '.$this->step.PHP_EOL; - $controller = TaskRepository::get($this->step, $this->container); - $controller->init(); - $controller->run(); - - $result = $controller->getResponse(); - $requireRestart = $this->checkIfRestartRequested($result); - $this->error = $result->getError(); - $this->stepDone = $result->getStepDone(); - $this->step = $result->getNext(); - } - - return (int) ($this->error || $this->step === 'error'); - } - /** * Customize the execution context with several options * > action: Replace the initial step to run @@ -67,8 +46,10 @@ public function run() * * @param array $options */ - public function setOptions($options) + public function setOptions(array $options) { + parent::setOptions($options); + if (!empty($options['action'])) { $this->step = $options['action']; } @@ -86,30 +67,16 @@ public function setOptions($options) } } - /** - * Tell the while loop if it can continue. - * - * @return bool - */ - protected function canContinue() - { - if (empty($this->step)) { - return false; - } - - if ($this->error) { - return false; - } - - return $this->step !== 'error'; - } - /** * For some steps, we may require a new request to be made. * For instance, in case of obsolete autoloader or loaded classes after a file copy. */ protected function checkIfRestartRequested(AjaxResponse $response) { + if (parent::checkIfRestartRequested($response)) { + return true; + } + if (!$response->getStepDone()) { return false; } From 40b73bee45dfc792247ea2a7bbd772c8c79442d9 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 7 Aug 2018 12:34:18 +0200 Subject: [PATCH 02/18] Prepare test file for rollback --- .travis.yml | 5 ++++- tests/{testCliUpgrade.php => testCliProcess.php} | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) rename tests/{testCliUpgrade.php => testCliProcess.php} (86%) diff --git a/.travis.yml b/.travis.yml index 85ecc737e..29ee6af23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,10 @@ before_script: script: - php vendor/phpunit/phpunit/phpunit tests - - docker exec -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliUpgrade.php admin-dev/autoupgrade/cli-upgrade.php --dir="admin-dev" --channel="$CHANNEL" + # Upgrade + - docker exec -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-upgrade.php --dir="admin-dev" --channel="$CHANNEL" + # Rollback + - docker exec -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-rollback.php --dir="admin-dev" --backup="`ls -td -- admin-dev/autoupgrade/backup/*/ | head -n 1 | cut -d'/' -f4`" after_script: - docker ps diff --git a/tests/testCliUpgrade.php b/tests/testCliProcess.php similarity index 86% rename from tests/testCliUpgrade.php rename to tests/testCliProcess.php index 26f605724..6af0b6586 100644 --- a/tests/testCliUpgrade.php +++ b/tests/testCliProcess.php @@ -49,18 +49,22 @@ function displayHelp() { echo << [Options] +testCliProcess.php [Options] ------------------ Options --help Display this message. --admin-dir Tells where the admin directory is. + +[UPGRADE] --channel Selects what upgrade to run (minor, major etc.) +[ROLLBACK] +--backup Select the backup to restore. To be found in autoupgrade/backup, in your admin folder. EOF; } From b8d7185872f42b8615f897c22f9014aa17eb8925 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 7 Aug 2018 12:35:04 +0200 Subject: [PATCH 03/18] Add files for CLI rollback --- .../TaskRunner/Rollback/AllRollbackTasks.php | 63 +++++++++++++++++++ cli-rollback.php | 40 ++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 classes/TaskRunner/Rollback/AllRollbackTasks.php create mode 100644 cli-rollback.php diff --git a/classes/TaskRunner/Rollback/AllRollbackTasks.php b/classes/TaskRunner/Rollback/AllRollbackTasks.php new file mode 100644 index 000000000..bdf38f740 --- /dev/null +++ b/classes/TaskRunner/Rollback/AllRollbackTasks.php @@ -0,0 +1,63 @@ + + * @copyright 2007-2018 PrestaShop SA + * @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\TaskRunner\Upgrade; + +use PrestaShop\Module\AutoUpgrade\TaskRunner\ChainedTasks; + +/** + * Execute the whole upgrade process in a single request. + */ +class AllUpgradeTasks extends ChainedTasks +{ + const initialTask = 'rollback'; + + /** + * Customize the execution context with several options + * > action: Replace the initial step to run + * > channel: Makes a specific upgrade (minor, major etc.) + * > data: Loads an encoded array of data coming from another request. + * + * @param array $options + */ + public function setOptions(array $options) + { + parent::setOptions($options); + + if (!empty($options['backup'])) { + $this->container->getState()->setRestoreName($options['backup']); + } + } + + /** + * Set default config on first run. + */ + public function init() + { + // Do nothing + } +} diff --git a/cli-rollback.php b/cli-rollback.php new file mode 100644 index 000000000..547c25ae8 --- /dev/null +++ b/cli-rollback.php @@ -0,0 +1,40 @@ + + * @copyright 2007-2018 PrestaShop SA + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +require_once realpath(dirname(__FILE__).'/../../modules/autoupgrade').'/ajax-upgradetabconfig.php'; +$container = autoupgrade_init_container(dirname(__FILE__)); + +if (php_sapi_name() !== 'cli') { + echo 'This script must be called from CLI'; + exit(1); +} + +$container->setLogger(new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger()); +$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\AllRollbackTasks($container); +$controller->setOptions(getopt('', array('backup::'))); +$controller->init(); +exit($controller->run()); From 276c748c6606283ef547c6c208c5d8e074fae112 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 7 Aug 2018 12:42:08 +0200 Subject: [PATCH 04/18] Fix namespaces & tests --- .travis.yml | 2 +- classes/TaskRunner/ChainedTasks.php | 2 +- classes/TaskRunner/Rollback/AllRollbackTasks.php | 6 ++++-- classes/TaskRunner/Upgrade/AllUpgradeTasks.php | 2 ++ cli-rollback.php | 2 +- cli-upgrade.php | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 29ee6af23..d7d28d7d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ script: # Upgrade - docker exec -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-upgrade.php --dir="admin-dev" --channel="$CHANNEL" # Rollback - - docker exec -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-rollback.php --dir="admin-dev" --backup="`ls -td -- admin-dev/autoupgrade/backup/*/ | head -n 1 | cut -d'/' -f4`" + - docker exec -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'"` after_script: - docker ps diff --git a/classes/TaskRunner/ChainedTasks.php b/classes/TaskRunner/ChainedTasks.php index 45d01a11b..4da558b8c 100644 --- a/classes/TaskRunner/ChainedTasks.php +++ b/classes/TaskRunner/ChainedTasks.php @@ -35,7 +35,7 @@ */ abstract class ChainedTasks extends AbstractTask { - private $step = self::initialTask; + protected $step; public function run() { diff --git a/classes/TaskRunner/Rollback/AllRollbackTasks.php b/classes/TaskRunner/Rollback/AllRollbackTasks.php index bdf38f740..c8b3b2d83 100644 --- a/classes/TaskRunner/Rollback/AllRollbackTasks.php +++ b/classes/TaskRunner/Rollback/AllRollbackTasks.php @@ -25,17 +25,19 @@ * International Registered Trademark & Property of PrestaShop SA */ -namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade; +namespace PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback; use PrestaShop\Module\AutoUpgrade\TaskRunner\ChainedTasks; /** * Execute the whole upgrade process in a single request. */ -class AllUpgradeTasks extends ChainedTasks +class AllRollbackTasks extends ChainedTasks { const initialTask = 'rollback'; + protected $step = self::initialTask; + /** * Customize the execution context with several options * > action: Replace the initial step to run diff --git a/classes/TaskRunner/Upgrade/AllUpgradeTasks.php b/classes/TaskRunner/Upgrade/AllUpgradeTasks.php index d0af39a0d..a759574be 100644 --- a/classes/TaskRunner/Upgrade/AllUpgradeTasks.php +++ b/classes/TaskRunner/Upgrade/AllUpgradeTasks.php @@ -38,6 +38,8 @@ class AllUpgradeTasks extends ChainedTasks { const initialTask = 'upgradeNow'; + protected $step = self::initialTask; + /** * Customize the execution context with several options * > action: Replace the initial step to run diff --git a/cli-rollback.php b/cli-rollback.php index 547c25ae8..777ab94a8 100644 --- a/cli-rollback.php +++ b/cli-rollback.php @@ -34,7 +34,7 @@ } $container->setLogger(new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger()); -$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\AllRollbackTasks($container); +$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback\AllRollbackTasks($container); $controller->setOptions(getopt('', array('backup::'))); $controller->init(); exit($controller->run()); diff --git a/cli-upgrade.php b/cli-upgrade.php index 9b597dd75..02cdfc412 100644 --- a/cli-upgrade.php +++ b/cli-upgrade.php @@ -34,7 +34,7 @@ } $container->setLogger(new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger()); -$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\AllUpgradeTasks($container); +$controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\AllUpgradeTasks($container); $controller->setOptions(getopt('', array('action::', 'channel::', 'data::'))); $controller->init(); exit($controller->run()); From a3f7b842af762c294843b4d173746e369337e13a Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 7 Aug 2018 15:21:39 +0200 Subject: [PATCH 05/18] Load parameter files prior database login --- classes/TaskRunner/Rollback/RestoreDb.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/classes/TaskRunner/Rollback/RestoreDb.php b/classes/TaskRunner/Rollback/RestoreDb.php index 12ca56745..842064211 100644 --- a/classes/TaskRunner/Rollback/RestoreDb.php +++ b/classes/TaskRunner/Rollback/RestoreDb.php @@ -252,5 +252,8 @@ public function init() { // We don't need the whole core being instanciated, only the autoloader $this->container->initPrestaShopAutoloader(); + + // Loads the parameters.php file on PrestaShop 1.7, needed for accessing the database + require_once $this->container->getProperty(UpgradeContainer::PS_ROOT_PATH).'/config/bootstrap.php'; } } From b8ee3ad326acceb6aa92b79f14b2db95958de7dc Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 7 Aug 2018 16:52:38 +0200 Subject: [PATCH 06/18] Check property of Context before translating --- classes/UpgradeTools/Translator.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/classes/UpgradeTools/Translator.php b/classes/UpgradeTools/Translator.php index 7dc59bf54..8e255917e 100644 --- a/classes/UpgradeTools/Translator.php +++ b/classes/UpgradeTools/Translator.php @@ -38,6 +38,11 @@ public function __construct($caller) public function trans($id, array $parameters = array(), $domain = null, $locale = null) { + // If PrestaShop core is not instancied properly, do not try to translate + if (!method_exists(\Context::class, 'getContext') || null === \Context::getContext()->language) { + return $this->applyParameters($id, $parameters); + } + if (method_exists(\Context::class, 'getTranslator')) { return \Context::getContext()->getTranslator()->trans($id, $parameters, $domain, $locale); } From f30a963dcb293df099b39629202f7fd9008f4294 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 7 Aug 2018 17:31:21 +0200 Subject: [PATCH 07/18] Remove lost echo --- classes/TaskRunner/ChainedTasks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/TaskRunner/ChainedTasks.php b/classes/TaskRunner/ChainedTasks.php index 4da558b8c..57c2d235e 100644 --- a/classes/TaskRunner/ChainedTasks.php +++ b/classes/TaskRunner/ChainedTasks.php @@ -41,7 +41,7 @@ public function run() { $requireRestart = false; while ($this->canContinue() && !$requireRestart) { - echo PHP_EOL.'=== Step '.$this->step.PHP_EOL; + $this->logger->info('=== Step '.$this->step); $controller = TaskRepository::get($this->step, $this->container); $controller->init(); $controller->run(); From 89b2397a41432949ec5a33c1d186aec9e91f7890 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Wed, 8 Aug 2018 10:34:42 +0200 Subject: [PATCH 08/18] Code review --- classes/TaskRunner/ChainedTasks.php | 9 ++++++--- classes/TaskRunner/Rollback/AllRollbackTasks.php | 2 -- classes/TaskRunner/Upgrade/AllUpgradeTasks.php | 2 -- cli-rollback.php | 6 +++--- cli-upgrade.php | 6 +++--- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/classes/TaskRunner/ChainedTasks.php b/classes/TaskRunner/ChainedTasks.php index 57c2d235e..c8e8726bf 100644 --- a/classes/TaskRunner/ChainedTasks.php +++ b/classes/TaskRunner/ChainedTasks.php @@ -37,6 +37,11 @@ abstract class ChainedTasks extends AbstractTask { protected $step; + /** + * Execute all the tasks from a specific initial step, until the end (complete or error). + * + * @return int Return code (0 for success, any value otherwise) + */ public function run() { $requireRestart = false; @@ -61,9 +66,7 @@ public function run() * * @param array $options */ - public function setOptions(array $options) - { - } + abstract public function setOptions(array $options); /** * Tell the while loop if it can continue. diff --git a/classes/TaskRunner/Rollback/AllRollbackTasks.php b/classes/TaskRunner/Rollback/AllRollbackTasks.php index c8b3b2d83..0e16504dd 100644 --- a/classes/TaskRunner/Rollback/AllRollbackTasks.php +++ b/classes/TaskRunner/Rollback/AllRollbackTasks.php @@ -48,8 +48,6 @@ class AllRollbackTasks extends ChainedTasks */ public function setOptions(array $options) { - parent::setOptions($options); - if (!empty($options['backup'])) { $this->container->getState()->setRestoreName($options['backup']); } diff --git a/classes/TaskRunner/Upgrade/AllUpgradeTasks.php b/classes/TaskRunner/Upgrade/AllUpgradeTasks.php index a759574be..d2b21e5f0 100644 --- a/classes/TaskRunner/Upgrade/AllUpgradeTasks.php +++ b/classes/TaskRunner/Upgrade/AllUpgradeTasks.php @@ -50,8 +50,6 @@ class AllUpgradeTasks extends ChainedTasks */ public function setOptions(array $options) { - parent::setOptions($options); - if (!empty($options['action'])) { $this->step = $options['action']; } diff --git a/cli-rollback.php b/cli-rollback.php index 777ab94a8..28c084c72 100644 --- a/cli-rollback.php +++ b/cli-rollback.php @@ -25,14 +25,14 @@ * International Registered Trademark & Property of PrestaShop SA */ -require_once realpath(dirname(__FILE__).'/../../modules/autoupgrade').'/ajax-upgradetabconfig.php'; -$container = autoupgrade_init_container(dirname(__FILE__)); - if (php_sapi_name() !== 'cli') { echo 'This script must be called from CLI'; exit(1); } +require_once realpath(dirname(__FILE__).'/../../modules/autoupgrade').'/ajax-upgradetabconfig.php'; +$container = autoupgrade_init_container(dirname(__FILE__)); + $container->setLogger(new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger()); $controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Rollback\AllRollbackTasks($container); $controller->setOptions(getopt('', array('backup::'))); diff --git a/cli-upgrade.php b/cli-upgrade.php index 02cdfc412..64de87eae 100644 --- a/cli-upgrade.php +++ b/cli-upgrade.php @@ -25,14 +25,14 @@ * International Registered Trademark & Property of PrestaShop SA */ -require_once realpath(dirname(__FILE__).'/../../modules/autoupgrade').'/ajax-upgradetabconfig.php'; -$container = autoupgrade_init_container(dirname(__FILE__)); - if (php_sapi_name() !== 'cli') { echo 'This script must be called from CLI'; exit(1); } +require_once realpath(dirname(__FILE__).'/../../modules/autoupgrade').'/ajax-upgradetabconfig.php'; +$container = autoupgrade_init_container(dirname(__FILE__)); + $container->setLogger(new PrestaShop\Module\AutoUpgrade\Log\StreamedLogger()); $controller = new \PrestaShop\Module\AutoUpgrade\TaskRunner\Upgrade\AllUpgradeTasks($container); $controller->setOptions(getopt('', array('action::', 'channel::', 'data::'))); From 1b49a6cf975e3f188774cd32255fa7aef922497e Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Fri, 10 Aug 2018 14:32:19 +0200 Subject: [PATCH 09/18] Remove use of channel17.xml --- classes/Upgrader.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/classes/Upgrader.php b/classes/Upgrader.php index 9f6a15747..696fde205 100755 --- a/classes/Upgrader.php +++ b/classes/Upgrader.php @@ -37,7 +37,6 @@ class Upgrader public $addons_api = 'api.addons.prestashop.com'; public $rss_channel_link = 'https://api.prestashop.com/xml/channel.xml'; public $rss_md5file_link_dir = 'https://api.prestashop.com/xml/md5/'; - public $rss_channel_link_major = 'https://api.prestashop.com/xml/channel17.xml'; public $rss_md5file_link_dir_major = 'https://api.prestashop.com/xml/md5-17/'; /** @@ -309,9 +308,11 @@ public function getXmlFile($xml_localfile, $xml_remotefile, $refresh = false) public function getXmlChannel($refresh = false) { - // TODO: To be removed, we should have only one file to get. - $file = ($this->channel === 'major' ? $this->rss_channel_link_major : $this->rss_channel_link); - $xml = $this->getXmlFile(_PS_ROOT_DIR_.'/config/xml/'.pathinfo($file, PATHINFO_BASENAME), $file, $refresh); + $xml = $this->getXmlFile( + _PS_ROOT_DIR_.'/config/xml/'.pathinfo($this->rss_channel_link, PATHINFO_BASENAME), + $this->rss_channel_link, + $refresh + ); if ($refresh) { if (class_exists('Configuration', false)) { Configuration::updateValue('PS_LAST_VERSION_CHECK', time()); From 662baae1e40d7a600191f97a7ed69a86cf099bcc Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Fri, 17 Aug 2018 10:33:12 +0200 Subject: [PATCH 10/18] Use a single folder for md5 files --- classes/Upgrader.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/classes/Upgrader.php b/classes/Upgrader.php index 8201ca319..f6edcbf44 100755 --- a/classes/Upgrader.php +++ b/classes/Upgrader.php @@ -38,7 +38,6 @@ class Upgrader public $addons_api = 'api.addons.prestashop.com'; public $rss_channel_link = 'https://api.prestashop.com/xml/channel.xml'; public $rss_md5file_link_dir = 'https://api.prestashop.com/xml/md5/'; - public $rss_md5file_link_dir_major = 'https://api.prestashop.com/xml/md5-17/'; /** * @var bool contains true if last version is not installed @@ -333,12 +332,7 @@ public function getXmlChannel($refresh = false) */ public function getXmlMd5File($version, $refresh = false) { - $source = $this->rss_md5file_link_dir; - if (version_compare($version, '1.7.0.0', '>=')) { - $source = $this->rss_md5file_link_dir_major; - } - - return $this->getXmlFIle(_PS_ROOT_DIR_.'/config/xml/'.$version.'.xml', $source.$version.'.xml', $refresh); + return $this->getXmlFIle(_PS_ROOT_DIR_.'/config/xml/'.$version.'.xml', $this->rss_md5file_link_dir.$version.'.xml', $refresh); } /** From d99c074cd1f1581ed73813e3e7e5ee1583ae14fd Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Wed, 15 Aug 2018 11:44:15 +0200 Subject: [PATCH 11/18] Force composer autoload to be appended --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index dbd921446..d7df70408 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ }, "config": { "preferred-install": "dist", + "prepend-autoloader": false, "platform": { "php": "5.6" } From cb263e3cac69db1d07bf902fa7a8788a8390ec4d Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Mon, 13 Aug 2018 17:05:05 +0200 Subject: [PATCH 12/18] Fix wording with replaced files --- classes/UpgradePage.php | 3 ++- js/upgrade.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/classes/UpgradePage.php b/classes/UpgradePage.php index 25f6b1430..119220a0a 100644 --- a/classes/UpgradePage.php +++ b/classes/UpgradePage.php @@ -360,7 +360,8 @@ private function getJsParams($ajaxResult) 'confirmPreserveFileOptions' => $translator->trans('Please confirm that you want to preserve file options.', array(), $translationDomain), 'lessOptions' => $translator->trans('Less options', array(), $translationDomain), 'moreOptions' => $translator->trans('More options (Expert mode)', array(), $translationDomain), - 'filesWillBeDeleted' => $translator->trans('Theses files will be deleted', array(), $translationDomain), + 'filesWillBeDeleted' => $translator->trans('These files will be deleted', array(), $translationDomain), + 'filesWillBeReplaced' => $translator->trans('These files will be replaced', array(), $translationDomain), ), ); diff --git a/js/upgrade.js b/js/upgrade.js index e6caf6dd9..d88e01210 100644 --- a/js/upgrade.js +++ b/js/upgrade.js @@ -52,7 +52,8 @@ if (typeof input === 'undefined') { confirmPreserveFileOptions: "Please confirm that you want to preserve file options.", lessOptions: "Less options", moreOptions: "More options (Expert mode)", - filesWillBeDeleted: "Theses files will be deleted" + filesWillBeDeleted: "These files will be deleted", + filesWillBeReplaced: "These files will be replaced", } }; } @@ -717,7 +718,7 @@ $(document).ready(function() { addModifiedFileList(input.translation.filesWillBeDeleted, answer.result.deleted, "diffImportant", "#diffList"); } if (answer.result.modified.length) { - addModifiedFileList(input.translation.filesWillBeDeleted, answer.result.modified, "diffImportant", "#diffList"); + addModifiedFileList(input.translation.filesWillBeReplaced, answer.result.modified, "diffImportant", "#diffList"); } $("#toggleDiffList").bind("click", function(e) { From f87b3922fda81f33c47c56c045c0bc6c0fb4f728 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Wed, 15 Aug 2018 11:44:15 +0200 Subject: [PATCH 13/18] Force composer autoload to be appended --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index dbd921446..d7df70408 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ }, "config": { "preferred-install": "dist", + "prepend-autoloader": false, "platform": { "php": "5.6" } From de8f3c1613b0c6a55d2b6a1035c328c03039c9b6 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Fri, 17 Aug 2018 14:38:28 +0200 Subject: [PATCH 14/18] Checks HTTP codes also after rollback --- .travis.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 766a88a88..14d30ed3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,15 +26,20 @@ before_script: script: - php vendor/phpunit/phpunit/phpunit tests + # Upgrade - docker exec -u www-data -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliProcess.php admin-dev/autoupgrade/cli-upgrade.php --dir="admin-dev" --channel="$CHANNEL" # 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 - bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/admin-dev/index.php)" == "200" ]' - - # Rollback + + # 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'"` + # 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 + - bash -c '[ "$(curl -L -s -o /dev/null -w %{http_code} http://localhost:8001/admin-dev/index.php)" == "200" ]' after_script: - docker ps From 9544e66b20b68695a60e393cdccf5c421beecd00 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Mon, 20 Aug 2018 11:52:41 +0200 Subject: [PATCH 15/18] Fix undefined class Tools --- classes/UpgradeTools/CoreUpgrader/CoreUpgrader16.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader16.php b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader16.php index 61b8c28a6..8f5d919ec 100644 --- a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader16.php +++ b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader16.php @@ -64,10 +64,10 @@ public function writeNewSettings() $datas['_RIJNDAEL_KEY_'] = _RIJNDAEL_KEY_; $datas['_RIJNDAEL_IV_'] = _RIJNDAEL_IV_; } elseif (function_exists('openssl_encrypt')) { - $datas['_RIJNDAEL_KEY_'] = Tools::passwdGen(32); + $datas['_RIJNDAEL_KEY_'] = Tools14::passwdGen(32); $datas['_RIJNDAEL_IV_'] = base64_encode(openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-128-CBC'))); } elseif (function_exists('mcrypt_encrypt')) { - $datas['_RIJNDAEL_KEY_'] = Tools::passwdGen(mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); + $datas['_RIJNDAEL_KEY_'] = Tools14::passwdGen(mcrypt_get_key_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)); $datas['_RIJNDAEL_IV_'] = base64_encode(mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND)); } From 8f838084afc3eb959b39c46a54d4c7606f10b819 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Mon, 20 Aug 2018 12:03:25 +0200 Subject: [PATCH 16/18] Bump version to 4.1.0 --- autoupgrade.php | 2 +- config.xml | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/autoupgrade.php b/autoupgrade.php index 958abab5e..dd65ca848 100644 --- a/autoupgrade.php +++ b/autoupgrade.php @@ -33,7 +33,7 @@ public function __construct() $this->name = 'autoupgrade'; $this->tab = 'administration'; $this->author = 'PrestaShop'; - $this->version = '4.0.0'; + $this->version = '4.1.0'; $this->need_instance = 1; $this->bootstrap = true; diff --git a/config.xml b/config.xml index aa5ec7998..334ce3f06 100644 --- a/config.xml +++ b/config.xml @@ -1,10 +1,10 @@ autoupgrade - - - - + + + + 1 1 From ff430c1971ea9cce8abc1531366860ec33b88860 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Mon, 20 Aug 2018 18:10:40 +0200 Subject: [PATCH 17/18] Revert "Force composer autoload to be appended" This reverts commit f87b3922fda81f33c47c56c045c0bc6c0fb4f728. --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index d7df70408..dbd921446 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ }, "config": { "preferred-install": "dist", - "prepend-autoloader": false, "platform": { "php": "5.6" } From 46b363be65e3b33a226141dfd4116eb12a9a1099 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 21 Aug 2018 11:21:52 +0200 Subject: [PATCH 18/18] Check bootstrap.php before require --- classes/TaskRunner/Rollback/RestoreDb.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/TaskRunner/Rollback/RestoreDb.php b/classes/TaskRunner/Rollback/RestoreDb.php index 842064211..8fbb644b2 100644 --- a/classes/TaskRunner/Rollback/RestoreDb.php +++ b/classes/TaskRunner/Rollback/RestoreDb.php @@ -254,6 +254,8 @@ public function init() $this->container->initPrestaShopAutoloader(); // Loads the parameters.php file on PrestaShop 1.7, needed for accessing the database - require_once $this->container->getProperty(UpgradeContainer::PS_ROOT_PATH).'/config/bootstrap.php'; + if (file_exists($this->container->getProperty(UpgradeContainer::PS_ROOT_PATH).'/config/bootstrap.php')) { + require_once $this->container->getProperty(UpgradeContainer::PS_ROOT_PATH).'/config/bootstrap.php'; + } } }