-
Notifications
You must be signed in to change notification settings - Fork 119
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
Use GenerateThemeMailTemplatesCommand during upgrade #434
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
abe45b1
Use GenerateThemeMailTemplatesCommand during upgrade instead of legac…
jolelievre 6ea0622
Create new CoreUpgrade80 to handle backward compatibility regardless …
jolelievre ddf316d
Remove comment
atomiix be6d365
Get command bus from moduleAdapter
atomiix b99c34d
Fix ps version detection & mail generation output folders
atomiix 86678ea
Fix tests
atomiix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aren't these folders supposed to always exist? Is it really needed to check their existence?
I just checked the handler, which actually handles the default folder internally when the command parameters are empty, so maybe specifying these parameters is actually not useful here? We could ignore this and let that handler handle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These folders aren't supposed to always exist, if you check the
themes/classic/
folder, you'll see nomails
folder.Also, I see that's what we do in src/PrestaShopBundle/Controller/Admin/Improve/Design/MailThemeController.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jolelievre yep, it's fixed in the core ;)