From 6218a88fe4da582d1b5769834b1053199702d4f5 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Thu, 13 Sep 2018 10:37:58 +0100 Subject: [PATCH 1/2] Fix syntax errors on old PHP versions, but prevent installation. --- autoupgrade.php | 12 +++++++++--- classes/UpgradeTools/Translator.php | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/autoupgrade.php b/autoupgrade.php index d3b6a3124..195c3d4a7 100644 --- a/autoupgrade.php +++ b/autoupgrade.php @@ -24,8 +24,6 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ -require_once _PS_ROOT_DIR_ . '/modules/autoupgrade/vendor/autoload.php'; - class Autoupgrade extends Module { public function __construct() @@ -57,6 +55,11 @@ public function __construct() 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; + } + if (defined('_PS_HOST_MODE_') && _PS_HOST_MODE_) { return false; } @@ -198,6 +201,9 @@ private static function _removeDirectory($dir) */ 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); + require_once _PS_ROOT_DIR_ . '/modules/autoupgrade/classes/UpgradeTools/Translator.php'; + + $translator = new \PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator(get_class()); + return $translator->trans($id, $parameters, $domain, $locale); } } diff --git a/classes/UpgradeTools/Translator.php b/classes/UpgradeTools/Translator.php index 2d6f75042..c00de4a6f 100644 --- a/classes/UpgradeTools/Translator.php +++ b/classes/UpgradeTools/Translator.php @@ -39,15 +39,15 @@ 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) { + if (!method_exists('\Context', 'getContext') || null === \Context::getContext()->language) { return $this->applyParameters($id, $parameters); } - if (method_exists(\Context::class, 'getTranslator')) { + if (method_exists('\Context', 'getTranslator')) { return \Context::getContext()->getTranslator()->trans($id, $parameters, $domain, $locale); } - if (method_exists(\Translate::class, 'getModuleTranslation')) { + if (method_exists('\Translate', 'getModuleTranslation')) { $translated = \Translate::getModuleTranslation('autoupgrade', $id, $this->caller, null); if (!count($parameters)) { return $translated; From f56cec6e345ecf39a59482e156a48278b098ca36 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Thu, 13 Sep 2018 10:40:52 +0100 Subject: [PATCH 2/2] Add prerequisites in the readme --- Readme.md | 5 +++++ composer.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 2a24869b9..c3ae80766 100644 --- a/Readme.md +++ b/Readme.md @@ -5,6 +5,11 @@ Provides an automated method to upgrade your shop to the latest version of PrestaShop. This module is compatible with all PrestaShop 1.6 & 1.7. +# Prerequisites + +* PrestaShop 1.6 or 1.7 +* PHP 5.6+ + # Installation You must have [composer][4] installed on your computer. Then, execute: diff --git a/composer.json b/composer.json index dbd921446..878ee7b40 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": ">=5.4", + "php": ">=5.6", "symfony/filesystem": "~2.8", "doctrine/collections": "~1.3.0", "twig/twig": "^1.35",