Skip to content

Commit

Permalink
Merge pull request PrestaShop#434 from jolelievre/mail-generation-com…
Browse files Browse the repository at this point in the history
…mand

Use GenerateThemeMailTemplatesCommand during upgrade
  • Loading branch information
Progi1984 authored and atomiix committed Sep 16, 2022
2 parents 5315d47 + 84d8234 commit cbe7ee5
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: PHP syntax checker 5.6
uses: prestashop/github-action-php-lint/5.6@master
with:
folder-to-exclude: "! -path \"./.github/*\""
folder-to-exclude: "! -path \"./.github/*\" ! -path \"./classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php\""

- name: PHP syntax checker 7.2
uses: prestashop/github-action-php-lint/7.2@master
Expand Down
9 changes: 7 additions & 2 deletions classes/TaskRunner/Upgrade/UpgradeDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use PrestaShop\Module\AutoUpgrade\UpgradeException;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\CoreUpgrader\CoreUpgrader16;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\CoreUpgrader\CoreUpgrader17;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\CoreUpgrader\CoreUpgrader80;
use PrestaShop\Module\AutoUpgrade\UpgradeTools\SettingsFileWriter;

class UpgradeDb extends AbstractTask
Expand Down Expand Up @@ -59,11 +60,15 @@ public function run()

public function getCoreUpgrader()
{
if (version_compare($this->container->getState()->getInstallVersion(), '1.7.0.0', '<=')) {
if (version_compare($this->container->getState()->getInstallVersion(), '1.7.0.0', '<')) {
return new CoreUpgrader16($this->container, $this->logger);
}

return new CoreUpgrader17($this->container, $this->logger);
if (version_compare($this->container->getState()->getInstallVersion(), '8.0.0', '<')) {
return new CoreUpgrader17($this->container, $this->logger);
}

return new CoreUpgrader80($this->container, $this->logger);
}

public function init()
Expand Down
103 changes: 103 additions & 0 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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)
*/

declare(strict_types=1);

namespace PrestaShop\Module\AutoUpgrade\UpgradeTools\CoreUpgrader;

use PrestaShop\Module\AutoUpgrade\UpgradeException;
use PrestaShop\PrestaShop\Core\CommandBus\CommandBusInterface;
use PrestaShop\PrestaShop\Core\Domain\MailTemplate\Command\GenerateThemeMailTemplatesCommand;
use PrestaShop\PrestaShop\Core\Exception\CoreException;

class CoreUpgrader80 extends CoreUpgrader
{
protected function initConstants()
{
parent::initConstants();

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

protected function upgradeDb($oldversion)
{
parent::upgradeDb($oldversion);

$commandResult = $this->container->getSymfonyAdapter()->runSchemaUpgradeCommand();
if (0 !== $commandResult['exitCode']) {
throw (new UpgradeException($this->container->getTranslator()->trans('Error upgrading Doctrine schema', [], 'Modules.Autoupgrade.Admin')))->setQuickInfos(explode("\n", $commandResult['output']));
}
}

protected function upgradeLanguage($lang)
{
$isoCode = $lang['iso_code'];

if (!\Validate::isLangIsoCode($isoCode)) {
return;
}
$errorsLanguage = [];

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'));
}

$lang_pack = \Language::getLangDetails($isoCode);
\Language::installSfLanguagePack($lang_pack['locale'], $errorsLanguage);

if (!$this->container->getUpgradeConfiguration()->shouldKeepMails()) {
$mailTheme = \Configuration::get('PS_MAIL_THEME', null, null, null, 'modern');

$frontTheme = _THEME_NAME_;
$frontThemeMailsFolder = _PS_ALL_THEMES_DIR_ . $frontTheme . '/mails';
$frontThemeModulesFolder = _PS_ALL_THEMES_DIR_ . $frontTheme . '/modules';

$generateCommand = new GenerateThemeMailTemplatesCommand(
$mailTheme,
$lang_pack['locale'],
true,
is_dir($frontThemeMailsFolder) ? $frontThemeMailsFolder : '',
is_dir($frontThemeModulesFolder) ? $frontThemeModulesFolder : ''
);
/** @var CommandBusInterface $commandBus */
$commandBus = $this->container->getModuleAdapter()->getCommandBus();

try {
$commandBus->handle($generateCommand);
} catch (CoreException $e) {
throw new UpgradeException($this->container->getTranslator()->trans('Cannot generate email templates: %s.', [$e->getMessage()], 'Modules.Autoupgrade.Admin'));
}
}

if (!empty($errorsLanguage)) {
throw new UpgradeException($this->container->getTranslator()->trans('Error while updating translations for lang %lang%. %details%', ['%lang%' => $isoCode, '%details%' => implode('; ', $errorsLanguage)], 'Modules.Autoupgrade.Admin'));
}
\Language::loadLanguages();

// TODO: Update AdminTranslationsController::addNewTabs to install tabs translated
}
}
1 change: 1 addition & 0 deletions tests/phpstan/phpstan-1.6.1.18.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parameters:
- ./../../classes/pclzip.lib.php
- ./../../functions.php
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader17.php
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
- ./../../classes/UpgradeTools/SymfonyAdapter.php
ignoreErrors:
- '#Access to an undefined property Autoupgrade::\$bootstrap.#'
Expand Down
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.2.5.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
excludes_analyse:
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
ignoreErrors:
- '#Access to an undefined property Autoupgrade::\$bootstrap.#'
- '#Access to an undefined property Module::\$installed.#'
Expand Down
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.3.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
excludes_analyse:
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
ignoreErrors:
- '#Access to an undefined property Autoupgrade::\$bootstrap.#'
- '#Access to an undefined property Module::\$installed.#'
Expand Down
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.4.4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
excludes_analyse:
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
ignoreErrors:
- '#Access to an undefined property Autoupgrade::\$bootstrap.#'
- '#Access to an undefined property Module::\$installed.#'
Expand Down
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.5.1.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
excludes_analyse:
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
ignoreErrors:
- '#Access to an undefined property Autoupgrade::\$bootstrap.#'
- '#Access to an undefined property Module::\$installed.#'
Expand Down
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.6.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
excludes_analyse:
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
ignoreErrors:
- '#Access to an undefined property Autoupgrade::\$bootstrap.#'
- '#Access to an undefined property Module::\$installed.#'
Expand Down
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.7.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
excludes_analyse:
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
ignoreErrors:
- '#Access to an undefined property Module::\$installed.#'
- '#Call to method fetchLocale\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Cldr\\Update.#'
Expand Down
2 changes: 2 additions & 0 deletions tests/phpstan/phpstan-1.7.8.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ includes:
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon

parameters:
excludes_analyse:
- ./../../classes/UpgradeTools/CoreUpgrader/CoreUpgrader80.php
ignoreErrors:
- '#Access to an undefined property Module::\$installed.#'
- '#Call to method fetchLocale\(\) on an unknown class PrestaShop\\PrestaShop\\Core\\Cldr\\Update.#'
Expand Down

0 comments on commit cbe7ee5

Please sign in to comment.