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

Release version 4.16.2 #610

Merged
merged 27 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a25767e
Fix product redirect_type
Hlavtox Jul 30, 2023
844d9ea
Move script to proper location
Hlavtox Jul 30, 2023
42a9782
Fix CS
Hlavtox Jul 30, 2023
db0bb22
Update ps_811_update_redirect_type.php
Hlavtox Jul 30, 2023
03365aa
Update 8.1.0.sql
Hlavtox Jul 30, 2023
b882947
Update ps_811_update_redirect_type.php
Hlavtox Jul 30, 2023
528530d
Add empty values for MPN fields
Hlavtox Jul 30, 2023
9126e97
Merge pull request #602 from Hlavtox/customization
kpodemski Jul 31, 2023
ded8f27
Add upgrade helptext
Hlavtox Jul 30, 2023
2d94860
Merge pull request #603 from Hlavtox/upgrade-help
kpodemski Jul 31, 2023
4837c41
Clean opcache
Hlavtox Jul 31, 2023
e7192e0
Merge pull request #606 from Hlavtox/extend-logging
Hlavtox Jul 31, 2023
4a8bd9f
To stop removing a popular STRIPEJS payment module during upgrade
nexustotalsolutions Aug 1, 2023
add0a9e
Update UpgradeModules.php
nexustotalsolutions Aug 1, 2023
0721d8b
Add more info to autoupgrade process
Hlavtox Jul 31, 2023
3ee2f50
Merge pull request #601 from Hlavtox/fix-enum
Hlavtox Aug 1, 2023
b59b71b
Merge pull request #607 from Hlavtox/moreinfo
kpodemski Aug 1, 2023
0c32d51
Add key check
Hlavtox Jul 19, 2023
938a70c
Fix CS
Hlavtox Aug 1, 2023
1aabd85
Merge pull request #608 from nexustotalsolutions/patch-1
matthieu-rolland Aug 1, 2023
149f874
Add force removing system for some files
boherm Aug 1, 2023
42b5319
Merge pull request #609 from boherm/fix-circuit-breaker-service-error
Hlavtox Aug 1, 2023
4366bc3
Merge pull request #599 from Hlavtox/check-key-generation
kpodemski Aug 2, 2023
c77f074
Merge pull request #604 from Hlavtox/177-mpn
Hlavtox Aug 2, 2023
1ad0f5f
Bump to 4.16.2
Hlavtox Aug 2, 2023
5118a62
Bump to 4.16.2
Hlavtox Aug 2, 2023
830a720
Merge pull request #612 from Hlavtox/bump4162
kpodemski Aug 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading