Skip to content

Commit

Permalink
Merge pull request #138 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Publishing v4.1.0
  • Loading branch information
Quetzacoalt91 authored Aug 23, 2018
2 parents aee95dc + 7260ef5 commit ed7a1c2
Show file tree
Hide file tree
Showing 15 changed files with 258 additions and 71 deletions.
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ before_script:

script:
- php vendor/phpunit/phpunit/phpunit tests
- docker exec -u www-data -ti prestashop_autoupgrade php modules/autoupgrade/tests/testCliUpgrade.php admin-dev/autoupgrade/cli-upgrade.php --dir="admin-dev" --channel="$CHANNEL"

# 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
- 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
Expand Down
2 changes: 1 addition & 1 deletion autoupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
97 changes: 97 additions & 0 deletions classes/TaskRunner/ChainedTasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/*
* 2007-2018 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 [email protected] 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 <[email protected]>
* @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
{
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;
while ($this->canContinue() && !$requireRestart) {
$this->logger->info('=== Step '.$this->step);
$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
*/
abstract 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;
}
}
63 changes: 63 additions & 0 deletions classes/TaskRunner/Rollback/AllRollbackTasks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* 2007-2018 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 [email protected] 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 <[email protected]>
* @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\Rollback;

use PrestaShop\Module\AutoUpgrade\TaskRunner\ChainedTasks;

/**
* Execute the whole upgrade process in a single request.
*/
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
* > 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)
{
if (!empty($options['backup'])) {
$this->container->getState()->setRestoreName($options['backup']);
}
}

/**
* Set default config on first run.
*/
public function init()
{
// Do nothing
}
}
5 changes: 5 additions & 0 deletions classes/TaskRunner/Rollback/RestoreDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,10 @@ 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
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';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,20 @@
* 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');
}
protected $step = self::initialTask;

/**
* Customize the execution context with several options
Expand All @@ -67,7 +48,7 @@ public function run()
*
* @param array $options
*/
public function setOptions($options)
public function setOptions(array $options)
{
if (!empty($options['action'])) {
$this->step = $options['action'];
Expand All @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion classes/UpgradePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
);

Expand Down
4 changes: 2 additions & 2 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader16.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
5 changes: 5 additions & 0 deletions classes/UpgradeTools/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 6 additions & 11 deletions classes/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +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_channel_link_major = 'https://api.prestashop.com/xml/channel17.xml';
public $rss_md5file_link_dir_major = 'https://api.prestashop.com/xml/md5-17/';

/**
* @var bool contains true if last version is not installed
Expand Down Expand Up @@ -310,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());
Expand All @@ -332,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);
}

/**
Expand Down
Loading

0 comments on commit ed7a1c2

Please sign in to comment.