Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploying v4.9.0 of the autoupgrade module #329

Merged
merged 29 commits into from Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6a7caa5
Add action option in command line upgrade doc
Quetzacoalt91 Jun 12, 2019
55cc14a
Merge pull request #320 from Quetzacoalt91/readme-action
Quetzacoalt91 Jun 12, 2019
9b933a7
Unused code cleanup
Quetzacoalt91 Feb 26, 2019
7fcdb6a
Add notice messages (dashboard + checklist) when PHP is unmaintained
Quetzacoalt91 Feb 27, 2019
0efd8da
Use lazy behavior on self checks.
Quetzacoalt91 Feb 27, 2019
06fba85
Update doc on UpgradeSelfCheck properties
Quetzacoalt91 Feb 27, 2019
3cf95d6
Fix spaces in views
Quetzacoalt91 Feb 27, 2019
29aebe0
Update classes/UpgradeSelfCheck.php
Quetzacoalt91 Jun 11, 2019
ea343fc
Replace links with build article
Quetzacoalt91 Jun 11, 2019
89cebc6
Apply CS Fixer
Quetzacoalt91 Jun 11, 2019
05e62d7
Use core method to get hook name
Quetzacoalt91 Jun 12, 2019
021d86e
Rename upgrade file for v4.9.0
Quetzacoalt91 Jun 14, 2019
997f898
Update classes/UpgradeSelfCheck.php
Quetzacoalt91 Jun 14, 2019
4418364
Fix warning in 1.7
jf-viguier Jun 14, 2019
758a302
Check file exists
jf-viguier Jun 14, 2019
1bacc92
Merge branch 'patch-merge' into dev
Quetzacoalt91 Jun 17, 2019
144660d
PHPdoc fix
Quetzacoalt91 Jun 17, 2019
935115f
Hook should return string
Quetzacoalt91 Jun 18, 2019
01dd4e6
Prepend and and optimize autoloader
Quetzacoalt91 Jun 27, 2019
4e1587d
Add phpdoc in UpgradeContainer
Quetzacoalt91 Jul 2, 2019
709ee00
Log when module switch the current theme + return immediately otherwise
Quetzacoalt91 Jul 2, 2019
7accaef
Update logs around zip upgrade
Quetzacoalt91 Jul 2, 2019
36995d7
Fix errors from CI
Quetzacoalt91 Jul 2, 2019
10461af
Merge pull request #327 from Quetzacoalt91/logs-zips-modules
Quetzacoalt91 Jul 3, 2019
f29b394
Merge pull request #326 from Quetzacoalt91/theme-switch-investigation
Quetzacoalt91 Jul 3, 2019
72d2e1b
Merge pull request #325 from Quetzacoalt91/autoload-changes
Quetzacoalt91 Jul 3, 2019
fd9f7a1
Merge pull request #284 from Quetzacoalt91/php56-warn
Quetzacoalt91 Jul 3, 2019
adb6d55
Bump version to 4.9.0
Quetzacoalt91 Jul 3, 2019
459eb4d
Merge pull request #328 from Quetzacoalt91/bump-version-4.9
Quetzacoalt91 Jul 3, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 4 additions & 21 deletions AdminSelfUpgrade.php
Expand Up @@ -293,6 +293,10 @@ public function postProcess()
Configuration::updateValue('PS_AUTOUP_IGNORE_REQS', 1);
}

if (Tools14::isSubmit('ignorePhpOutdated')) {
Configuration::updateValue('PS_AUTOUP_IGNORE_PHP_UPGRADE', 1);
}

if (Tools14::isSubmit('customSubmitAutoUpgrade')) {
$config_keys = array_keys(array_merge($this->_fieldsUpgradeOptions, $this->_fieldsBackupOptions));
$config = array();
Expand Down Expand Up @@ -333,27 +337,6 @@ public function postProcess()
parent::postProcess();
}

/**
* update module configuration (saved in file UpgradeFiles::configFilename) with $new_config.
*
* @param array $new_config
*
* @return bool true if success
*/
// public function writeConfig($config)
// {
// if (!$this->upgradeContainer->getFileConfigurationStorage()->exists(UpgradeFileNames::configFilename) && !empty($config['channel'])) {
// $this->upgradeContainer->getUpgrader()->channel = $config['channel'];
// $this->upgradeContainer->getUpgrader()->checkPSVersion();
//
// $this->upgradeContainer->getState()->setInstallVersion($this->upgradeContainer->getUpgrader()->version_num);
// }
//
// $this->upgradeContainer->getUpgradeConfiguration()->merge($config);
// $this->upgradeContainer->getLogger()->info($this->trans('Configuration successfully updated.', array(), 'Modules.Autoupgrade.Admin').' <strong>'.$this->trans('This page will now be reloaded and the module will check if a new version is available.', array(), 'Modules.Autoupgrade.Admin').'</strong>');
// return (new UpgradeConfigurationStorage($this->autoupgradePath.DIRECTORY_SEPARATOR))->save($this->upgradeContainer->getUpgradeConfiguration(), UpgradeFileNames::configFilename);
// }

public function display()
{
// Make sure the user has configured the upgrade options, or set default values
Expand Down
1 change: 1 addition & 0 deletions Readme.md
Expand Up @@ -37,6 +37,7 @@ The following parameters are mandatory:

* **--dir**: Tells where the admin directory is.
* **--channel**: Selects what upgrade to run (minor, major etc.)
* **--action**: Advanced users only. Sets the step you want to start from (Default: `UpgradeNow`, [other values available](classes/TaskRunner/Upgrade/)).

```
$ php cli-upgrade.php --dir=admin-dev --channel=major
Expand Down
49 changes: 47 additions & 2 deletions autoupgrade.php
Expand Up @@ -31,7 +31,7 @@ public function __construct()
$this->name = 'autoupgrade';
$this->tab = 'administration';
$this->author = 'PrestaShop';
$this->version = '4.8.0';
$this->version = '4.9.0';
$this->need_instance = 1;

$this->bootstrap = true;
Expand Down Expand Up @@ -135,7 +135,7 @@ public function install()
return $this->_abortInstall($this->trans('Unable to create the directory "%s"', array(_PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'xml'), 'Modules.Autoupgrade.Admin'));
}

return parent::install();
return parent::install() && $this->registerHookAndSetToTop('dashboardZoneOne');
}

public function uninstall()
Expand All @@ -149,9 +149,54 @@ public function uninstall()
// Remove the 1-click upgrade working directory
self::_removeDirectory(_PS_ADMIN_DIR_ . DIRECTORY_SEPARATOR . 'autoupgrade');

Configuration::deleteByName('PS_AUTOUP_IGNORE_REQS');
Configuration::deleteByName('PS_AUTOUP_IGNORE_PHP_UPGRADE');

return parent::uninstall();
}

/**
* Register the current module to a given hook and moves it at the first position.
*
* @param string $hookName
*
* @return bool
*/
private function registerHookAndSetToTop($hookName)
{
return $this->registerHook($hookName) && $this->updatePosition((int) Hook::getIdByName($hookName), 0);
}

public function hookDashboardZoneOne($params)
{
// Display panel if PHP is not supported by the community
require_once __DIR__ . '/vendor/autoload.php';

$upgradeContainer = new \PrestaShop\Module\AutoUpgrade\UpgradeContainer(_PS_ROOT_DIR_, _PS_ADMIN_DIR_);
$upgrader = $upgradeContainer->getUpgrader();
$upgradeSelfCheck = new \PrestaShop\Module\AutoUpgrade\UpgradeSelfCheck(
$upgrader,
_PS_ROOT_DIR_,
_PS_ADMIN_DIR_,
__DIR__
);

$upgradeNotice = $upgradeSelfCheck->isPhpUpgradeRequired();
if (false === $upgradeNotice) {
return '';
}

$this->context->controller->addCSS($this->_path . '/css/styles.css');
$this->context->controller->addJS($this->_path . '/js/dashboard.js');

$this->context->smarty->assign([
'ignore_link' => Context::getContext()->link->getAdminLink('AdminSelfUpgrade') . '&ignorePhpOutdated=1',
'learn_more_link' => 'http://build.prestashop.com/news/announcing-end-of-support-for-obsolete-php-versions/',
]);

return $this->context->smarty->fetch($this->local_path . 'views/templates/hook/dashboard_zone_one.tpl');
}

public function getContent()
{
global $cookie;
Expand Down
3 changes: 3 additions & 0 deletions classes/PrestashopConfiguration.php
Expand Up @@ -78,6 +78,9 @@ public function getPrestaShopVersion()
$this->psRootDir . '/app/AppKernel.php',
);
foreach ($files as $file) {
if (!file_exists($file)) {
continue;
}
$version = $this->findPrestaShopVersionInFile(file_get_contents($file));
if ($version) {
return $version;
Expand Down
6 changes: 3 additions & 3 deletions classes/TaskRunner/Rollback/RestoreFiles.php
Expand Up @@ -69,11 +69,11 @@ public function run()
$this->logger->debug($this->translator->trans('%s file(s) will be removed before restoring the backup files.', array(count($toRemoveOnly)), 'Modules.Autoupgrade.Admin'));
$this->container->getFileConfigurationStorage()->save($toRemoveOnly, UpgradeFileNames::FILES_TO_REMOVE_LIST);

if ($fromArchive === false || $toRemove === false) {
if (!$fromArchive) {
if (empty($fromArchive) || empty($toRemove)) {
if (empty($fromArchive)) {
$this->logger->error($this->translator->trans('[ERROR] Backup file %s does not exist.', array(UpgradeFileNames::FILES_FROM_ARCHIVE_LIST), 'Modules.Autoupgrade.Admin'));
}
if (!$toRemove) {
if (empty($toRemove)) {
$this->logger->error($this->translator->trans('[ERROR] File "%s" does not exist.', array(UpgradeFileNames::FILES_TO_REMOVE_LIST), 'Modules.Autoupgrade.Admin'));
}
$this->logger->info($this->translator->trans('Unable to remove upgraded files.', array(), 'Modules.Autoupgrade.Admin'));
Expand Down
1 change: 1 addition & 0 deletions classes/TaskRunner/Upgrade/UpgradeModules.php
Expand Up @@ -62,6 +62,7 @@ public function run()
do {
$module_info = array_shift($listModules);
try {
$this->logger->debug($this->translator->trans('Upgrading module %module%...', ['%module%' => $module_info['name']], 'Modules.Autoupgrade.Admin'));
$this->container->getModuleAdapter()->upgradeModule($module_info['id'], $module_info['name']);
$this->logger->debug($this->translator->trans('The files of module %s have been upgraded.', array($module_info['name']), 'Modules.Autoupgrade.Admin'));
} catch (UpgradeException $e) {
Expand Down
1 change: 1 addition & 0 deletions classes/Twig/Block/UpgradeChecklist.php
Expand Up @@ -127,6 +127,7 @@ public function render()
'token' => $this->token,
'cachingIsDisabled' => $this->selfCheck->isCacheDisabled(),
'maxExecutionTime' => $this->selfCheck->getMaxExecutionTime(),
'phpUpgradeRequired' => $this->selfCheck->isPhpUpgradeRequired(),
'isPrestaShopReady' => $this->selfCheck->isPrestaShopReady(),
);

Expand Down
51 changes: 51 additions & 0 deletions classes/UpgradeContainer.php
Expand Up @@ -168,6 +168,9 @@ public function __construct($psRootDir, $adminDir, $moduleSubDir = 'autoupgrade'
$this->psRootDir = $psRootDir;
}

/**
* @return string
*/
public function getProperty($property)
{
switch ($property) {
Expand Down Expand Up @@ -212,6 +215,9 @@ public function getCacheCleaner()
return $this->cacheCleaner = new CacheCleaner($this, $this->getLogger());
}

/**
* @return Cookie
*/
public function getCookie()
{
if (null !== $this->cookie) {
Expand All @@ -225,6 +231,9 @@ public function getCookie()
return $this->cookie;
}

/**
* @return \Db
*/
public function getDb()
{
return \Db::getInstance();
Expand All @@ -240,6 +249,9 @@ public function getFilePath()
return $this->getProperty(self::ARCHIVE_FILEPATH);
}

/**
* @return FileConfigurationStorage
*/
public function getFileConfigurationStorage()
{
if (null !== $this->fileConfigurationStorage) {
Expand All @@ -251,6 +263,9 @@ public function getFileConfigurationStorage()
return $this->fileConfigurationStorage;
}

/**
* @return FileFilter
*/
public function getFileFilter()
{
if (null !== $this->fileFilter) {
Expand All @@ -262,6 +277,9 @@ public function getFileFilter()
return $this->fileFilter;
}

/**
* @return Upgrader
*/
public function getUpgrader()
{
if (null !== $this->upgrader) {
Expand Down Expand Up @@ -301,6 +319,9 @@ public function getUpgrader()
return $this->upgrader;
}

/**
* @return FilesystemAdapter
*/
public function getFilesystemAdapter()
{
if (null !== $this->filesystemAdapter) {
Expand Down Expand Up @@ -339,6 +360,9 @@ public function setLogger(Logger $logger)
$this->logger = $logger;
}

/**
* @return ModuleAdapter
*/
public function getModuleAdapter()
{
if (null !== $this->moduleAdapter) {
Expand All @@ -358,6 +382,9 @@ public function getModuleAdapter()
return $this->moduleAdapter;
}

/**
* @return State
*/
public function getState()
{
if (null !== $this->state) {
Expand All @@ -369,16 +396,25 @@ public function getState()
return $this->state;
}

/**
* @return Translation
*/
public function getTranslationAdapter()
{
return new Translation($this->getTranslator(), $this->getLogger(), $this->getState()->getInstalledLanguagesIso());
}

/**
* @return Translator
*/
public function getTranslator()
{
return new Translator('AdminSelfUpgrade');
}

/**
* @return Twig_Environment
*/
public function getTwig()
{
if (null !== $this->twig) {
Expand All @@ -396,6 +432,9 @@ public function getTwig()
return $this->twig;
}

/**
* @return PrestashopConfiguration
*/
public function getPrestaShopConfiguration()
{
if (null !== $this->prestashopConfiguration) {
Expand Down Expand Up @@ -424,6 +463,9 @@ public function getSymfonyAdapter()
return $this->symfonyAdapter;
}

/**
* @return UpgradeConfiguration
*/
public function getUpgradeConfiguration()
{
if (null !== $this->upgradeConfiguration) {
Expand All @@ -435,11 +477,17 @@ public function getUpgradeConfiguration()
return $this->upgradeConfiguration;
}

/**
* @return UpgradeConfigurationStorage
*/
public function getUpgradeConfigurationStorage()
{
return new UpgradeConfigurationStorage($this->getProperty(self::WORKSPACE_PATH) . DIRECTORY_SEPARATOR);
}

/**
* @return Workspace
*/
public function getWorkspace()
{
if (null !== $this->workspace) {
Expand All @@ -465,6 +513,9 @@ public function getWorkspace()
return $this->workspace;
}

/**
* @return ZipAction
*/
public function getZipAction()
{
if (null !== $this->zipAction) {
Expand Down