Skip to content

Commit

Permalink
Merge pull request #610 from PrestaShop/dev
Browse files Browse the repository at this point in the history
Release version 4.16.2
  • Loading branch information
Hlavtox authored Aug 2, 2023
2 parents a71bfb0 + 830a720 commit 5c49dcb
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 54 deletions.
2 changes: 1 addition & 1 deletion autoupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct()
$this->name = 'autoupgrade';
$this->tab = 'administration';
$this->author = 'PrestaShop';
$this->version = '4.16.1';
$this->version = '4.16.2';
$this->need_instance = 1;

$this->bootstrap = true;
Expand Down
3 changes: 3 additions & 0 deletions classes/TaskRunner/Upgrade/UpgradeDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ public function getCoreUpgrader()

public function init()
{
$this->logger->info($this->translator->trans('Cleaning file cache', [], 'Modules.Autoupgrade.Admin'));
$this->container->getCacheCleaner()->cleanFolders();
$this->logger->info($this->translator->trans('Running opcache_reset', [], 'Modules.Autoupgrade.Admin'));
$this->container->resetOpcache();

// Migrating settings file
$this->container->initPrestaShopAutoloader();
Expand Down
45 changes: 0 additions & 45 deletions classes/TaskRunner/Upgrade/UpgradeModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@

use PrestaShop\Module\AutoUpgrade\Parameters\UpgradeFileNames;
use PrestaShop\Module\AutoUpgrade\TaskRunner\AbstractTask;
use PrestaShop\Module\AutoUpgrade\UpgradeContainer;
use PrestaShop\Module\AutoUpgrade\UpgradeException;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\FilesystemAdapter;

/**
* Upgrade all partners modules according to the installed prestashop version.
Expand Down Expand Up @@ -83,49 +81,6 @@ public function run()
}
$this->stepDone = false;
} else {
$modules_to_delete = [
'backwardcompatibility' => 'Backward Compatibility',
'dibs' => 'Dibs',
'cloudcache' => 'Cloudcache',
'mobile_theme' => 'The 1.4 mobile_theme',
'trustedshops' => 'Trustedshops',
'dejala' => 'Dejala',
'stripejs' => 'Stripejs',
'blockvariouslinks' => 'Block Various Links',
];

foreach ($modules_to_delete as $key => $module) {
$this->container->getDb()->execute('DELETE ms.*, hm.*
FROM `' . _DB_PREFIX_ . 'module_shop` ms
INNER JOIN `' . _DB_PREFIX_ . 'hook_module` hm USING (`id_module`)
INNER JOIN `' . _DB_PREFIX_ . 'module` m USING (`id_module`)
WHERE m.`name` LIKE \'' . pSQL($key) . '\'');
$this->container->getDb()->execute('UPDATE `' . _DB_PREFIX_ . 'module` SET `active` = 0 WHERE `name` LIKE \'' . pSQL($key) . '\'');

$path = $this->container->getProperty(UpgradeContainer::PS_ROOT_PATH) . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR;
if (file_exists($path . $key . '.php')) {
if (FilesystemAdapter::deleteDirectory($path)) {
$this->logger->debug($this->translator->trans(
'The %modulename% module is not compatible with version %version%, it will be removed from your FTP.',
[
'%modulename%' => $module,
'%version%' => $this->container->getState()->getInstallVersion(),
],
'Modules.Autoupgrade.Admin'
));
} else {
$this->logger->error($this->translator->trans(
'The %modulename% module is not compatible with version %version%, please remove it from your FTP.',
[
'%modulename%' => $module,
'%version%' => $this->container->getState()->getInstallVersion(),
],
'Modules.Autoupgrade.Admin'
));
}
}
}

$this->stepDone = true;
$this->status = 'ok';
$this->next = 'cleanDatabase';
Expand Down
1 change: 1 addition & 0 deletions classes/Twig/Block/UpgradeChecklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function render()
'checkPhpVersionCompatibility' => $this->selfCheck->isPhpVersionCompatible(),
'checkApacheModRewrite' => $this->selfCheck->isApacheModRewriteEnabled(),
'notLoadedPhpExtensions' => $this->selfCheck->getNotLoadedPhpExtensions(),
'checkKeyGeneration' => $this->selfCheck->checkKeyGeneration(),
'checkMemoryLimit' => $this->selfCheck->isMemoryLimitValid(),
'checkFileUploads' => $this->selfCheck->isPhpFileUploadsConfigurationEnabled(),
'notExistsPhpFunctions' => $this->selfCheck->getNotExistsPhpFunctions(),
Expand Down
14 changes: 14 additions & 0 deletions classes/UpgradeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,18 @@ public function initPrestaShopCore()
$id_employee = !empty($_COOKIE['id_employee']) ? $_COOKIE['id_employee'] : 1;
\Context::getContext()->employee = new \Employee((int) $id_employee);
}

/**
* Attemps to flush opcache
*/
public function resetOpcache()
{
$disabled = explode(',', ini_get('disable_functions'));

if (in_array('opcache_reset', $disabled) || !is_callable('opcache_reset')) {
return;
}

opcache_reset();
}
}
1 change: 1 addition & 0 deletions classes/UpgradePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ private function getJsParams($ajaxResult)
$translator->trans('Please check that your front-office theme is functional (try to create an account, place an order...)', [], 'Modules.Autoupgrade.Admin'),
$translator->trans('Product images do not appear in the front-office? Try regenerating the thumbnails in Preferences > Images', [], 'Modules.Autoupgrade.Admin'),
$translator->trans('Do not forget to reactivate your shop once you have checked everything!', [], 'Modules.Autoupgrade.Admin'),
$translator->trans('If you can\'t access the back-office and need to see what\'s wrong, manually enable debug mode in config/defines.inc.php by changing _PS_MODE_DEV_ to true.', [], 'Modules.Autoupgrade.Admin'),
],
'todoListTitle' => $translator->trans('ToDo list:', [], 'Modules.Autoupgrade.Admin'),
'startingRestore' => $translator->trans('Starting restoration...', [], 'Modules.Autoupgrade.Admin'),
Expand Down
23 changes: 23 additions & 0 deletions classes/UpgradeSelfCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public function isOkForUpgrade()
&& $this->isModuleVersionLatest()
&& $this->isPhpVersionCompatible()
&& $this->isApacheModRewriteEnabled()
&& $this->checkKeyGeneration()
&& $this->getNotLoadedPhpExtensions() === []
&& $this->isMemoryLimitValid()
&& $this->isPhpFileUploadsConfigurationEnabled()
Expand Down Expand Up @@ -520,6 +521,28 @@ public function isApacheModRewriteEnabled()
return true;
}

/**
* @return bool
*/
public function checkKeyGeneration()
{
// Check if key is needed on the version we are upgrading to, if lower, not needed
if (version_compare($this->upgrader->version_num, '8.1.0', '<')) {
return true;
}

$privateKey = openssl_pkey_new([
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
]);

if ($privateKey === false) {
return false;
}

return true;
}

/**
* @return array<string>
*/
Expand Down
26 changes: 25 additions & 1 deletion classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,36 +84,54 @@ public function __construct(UpgradeContainer $container, LoggerInterface $logger

public function doUpgrade()
{
$this->logger->info($this->container->getTranslator()->trans('Initializing required environment constants', [], 'Modules.Autoupgrade.Admin'));
$this->initConstants();

$this->logger->info($this->container->getTranslator()->trans('Checking version validity', [], 'Modules.Autoupgrade.Admin'));
$oldversion = $this->getPreUpgradeVersion();
$this->checkVersionIsNewer($oldversion);

//check DB access
$this->logger->info($this->container->getTranslator()->trans('Checking connection to database', [], 'Modules.Autoupgrade.Admin'));
error_reporting(E_ALL);
$resultDB = \Db::checkConnection(_DB_SERVER_, _DB_USER_, _DB_PASSWD_, _DB_NAME_);
if ($resultDB !== 0) {
throw new UpgradeException($this->container->getTranslator()->trans('Invalid database configuration', [], 'Modules.Autoupgrade.Admin'));
}

if ($this->container->getUpgradeConfiguration()->shouldDeactivateCustomModules()) {
$this->logger->info($this->container->getTranslator()->trans('Disabling all non native modules', [], 'Modules.Autoupgrade.Admin'));
$this->disableCustomModules();
} else {
$this->logger->info($this->container->getTranslator()->trans('Keeping non native modules enabled', [], 'Modules.Autoupgrade.Admin'));
}

$this->logger->info($this->container->getTranslator()->trans('Updating database data and structure', [], 'Modules.Autoupgrade.Admin'));
$this->upgradeDb($oldversion);

// At this point, database upgrade is over.
// Now we need to add all previous missing settings items, and reset cache and compile directories
$this->writeNewSettings();

$this->logger->info($this->container->getTranslator()->trans('Running generic queries', [], 'Modules.Autoupgrade.Admin'));
$this->runRecurrentQueries();
$this->logger->debug($this->container->getTranslator()->trans('Database upgrade OK', [], 'Modules.Autoupgrade.Admin')); // no error!

$this->logger->info($this->container->getTranslator()->trans('Database upgrade OK', [], 'Modules.Autoupgrade.Admin')); // no error!

$this->logger->info($this->container->getTranslator()->trans('Upgrading languages', [], 'Modules.Autoupgrade.Admin'));
$this->upgradeLanguages();

$this->logger->info($this->container->getTranslator()->trans('Regenerating htaccess', [], 'Modules.Autoupgrade.Admin'));
$this->generateHtaccess();

$this->logger->info($this->container->getTranslator()->trans('Cleaning XML files', [], 'Modules.Autoupgrade.Admin'));
$this->cleanXmlFiles();

if (Configuration::get('PS_DISABLE_OVERRIDES')) {
$this->logger->info($this->container->getTranslator()->trans('Disabling overrides', [], 'Modules.Autoupgrade.Admin'));
$this->disableOverrides();
} else {
$this->logger->info($this->container->getTranslator()->trans('Keeping overrides in place', [], 'Modules.Autoupgrade.Admin'));
}

$this->updateTheme();
Expand Down Expand Up @@ -651,8 +669,11 @@ protected function updateTheme()
{
// The merchant can ask for keeping its current theme.
if (!$this->container->getUpgradeConfiguration()->shouldSwitchToDefaultTheme()) {
$this->logger->info($this->container->getTranslator()->trans('Keeping current theme', [], 'Modules.Autoupgrade.Admin'));

return;
}

$this->logger->info($this->container->getTranslator()->trans('Switching to default theme.', [], 'Modules.Autoupgrade.Admin'));
$themeAdapter = new ThemeAdapter($this->db, $this->destinationUpgradeVersion);

Expand All @@ -669,6 +690,9 @@ protected function updateTheme()

protected function runCoreCacheClean()
{
$this->logger->info($this->container->getTranslator()->trans('Cleaning file cache', [], 'Modules.Autoupgrade.Admin'));
$this->container->getCacheCleaner()->cleanFolders();
$this->logger->info($this->container->getTranslator()->trans('Running opcache_reset', [], 'Modules.Autoupgrade.Admin'));
$this->container->resetOpcache();
}
}
22 changes: 22 additions & 0 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,29 @@ class CoreUpgrader80 extends CoreUpgrader
{
protected function initConstants()
{
$this->forceRemovingFiles();
parent::initConstants();

// Container may be needed to run upgrade scripts
$this->container->getSymfonyAdapter()->initAppKernel();
}

/**
* Force remove files if they aren't removed properly after files upgrade.
*/
protected function forceRemovingFiles()
{
$filesToForceRemove = [
'/src/PrestaShopBundle/Resources/config/services/adapter/news.yml',
];

foreach ($filesToForceRemove as $file) {
if (file_exists(_PS_ROOT_DIR_ . $file)) {
unlink(_PS_ROOT_DIR_ . $file);
}
}
}

protected function upgradeDb($oldversion)
{
parent::upgradeDb($oldversion);
Expand All @@ -59,18 +76,23 @@ protected function upgradeLanguage($lang)
$isoCode = $lang['iso_code'];

if (!\Validate::isLangIsoCode($isoCode)) {
$this->logger->debug($this->container->getTranslator()->trans('%lang% is not a valid iso code, skipping', ['%lang%' => $isoCode], 'Modules.Autoupgrade.Admin'));

return;
}
$errorsLanguage = [];

$this->logger->debug($this->container->getTranslator()->trans('Downloading language pack for %lang%', ['%lang%' => $isoCode], 'Modules.Autoupgrade.Admin'));
if (!\Language::downloadLanguagePack($isoCode, _PS_VERSION_, $errorsLanguage)) {
throw new UpgradeException($this->container->getTranslator()->trans('Download of the language pack %lang% failed. %details%', ['%lang%' => $isoCode, '%details%' => implode('; ', $errorsLanguage)], 'Modules.Autoupgrade.Admin'));
}

$this->logger->debug($this->container->getTranslator()->trans('Installing %lang% language pack', ['%lang%' => $isoCode], 'Modules.Autoupgrade.Admin'));
$lang_pack = \Language::getLangDetails($isoCode);
\Language::installSfLanguagePack($lang_pack['locale'], $errorsLanguage);

if (!$this->container->getUpgradeConfiguration()->shouldKeepMails()) {
$this->logger->debug($this->container->getTranslator()->trans('Generating mail templates for %lang%', ['%lang%' => $isoCode], 'Modules.Autoupgrade.Admin'));
$mailTheme = \Configuration::get('PS_MAIL_THEME', null, null, null, 'modern');

$frontTheme = _THEME_NAME_;
Expand Down
6 changes: 6 additions & 0 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader81.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,26 @@ public function writeNewSettings()
$parametersPath = $this->container->getProperty(UpgradeContainer::PS_ROOT_PATH) . '/app/config/parameters.php';
$parameters = require $parametersPath;
if (!isset($parameters['parameters']['api_public_key']) || isset($parameters['parameters']['api_private_key'])) {
$this->logger->debug($this->container->getTranslator()->trans('API keys not present in parameters, generating', [], 'Modules.Autoupgrade.Admin'));
$privateKey = openssl_pkey_new([
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
]);

$this->logger->debug($this->container->getTranslator()->trans('Keys generated using openssl_pkey_new, exporting private and public keys', [], 'Modules.Autoupgrade.Admin'));
openssl_pkey_export($privateKey, $apiPrivateKey);
$apiPublicKey = openssl_pkey_get_details($privateKey)['key'];
$parameters['parameters']['api_public_key'] = $apiPublicKey;
$parameters['parameters']['api_private_key'] = $apiPrivateKey;

$parametersContent = sprintf('<?php return %s;', var_export($parameters, true));
$this->logger->debug($this->container->getTranslator()->trans('Updating parameters file', [], 'Modules.Autoupgrade.Admin'));
if (!file_put_contents($parametersPath, $parametersContent)) {
throw new UpgradeException($this->container->getTranslator()->trans('Unable to migrate parameters', [], 'Modules.Autoupgrade.Admin'));
}

if (function_exists('opcache_invalidate')) {
$this->logger->debug($this->container->getTranslator()->trans('Invalidating opcache for parameters file', [], 'Modules.Autoupgrade.Admin'));
opcache_invalidate($parametersPath);
}
$this->logger->debug($this->container->getTranslator()->trans('Parameters file updated', [], 'Modules.Autoupgrade.Admin'));
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>autoupgrade</name>
<displayName><![CDATA[1-Click Upgrade]]></displayName>
<version><![CDATA[4.16.1]]></version>
<version><![CDATA[4.16.2]]></version>
<description><![CDATA[Upgrade to the latest version of PrestaShop in a few clicks, thanks to this automated method.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
Expand Down
53 changes: 53 additions & 0 deletions upgrade/php/ps_811_update_redirect_type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* 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.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* 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 license@prestashop.com 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 https://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/
function ps_811_update_redirect_type()
{
// Get information about redirect_type column
$columnInformation = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'product` LIKE "redirect_type"');
if (empty($columnInformation)) {
return true;
}

// Get first record found
$columnInformation = reset($columnInformation);

// Check if it was already upgraded and contains new information
if (strpos($columnInformation['Type'], '200-displayed') !== false) {
return true;
}

// If not, we execute our upgrade queries
Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . "product` MODIFY COLUMN `redirect_type` ENUM(
'','404','410','301-product','302-product','301-category','302-category','200-displayed','404-displayed','410-displayed','default'
) NOT NULL DEFAULT 'default';");
Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . "product_shop` MODIFY COLUMN `redirect_type` ENUM(
'','404','410','301-product','302-product','301-category','302-category','200-displayed','404-displayed','410-displayed','default'
) NOT NULL DEFAULT 'default';");
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . "product` SET `redirect_type` = 'default' WHERE `redirect_type` = '404' OR `redirect_type` = '' OR `redirect_type` IS NULL;");
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . "product_shop` SET `redirect_type` = 'default' WHERE `redirect_type` = '404' OR `redirect_type` = '' OR `redirect_type` IS NULL;");

return true;
}
7 changes: 6 additions & 1 deletion upgrade/sql/1.7.7.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VAL
('PS_SEARCH_MAX_WORD_LENGTH', '15', NOW(), NOW())
;

/* Add field MPN to tables */
/* Add field MPN to tables and assign empty values */
ALTER TABLE `PREFIX_order_detail` ADD `product_mpn` VARCHAR(40) NULL AFTER `product_upc`;
ALTER TABLE `PREFIX_supply_order_detail` ADD `mpn` VARCHAR(40) NULL AFTER `upc`;
ALTER TABLE `PREFIX_stock` ADD `mpn` VARCHAR(40) NULL AFTER `upc`;
ALTER TABLE `PREFIX_product_attribute` ADD `mpn` VARCHAR(40) NULL AFTER `upc`;
ALTER TABLE `PREFIX_product` ADD `mpn` VARCHAR(40) NULL AFTER `upc`;
UPDATE `PREFIX_order_detail` SET `product_mpn` = '';
UPDATE `PREFIX_supply_order_detail` SET `mpn` = '';
UPDATE `PREFIX_stock` SET `mpn` = '';
UPDATE `PREFIX_product_attribute` SET `mpn` = '';
UPDATE `PREFIX_product` SET `mpn` = '';

/* Delete price display precision configuration */
DELETE FROM `PREFIX_configuration` WHERE `name` = 'PS_PRICE_DISPLAY_PRECISION';
Expand Down
Loading

0 comments on commit 5c49dcb

Please sign in to comment.