From 48468c69de01bfe9269119b26f86cda5f25ce3ce Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Tue, 15 Oct 2024 14:38:50 +0200 Subject: [PATCH 1/2] Remove module configuration feature flag --- install-dev/data/xml/feature_flag.xml | 2 -- src/Core/FeatureFlag/FeatureFlagSettings.php | 2 -- .../Controller/Admin/Improve/ModuleController.php | 5 ----- .../config/routing/admin/improve/modules/_modules.yml | 1 - 4 files changed, 10 deletions(-) diff --git a/install-dev/data/xml/feature_flag.xml b/install-dev/data/xml/feature_flag.xml index ac9927b525743..d33f5197a5953 100644 --- a/install-dev/data/xml/feature_flag.xml +++ b/install-dev/data/xml/feature_flag.xml @@ -26,7 +26,5 @@ - - diff --git a/src/Core/FeatureFlag/FeatureFlagSettings.php b/src/Core/FeatureFlag/FeatureFlagSettings.php index aaa03edf20ef2..fb23488254027 100644 --- a/src/Core/FeatureFlag/FeatureFlagSettings.php +++ b/src/Core/FeatureFlag/FeatureFlagSettings.php @@ -53,6 +53,4 @@ class FeatureFlagSettings public const FEATURE_FLAG_ADMIN_API_MULTISTORE = 'admin_api_multistore'; public const FEATURE_FLAG_ADMIN_API_EXPERIMENTAL_ENDPOINTS = 'admin_api_experimental_endpoints'; public const FEATURE_FLAG_FRONT_CONTAINER_V2 = 'front_container_v2'; - - public const FEATURE_FLAG_MODULE_CONFIGURATION = 'module_configuration'; } diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php index 0207815ecf64f..899179002ecca 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php @@ -33,7 +33,6 @@ use PrestaShop\PrestaShop\Adapter\LegacyContext; use PrestaShop\PrestaShop\Adapter\Module\AdminModuleDataProvider; use PrestaShop\PrestaShop\Adapter\Module\Module as ModuleAdapter; -use PrestaShop\PrestaShop\Core\FeatureFlag\FeatureFlagSettings; use PrestaShop\PrestaShop\Core\Module\ModuleCollection; use PrestaShop\PrestaShop\Core\Module\ModuleManager; use PrestaShop\PrestaShop\Core\Module\SourceHandler\SourceHandlerNotFoundException; @@ -139,10 +138,6 @@ public function configureModuleAction( $layoutSubTitle = $module->getInstance()->displayName; } - if ($this->getFeatureFlagStateChecker()->isDisabled(FeatureFlagSettings::FEATURE_FLAG_MODULE_CONFIGURATION)) { - return $this->redirect($legacyContext->getAdminLink('AdminModules', true, ['configure' => $module_name])); - } - // This controller is not purely migrated, in the sense that it still relies on the legacy layout because module implementing // getContent need the default theme to be working as expected $smarty = $legacyContext->getSmarty(); diff --git a/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/_modules.yml b/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/_modules.yml index bbd250c2648a4..d1c2ae8957d9f 100644 --- a/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/_modules.yml +++ b/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/_modules.yml @@ -27,7 +27,6 @@ admin_module_configure_action: _legacy_link: AdminModules:configure _legacy_parameters: configure: module_name - _legacy_feature_flag: module_configuration admin_module_manage_action_bulk: path: /manage/bulk/{action} From 353e6337518db97491ac7cf5452cf2af97726930 Mon Sep 17 00:00:00 2001 From: Jonathan LELIEVRE Date: Tue, 15 Oct 2024 15:51:43 +0200 Subject: [PATCH 2/2] Remove legacy AdminModule controller along with its templates --- .../controllers/modules/configuration_bar.tpl | 46 --- .../controllers/modules/configure.tpl | 86 ---- .../controllers/modules/content-legacy.tpl | 28 -- .../template/controllers/modules/index.php | 35 -- .../controllers/modules/modal_translation.tpl | 40 -- controllers/admin/AdminModulesController.php | 368 ------------------ 6 files changed, 603 deletions(-) delete mode 100644 admin-dev/themes/default/template/controllers/modules/configuration_bar.tpl delete mode 100644 admin-dev/themes/default/template/controllers/modules/configure.tpl delete mode 100644 admin-dev/themes/default/template/controllers/modules/content-legacy.tpl delete mode 100644 admin-dev/themes/default/template/controllers/modules/index.php delete mode 100644 admin-dev/themes/default/template/controllers/modules/modal_translation.tpl delete mode 100644 controllers/admin/AdminModulesController.php diff --git a/admin-dev/themes/default/template/controllers/modules/configuration_bar.tpl b/admin-dev/themes/default/template/controllers/modules/configuration_bar.tpl deleted file mode 100644 index 10f6bc4d806ba..0000000000000 --- a/admin-dev/themes/default/template/controllers/modules/configuration_bar.tpl +++ /dev/null @@ -1,46 +0,0 @@ -{** - * 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 - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - *} - -{if isset($display_multishop_checkbox) && $display_multishop_checkbox} -
-
{l s='Configuration' d='Admin.Global'}
-
-
- -
- - isEnabledForShopContext()} checked="checked"{/if} onclick="location.href = '{$multishop_enable_url}'"> - - isEnabledForShopContext()} checked="checked"{/if} onclick="location.href = '{$multishop_disable_url}'"> - - - -
-
-
-
-{/if} diff --git a/admin-dev/themes/default/template/controllers/modules/configure.tpl b/admin-dev/themes/default/template/controllers/modules/configure.tpl deleted file mode 100644 index b5dea7dde248c..0000000000000 --- a/admin-dev/themes/default/template/controllers/modules/configure.tpl +++ /dev/null @@ -1,86 +0,0 @@ -{** - * 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 - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - *} -{extends file="page_header_toolbar.tpl"} - - -{block name=pageTitle} -

- {l s='Configure' d='Admin.Actions'} -

-

{$module_display_name}

-{/block} -{block name=pageBreadcrumb} - -{/block} -{block name=toolbarBox} -
-
- -
-
- - -{/block} diff --git a/admin-dev/themes/default/template/controllers/modules/content-legacy.tpl b/admin-dev/themes/default/template/controllers/modules/content-legacy.tpl deleted file mode 100644 index 2417a3425b0c0..0000000000000 --- a/admin-dev/themes/default/template/controllers/modules/content-legacy.tpl +++ /dev/null @@ -1,28 +0,0 @@ -{** - * 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 - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - *} - -{if isset($module_content)} - {$module_content} -{/if} diff --git a/admin-dev/themes/default/template/controllers/modules/index.php b/admin-dev/themes/default/template/controllers/modules/index.php deleted file mode 100644 index 6c011614e2845..0000000000000 --- a/admin-dev/themes/default/template/controllers/modules/index.php +++ /dev/null @@ -1,35 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - */ - -header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); -header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - -header('Cache-Control: no-store, no-cache, must-revalidate'); -header('Cache-Control: post-check=0, pre-check=0', false); -header('Pragma: no-cache'); - -header('Location: ../../../../../../'); -exit; diff --git a/admin-dev/themes/default/template/controllers/modules/modal_translation.tpl b/admin-dev/themes/default/template/controllers/modules/modal_translation.tpl deleted file mode 100644 index 3d2df5866ba26..0000000000000 --- a/admin-dev/themes/default/template/controllers/modules/modal_translation.tpl +++ /dev/null @@ -1,40 +0,0 @@ -{** - * 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 - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - *} - diff --git a/controllers/admin/AdminModulesController.php b/controllers/admin/AdminModulesController.php deleted file mode 100644 index 1d0fbecf8f7bf..0000000000000 --- a/controllers/admin/AdminModulesController.php +++ /dev/null @@ -1,368 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - */ - -use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder; - -class AdminModulesControllerCore extends AdminController -{ - /* - ** @var array map with $_GET keywords and their callback - */ - protected $map = [ - 'configure' => 'getContent', - ]; - - protected $id_employee; - - /** - * Admin Modules Controller Constructor - * Init list modules categories - * Load id employee - * Load filter configuration - * Load cache file. - */ - public function __construct() - { - parent::__construct(); - - // Rely on new module controller for right management - $this->id = Tab::getIdFromClassName('AdminModulesSf'); - $this->template = 'content-legacy.tpl'; - - register_shutdown_function('displayFatalError'); - - // Set Id Employee, Iso Default Country and Filter Configuration - $this->id_employee = (int) $this->context->employee->id; - } - - public function setMedia($isNewTheme = false) - { - parent::setMedia($isNewTheme); - $this->addJqueryPlugin(['autocomplete', 'fancybox', 'tablefilter']); - } - - /** - * Get current URL - * - * @param array $remove List of keys to remove from URL - * - * @return string - */ - protected function getCurrentUrl(array $remove = []) - { - $url = $_SERVER['REQUEST_URI']; - if (!$remove) { - return $url; - } - - if (!is_array($remove)) { - $remove = [$remove]; - } - - $url = preg_replace('#(?<=&|\?)(' . implode('|', $remove) . ')=.*?(&|$)#i', '', $url); - $len = strlen($url); - if ($url[$len - 1] == '&') { - $url = substr($url, 0, $len - 1); - } - - return $url; - } - - /** - * {@inheritdoc} - */ - public function checkAccess() - { - if (!parent::checkAccess()) { - return false; - } - - // only accept configuring a module - if (Tools::getIsset('configure')) { - return true; - } - - // redirect to module manager - Tools::redirectAdmin($this->context->link->getAdminLink('AdminModulesSf')); - - return false; - } - - /** - * {@inheritdoc} - */ - public function postProcess() - { - /* PrestaShop demo mode */ - if (_PS_MODE_DEMO_) { - $this->errors[] = $this->trans('This functionality has been disabled.', [], 'Admin.Notifications.Error'); - - return; - } - - parent::postProcess(); - - $moduleName = Tools::getValue('configure'); - $moduleManagerBuilder = ModuleManagerBuilder::getInstance(); - $moduleManager = $moduleManagerBuilder->build(); - - // Check potential error - if (!$moduleManager->isInstalled($moduleName) || !($module = Module::getInstanceByName($moduleName))) { - $this->errors[] = $this->trans( - 'The module "%modulename%" cannot be found', - ['%modulename%' => $moduleName], - 'Admin.Modules.Notification' - ); - } elseif (!$this->access('edit') || !$module->getPermission('configure')) { - $this->errors[] = $this->trans( - 'You do not have permission to configure this module.', - [], - 'Admin.Modules.Notification' - ); - } else { - // build RTL assets - if (Tools::getValue('generate_rtl')) { - $this->buildRtlAssets($module); - - return; - } - - // enable/disable - if (($enable = ('1' === Tools::getValue('enable'))) || '1' === Tools::getValue('disable')) { - $this->toggleActiveStatus($module, $enable); - - return; - } - - // show module configuration page - $this->buildModuleConfigurationPage($module); - } - } - - public function initModal() - { - parent::initModal(); - - $languages = Language::getLanguages(false); - $translateLinks = []; - - if (Tools::getIsset('configure')) { - /** @var Module|false $module */ - $module = Module::getInstanceByName(Tools::getValue('configure')); - - if (false === $module) { - return; - } - - $isNewTranslateSystem = $module->isUsingNewTranslationSystem(); - $link = Context::getContext()->link; - foreach ($languages as $lang) { - if ($isNewTranslateSystem) { - $translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslationSf', true, [ - 'lang' => $lang['iso_code'], - 'type' => 'modules', - 'selected' => $module->name, - 'locale' => $lang['locale'], - ]); - } else { - $translateLinks[$lang['iso_code']] = $link->getAdminLink('AdminTranslations', true, [], [ - 'type' => 'modules', - 'module' => $module->name, - 'lang' => $lang['iso_code'], - ]); - } - } - } - - $this->context->smarty->assign([ - 'module_languages' => $languages, - 'module_name' => Tools::getValue('configure'), - 'translateLinks' => $translateLinks, - ]); - - $modal_content = $this->context->smarty->fetch('controllers/modules/modal_translation.tpl'); - $this->modals[] = [ - 'modal_id' => 'moduleTradLangSelect', - 'modal_class' => 'modal-sm', - 'modal_title' => $this->trans('Translate this module'), - 'modal_content' => $modal_content, - ]; - } - - /** - * Toggles the module enabled or disabled - * - * @param Module $module - * @param bool $enabled - * - * @return void - */ - protected function toggleActiveStatus(Module $module, bool $enabled): void - { - try { - $success = ($enabled) ? $module->enable() : $module->disable(); - } catch (Exception $e) { - $success = false; - $errorMessage = $e->getMessage(); - } - - if ($success) { - Tools::redirectAdmin($this->context->link->getAdminLink('AdminModules', true, [], ['configure' => $module->name, 'conf' => 6])); - - return; - } - - if (!isset($errorMessage)) { - $moduleErrors = $module->getErrors(); - if (!empty($moduleErrors)) { - $errorMessage = implode('; ', $moduleErrors); - } else { - $errorMessage = $this->trans('Unfortunately, the module did not return additional details.', [], 'Admin.Modules.Notifications'); - } - } - - $params = ['%module%' => $module->name, '%error_details%' => $errorMessage]; - $this->errors[] = ($enabled) - ? $this->trans('Error when enabling module %module%. %error_details%.', $params, 'Admin.Modules.Notifications') - : $this->trans('Error when disabling module %module%. %error_details%.', $params, 'Admin.Modules.Notifications'); - } - - /** - * @return void - * - * @throws PrestaShopDatabaseException - * @throws PrestaShopException - * @throws SmartyException - */ - protected function buildModuleConfigurationPage(Module $module): void - { - // We check if method of module exists - if (!method_exists($module, 'getContent')) { - throw new PrestaShopException(sprintf('Module %s has no getContent() method', $module->name)); - } - - // Get the page content - $content = $module->getContent(); - - $this->bootstrap = (bool) $module->bootstrap; - if (isset($module->multishop_context)) { - $this->multishop_context = $module->multishop_context; - } - - $link = Context::getContext()->link; - $back_link = self::$currentIndex . '&token=' . $this->token . '&tab_module=' . $module->tab . '&module_name=' . $module->name; - $hook_link = $link->getAdminLink('AdminModulesPositions', true, [], ['show_modules' => (int) $module->id]); - $trad_link = $link->getAdminLink('AdminTranslations', true, [], ['type' => 'modules', 'lang=' => '']); - $rtl_link = $link->getAdminLink('AdminModules', true, [], ['configure' => $module->name, 'generate_rtl' => 1]); - - $this->context->smarty->assign([ - 'module_name' => $module->name, - 'module_display_name' => $module->displayName, - 'back_link' => $back_link, - 'module_hook_link' => $hook_link, - 'trad_link' => $trad_link, - 'module_rtl_link' => ($this->context->language->is_rtl ? $rtl_link : null), - 'module_languages' => Language::getLanguages(false), - 'theme_language_dir' => _THEME_LANG_DIR_, - 'page_header_toolbar_title' => $this->page_header_toolbar_title, - 'page_header_toolbar_btn' => $this->page_header_toolbar_btn, - 'add_permission' => $this->access('add'), - ]); - - // Since this controller renders the header itself we must prevent le one from the layout to be displayed - $this->show_page_header_toolbar = false; - - // Display checkbox in toolbar if multishop - if (Shop::isFeatureActive()) { - if (Shop::getContext() == Shop::CONTEXT_SHOP) { - $shop_context = 'shop ' . $this->context->shop->name . ''; - } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) { - $shop_group = new ShopGroup((int) Shop::getContextShopGroupID()); - $shop_context = 'all shops of group shop ' . $shop_group->name . ''; - } else { - $shop_context = 'all shops'; - } - - $this->context->smarty->assign([ - 'module' => $module, - 'display_multishop_checkbox' => true, - 'shop_context' => $shop_context, - 'multishop_enable_url' => $link->getAdminLink('AdminModules', true, [], ['configure' => $module->name, 'enable' => 1]), - 'multishop_disable_url' => $link->getAdminLink('AdminModules', true, [], ['configure' => $module->name, 'disable' => 1]), - ]); - - $configuration_bar = $this->context->smarty->fetch('controllers/modules/configuration_bar.tpl'); - } else { - $configuration_bar = ''; - } - - $this->context->smarty->assign([ - 'is_multishop' => Shop::isFeatureActive(), - 'multishop_context' => Shop::CONTEXT_ALL | Shop::CONTEXT_GROUP | Shop::CONTEXT_SHOP, - ]); - - if (Shop::isFeatureActive() - && isset(Context::getContext()->tmpOldShop) - ) { - Context::getContext()->shop = clone Context::getContext()->tmpOldShop; - unset(Context::getContext()->tmpOldShop); - } - - // Display module configuration - $header = $this->context->smarty->fetch('controllers/modules/configure.tpl'); - - $this->context->smarty->assign('module_content', $header . $content . $configuration_bar); - } - - /** - * Builds RTL assets for the module & redirects to a success page - * - * @return void - * - * @throws PrestaShop\PrestaShop\Core\Localization\RTL\Exception\GenerationException - */ - protected function buildRtlAssets(Module $module): void - { - Language::getRtlStylesheetProcessor() - ->setProcessPaths([ - _PS_MODULE_DIR_ . $module->name, - ]) - ->process(); - - Tools::redirectAdmin( - $this->context->link->getAdminLink( - 'AdminModules', - true, - [], - [ - 'configure' => Tools::getValue('configure'), - // @see AdminController::_conf - 'conf' => 6, - ] - ) - ); - } -}