Skip to content

Commit

Permalink
Merge pull request #281 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Deploy v4.6.0 of the autoupgrade module
  • Loading branch information
Quetzacoalt91 authored Feb 19, 2019
2 parents 33b71ca + 6f0ea60 commit bc38995
Show file tree
Hide file tree
Showing 57 changed files with 581 additions and 305 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
Binary file modified AdminSelfUpgrade.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 23 additions & 23 deletions AdminSelfUpgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <contact@prestashop.com>
* @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 <contact@prestashop.com>
* @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;
Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion ajax-upgradetabconfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
function autoupgrade_init_container($callerFilePath)
{
if (php_sapi_name() === 'cli') {
if (PHP_SAPI === 'cli') {
$_POST['dir'] = getopt('', array('dir:'))['dir'];
}

Expand Down
28 changes: 15 additions & 13 deletions autoupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,22 +57,23 @@ 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;
}

/* 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()) {
$this->_errors[] = $this->trans('Unable to delete outdated "AdminUpgrade" tab (tab ID: %idtab%).', array('%idtab%' => (int) $id_tab), 'Modules.Autoupgrade.Admin');
}
}

/* 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';
Expand All @@ -91,43 +92,43 @@ 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'));
} else {
@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'))) {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}
8 changes: 2 additions & 6 deletions classes/AjaxResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ public function getJson()
return json_encode($this->getResponse());
}

/*
* GETTERS
*/
// GETTERS

public function getError()
{
Expand Down Expand Up @@ -157,9 +155,7 @@ public function getUpgradeConfiguration()
return $this->upgradeConfiguration;
}

/*
* SETTERS
*/
// SETTERS

public function setError($error)
{
Expand Down
1 change: 0 additions & 1 deletion classes/BackupFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion classes/ChannelInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion classes/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion classes/Log/LegacyLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion classes/Parameters/UpgradeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 10 additions & 3 deletions classes/PrestashopConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class PrestashopConfiguration
{
// Variables used for cache
private $moduleVersion = null;
private $moduleVersion;
private $allowed_array = array();

// Variables from main class
Expand Down Expand Up @@ -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;
Expand All @@ -79,7 +79,7 @@ public function getCompliancyResults()
*/
public function getModuleVersion()
{
if (!is_null($this->moduleVersion)) {
if (null !== $this->moduleVersion) {
return $this->moduleVersion;
}

Expand All @@ -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));
Expand Down Expand Up @@ -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_[\"'], [\"'](?<version>[0-9.]+)[\"']\)/", $content, $matches)) {
return $matches['version'];
}

// Example: const VERSION = '1.7.6.0';
if (1 === preg_match("/const VERSION = [\"'](?<version>[0-9.]+)[\"'];/", $content, $matches)) {
return $matches['version'];
}

return false;
}
}
Loading

0 comments on commit bc38995

Please sign in to comment.