Skip to content

Commit

Permalink
Automatic detection of rtl regeneration
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgan Pichat committed Sep 12, 2024
1 parent efe5dc0 commit 659563d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
1 change: 0 additions & 1 deletion classes/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public function getProperties($type)
'backup_images' => $this->upgradeConfiguration->shouldBackupImages(),
'disable_non_native_modules' => $this->upgradeConfiguration->shouldDeactivateCustomModules(),
'switch_to_default_theme' => $this->upgradeConfiguration->shouldSwitchToDefaultTheme(),
'regenerate_rtl_stylesheet' => $this->upgradeConfiguration->shouldUpdateRTLFiles(),
'keep_customized_email_templates' => $this->upgradeConfiguration->shouldKeepMails(),
];
break;
Expand Down
8 changes: 0 additions & 8 deletions classes/Parameters/UpgradeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,6 @@ public function shouldSwitchToDefaultTheme(): bool
return (bool) $this->get('PS_AUTOUP_CHANGE_DEFAULT_THEME');
}

/**
* @return bool True if we should update RTL files
*/
public function shouldUpdateRTLFiles(): bool
{
return (bool) $this->get('PS_AUTOUP_UPDATE_RTL_FILES');
}

public static function isOverrideAllowed(): bool
{
return (bool) Configuration::get('PS_DISABLE_OVERRIDES');
Expand Down
10 changes: 0 additions & 10 deletions classes/Twig/Form/UpgradeOptionsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,6 @@ public function __construct(Translator $translator, FormRenderer $formRenderer)
'desc' => $translator->trans('This will change your theme: your shop will then use the default theme of the version of PrestaShop you are upgrading to.'),
],

'PS_AUTOUP_UPDATE_RTL_FILES' => [
'title' => $translator->trans('Regenerate RTL stylesheet'),
'cast' => 'intval',
'validation' => 'isBool',
'defaultValue' => '1',
'type' => 'bool',
'desc' => $translator->trans(
'If enabled, any RTL-specific files that you might have added to all your themes might be deleted by the created stylesheet.'),
],

'PS_AUTOUP_KEEP_MAILS' => [
'title' => $translator->trans('Keep the customized email templates'),
'cast' => 'intval',
Expand Down
18 changes: 18 additions & 0 deletions classes/UpgradeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
namespace PrestaShop\Module\AutoUpgrade;

use Exception;
use Language;
use PrestaShop\Module\AutoUpgrade\Log\LegacyLogger;
use PrestaShop\Module\AutoUpgrade\Log\Logger;
use PrestaShop\Module\AutoUpgrade\Parameters\FileConfigurationStorage;
Expand Down Expand Up @@ -248,6 +249,7 @@ public function getAnalytics(): Analytics
'php_version' => VersionUtils::getHumanReadableVersionOf(PHP_VERSION_ID),
'autoupgrade_version' => $this->getPrestaShopConfiguration()->getModuleVersion(),
'disable_all_overrides' => class_exists('\Configuration', false) ? UpgradeConfiguration::isOverrideAllowed() : null,
'regenerate_rtl_stylesheet' => $this->shouldUpdateRTLFiles(),
],
]);
}
Expand Down Expand Up @@ -681,4 +683,20 @@ public function resetOpcache(): void

opcache_reset();
}

/**
* @return bool True if we should update RTL files
*/
public function shouldUpdateRTLFiles(): bool
{
$languages = Language::getLanguages(false);

foreach ($languages as $lang) {
if ($lang['is_rtl']) {
return true;
}
}

return false;
}
}
5 changes: 4 additions & 1 deletion classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Cache;
use Exception;
use InvalidArgumentException;
use Language;
use ParseError;
use PrestaShop\Module\AutoUpgrade\Exceptions\UpgradeException;
use PrestaShop\Module\AutoUpgrade\Log\LoggerInterface;
Expand Down Expand Up @@ -806,7 +807,9 @@ protected function switchToDefaultTheme(): void

protected function updateRTLFiles(): void
{
if (!$this->container->getUpgradeConfiguration()->shouldUpdateRTLFiles()) {
if (!$this->container->shouldUpdateRTLFiles()) {
$this->logger->info($this->container->getTranslator()->trans('"No RTL language detected, skipping RTL file update process.'));

return;
}

Expand Down
8 changes: 0 additions & 8 deletions controllers/admin/AdminSelfUpgradeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,6 @@ private function _setFields()
'type' => 'bool',
'desc' => $this->trans('Enable or disable all classes and controllers overrides.'),
],
'PS_AUTOUP_UPDATE_RTL_FILES' => [
'title' => $this->trans('Regenerate RTL stylesheet'),
'cast' => 'intval',
'validation' => 'isBool',
'defaultValue' => '1',
'type' => 'bool',
'desc' => $this->trans('If enabled, any RTL-specific files that you might have added to all your themes might be deleted by the created stylesheet.'),
],
'PS_AUTOUP_CHANGE_DEFAULT_THEME' => [
'title' => $this->trans('Switch to the default theme'),
'cast' => 'intval',
Expand Down
5 changes: 4 additions & 1 deletion tests/unit/AnalyticsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function testProperties()
'php_version' => '6.0.8',
'autoupgrade_version' => '9.8.7',
'disable_all_overrides' => true,
'regenerate_rtl_stylesheet' => false,
],
]
);
Expand All @@ -70,6 +71,7 @@ public function testProperties()
'autoupgrade_version' => '9.8.7',
'disable_all_overrides' => true,
'module' => 'autoupgrade',
'regenerate_rtl_stylesheet' => false,
]),
],
$analytics->getProperties(Analytics::WITH_COMMON_PROPERTIES)
Expand All @@ -93,8 +95,8 @@ public function testProperties()
'backup_images' => false,
'disable_non_native_modules' => false,
'switch_to_default_theme' => true,
'regenerate_rtl_stylesheet' => false,
'keep_customized_email_templates' => false,
'regenerate_rtl_stylesheet' => false,
]),
],
$analytics->getProperties(Analytics::WITH_UPGRADE_PROPERTIES)
Expand All @@ -113,6 +115,7 @@ public function testProperties()

'from_ps_version' => '8.8.8',
'to_ps_version' => '1.2.3',
'regenerate_rtl_stylesheet' => false,
]),
],
$analytics->getProperties(Analytics::WITH_ROLLBACK_PROPERTIES)
Expand Down

0 comments on commit 659563d

Please sign in to comment.