From 659563d2ea1d0b4dd65a6ea5411d9f3ce29c761c Mon Sep 17 00:00:00 2001 From: Morgan Pichat Date: Wed, 11 Sep 2024 16:45:33 +0200 Subject: [PATCH] Automatic detection of rtl regeneration --- classes/Analytics.php | 1 - classes/Parameters/UpgradeConfiguration.php | 8 -------- classes/Twig/Form/UpgradeOptionsForm.php | 10 ---------- classes/UpgradeContainer.php | 18 ++++++++++++++++++ .../UpgradeTools/CoreUpgrader/CoreUpgrader.php | 5 ++++- .../admin/AdminSelfUpgradeController.php | 8 -------- tests/unit/AnalyticsTest.php | 5 ++++- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/classes/Analytics.php b/classes/Analytics.php index a51aa476ba..0426a3907b 100644 --- a/classes/Analytics.php +++ b/classes/Analytics.php @@ -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; diff --git a/classes/Parameters/UpgradeConfiguration.php b/classes/Parameters/UpgradeConfiguration.php index 73669bc4c1..35be754f25 100644 --- a/classes/Parameters/UpgradeConfiguration.php +++ b/classes/Parameters/UpgradeConfiguration.php @@ -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'); diff --git a/classes/Twig/Form/UpgradeOptionsForm.php b/classes/Twig/Form/UpgradeOptionsForm.php index 73316f6fdf..fbf715b560 100644 --- a/classes/Twig/Form/UpgradeOptionsForm.php +++ b/classes/Twig/Form/UpgradeOptionsForm.php @@ -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', diff --git a/classes/UpgradeContainer.php b/classes/UpgradeContainer.php index ddee770d46..a1d607bfc4 100644 --- a/classes/UpgradeContainer.php +++ b/classes/UpgradeContainer.php @@ -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; @@ -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(), ], ]); } @@ -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; + } } diff --git a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php index 0231511924..ee56d3ca94 100644 --- a/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php +++ b/classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php @@ -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; @@ -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; } diff --git a/controllers/admin/AdminSelfUpgradeController.php b/controllers/admin/AdminSelfUpgradeController.php index 85b09767ab..185badc900 100644 --- a/controllers/admin/AdminSelfUpgradeController.php +++ b/controllers/admin/AdminSelfUpgradeController.php @@ -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', diff --git a/tests/unit/AnalyticsTest.php b/tests/unit/AnalyticsTest.php index 2c9df7bb92..0b772259bc 100644 --- a/tests/unit/AnalyticsTest.php +++ b/tests/unit/AnalyticsTest.php @@ -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, ], ] ); @@ -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) @@ -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) @@ -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)