From 0229ba041d05d7871d2e677609bf5cbb93d1bba7 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 26 Jun 2018 16:57:13 +0200 Subject: [PATCH 01/21] Introduce new controler for tab notifications, renamed alerts --- .../Presenter/Module/ModulePresenter.php | 16 ++++ .../Improve/Modules/AbstractController.php | 83 +++++++++++++++++++ .../Modules/ModuleAlertsController.php | 80 ++++++++++++++++++ .../Controller/Admin/ModuleController.php | 52 +----------- .../routing/admin/improve/modules/modules.yml | 8 +- .../Includes/notification_kpis.html.twig | 43 ---------- .../views/Admin/Module/alerts.html.twig | 47 +++++++++++ .../views/Admin/Module/updates.html.twig | 57 +++++++++++++ 8 files changed, 289 insertions(+), 97 deletions(-) create mode 100644 src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php create mode 100644 src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php delete mode 100644 src/PrestaShopBundle/Resources/views/Admin/Module/Includes/notification_kpis.html.twig create mode 100644 src/PrestaShopBundle/Resources/views/Admin/Module/alerts.html.twig create mode 100644 src/PrestaShopBundle/Resources/views/Admin/Module/updates.html.twig diff --git a/src/Adapter/Presenter/Module/ModulePresenter.php b/src/Adapter/Presenter/Module/ModulePresenter.php index a0d70fe464cbc..0363896d1c146 100644 --- a/src/Adapter/Presenter/Module/ModulePresenter.php +++ b/src/Adapter/Presenter/Module/ModulePresenter.php @@ -82,6 +82,22 @@ private function getModulePrice($prices) return $prices; } + /** + * Transform a collection of addons as a simple array of data. + * + * @param array $modules + * @return array + */ + public function presentCollection(array $modules) + { + $presentedProducts = array(); + foreach ($modules as $name => $product) { + $presentedProducts[$name] = $this->present($product); + } + + return $presentedProducts; + } + /** * Generate the list of small icons to be displayed near the module name * diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php new file mode 100644 index 0000000000000..fdd96a37482b8 --- /dev/null +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php @@ -0,0 +1,83 @@ + + * @copyright 2007-2018 PrestaShop SA + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +namespace PrestaShopBundle\Controller\Admin\Improve\Modules; + +use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Security\Voter\PageVoter; + +abstract class AbstractController extends FrameworkBundleAdminController +{ + const CONTROLLER_NAME = 'ADMINMODULESSF'; + + protected function getToolbarButtons() + { + // toolbarButtons + $toolbarButtons = array(); + + if (!in_array( + $this->authorizationLevel($this::CONTROLLER_NAME), + array( + PageVoter::LEVEL_READ, + PageVoter::LEVEL_UPDATE, + ) + )) { + $toolbarButtons['add_module'] = array( + 'href' => '#', + 'desc' => $this->trans('Upload a module', 'Admin.Modules.Feature'), + 'icon' => 'cloud_upload', + 'help' => $this->trans('Upload a module', 'Admin.Modules.Feature'), + ); + } + + return array_merge($toolbarButtons, $this->getAddonsConnectToolbar()); + } + + private function getAddonsConnectToolbar() + { + $addonsProvider = $this->get('prestashop.core.admin.data_provider.addons_interface'); + $addonsConnect = array(); + + if ($addonsProvider->isAddonsAuthenticated()) { + $addonsEmail = $addonsProvider->getAddonsEmail(); + $addonsConnect['addons_logout'] = array( + 'href' => '#', + 'desc' => $addonsEmail['username_addons'], + 'icon' => 'exit_to_app', + 'help' => $this->trans('Synchronized with Addons marketplace!', 'Admin.Modules.Notification'), + ); + } else { + $addonsConnect['addons_connect'] = array( + 'href' => '#', + 'desc' => $this->trans('Connect to Addons marketplace', 'Admin.Modules.Feature'), + 'icon' => 'vpn_key', + 'help' => $this->trans('Connect to Addons marketplace', 'Admin.Modules.Feature'), + ); + } + + return $addonsConnect; + } +} diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php new file mode 100644 index 0000000000000..bdc3ebfbb302d --- /dev/null +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php @@ -0,0 +1,80 @@ + + * @copyright 2007-2018 PrestaShop SA + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +namespace PrestaShopBundle\Controller\Admin\Improve\Modules; + +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\JsonResponse; + +class ModuleAlertsController extends AbstractController +{ + /** + * @return Response + */ + public function indexAction() + { + $modulePresenter = $this->get('prestashop.adapter.presenter.module'); + $modulesPresenterCallback = function (array &$modules) use ($modulePresenter) { + return $modulePresenter->presentCollection($modules); + }; + + $moduleManager = $this->get('prestashop.module.manager'); + $modules = $moduleManager->getModulesWithNotifications($modulesPresenterCallback); + $layoutTitle = $this->trans('Module notifications', 'Admin.Modules.Feature'); + + $errorMessage = $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'); + +// dump($modules);die; + + return $this->render('PrestaShopBundle:Admin/Module:alerts.html.twig', array( + 'enableSidebar' => true, + 'layoutHeaderToolbarBtn' => $this->getToolbarButtons(), + 'layoutTitle' => $layoutTitle, + 'help_link' => $this->generateSidebarLink('AdminModules'), + 'modules' => $modules->to_configure, + 'requireAddonsSearch' => false, + 'requireBulkActions' => false, + 'requireFilterStatus' => false, + 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), + 'errorMessage' => $errorMessage, + )); + } + + /** + * @return JsonResponse with number of modules having at least one notification + */ + public function notificationsCountAction() + { + $moduleManager = $this->container->get('prestashop.module.manager'); + + $modulesWithNotif = $moduleManager->groupModulesByInstallationProgress(); + return new JsonResponse(array( + 'count' => $moduleManager->countModulesWithNotifications(), + 'alerts' => count($modulesWithNotif->to_configure), + 'updates' => count($modulesWithNotif->to_update), + )); + } +} diff --git a/src/PrestaShopBundle/Controller/Admin/ModuleController.php b/src/PrestaShopBundle/Controller/Admin/ModuleController.php index 5e1ac21cf7634..b230ac96cdcc5 100755 --- a/src/PrestaShopBundle/Controller/Admin/ModuleController.php +++ b/src/PrestaShopBundle/Controller/Admin/ModuleController.php @@ -27,13 +27,13 @@ namespace PrestaShopBundle\Controller\Admin; use Exception; -use PrestaShop\PrestaShop\Adapter\Module\Module as ModuleAdapter; use PrestaShop\PrestaShop\Core\Addon\AddonListFilter; use PrestaShop\PrestaShop\Core\Addon\AddonListFilterStatus; use PrestaShop\PrestaShop\Core\Addon\AddonListFilterType; use PrestaShop\PrestaShop\Core\Addon\AddonsCollection; use PrestaShop\PrestaShop\Core\Addon\Module\ModuleRepository; use PrestaShop\PrestaShop\Core\Addon\Module\Exception\UnconfirmedModuleActionException; +use PrestaShopBundle\Controller\Admin\Improve\Modules\AbstractController; use PrestaShopBundle\Security\Voter\PageVoter; use PrestaShopBundle\Entity\ModuleHistory; use Symfony\Component\HttpFoundation\Request; @@ -46,7 +46,7 @@ use stdClass; use DateTime; -class ModuleController extends FrameworkBundleAdminController +class ModuleController extends AbstractController { const CONTROLLER_NAME = 'ADMINMODULESSF'; @@ -710,29 +710,6 @@ public function configureModuleAction($module_name) ); } - protected function getToolbarButtons() - { - // toolbarButtons - $toolbarButtons = array(); - - if (!in_array( - $this->authorizationLevel($this::controller_name), - array( - PageVoter::LEVEL_READ, - PageVoter::LEVEL_UPDATE, - ) - )) { - $toolbarButtons['add_module'] = array( - 'href' => '#', - 'desc' => $this->trans('Upload a module', 'Admin.Modules.Feature'), - 'icon' => 'cloud_upload', - 'help' => $this->trans('Upload a module', 'Admin.Modules.Feature'), - ); - } - - return array_merge($toolbarButtons, $this->getAddonsConnectToolbar()); - } - private function getPresentedProducts(array &$modules) { $modulePresenter = $this->get('prestashop.adapter.presenter.module'); @@ -757,31 +734,6 @@ private function getTopMenuData(array $topMenuData, $activeMenu = null) return (array) $topMenuData; } - private function getAddonsConnectToolbar() - { - $addonsProvider = $this->get('prestashop.core.admin.data_provider.addons_interface'); - $addonsConnect = array(); - - if ($addonsProvider->isAddonsAuthenticated()) { - $addonsEmail = $addonsProvider->getAddonsEmail(); - $addonsConnect['addons_logout'] = array( - 'href' => '#', - 'desc' => $addonsEmail['username_addons'], - 'icon' => 'exit_to_app', - 'help' => $this->trans('Synchronized with Addons marketplace!', 'Admin.Modules.Notification'), - ); - } else { - $addonsConnect['addons_connect'] = array( - 'href' => '#', - 'desc' => $this->trans('Connect to Addons marketplace', 'Admin.Modules.Feature'), - 'icon' => 'vpn_key', - 'help' => $this->trans('Connect to Addons marketplace', 'Admin.Modules.Feature'), - ); - } - - return $addonsConnect; - } - public function getModuleCartAction($moduleId) { $moduleRepository = $this->get('prestashop.core.admin.module.repository'); 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 42f9172228ba8..66d24774e2e71 100644 --- a/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/modules.yml +++ b/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/modules.yml @@ -79,17 +79,17 @@ admin_module_import: _controller: PrestaShopBundle:Admin/Module:importModule admin_module_notification: - path: /notifications + path: /alerts methods: [GET] defaults: - _controller: PrestaShopBundle:Admin/Module:notification + _controller: PrestaShopBundle:Admin/Improve/Modules/ModuleAlerts:index _legacy_controller: AdminModulesNotifications admin_module_notification_count: - path: /notifications/count + path: /alerts/count methods: [GET] defaults: - _controller: PrestaShopBundle:Admin/Module:notificationsCount + _controller: PrestaShopBundle:Admin\Improve\Modules\ModuleAlerts:notificationsCount _legacy_controller: AdminModulesNotifications admin_module_addons_store: diff --git a/src/PrestaShopBundle/Resources/views/Admin/Module/Includes/notification_kpis.html.twig b/src/PrestaShopBundle/Resources/views/Admin/Module/Includes/notification_kpis.html.twig deleted file mode 100644 index a26284dcf883f..0000000000000 --- a/src/PrestaShopBundle/Resources/views/Admin/Module/Includes/notification_kpis.html.twig +++ /dev/null @@ -1,43 +0,0 @@ -{#** - * 2007-2018 PrestaShop - * - * 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.txt. - * 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 http://www.prestashop.com for more information. - * - * @author PrestaShop SA - * @copyright 2007-2018 PrestaShop SA - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * International Registered Trademark & Property of PrestaShop SA - *#} -
-
-
- -
- settings - {{ '%nbModules% modules to configure'|trans({'%nbModules%' : modules.to_configure|length}, 'Admin.Modules.Feature')|replace({'[1]' : '', '[/1]' : ''})|raw }} -
- -
- update - {{ '%nbModules% modules to update'|trans({'%nbModules%' : modules.to_update|length}, 'Admin.Modules.Feature')|replace({'[1]' : '', '[/1]' : ''})|raw }} -
- -
-
-
- -
diff --git a/src/PrestaShopBundle/Resources/views/Admin/Module/alerts.html.twig b/src/PrestaShopBundle/Resources/views/Admin/Module/alerts.html.twig new file mode 100644 index 0000000000000..b09c1c9a6ada2 --- /dev/null +++ b/src/PrestaShopBundle/Resources/views/Admin/Module/alerts.html.twig @@ -0,0 +1,47 @@ +{#** + * 2007-2018 PrestaShop + * + * 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.txt. + * 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 http://www.prestashop.com for more information. + * + * @author PrestaShop SA + * @copyright 2007-2018 PrestaShop SA + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + *#} +{% extends '@PrestaShop/Admin/Module/common.html.twig' %} + +{% block content %} + {# Addons connect modal #} + {% include 'PrestaShopBundle:Admin/Module/Includes:modal_addons_connect.html.twig' with { 'level' : level, 'errorMessage' : errorMessage } %} + {# PrestaTrust modal #} + {% include 'PrestaShopBundle:Admin/Module/Includes:modal_confirm_prestatrust.html.twig' %} + {# Contains toolbar-nav for module page #} + {% include 'PrestaShopBundle:Admin/Module/Includes:modal_import.html.twig' with { 'level' : level, 'errorMessage' : errorMessage } %} + {# Actual Page Content #} +
+
+
+ {{ '%nbModules% modules to configure'|trans({'%nbModules%' : modules|length}, 'Admin.Modules.Feature') }} + + +
+ {% include 'PrestaShopBundle:Admin/Module/Includes:grid_notification_configure.html.twig' with { 'modules': modules, 'display_type': 'list', id: 'notification' } %} +
+
+{% endblock %} diff --git a/src/PrestaShopBundle/Resources/views/Admin/Module/updates.html.twig b/src/PrestaShopBundle/Resources/views/Admin/Module/updates.html.twig new file mode 100644 index 0000000000000..ca5848d0de297 --- /dev/null +++ b/src/PrestaShopBundle/Resources/views/Admin/Module/updates.html.twig @@ -0,0 +1,57 @@ +{#** + * 2007-2018 PrestaShop + * + * 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.txt. + * 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 http://www.prestashop.com for more information. + * + * @author PrestaShop SA + * @copyright 2007-2018 PrestaShop SA + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + *#} +{% extends '@PrestaShop/Admin/layout.html.twig' %} + +{% block javascripts %} + {{ parent() }} + + + + +{% endblock %} + +{% block content %} + {# Addons connect modal #} + {% include 'PrestaShopBundle:Admin/Module/Includes:modal_addons_connect.html.twig' with { 'level' : level, 'errorMessage' : errorMessage } %} + {# PrestaTrust modal #} + {% include 'PrestaShopBundle:Admin/Module/Includes:modal_confirm_prestatrust.html.twig' %} + {# Contains toolbar-nav for module page #} + {% include 'PrestaShopBundle:Admin/Module/Includes:modal_import.html.twig' with { 'level' : level, 'errorMessage' : errorMessage } %} + {# Actual Page Content #} +
+
+ {{ '%nbModules% modules to update'|trans({'%nbModules%' : modules.to_update|length}, 'Admin.Modules.Feature') }} + + + {% if (modules.to_update|length > 1) and (level >= constant('PrestaShopBundle\\Security\\Voter\\PageVoter::LEVEL_UPDATE')) %} + {{ "Upgrade All"|trans({}, 'Admin.Modules.Feature') }} + {% endif %} +
+ {% include 'PrestaShopBundle:Admin/Module/Includes:grid_notification_update.html.twig' with { 'modules': modules.to_update, 'display_type': 'list', id: 'update', 'level' : level } %} +
+ +{% endblock %} From 3935ce241b0024aa9f0bed05e16fcafc48a8a700 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 26 Jun 2018 17:26:30 +0200 Subject: [PATCH 02/21] Introduce new controler for module updates --- .../Improve/Modules/AbstractController.php | 27 ++++++++ .../Modules/ModuleAlertsController.php | 29 ++------- .../Modules/ModuleUpdatesController.php | 43 +++++++++++++ .../routing/admin/improve/modules/modules.yml | 8 +++ .../Admin/Module/notifications.html.twig | 62 ------------------- .../views/Admin/Module/updates.html.twig | 17 ++--- 6 files changed, 87 insertions(+), 99 deletions(-) create mode 100644 src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php delete mode 100644 src/PrestaShopBundle/Resources/views/Admin/Module/notifications.html.twig diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php index fdd96a37482b8..9d45aa003daa1 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php @@ -32,6 +32,33 @@ abstract class AbstractController extends FrameworkBundleAdminController { const CONTROLLER_NAME = 'ADMINMODULESSF'; + + protected function getNotificationPageData($type) + { + $modulePresenter = $this->get('prestashop.adapter.presenter.module'); + $modulesPresenterCallback = function (array &$modules) use ($modulePresenter) { + return $modulePresenter->presentCollection($modules); + }; + + $moduleManager = $this->get('prestashop.module.manager'); + $modules = $moduleManager->getModulesWithNotifications($modulesPresenterCallback); + $layoutTitle = $this->trans('Module notifications', 'Admin.Modules.Feature'); + + $errorMessage = $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'); + + return array( + 'enableSidebar' => true, + 'layoutHeaderToolbarBtn' => $this->getToolbarButtons(), + 'layoutTitle' => $layoutTitle, + 'help_link' => $this->generateSidebarLink('AdminModules'), + 'modules' => $modules->{$type}, + 'requireAddonsSearch' => false, + 'requireBulkActions' => false, + 'requireFilterStatus' => false, + 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), + 'errorMessage' => $errorMessage, + ); + } protected function getToolbarButtons() { diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php index bdc3ebfbb302d..fe79f634e13ca 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php @@ -36,31 +36,10 @@ class ModuleAlertsController extends AbstractController */ public function indexAction() { - $modulePresenter = $this->get('prestashop.adapter.presenter.module'); - $modulesPresenterCallback = function (array &$modules) use ($modulePresenter) { - return $modulePresenter->presentCollection($modules); - }; - - $moduleManager = $this->get('prestashop.module.manager'); - $modules = $moduleManager->getModulesWithNotifications($modulesPresenterCallback); - $layoutTitle = $this->trans('Module notifications', 'Admin.Modules.Feature'); - - $errorMessage = $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'); - -// dump($modules);die; - - return $this->render('PrestaShopBundle:Admin/Module:alerts.html.twig', array( - 'enableSidebar' => true, - 'layoutHeaderToolbarBtn' => $this->getToolbarButtons(), - 'layoutTitle' => $layoutTitle, - 'help_link' => $this->generateSidebarLink('AdminModules'), - 'modules' => $modules->to_configure, - 'requireAddonsSearch' => false, - 'requireBulkActions' => false, - 'requireFilterStatus' => false, - 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), - 'errorMessage' => $errorMessage, - )); + return $this->render( + 'PrestaShopBundle:Admin/Module:alerts.html.twig', + $this->getNotificationPageData('to_configure') + ); } /** diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php new file mode 100644 index 0000000000000..52bf5901e8d55 --- /dev/null +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php @@ -0,0 +1,43 @@ + + * @copyright 2007-2018 PrestaShop SA + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +namespace PrestaShopBundle\Controller\Admin\Improve\Modules; + +use Symfony\Component\HttpFoundation\Response; + +class ModuleUpdatesController extends AbstractController +{ + /** + * @return Response + */ + public function indexAction() + { + return $this->render( + 'PrestaShopBundle:Admin/Module:updates.html.twig', + $this->getNotificationPageData('to_update') + ); + } +} 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 66d24774e2e71..6722c7d470974 100644 --- a/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/modules.yml +++ b/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/modules.yml @@ -91,6 +91,14 @@ admin_module_notification_count: defaults: _controller: PrestaShopBundle:Admin\Improve\Modules\ModuleAlerts:notificationsCount _legacy_controller: AdminModulesNotifications + + +admin_module_updates: + path: /updates + methods: [GET] + defaults: + _controller: PrestaShopBundle:Admin/Improve/Modules/ModuleUpdates:index + _legacy_controller: AdminModulesUpdates admin_module_addons_store: path: /addons-store diff --git a/src/PrestaShopBundle/Resources/views/Admin/Module/notifications.html.twig b/src/PrestaShopBundle/Resources/views/Admin/Module/notifications.html.twig deleted file mode 100644 index bca52c7e70fd3..0000000000000 --- a/src/PrestaShopBundle/Resources/views/Admin/Module/notifications.html.twig +++ /dev/null @@ -1,62 +0,0 @@ -{#** - * 2007-2018 PrestaShop - * - * 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.txt. - * 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 http://www.prestashop.com for more information. - * - * @author PrestaShop SA - * @copyright 2007-2018 PrestaShop SA - * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) - * International Registered Trademark & Property of PrestaShop SA - *#} -{% extends '@PrestaShop/Admin/Module/common.html.twig' %} - -{% block content %} - {# Addons connect modal #} - {% include 'PrestaShopBundle:Admin/Module/Includes:modal_addons_connect.html.twig' with { 'level' : level, 'errorMessage' : errorMessage } %} - {# PrestaTrust modal #} - {% include 'PrestaShopBundle:Admin/Module/Includes:modal_confirm_prestatrust.html.twig' %} - {# Contains toolbar-nav for module page #} - {% include 'PrestaShopBundle:Admin/Module/Includes:modal_import.html.twig' with { 'level' : level, 'errorMessage' : errorMessage } %} - {# Module notification KPI's #} - {% include 'PrestaShopBundle:Admin/Module/Includes:notification_kpis.html.twig' %} - {# Actual Page Content #} -
-
-
- {{ '%nbModules% modules to configure'|trans({'%nbModules%' : modules.to_configure|length}, 'Admin.Modules.Feature') }} - - -
- {% include 'PrestaShopBundle:Admin/Module/Includes:grid_notification_configure.html.twig' with { 'modules': modules.to_configure, 'display_type': 'list', id: 'notification' } %} - -
-
- {{ '%nbModules% modules to update'|trans({'%nbModules%' : modules.to_update|length}, 'Admin.Modules.Feature') }} - - - {% if (modules.to_update|length > 1) and (level >= constant('PrestaShopBundle\\Security\\Voter\\PageVoter::LEVEL_UPDATE')) %} - {{ "Upgrade All"|trans({}, 'Admin.Modules.Feature') }} - {% endif %} -
- {% include 'PrestaShopBundle:Admin/Module/Includes:grid_notification_update.html.twig' with { 'modules': modules.to_update, 'display_type': 'list', id: 'update', 'level' : level } %} -
-
-{% endblock %} diff --git a/src/PrestaShopBundle/Resources/views/Admin/Module/updates.html.twig b/src/PrestaShopBundle/Resources/views/Admin/Module/updates.html.twig index ca5848d0de297..220699ced2540 100644 --- a/src/PrestaShopBundle/Resources/views/Admin/Module/updates.html.twig +++ b/src/PrestaShopBundle/Resources/views/Admin/Module/updates.html.twig @@ -22,15 +22,7 @@ * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA *#} -{% extends '@PrestaShop/Admin/layout.html.twig' %} - -{% block javascripts %} - {{ parent() }} - - - - -{% endblock %} +{% extends '@PrestaShop/Admin/Module/common.html.twig' %} {% block content %} {# Addons connect modal #} @@ -41,17 +33,18 @@ {% include 'PrestaShopBundle:Admin/Module/Includes:modal_import.html.twig' with { 'level' : level, 'errorMessage' : errorMessage } %} {# Actual Page Content #}
+
- {{ '%nbModules% modules to update'|trans({'%nbModules%' : modules.to_update|length}, 'Admin.Modules.Feature') }} + {{ '%nbModules% modules to update'|trans({'%nbModules%' : modules|length}, 'Admin.Modules.Feature') }} - {% if (modules.to_update|length > 1) and (level >= constant('PrestaShopBundle\\Security\\Voter\\PageVoter::LEVEL_UPDATE')) %} + {% if (modules|length > 1) and (level >= constant('PrestaShopBundle\\Security\\Voter\\PageVoter::LEVEL_UPDATE')) %} {{ "Upgrade All"|trans({}, 'Admin.Modules.Feature') }} {% endif %}
- {% include 'PrestaShopBundle:Admin/Module/Includes:grid_notification_update.html.twig' with { 'modules': modules.to_update, 'display_type': 'list', id: 'update', 'level' : level } %} + {% include 'PrestaShopBundle:Admin/Module/Includes:grid_notification_update.html.twig' with { 'modules': modules, 'display_type': 'list', id: 'update', 'level' : level } %}
{% endblock %} From d968132387c47315e7f5467304449e94413f49a5 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 26 Jun 2018 17:36:12 +0200 Subject: [PATCH 03/21] Add upgrade file for adding new module updates tab --- .../php/ps_1750_update_module_tabs.php | 43 +++++++++++++++++++ install-dev/upgrade/sql/1.7.5.0.sql | 4 ++ 2 files changed, 47 insertions(+) create mode 100644 install-dev/upgrade/php/ps_1750_update_module_tabs.php create mode 100644 install-dev/upgrade/sql/1.7.5.0.sql diff --git a/install-dev/upgrade/php/ps_1750_update_module_tabs.php b/install-dev/upgrade/php/ps_1750_update_module_tabs.php new file mode 100644 index 0000000000000..5f01ad22d9fde --- /dev/null +++ b/install-dev/upgrade/php/ps_1750_update_module_tabs.php @@ -0,0 +1,43 @@ + + * @copyright 2007-2018 PrestaShop SA + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +/** + * File copied from ps_update_tabs.php and modified for only adding modules related tabs + */ +function ps_1750_update_module_tabs() +{ + // Add new sub menus for modules + $moduleTabsToBeAdded = array( + 'AdminModulesUpdates' => 'en:Updates|fr:Mises à jour|es:Actualizaciones|de:Aktualisierung|it:Aggiornamenti', + ); + + include_once('add_new_tab.php'); + foreach ($moduleTabsToBeAdded as $className => $translations) { + add_new_tab_17($className, $translations, 0, false, 'AdminModulesSf'); + } + + Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'tab` SET `active`=1 WHERE `class_name` = "AdminModulesUpdates"'); +} diff --git a/install-dev/upgrade/sql/1.7.5.0.sql b/install-dev/upgrade/sql/1.7.5.0.sql new file mode 100644 index 0000000000000..9d0e3f5e146e4 --- /dev/null +++ b/install-dev/upgrade/sql/1.7.5.0.sql @@ -0,0 +1,4 @@ +SET SESSION sql_mode = ''; +SET NAMES 'utf8'; + +/* PHP:ps_1750_update_module_tabs(); */; From 915b527ff3e0a0ac30dc3eb5523e99b501a67266 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 26 Jun 2018 18:14:47 +0200 Subject: [PATCH 04/21] Fix tab link AdminModuleUpdates --- classes/Link.php | 1 + 1 file changed, 1 insertion(+) diff --git a/classes/Link.php b/classes/Link.php index b46e72de229b0..8f95f8f4dabcc 100644 --- a/classes/Link.php +++ b/classes/Link.php @@ -743,6 +743,7 @@ public function getAdminLink($controller, $withToken = true, $sfRouteParams = ar 'AdminModulesCatalog' => 'admin_module_catalog', 'AdminModulesManage' => 'admin_module_manage', 'AdminModulesNotifications' => 'admin_module_notification', + 'AdminModulesUpdates' => 'admin_module_updates', 'AdminModulesSf' => 'admin_module_manage', 'AdminOrderPreferences' => 'admin_order_preferences', 'AdminShipping' => 'admin_shipping_preferences', From 7981795856d24f808e9e712d1ef3e7c19c418154 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 26 Jun 2018 18:15:31 +0200 Subject: [PATCH 05/21] Update notification count call to update several tabs --- .../themes/default/js/bundle/module/module.js | 32 ++++++++++++------- src/Core/Addon/Module/ModuleManager.php | 26 +++++++++++++++ .../Modules/ModuleAlertsController.php | 8 +---- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/admin-dev/themes/default/js/bundle/module/module.js b/admin-dev/themes/default/js/bundle/module/module.js index 79eba38e766ef..a615d1a9541f5 100644 --- a/admin-dev/themes/default/js/bundle/module/module.js +++ b/admin-dev/themes/default/js/bundle/module/module.js @@ -653,23 +653,33 @@ var AdminModuleController = function() { * @return void */ this.getNotificationsCount = function () { - var destinationTab = $("#subtab-AdminModulesNotifications"); - if (destinationTab.length === 0) { - return; - } - var token = window.location.search; var urlToCall = moduleURLs.notificationsCount; - $.getJSON(urlToCall, function(badge) { + $.getJSON( + urlToCall, + this.updateNotificationsCount + ).fail(function() { + console.error('Could not retrieve module notifications count.'); + }); + }; + + this.updateNotificationsCount = function(badge) { + var destinationTabs = { + 'to_configure': $("#subtab-AdminModulesNotifications"), + 'to_update': $("#subtab-AdminModulesUpdates"), + }; + + for (var key in destinationTabs) { + if (destinationTabs[key].length === 0) { + return; + } // TODO: This HTML code comes from an already specific template. // To be moved in a template, with generic classes for badges - destinationTab.append('\ - '+badge.count+'\ + destinationTabs[key].append('\ + '+badge[key]+'\ \ '); - }).fail(function() { - console.error('Could not retrieve module notifications count.'); - }); + }; }; this.initAddonsSearch = function () { diff --git a/src/Core/Addon/Module/ModuleManager.php b/src/Core/Addon/Module/ModuleManager.php index a9eb0dae14a37..41622fd09383e 100644 --- a/src/Core/Addon/Module/ModuleManager.php +++ b/src/Core/Addon/Module/ModuleManager.php @@ -156,6 +156,13 @@ public function getModulesWithNotifications(callable $modulesPresenter) return $modules; } + /** + * Returns the total of module notifications + * Not used anymore, but kept for backward compatibility + * + * @return int + * @deprecated since 1.7.4.0 + */ public function countModulesWithNotifications() { $modules = (array) $this->groupModulesByInstallationProgress(); @@ -165,6 +172,25 @@ public function countModulesWithNotifications() }, 0); } + /** + * Detailed array of number of modules per notification type + * + * @return array + */ + public function countModulesWithNotificationsDetailed() + { + $notificationCounts = array( + 'count' => 0, + ); + + foreach ((array) $this->groupModulesByInstallationProgress() as $key => $modules) { + $count = count($modules); + $notificationCounts[$key] = $count; + $notificationCounts['count'] += $count; + } + return $notificationCounts; + } + /** * @return object */ diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php index fe79f634e13ca..9a7e5bee869a4 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php @@ -48,12 +48,6 @@ public function indexAction() public function notificationsCountAction() { $moduleManager = $this->container->get('prestashop.module.manager'); - - $modulesWithNotif = $moduleManager->groupModulesByInstallationProgress(); - return new JsonResponse(array( - 'count' => $moduleManager->countModulesWithNotifications(), - 'alerts' => count($modulesWithNotif->to_configure), - 'updates' => count($modulesWithNotif->to_update), - )); + return new JsonResponse($moduleManager->countModulesWithNotificationsDetailed()); } } From b5c53ac3f76bb4903f4c74d563d7b79a32b504e4 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Wed, 27 Jun 2018 18:08:50 +0100 Subject: [PATCH 06/21] Update tab notifications > Alerts --- install-dev/langs/en/data/tab.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install-dev/langs/en/data/tab.xml b/install-dev/langs/en/data/tab.xml index 26eb7dfbcea6d..830dbe0af6524 100644 --- a/install-dev/langs/en/data/tab.xml +++ b/install-dev/langs/en/data/tab.xml @@ -9,7 +9,7 @@ - + From d5aee10eaa289a68641829956dda7ac9f9649c2a Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Mon, 2 Jul 2018 11:37:58 +0100 Subject: [PATCH 07/21] Add Updates tab in installation data --- install-dev/data/xml/tab.xml | 3 +++ install-dev/langs/en/data/tab.xml | 1 + 2 files changed, 4 insertions(+) diff --git a/install-dev/data/xml/tab.xml b/install-dev/data/xml/tab.xml index a36468fb139d0..863e9a6f6ad35 100644 --- a/install-dev/data/xml/tab.xml +++ b/install-dev/data/xml/tab.xml @@ -181,6 +181,9 @@ AdminModulesNotifications + + AdminModulesUpdates + AdminModules diff --git a/install-dev/langs/en/data/tab.xml b/install-dev/langs/en/data/tab.xml index 830dbe0af6524..17a3a491e954f 100644 --- a/install-dev/langs/en/data/tab.xml +++ b/install-dev/langs/en/data/tab.xml @@ -10,6 +10,7 @@ + From a7ed5ea88a44f99e2302939c351ade5e53d7e4ed Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Mon, 2 Jul 2018 15:09:08 +0100 Subject: [PATCH 08/21] Rename Notifications Tab in upgrade script --- .../php/ps_1750_update_module_tabs.php | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/install-dev/upgrade/php/ps_1750_update_module_tabs.php b/install-dev/upgrade/php/ps_1750_update_module_tabs.php index 5f01ad22d9fde..4d3238d705fb9 100644 --- a/install-dev/upgrade/php/ps_1750_update_module_tabs.php +++ b/install-dev/upgrade/php/ps_1750_update_module_tabs.php @@ -29,7 +29,7 @@ */ function ps_1750_update_module_tabs() { - // Add new sub menus for modules + // STEP 1: Add new sub menus for modules $moduleTabsToBeAdded = array( 'AdminModulesUpdates' => 'en:Updates|fr:Mises à jour|es:Actualizaciones|de:Aktualisierung|it:Aggiornamenti', ); @@ -37,7 +37,26 @@ function ps_1750_update_module_tabs() include_once('add_new_tab.php'); foreach ($moduleTabsToBeAdded as $className => $translations) { add_new_tab_17($className, $translations, 0, false, 'AdminModulesSf'); + Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'tab` SET `active`= 1 WHERE `class_name` = "' . $className . '"'); } - Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'tab` SET `active`=1 WHERE `class_name` = "AdminModulesUpdates"'); + + // STEP 2: Rename Notifications as Alerts + $adminModulesNotificationsTabId = Db::getInstance()->getValue('SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE class_name = "AdminModulesNotifications"'); + if (empty($adminModulesNotificationsTabId)) { + return; + } + + include_once('clean_tabs_15.php'); + renameTab( + $adminModulesNotificationsTabId, + [ + 'fr' => 'Alertes', + 'es' => 'Alertas', + 'en' => 'Alerts', + 'gb' => 'Alerts', + 'de' => 'Benachrichtigungen', + 'it' => 'Avvisi', + ] + ); } From dbc11c80289233eb87613cbba54f80fa33625dd2 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Mon, 2 Jul 2018 15:59:16 +0100 Subject: [PATCH 09/21] Replace return; with continue; --- admin-dev/themes/default/js/bundle/module/module.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin-dev/themes/default/js/bundle/module/module.js b/admin-dev/themes/default/js/bundle/module/module.js index a615d1a9541f5..dc0600e2fd0c1 100644 --- a/admin-dev/themes/default/js/bundle/module/module.js +++ b/admin-dev/themes/default/js/bundle/module/module.js @@ -671,7 +671,7 @@ var AdminModuleController = function() { for (var key in destinationTabs) { if (destinationTabs[key].length === 0) { - return; + continue; } // TODO: This HTML code comes from an already specific template. // To be moved in a template, with generic classes for badges From 12ef0e049425f8ea63bd8a1149007fcd156b4531 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Mon, 2 Jul 2018 15:59:35 +0100 Subject: [PATCH 10/21] Allow all BO tabs to have a notification count --- admin-dev/themes/default/js/bundle/module/module.js | 5 +---- admin-dev/themes/default/template/page_header_toolbar.tpl | 7 ++++++- .../themes/new-theme/template/page_header_toolbar.tpl | 7 ++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/admin-dev/themes/default/js/bundle/module/module.js b/admin-dev/themes/default/js/bundle/module/module.js index dc0600e2fd0c1..1cfa0b15d2eec 100644 --- a/admin-dev/themes/default/js/bundle/module/module.js +++ b/admin-dev/themes/default/js/bundle/module/module.js @@ -675,10 +675,7 @@ var AdminModuleController = function() { } // TODO: This HTML code comes from an already specific template. // To be moved in a template, with generic classes for badges - destinationTabs[key].append('\ - '+badge[key]+'\ - \ - '); + destinationTabs[key].find('.notification-counter').text(badge[key]); }; }; diff --git a/admin-dev/themes/default/template/page_header_toolbar.tpl b/admin-dev/themes/default/template/page_header_toolbar.tpl index bdd2b926ffff4..aed10a1ebbb74 100644 --- a/admin-dev/themes/default/template/page_header_toolbar.tpl +++ b/admin-dev/themes/default/template/page_header_toolbar.tpl @@ -154,7 +154,12 @@ {foreach $level_3.sub_tabs as $level_4} {if $level_4.active}
  • - {$level_4.name} + + {$level_4.name} + + + +
  • {/if} {/foreach} diff --git a/admin-dev/themes/new-theme/template/page_header_toolbar.tpl b/admin-dev/themes/new-theme/template/page_header_toolbar.tpl index a3637b6ad9a2f..5951a9cb972e1 100644 --- a/admin-dev/themes/new-theme/template/page_header_toolbar.tpl +++ b/admin-dev/themes/new-theme/template/page_header_toolbar.tpl @@ -103,7 +103,12 @@ {foreach $level_3.sub_tabs as $level_4} {if $level_4.active} {/if} {/foreach} From 3d775b290c1b72394b13d4bf6a088d0ea7de564a Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 3 Jul 2018 09:51:37 +0100 Subject: [PATCH 11/21] Rename ModuleAbstractController & Add PHPDoc --- ...oller.php => ModuleAbstractController.php} | 20 +++++++++++++++++-- .../Modules/ModuleAlertsController.php | 5 ++++- .../Modules/ModuleUpdatesController.php | 5 ++++- .../Controller/Admin/ModuleController.php | 7 +++++-- 4 files changed, 31 insertions(+), 6 deletions(-) rename src/PrestaShopBundle/Controller/Admin/Improve/Modules/{AbstractController.php => ModuleAbstractController.php} (88%) diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php similarity index 88% rename from src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php rename to src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php index 9d45aa003daa1..b8db115da61b6 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AbstractController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php @@ -29,10 +29,16 @@ use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use PrestaShopBundle\Security\Voter\PageVoter; -abstract class AbstractController extends FrameworkBundleAdminController +abstract class ModuleAbstractController extends FrameworkBundleAdminController { const CONTROLLER_NAME = 'ADMINMODULESSF'; - + + /** + * Common method of alerts & updates routes for getting template variables + * + * @param string $type Type of alert to display (to_configure / to_update ...) + * @return array + */ protected function getNotificationPageData($type) { $modulePresenter = $this->get('prestashop.adapter.presenter.module'); @@ -60,6 +66,11 @@ protected function getNotificationPageData($type) ); } + /** + * Common method for all module related controller for getting the header buttons + * + * @return array + */ protected function getToolbarButtons() { // toolbarButtons @@ -83,6 +94,11 @@ protected function getToolbarButtons() return array_merge($toolbarButtons, $this->getAddonsConnectToolbar()); } + /** + * Create a button in the header for the marketplace account (login or logout) + * + * @return array + */ private function getAddonsConnectToolbar() { $addonsProvider = $this->get('prestashop.core.admin.data_provider.addons_interface'); diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php index 9a7e5bee869a4..072badcadcd41 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php @@ -29,7 +29,10 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\JsonResponse; -class ModuleAlertsController extends AbstractController +/** + * Responsible of "Improve > Modules > Modules & Services > Alerts" page display + */ +class ModuleAlertsController extends ModuleAbstractController { /** * @return Response diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php index 52bf5901e8d55..2ebd22a84bbe5 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php @@ -28,7 +28,10 @@ use Symfony\Component\HttpFoundation\Response; -class ModuleUpdatesController extends AbstractController +/** + * Responsible of "Improve > Modules > Modules & Services > Updates" page display + */ +class ModuleUpdatesController extends ModuleAbstractController { /** * @return Response diff --git a/src/PrestaShopBundle/Controller/Admin/ModuleController.php b/src/PrestaShopBundle/Controller/Admin/ModuleController.php index b230ac96cdcc5..829942a46244f 100755 --- a/src/PrestaShopBundle/Controller/Admin/ModuleController.php +++ b/src/PrestaShopBundle/Controller/Admin/ModuleController.php @@ -33,7 +33,7 @@ use PrestaShop\PrestaShop\Core\Addon\AddonsCollection; use PrestaShop\PrestaShop\Core\Addon\Module\ModuleRepository; use PrestaShop\PrestaShop\Core\Addon\Module\Exception\UnconfirmedModuleActionException; -use PrestaShopBundle\Controller\Admin\Improve\Modules\AbstractController; +use PrestaShopBundle\Controller\Admin\Improve\Modules\ModuleAbstractController; use PrestaShopBundle\Security\Voter\PageVoter; use PrestaShopBundle\Entity\ModuleHistory; use Symfony\Component\HttpFoundation\Request; @@ -46,7 +46,10 @@ use stdClass; use DateTime; -class ModuleController extends AbstractController +/** + * Responsible of "Improve > Modules > Modules & Services > Catalog / Manage" page display + */ +class ModuleController extends ModuleAbstractController { const CONTROLLER_NAME = 'ADMINMODULESSF'; From ee46c4ecaa40578f83618cd300cdc33d7ff6e237 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 3 Jul 2018 10:49:30 +0100 Subject: [PATCH 12/21] Use AddonsCollection for module presenter --- .../Module/AdminModuleDataProvider.php | 3 +- .../Presenter/Module/ModulePresenter.php | 5 +- src/Core/Addon/Module/ModuleManager.php | 4 +- .../Modules/ModuleAbstractController.php | 3 +- .../Controller/Admin/ModuleController.php | 56 ++----------------- 5 files changed, 14 insertions(+), 57 deletions(-) diff --git a/src/Adapter/Module/AdminModuleDataProvider.php b/src/Adapter/Module/AdminModuleDataProvider.php index 995c4b3c0697e..b397a8be556e1 100644 --- a/src/Adapter/Module/AdminModuleDataProvider.php +++ b/src/Adapter/Module/AdminModuleDataProvider.php @@ -249,8 +249,7 @@ public function isAllowedAccess($action, $name = '') */ public function generateAddonsUrls(AddonsCollection $addons, $specific_action = null) { - $addons = $addons->toArray(); - foreach ($addons as &$addon) { + foreach ($addons as $addon) { $urls = array(); foreach ($this->moduleActions as $action) { $urls[$action] = $this->router->generate('admin_module_manage_action', array( diff --git a/src/Adapter/Presenter/Module/ModulePresenter.php b/src/Adapter/Presenter/Module/ModulePresenter.php index 0363896d1c146..239f5e8a6a82c 100644 --- a/src/Adapter/Presenter/Module/ModulePresenter.php +++ b/src/Adapter/Presenter/Module/ModulePresenter.php @@ -29,6 +29,7 @@ use PrestaShop\PrestaShop\Adapter\Module\Module; use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter; use PrestaShop\PrestaShop\Adapter\Presenter\PresenterInterface; +use PrestaShop\PrestaShop\Core\Addon\AddonsCollection; use Exception; class ModulePresenter implements PresenterInterface @@ -85,10 +86,10 @@ private function getModulePrice($prices) /** * Transform a collection of addons as a simple array of data. * - * @param array $modules + * @param AddonsCollection $modules * @return array */ - public function presentCollection(array $modules) + public function presentCollection(AddonsCollection $modules) { $presentedProducts = array(); foreach ($modules as $name => $product) { diff --git a/src/Core/Addon/Module/ModuleManager.php b/src/Core/Addon/Module/ModuleManager.php index 41622fd09383e..5602c0e159083 100644 --- a/src/Core/Addon/Module/ModuleManager.php +++ b/src/Core/Addon/Module/ModuleManager.php @@ -149,8 +149,8 @@ public function getModulesWithNotifications(callable $modulesPresenter) $modulesProvider = $this->adminModuleProvider; foreach ($modules as $moduleLabel => $modulesPart) { $collection = AddonsCollection::createFrom($modulesPart); - $modules->{$moduleLabel} = $modulesProvider->generateAddonsUrls($collection, str_replace("to_", "", $moduleLabel)); - $modules->{$moduleLabel} = $modulesPresenter($modulesPart); + $modulesProvider->generateAddonsUrls($collection, str_replace("to_", "", $moduleLabel)); + $modules->{$moduleLabel} = $modulesPresenter($collection); } return $modules; diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php index b8db115da61b6..1d3f6f618ab00 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php @@ -26,6 +26,7 @@ namespace PrestaShopBundle\Controller\Admin\Improve\Modules; +use PrestaShop\PrestaShop\Core\Addon\AddonsCollection; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use PrestaShopBundle\Security\Voter\PageVoter; @@ -42,7 +43,7 @@ abstract class ModuleAbstractController extends FrameworkBundleAdminController protected function getNotificationPageData($type) { $modulePresenter = $this->get('prestashop.adapter.presenter.module'); - $modulesPresenterCallback = function (array &$modules) use ($modulePresenter) { + $modulesPresenterCallback = function (AddonsCollection &$modules) use ($modulePresenter) { return $modulePresenter->presentCollection($modules); }; diff --git a/src/PrestaShopBundle/Controller/Admin/ModuleController.php b/src/PrestaShopBundle/Controller/Admin/ModuleController.php index 829942a46244f..33e3934f0af12 100755 --- a/src/PrestaShopBundle/Controller/Admin/ModuleController.php +++ b/src/PrestaShopBundle/Controller/Admin/ModuleController.php @@ -121,8 +121,9 @@ public function refreshCatalogAction(Request $request) try { $modulesFromRepository = AddonsCollection::createFrom($moduleRepository->getFilteredList($filters)); - $modules = $modulesProvider->generateAddonsUrls($modulesFromRepository); + $modulesProvider->generateAddonsUrls($modulesFromRepository); + $modules = $modulesFromRepository->toArray(); $categoriesMenu = $this->get('prestashop.categories_provider')->getCategoriesMenu($modules); shuffle($modules); $responseArray['domElements'][] = $this->constructJsonCatalogCategoriesMenuResponse($categoriesMenu); @@ -235,8 +236,8 @@ public function manageAction() foreach ($modules as $moduleLabel => $modulesPart) { $collection = AddonsCollection::createFrom($modulesPart); - $modules->{$moduleLabel} = $modulesProvider->generateAddonsUrls($collection); - $modules->{$moduleLabel} = $this->getPresentedProducts($modulesPart); + $modulesProvider->generateAddonsUrls($collection); + $modules->{$moduleLabel} = $this->getPresentedProducts($collection); } $categoriesMenu = $this->get('prestashop.categories_provider')->getCategoriesMenu($installedProducts); @@ -392,46 +393,6 @@ protected function getDisabledFunctionalityResponse($request) return new JsonResponse($content); } - /** - * @return Response - */ - public function notificationAction() - { - $modulesPresenter = function (array &$modules) { - return $this->getPresentedProducts($modules); - }; - - $moduleManager = $this->get('prestashop.module.manager'); - $modules = $moduleManager->getModulesWithNotifications($modulesPresenter); - $layoutTitle = $this->trans('Module notifications', 'Admin.Modules.Feature'); - - $errorMessage = $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'); - - return $this->render('PrestaShopBundle:Admin/Module:notifications.html.twig', array( - 'enableSidebar' => true, - 'layoutHeaderToolbarBtn' => $this->getToolbarButtons(), - 'layoutTitle' => $layoutTitle, - 'help_link' => $this->generateSidebarLink('AdminModules'), - 'modules' => $modules, - 'requireAddonsSearch' => false, - 'requireBulkActions' => false, - 'requireFilterStatus' => false, - 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), - 'errorMessage' => $errorMessage, - )); - } - - /** - * @return JsonResponse with number of modules having at least one notification - */ - public function notificationsCountAction() - { - $moduleManager = $this->container->get('prestashop.module.manager'); - return new JsonResponse(array( - 'count' => $moduleManager->countModulesWithNotifications(), - )); - } - /** * @param Request $request * @return Response @@ -713,15 +674,10 @@ public function configureModuleAction($module_name) ); } - private function getPresentedProducts(array &$modules) + private function getPresentedProducts(AddonsCollection $modules) { $modulePresenter = $this->get('prestashop.adapter.presenter.module'); - $presentedProducts = array(); - foreach ($modules as $name => $product) { - $presentedProducts[$name] = $modulePresenter->present($product); - } - - return $presentedProducts; + return $modulePresenter->presentCollection($modules); } private function getTopMenuData(array $topMenuData, $activeMenu = null) From 0af2a66a413a692fd9a2fd3dc4409a674ed0ee2c Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 3 Jul 2018 15:34:49 +0100 Subject: [PATCH 13/21] Remove TODO --- admin-dev/themes/default/js/bundle/module/module.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/admin-dev/themes/default/js/bundle/module/module.js b/admin-dev/themes/default/js/bundle/module/module.js index 1cfa0b15d2eec..5daf5ebb63627 100644 --- a/admin-dev/themes/default/js/bundle/module/module.js +++ b/admin-dev/themes/default/js/bundle/module/module.js @@ -673,8 +673,6 @@ var AdminModuleController = function() { if (destinationTabs[key].length === 0) { continue; } - // TODO: This HTML code comes from an already specific template. - // To be moved in a template, with generic classes for badges destinationTabs[key].find('.notification-counter').text(badge[key]); }; }; From 24dbcb120cedc234164fccde3f7f787d33e0e578 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Tue, 3 Jul 2018 16:26:45 +0100 Subject: [PATCH 14/21] Add new module controllers to survival tests --- .../PrestaShopBundle/Controller/Admin/SurvivalTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Integration/PrestaShopBundle/Controller/Admin/SurvivalTest.php b/tests/Integration/PrestaShopBundle/Controller/Admin/SurvivalTest.php index 0a208cb900381..88aea74079d6a 100644 --- a/tests/Integration/PrestaShopBundle/Controller/Admin/SurvivalTest.php +++ b/tests/Integration/PrestaShopBundle/Controller/Admin/SurvivalTest.php @@ -81,6 +81,8 @@ public function getDataProvider() 'admin_maintenance' => ['Maintenance', 'admin_maintenance'], 'admin_product_preferences' => ['Product Preferences', 'admin_product_preferences'], 'admin_customer_preferences' => ['Customer preferences', 'admin_customer_preferences'], + 'admin_module_notification' => ['Alerts', 'admin_module_notification'], + 'admin_module_updates' => ['Alerts', 'admin_module_updates'], ]; } } From 9e87208c51f5e82e7c24eadf1d880fe6c7198677 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Mon, 9 Jul 2018 14:48:41 +0100 Subject: [PATCH 15/21] Allow array & AddonsCollection to be sent --- .../Service/DataProvider/Admin/CategoriesProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PrestaShopBundle/Service/DataProvider/Admin/CategoriesProvider.php b/src/PrestaShopBundle/Service/DataProvider/Admin/CategoriesProvider.php index 259edb49bba29..171eb7051c4f3 100644 --- a/src/PrestaShopBundle/Service/DataProvider/Admin/CategoriesProvider.php +++ b/src/PrestaShopBundle/Service/DataProvider/Admin/CategoriesProvider.php @@ -63,11 +63,11 @@ public function getCategories() /** * Return the list of categories with the number of associated modules. * - * @param array the list of modules + * @param array|AddonsCollection the list of modules * * @return array the list of categories */ - public function getCategoriesMenu(array $modules) + public function getCategoriesMenu($modules) { if (null === self::$categories) { // The Root category is "Categories" From ff706edb8871c78633f4afd2d01ec88afbfdc46b Mon Sep 17 00:00:00 2001 From: Pierre RAMBAUD Date: Fri, 27 Jul 2018 10:05:36 +0200 Subject: [PATCH 16/21] Continue refactoring --- .../Presenter/Module/ModulePresenter.php | 6 +- .../Admin/{ => Improve}/ModuleController.php | 974 +++++++++--------- ...rtsController.php => AlertsController.php} | 8 +- .../Modules/ModuleAbstractController.php | 59 +- ...esController.php => UpdatesController.php} | 2 +- .../admin/improve/modules/_modules.yml | 24 +- 6 files changed, 562 insertions(+), 511 deletions(-) rename src/PrestaShopBundle/Controller/Admin/{ => Improve}/ModuleController.php (56%) rename src/PrestaShopBundle/Controller/Admin/Improve/Modules/{ModuleAlertsController.php => AlertsController.php} (87%) rename src/PrestaShopBundle/Controller/Admin/Improve/Modules/{ModuleUpdatesController.php => UpdatesController.php} (95%) diff --git a/src/Adapter/Presenter/Module/ModulePresenter.php b/src/Adapter/Presenter/Module/ModulePresenter.php index 239f5e8a6a82c..c9143fec3a6d6 100644 --- a/src/Adapter/Presenter/Module/ModulePresenter.php +++ b/src/Adapter/Presenter/Module/ModulePresenter.php @@ -86,10 +86,10 @@ private function getModulePrice($prices) /** * Transform a collection of addons as a simple array of data. * - * @param AddonsCollection $modules + * @param AddonsCollection|array $modules * @return array */ - public function presentCollection(AddonsCollection $modules) + public function presentCollection($modules) { $presentedProducts = array(); foreach ($modules as $name => $product) { @@ -101,7 +101,7 @@ public function presentCollection(AddonsCollection $modules) /** * Generate the list of small icons to be displayed near the module name - * + * * @param array $attributes Attributes of presented module * @return array */ diff --git a/src/PrestaShopBundle/Controller/Admin/ModuleController.php b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php similarity index 56% rename from src/PrestaShopBundle/Controller/Admin/ModuleController.php rename to src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php index 33e3934f0af12..c88c4aecf44d9 100755 --- a/src/PrestaShopBundle/Controller/Admin/ModuleController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php @@ -24,7 +24,7 @@ * International Registered Trademark & Property of PrestaShop SA */ -namespace PrestaShopBundle\Controller\Admin; +namespace PrestaShopBundle\Controller\Admin\Improve; use Exception; use PrestaShop\PrestaShop\Core\Addon\AddonListFilter; @@ -41,6 +41,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Validator\Constraints as Assert; use PrestaShop\PrestaShop\Core\Addon\AddonListFilterOrigin; +use PrestaShopBundle\Security\Annotation\AdminSecurity; use Module; use Profile; use stdClass; @@ -54,65 +55,263 @@ class ModuleController extends ModuleAbstractController const CONTROLLER_NAME = 'ADMINMODULESSF'; /** - * @deprecated + * @AdminSecurity("is_granted(['read', 'create'], 'ADMINMODULESSF_')") + * @return Response */ - const controller_name = self::CONTROLLER_NAME; + public function catalogAction() + { + return $this->render( + 'PrestaShopBundle:Admin/Module:catalog.html.twig', + [ + 'layoutHeaderToolbarBtn' => $this->getToolbarButtons(), + 'layoutTitle' => $this->trans('Module selection', 'Admin.Navigation.Menu'), + 'requireAddonsSearch' => true, + 'requireBulkActions' => false, + 'showContentHeader' => true, + 'enableSidebar' => true, + 'help_link' => $this->generateSidebarLink('AdminModules'), + 'requireFilterStatus' => false, + 'level' => $this->authorizationLevel(self::CONTROLLER_NAME), + 'errorMessage' => $this->trans( + 'You do not have permission to add this.', + 'Admin.Notifications.Error' + ), + ] + ); + } /** + * Controller responsible for displaying "Catalog Module Grid" section of Module management pages with ajax. + * + * @AdminSecurity("is_granted(['read', 'create'], 'ADMINMODULESSF_')") + * + * @param Request $request + * * @return Response */ - public function catalogAction() + public function manageAction() { - if ( - !in_array( - $this->authorizationLevel($this::CONTROLLER_NAME), - array( - PageVoter::LEVEL_READ, - PageVoter::LEVEL_UPDATE, - PageVoter::LEVEL_CREATE, - PageVoter::LEVEL_DELETE, - ) - ) - ) { - return $this->redirect('admin_dashboard'); + $modulesProvider = $this->get('prestashop.core.admin.data_provider.module_interface'); + $shopService = $this->get('prestashop.adapter.shop.context'); + $moduleRepository = $this->get('prestashop.core.admin.module.repository'); + $themeRepository = $this->get('prestashop.core.addon.theme.repository'); + + // Retrieve current shop + $shopId = $shopService->getContextShopId(); + $shops = $shopService->getShops(); + $modulesTheme = []; + if (isset($shops[$shopId]) && is_array($shops[$shopId])) { + $shop = $shops[$shopId]; + $currentTheme = $themeRepository->getInstanceByName($shop['theme_name']); + $modulesTheme = $currentTheme->getModulesToEnable(); + } + + $filters = new AddonListFilter(); + $filters->setType(AddonListFilterType::MODULE | AddonListFilterType::SERVICE) + ->removeStatus(AddonListFilterStatus::UNINSTALLED); + $installedProducts = $moduleRepository->getFilteredList($filters); + + $modules = new stdClass(); + foreach (['native_modules', 'theme_bundle', 'modules'] as $subpart) { + $modules->{$subpart} = []; + } + + foreach ($installedProducts as $installedProduct) { + $modules->{$this->findModuleType($installedProduct, $modulesTheme)}[] = $installedProduct; + } + + foreach ($modules as $moduleLabel => $modulesPart) { + $collection = AddonsCollection::createFrom($modulesPart); + $modules->{$moduleLabel} = $modulesProvider->generateAddonsUrls($collection); + $modules->{$moduleLabel} = $this->get('prestashop.adapter.presenter.module') + ->presentCollection($modulesPart); + } + + return $this->render( + 'PrestaShopBundle:Admin/Module:manage.html.twig', + [ + 'layoutHeaderToolbarBtn' => $this->getToolbarButtons(), + 'layoutTitle' => $this->trans('Manage installed modules', 'Admin.Modules.Feature'), + 'modules' => $modules, + 'topMenuData' => $this->getTopMenuData( + $this->get('prestashop.categories_provider')->getCategoriesMenu($installedProducts) + ), + 'requireAddonsSearch' => false, + 'requireBulkActions' => true, + 'enableSidebar' => true, + 'help_link' => $this->generateSidebarLink('AdminModules'), + 'requireFilterStatus' => true, + 'level' => $this->authorizationLevel(self::CONTROLLER_NAME), + 'errorMessage' => $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'), + ] + ); + } + + /** + * @AdminSecurity("is_granted(['read', 'create'], 'ADMINMODULESSF_')") + * + * @param Request $request + * @return Response + */ + public function getPreferredModulesAction(Request $request) + { + $tabModulesList = $request->get('tab_modules_list'); + + if ($tabModulesList) { + $tabModulesList = explode(',', $tabModulesList); + $modulesListUnsorted = $this->getModulesByInstallation( + $tabModulesList, + $request->request->get('admin_list_from_source') + ); + } + + $installed = $uninstalled = []; + + if (!empty($tabModulesList)) { + foreach ($tabModulesList as $key => $value) { + foreach ($modulesListUnsorted['installed'] as $moduleInstalled) { + if ($moduleInstalled['attributes']['name'] == $value) { + $installed[] = $moduleInstalled; + continue 2; + } + } + + foreach ($modulesListUnsorted['not_installed'] as $moduleNotInstalled) { + if ($moduleNotInstalled['attributes']['name'] == $value) { + $uninstalled[] = $moduleNotInstalled; + continue 2; + } + } + } + } + + $moduleListSorted = [ + 'installed' => $installed, + 'notInstalled' => $uninstalled, + ]; + + $twigParams = [ + 'currentIndex' => '', + 'modulesList' => $moduleListSorted, + 'level' => $this->authorizationLevel(self::CONTROLLER_NAME), + ]; + + if ($request->request->has('admin_list_from_source')) { + $twigParams['adminListFromSource'] = $request->request->get('admin_list_from_source'); } - $errorMessage = $this->trans( - 'You do not have permission to add this.', - 'Admin.Notifications.Error' + return $this->render( + 'PrestaShopBundle:Admin/Module:tab-modules-list.html.twig', + $twigParams ); + } - return $this->render('PrestaShopBundle:Admin/Module:catalog.html.twig', array( - 'layoutHeaderToolbarBtn' => $this->getToolbarButtons(), - 'layoutTitle' => $this->trans('Module selection', 'Admin.Navigation.Menu'), - 'requireAddonsSearch' => true, - 'requireBulkActions' => false, - 'showContentHeader' => true, - 'enableSidebar' => true, - 'help_link' => $this->generateSidebarLink('AdminModules'), - 'requireFilterStatus' => false, - 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), - 'errorMessage' => $errorMessage, - )); + /** + * @AdminSecurity("is_granted(['read', 'create', 'update', 'delete'], 'ADMINMODULESSF_')") + * + * @param Request $module_name + * + * @return Response + */ + public function configureModuleAction($module_name) + { + /* @var $legacyUrlGenerator UrlGeneratorInterface */ + $legacyUrlGenerator = $this->get('prestashop.core.admin.url_generator_legacy'); + $legacyContextProvider = $this->get('prestashop.adapter.legacy.context'); + $legacyContext = $legacyContextProvider->getContext(); + $moduleRepository = $this->get('prestashop.core.admin.module.repository'); + // Get accessed module object + $moduleAccessed = $moduleRepository->getModule($module_name); + + // Get current employee Id + $currentEmployeeId = $legacyContext->employee->id; + // Get accessed module DB Id + $moduleAccessedId = (int) $moduleAccessed->database->get('id'); + + // Save history for this module + $moduleHistory = $this->getDoctrine() + ->getRepository('PrestaShopBundle:ModuleHistory') + ->findOneBy( + [ + 'idEmployee' => $currentEmployeeId, + 'idModule' => $moduleAccessedId, + ] + ); + + if (null === $moduleHistory) { + $moduleHistory = new ModuleHistory(); + } + + $moduleHistory->setIdEmployee($currentEmployeeId); + $moduleHistory->setIdModule($moduleAccessedId); + $moduleHistory->setDateUpd(new DateTime()); + + $em = $this->getDoctrine()->getManager(); + $em->persist($moduleHistory); + $em->flush(); + + return $this->redirect( + $legacyUrlGenerator->generate( + 'admin_module_configure_action', + [ + // do not transmit limit & offset: go to the first page when redirecting + 'configure' => $module_name, + ] + ) + ); } /** - * Controller responsible for displaying "Catalog Module Grid" section of Module management pages with ajax. + * @AdminSecurity("is_granted(['read', 'create', 'update', 'delete'], 'ADMINMODULESSF_')") * * @param Request $request * * @return Response */ + public function getModuleCartAction($moduleId) + { + $moduleRepository = $this->get('prestashop.core.admin.module.repository'); + $module = $moduleRepository->getModuleById($moduleId); + + $addOnsAdminDataProvider = $this->get('prestashop.core.admin.data_provider.module_interface'); + $addOnsAdminDataProvider->generateAddonsUrls( + AddonsCollection::createFrom([$module]) + ); + + $modulePresenter = $this->get('prestashop.adapter.presenter.module'); + $moduleToPresent = $modulePresenter->present($module); + + return $this->render( + '@PrestaShop/Admin/Module/Includes/modal_read_more_content.html.twig', + [ + 'module' => $moduleToPresent, + 'level' => $this->authorizationLevel(self::CONTROLLER_NAME), + ] + ); + } + + /** + * Controller responsible for displaying "Catalog Module Grid" section of Module management pages with ajax. + * + * @param Request $request + * + * @return JsonResponse + */ public function refreshCatalogAction(Request $request) { - if (!$request->isXmlHttpRequest()) { - // Bad request - return new Response('', 400); + $deniedAccess = $this->checkPermissions( + [ + PageVoter::LEVEL_READ, + PageVoter::LEVEL_CREATE + ] + ); + if (null !== $deniedAccess) { + return $deniedAccess; } $modulesProvider = $this->get('prestashop.core.admin.data_provider.module_interface'); $moduleRepository = $this->get('prestashop.core.admin.module.repository'); - $responseArray = array(); + $responseArray = []; $filters = new AddonListFilter(); $filters->setType(AddonListFilterType::MODULE | AddonListFilterType::SERVICE) @@ -138,140 +337,26 @@ public function refreshCatalogAction(Request $request) $responseArray['status'] = false; } - return new JsonResponse($responseArray, 200); - } - - private function constructJsonCatalogBodyResponse($modulesProvider, $modules) - { - $collection = AddonsCollection::createFrom($modules); - $modules = $modulesProvider->generateAddonsUrls($collection); - $formattedContent = array(); - $formattedContent['selector'] = '.module-catalog-page'; - $formattedContent['content'] = $this->render( - 'PrestaShopBundle:Admin/Module/Includes:sorting.html.twig', - array( - 'totalModules' => count($modules), - ) - )->getContent(); - - $errorMessage = $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'); - - $formattedContent['content'] .= $this->render( - 'PrestaShopBundle:Admin/Module/Includes:grid.html.twig', - array( - 'modules' => $this->getPresentedProducts($modules), - 'requireAddonsSearch' => true, - 'id' => 'all', - 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), - 'errorMessage' => $errorMessage, - ) - )->getContent(); - - return $formattedContent; - } - - private function constructJsonCatalogCategoriesMenuResponse($categoriesMenu) - { - $formattedContent = array(); - $formattedContent['selector'] = '.module-menu-item'; - $formattedContent['content'] = $this->render( - 'PrestaShopBundle:Admin/Module/Includes:dropdown_categories.html.twig', - array( - 'topMenuData' => $this->getTopMenuData($categoriesMenu), - ) - )->getContent(); - - return $formattedContent; - } - - public function manageAction() - { - $modulesProvider = $this->get('prestashop.core.admin.data_provider.module_interface'); - $shopService = $this->get('prestashop.adapter.shop.context'); - $moduleRepository = $this->get('prestashop.core.admin.module.repository'); - $themeRepository = $this->get('prestashop.core.addon.theme.repository'); - - // Retrieve current shop - $shopID = $shopService->getContextShopID(); - $shops = $shopService->getShops(); - - if (!empty($shopID) && is_array($shops) && array_key_exists($shopID, $shops)) { - $shop = $shops[$shopID]; - $currentTheme = $themeRepository->getInstanceByName($shop['theme_name']); - $modulesTheme = $currentTheme->getModulesToEnable(); - } else { - $modulesTheme = array(); - } - - $filters = new AddonListFilter(); - $filters->setType(AddonListFilterType::MODULE | AddonListFilterType::SERVICE) - ->removeStatus(AddonListFilterStatus::UNINSTALLED); - $installedProducts = $moduleRepository->getFilteredList($filters); - - $modules = new stdClass(); - foreach (array('native_modules', 'theme_bundle', 'modules') as $subpart) { - $modules->{$subpart} = array(); - } - - foreach ($installedProducts as $installedProduct) { - if (in_array($installedProduct->attributes->get('name'), $modulesTheme)) { - $row = 'theme_bundle'; - } elseif ( - $installedProduct->attributes->has('origin_filter_value') - && in_array( - $installedProduct->attributes->get('origin_filter_value'), - array( - AddonListFilterOrigin::ADDONS_NATIVE, - AddonListFilterOrigin::ADDONS_NATIVE_ALL, - ) - ) - && 'PrestaShop' === $installedProduct->attributes->get('author') - ) { - $row = 'native_modules'; - } else { - $row = 'modules'; - } - $modules->{$row}[] = (object) $installedProduct; - } - - foreach ($modules as $moduleLabel => $modulesPart) { - $collection = AddonsCollection::createFrom($modulesPart); - $modulesProvider->generateAddonsUrls($collection); - $modules->{$moduleLabel} = $this->getPresentedProducts($collection); - } - - $categoriesMenu = $this->get('prestashop.categories_provider')->getCategoriesMenu($installedProducts); - - $errorMessage = $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'); - - return $this->render('PrestaShopBundle:Admin/Module:manage.html.twig', array( - 'layoutHeaderToolbarBtn' => $this->getToolbarButtons(), - 'layoutTitle' => $this->trans('Manage installed modules', 'Admin.Modules.Feature'), - 'modules' => $modules, - 'topMenuData' => $this->getTopMenuData($categoriesMenu), - 'requireAddonsSearch' => false, - 'requireBulkActions' => true, - 'enableSidebar' => true, - 'help_link' => $this->generateSidebarLink('AdminModules'), - 'requireFilterStatus' => true, - 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), - 'errorMessage' => $errorMessage, - )); + return new JsonResponse($responseArray); } + /** + * @param Request $request + * + * @return JsonResponse + */ public function moduleAction(Request $request) { - if ( - !in_array( - $this->authorizationLevel($this::CONTROLLER_NAME), - array( - PageVoter::LEVEL_CREATE, - PageVoter::LEVEL_UPDATE, - PageVoter::LEVEL_DELETE, - ) - ) - ) { - return $this->redirect('admin_dashboard'); + $deniedAccess = $this->checkPermissions( + [ + PageVoter::LEVEL_READ, + PageVoter::LEVEL_UPDATE, + PageVoter::LEVEL_CREATE, + PageVoter::LEVEL_DELETE, + ] + ); + if (null !== $deniedAccess) { + return $deniedAccess; } if ($this->isDemoModeEnabled()) { @@ -280,15 +365,12 @@ public function moduleAction(Request $request) $action = $request->get('action'); $module = $request->get('module_name'); + $moduleManager = $this->container->get('prestashop.module.manager'); + $moduleManager->setActionParams($request->request->get('actionParams', [])); + $moduleRepository = $this->container->get('prestashop.core.admin.module.repository'); + $modulesProvider = $this->container->get('prestashop.core.admin.data_provider.module_interface'); + $response = [$module => []]; - $moduleManager = $this->get('prestashop.module.manager'); - $moduleManager->setActionParams($request->request->get('actionParams', array())); - $moduleRepository = $this->get('prestashop.core.admin.module.repository'); - $modulesProvider = $this->get('prestashop.core.admin.data_provider.module_interface'); - - $response = array( - $module => array(), - ); if (!method_exists($moduleManager, $action)) { $response[$module]['status'] = false; $response[$module]['msg'] = $this->trans('Invalid action', 'Admin.Notifications.Error'); @@ -297,153 +379,215 @@ public function moduleAction(Request $request) try { $response[$module]['status'] = $moduleManager->{$action}($module); - if ($response[$module]['status'] === null) { $response[$module]['status'] = false; $response[$module]['msg'] = $this->trans( '%module% did not return a valid response on %action% action.', 'Admin.Modules.Notification', - array( + [ '%module%' => $module, '%action%' => $action, - ) + ] ); } elseif ($response[$module]['status'] === false) { $error = $moduleManager->getError($module); $response[$module]['msg'] = $this->trans( 'Cannot %action% module %module%. %error_details%', 'Admin.Modules.Notification', - array( + [ '%action%' => str_replace('_', ' ', $action), '%module%' => $module, '%error_details%' => $error, - ) + ] ); } else { $response[$module]['msg'] = $this->trans( '%action% action on module %module% succeeded.', 'Admin.Modules.Notification', - array( + [ '%action%' => ucfirst(str_replace('_', ' ', $action)), '%module%' => $module, - ) + ] ); } } catch (UnconfirmedModuleActionException $e) { $collection = AddonsCollection::createFrom(array($e->getModule())); $modules = $modulesProvider->generateAddonsUrls($collection); - $response[$module] = array_replace($response[$module], - array( - 'status' => false, - 'confirmation_subject' => $e->getSubject(), - 'module' => $this->getPresentedProducts($modules)[0], - 'msg' => $this->trans( - 'Confirmation needed by module %module% on %action% (%subject%).', - 'Admin.Modules.Notification', - array( - '%subject%' => $e->getSubject(), - '%action%' => $e->getAction(), - '%module%' => $module, - ) - ) - )); + $response[$module] = array_replace( + $response[$module], + [ + 'status' => false, + 'confirmation_subject' => $e->getSubject(), + 'module' => $this->container->get('prestashop.adapter.presenter.module') + ->presentCollection($modules)[0], + 'msg' => $this->trans( + 'Confirmation needed by module %module% on %action% (%subject%).', + 'Admin.Modules.Notification', + [ + '%subject%' => $e->getSubject(), + '%action%' => $e->getAction(), + '%module%' => $module, + ] + ) + ] + ); } catch (Exception $e) { $response[$module]['status'] = false; $response[$module]['msg'] = $this->trans( 'Exception thrown by module %module% on %action%. %error_details%', 'Admin.Modules.Notification', - array( + [ '%action%' => str_replace('_', ' ', $action), '%module%' => $module, '%error_details%' => $e->getMessage(), - ) + ] ); - - $logger = $this->get('logger'); + $logger = $this->container->get('logger'); $logger->error($response[$module]['msg']); } if ($response[$module]['status'] === true && $action != 'uninstall') { $moduleInstance = $moduleRepository->getModule($module); - $collection = AddonsCollection::createFrom(array($moduleInstance)); - $moduleInstanceWithUrl = $modulesProvider->generateAddonsUrls($collection); - $response[$module]['action_menu_html'] = $this->render('PrestaShopBundle:Admin/Module/Includes:action_menu.html.twig', array( - 'module' => $this->getPresentedProducts($moduleInstanceWithUrl)[0], - 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), - ))->getContent(); + $collection = AddonsCollection::createFrom([$moduleInstance]); + $response[$module]['action_menu_html'] = $this->container->get('templating')->render( + 'PrestaShopBundle:Admin/Module/Includes:action_menu.html.twig', + [ + 'module' => $this->container->get('prestashop.adapter.presenter.module') + ->presentCollection($modulesProvider->generateAddonsUrls($collection))[0], + 'level' => $this->authorizationLevel(self::CONTROLLER_NAME), + ] + ); } - return new JsonResponse($response, 200); - } - - /** - * @param \Symfony\Component\HttpFoundation\Request $request - * @return JsonResponse - */ - protected function getDisabledFunctionalityResponse($request) - { - $module = $request->get('module_name'); - $content = array( - $module => array( - 'status' => false, - 'msg' => $this->getDemoModeErrorMessage(), - ), - ); - - return new JsonResponse($content); + return new JsonResponse($response); } /** + * Controller responsible for importing new module from DropFile zone in BO. + * * @param Request $request - * @return Response + * + * @return JsonResponse */ - public function getPreferredModulesAction(Request $request) + public function importModuleAction(Request $request) { - $tabModulesList = $request->get('tab_modules_list'); + if ($this->isDemoModeEnabled()) { + return new JsonResponse( + [ + 'status' => false, + 'msg' => $this->getDemoModeErrorMessage(), + ] + ); + } - if ($tabModulesList) { - $tabModulesList = explode(',', $tabModulesList); - $modulesListUnsorted = $this->getModulesByInstallation($tabModulesList, $request->request->get('admin_list_from_source')); + $deniedAccess = $this->checkPermissions( + [ + PageVoter::LEVEL_CREATE, + PageVoter::LEVEL_DELETE + ] + ); + if (null !== $deniedAccess) { + return $deniedAccess; } - $installed = $uninstalled = array(); + $moduleManager = $this->get('prestashop.module.manager'); + $moduleZipManager = $this->get('prestashop.module.zip.manager'); - if (!empty($tabModulesList)) { - foreach ($tabModulesList as $key => $value) { - $continue = 0; - foreach ($modulesListUnsorted['installed'] as $moduleInstalled) { - if ($moduleInstalled['attributes']['name'] == $value) { - $continue = 1; - $installed[] = $moduleInstalled; - } - } - if ($continue) { - continue; - } - foreach ($modulesListUnsorted['not_installed'] as $moduleNotInstalled) { - if ($moduleNotInstalled['attributes']['name'] == $value) { - $uninstalled[] = $moduleNotInstalled; - } + try { + $fileUploaded = $request->files->get('file_uploaded'); + $constraints = [ + new Assert\NotNull(), + new Assert\File( + [ + 'maxSize' => ini_get('upload_max_filesize'), + 'mimeTypes' => [ + 'application/zip', + 'application/x-gzip', + 'application/gzip', + 'application/x-gtar', + 'application/x-tgz', + ], + ] + ), + ]; + + $violations = $this->get('validator')->validate($fileUploaded, $constraints); + if (0 !== count($violations)) { + $violationsMessages = []; + foreach ($violations as $violation) { + $violationsMessages[] = $violation->getMessage(); } + + throw new Exception(implode(PHP_EOL, $violationsMessages)); } - } - $moduleListSorted = array( - 'installed' => $installed, - 'notInstalled' => $uninstalled, - ); + $moduleName = $moduleZipManager->getName($fileUploaded->getPathname()); - $twigParams = array( - 'currentIndex' => '', - 'modulesList' => $moduleListSorted, - 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), - ); + // Install the module + $installationResponse = array( + 'status' => $moduleManager->install($fileUploaded->getPathname()), + 'msg' => '', + 'module_name' => $moduleName, + ); - if ($request->request->has('admin_list_from_source')) { - $twigParams['adminListFromSource'] = $request->request->get('admin_list_from_source'); + if ($installationResponse['status'] === null) { + $installationResponse['status'] = false; + $installationResponse['msg'] = $this->trans( + '%module% did not return a valid response on installation.', + 'Admin.Modules.Notification', + ['%module%' => $moduleName] + ); + } elseif ($installationResponse['status'] === true) { + $installationResponse['msg'] = $this->trans( + 'Installation of module %module% was successful.', + 'Admin.Modules.Notification', + ['%module%' => $moduleName] + ); + $installationResponse['is_configurable'] = (bool) $this->get('prestashop.core.admin.module.repository') + ->getModule($moduleName) + ->attributes + ->get('is_configurable'); + } else { + $error = $moduleManager->getError($moduleName); + $installationResponse['msg'] = $this->trans( + 'Installation of module %module% failed. %error%', + 'Admin.Modules.Notification', + [ + '%module%' => $moduleName, + '%error%' => $error, + ] + ); + } + } catch (UnconfirmedModuleActionException $e) { + $collection = AddonsCollection::createFrom(array($e->getModule())); + $modules = $this->get('prestashop.core.admin.data_provider.module_interface') + ->generateAddonsUrls($collection); + $installationResponse = [ + 'status' => false, + 'confirmation_subject' => $e->getSubject(), + 'module' => $this->get('prestashop.adapter.presenter.module')->presentCollection($modules)[0], + 'msg' => $this->trans( + 'Confirmation needed by module %module% on %action% (%subject%).', + 'Admin.Modules.Notification', + [ + '%subject%' => $e->getSubject(), + '%action%' => $e->getAction(), + '%module%' => $moduleName, + ] + ) + ]; + } catch (Exception $e) { + if (isset($moduleName)) { + $moduleManager->disable($moduleName); + } + + $installationResponse = [ + 'status' => false, + 'msg' => $e->getMessage(), + ]; } - return $this->render('PrestaShopBundle:Admin/Module:tab-modules-list.html.twig', $twigParams); + return new JsonResponse($installationResponse); } private function getModulesByInstallation($modulesSelectList = null) @@ -456,8 +600,8 @@ private function getModulesByInstallation($modulesSelectList = null) $modulesOnDisk = AddonsCollection::createFrom($moduleRepository->getList()); $modulesList = array( - 'installed' => array(), - 'not_installed' => array(), + 'installed' => [], + 'not_installed' => [], ); $modulesOnDisk = $addonsProvider->generateAddonsUrls($modulesOnDisk); @@ -465,13 +609,19 @@ private function getModulesByInstallation($modulesSelectList = null) if (!isset($modulesSelectList) || in_array($module->get('name'), $modulesSelectList)) { $perm = true; if ($module->get('id')) { - $perm &= Module::getPermissionStatic($module->get('id'), 'configure', $this->getContext()->employee); + $perm &= Module::getPermissionStatic( + $module->get('id'), + 'configure', + $this->getContext()->employee + ); } else { $id_admin_module = $tabRepository->findOneIdByClassName('AdminModules'); - $access = Profile::getProfileAccess($this->getContext()->employee->id_profile, $id_admin_module); - if (!$access['edit']) { - $perm &= false; - } + $access = Profile::getProfileAccess( + $this->getContext()->employee->id_profile, + $id_admin_module + ); + + $perm &= !$access['edit']; } if ($module->get('author') === ModuleRepository::PARTNER_AUTHOR) { @@ -492,225 +642,127 @@ private function getModulesByInstallation($modulesSelectList = null) return $modulesList; } + private function getTopMenuData(array $topMenuData, $activeMenu = null) + { + if (isset($activeMenu)) { + if (!isset($topMenuData[$activeMenu])) { + throw new Exception( + sprintf( + 'Menu \'%s\' not found in Top Menu data', + $activeMenu + ), + 1 + ); + } + + $topMenuData[$activeMenu]->class = 'active'; + } + + return $topMenuData; + } + /** - * Controller responsible for importing new module from DropFile zone in BO. - * * @param Request $request * * @return JsonResponse */ - public function importModuleAction(Request $request) + private function getDisabledFunctionalityResponse(Request $request) { - $moduleManager = $this->get('prestashop.module.manager'); - $moduleZipManager = $this->get('prestashop.module.zip.manager'); - - if ($this->isDemoModeEnabled()) { - return new JsonResponse(array( + $content = array( + $request->get('module_name') => array( 'status' => false, 'msg' => $this->getDemoModeErrorMessage(), - )); - } - - try { - if ( - !in_array( - $this->authorizationLevel($this::CONTROLLER_NAME), - array( - PageVoter::LEVEL_CREATE, - PageVoter::LEVEL_DELETE - ) - ) - ) { - return new JsonResponse( - array( - 'status' => false, - 'msg' => $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'), - ), - 200, - array('Content-Type' => 'application/json') - ); - } - $file_uploaded = $request->files->get('file_uploaded'); - $constraints = array( - new Assert\NotNull(), - new Assert\File( - array( - 'maxSize' => ini_get('upload_max_filesize'), - 'mimeTypes' => array( - 'application/zip', - 'application/x-gzip', - 'application/gzip', - 'application/x-gtar', - 'application/x-tgz', - ), - ) - ), - ); - - $violations = $this->get('validator')->validate($file_uploaded, $constraints); - if (0 !== count($violations)) { - $violationsMessages = ''; - foreach ($violations as $violation) { - $violationsMessages .= $violation->getMessage().PHP_EOL; - } - throw new Exception($violationsMessages); - } - - $module_name = $moduleZipManager->getName($file_uploaded->getPathname()); - - // Install the module - $installation_response = array( - 'status' => $moduleManager->install($file_uploaded->getPathname()), - 'msg' => '', - 'module_name' => $module_name, - ); - - if ($installation_response['status'] === null) { - $installation_response['status'] = false; - $installation_response['msg'] = $this->trans( - '%module% did not return a valid response on installation.', - 'Admin.Modules.Notification', - array('%module%' => $module_name) - ); - } elseif ($installation_response['status'] === true) { - $installation_response['msg'] = $this->trans( - 'Installation of module %module% was successful.', - 'Admin.Modules.Notification', - array('%module%' => $module_name) - ); - $installation_response['is_configurable'] = (bool) $this->get('prestashop.core.admin.module.repository')->getModule($module_name)->attributes->get('is_configurable'); - } else { - $error = $moduleManager->getError($module_name); - $installation_response['msg'] = $this->trans( - 'Installation of module %module% failed. %error%', - 'Admin.Modules.Notification', - array( - '%module%' => $module_name, - '%error%' => $error, - ) - ); - } - - return new JsonResponse( - $installation_response, - 200, - array('Content-Type' => 'application/json') - ); - } catch (UnconfirmedModuleActionException $e) { - $collection = AddonsCollection::createFrom(array($e->getModule())); - $modules = $this->get('prestashop.core.admin.data_provider.module_interface')->generateAddonsUrls($collection); - return new JsonResponse( - array( - 'status' => false, - 'confirmation_subject' => $e->getSubject(), - 'module' => $this->getPresentedProducts($modules)[0], - 'msg' => $this->trans( - 'Confirmation needed by module %module% on %action% (%subject%).', - 'Admin.Modules.Notification', - array( - '%subject%' => $e->getSubject(), - '%action%' => $e->getAction(), - '%module%' => $module_name, - ) - ))); - } catch (Exception $e) { - if (isset($module_name)) { - $moduleManager->disable($module_name); - } + ), + ); - return new JsonResponse( - array( - 'status' => false, - 'msg' => $e->getMessage(), ), - 200, - array('Content-Type' => 'application/json') - ); - } + return new JsonResponse($content); } - public function configureModuleAction($module_name) + /** + * @param TODO + */ + private function constructJsonCatalogBodyResponse($modulesProvider, $modules) { - /* @var $legacyUrlGenerator UrlGeneratorInterface */ - $legacyUrlGenerator = $this->get('prestashop.core.admin.url_generator_legacy'); - $legacyContextProvider = $this->get('prestashop.adapter.legacy.context'); - $legacyContext = $legacyContextProvider->getContext(); - $moduleRepository = $this->get('prestashop.core.admin.module.repository'); - // Get accessed module object - $moduleAccessed = $moduleRepository->getModule($module_name); - - // Get current employee ID - $currentEmployeeID = $legacyContext->employee->id; - // Get accessed module DB ID - $moduleAccessedID = (int) $moduleAccessed->database->get('id'); - - // Save history for this module - $moduleHistory = $this->getDoctrine() - ->getRepository('PrestaShopBundle:ModuleHistory') - ->findOneBy(array( - 'idEmployee' => $currentEmployeeID, - 'idModule' => $moduleAccessedID, - )); - - if (is_null($moduleHistory)) { - $moduleHistory = new ModuleHistory(); - } - - $moduleHistory->setIdEmployee($currentEmployeeID); - $moduleHistory->setIdModule($moduleAccessedID); - $moduleHistory->setDateUpd(new DateTime(date('Y-m-d H:i:s'))); + $collection = AddonsCollection::createFrom($modules); + $modules = $modulesProvider->generateAddonsUrls($collection); + $formattedContent = []; + $formattedContent['selector'] = '.module-catalog-page'; + $formattedContent['content'] = $this->render( + 'PrestaShopBundle:Admin/Module/Includes:sorting.html.twig', + array( + 'totalModules' => count($modules), + ) + )->getContent(); - $em = $this->getDoctrine()->getManager(); - $em->persist($moduleHistory); - $em->flush(); + $errorMessage = $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'); - $redirectionParams = array( - // do not transmit limit & offset: go to the first page when redirecting - 'configure' => $module_name, - ); + $formattedContent['content'] .= $this->render( + 'PrestaShopBundle:Admin/Module/Includes:grid.html.twig', + array( + 'modules' => $this->get('prestashop.adapter.presenter.module')->presentCollection($modules), + 'requireAddonsSearch' => true, + 'id' => 'all', + 'level' => $this->authorizationLevel(self::CONTROLLER_NAME), + 'errorMessage' => $errorMessage, + ) + )->getContent(); - return $this->redirect( - $legacyUrlGenerator->generate('admin_module_configure_action', $redirectionParams), - 302 - ); + return $formattedContent; } - private function getPresentedProducts(AddonsCollection $modules) + private function constructJsonCatalogCategoriesMenuResponse($categoriesMenu) { - $modulePresenter = $this->get('prestashop.adapter.presenter.module'); - return $modulePresenter->presentCollection($modules); + $formattedContent = []; + $formattedContent['selector'] = '.module-menu-item'; + $formattedContent['content'] = $this->render( + 'PrestaShopBundle:Admin/Module/Includes:dropdown_categories.html.twig', + array( + 'topMenuData' => $this->getTopMenuData($categoriesMenu), + ) + )->getContent(); + + return $formattedContent; } - private function getTopMenuData(array $topMenuData, $activeMenu = null) + /** + * Find module type + * + */ + private function findModuleType(object $installedProduct, $modulesTheme) { - if (isset($activeMenu)) { - if (!isset($topMenuData[$activeMenu])) { - throw new Exception("Menu '$activeMenu' not found in Top Menu data", 1); - } else { - $topMenuData[$activeMenu]->class = 'active'; - } + if (in_array($installedProduct->attributes->get('name'), $modulesTheme)) { + return 'theme_bundle'; + } + + if ($installedProduct->attributes->has('origin_filter_value') && + in_array( + $installedProduct->attributes->get('origin_filter_value'), + [ + AddonListFilterOrigin::ADDONS_NATIVE, + AddonListFilterOrigin::ADDONS_NATIVE_ALL, + ] + ) && + 'PrestaShop' === $installedProduct->attributes->get('author') + ) { + return 'native_modules'; } - return (array) $topMenuData; + return 'modules'; } - public function getModuleCartAction($moduleId) + private function checkPermissions(array $pageVoter) { - $moduleRepository = $this->get('prestashop.core.admin.module.repository'); - $module = $moduleRepository->getModuleById($moduleId); - - $addOnsAdminDataProvider = $this->get('prestashop.core.admin.data_provider.module_interface'); - $collection = AddonsCollection::createFrom(array($module)); - $addOnsAdminDataProvider->generateAddonsUrls($collection); - - $modulePresenter = $this->get('prestashop.adapter.presenter.module'); - $moduleToPresent = $modulePresenter->present($module); - - return $this->render( - '@PrestaShop/Admin/Module/Includes/modal_read_more_content.html.twig', - array( - 'module' => $moduleToPresent, - 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), - ) - ); + if (!in_array( + $this->authorizationLevel(self::CONTROLLER_NAME), + $pageVoter + ) + ) { + return new JsonResponse( + [ + 'status' => false, + 'msg' => $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'), + ] + ); + } } } diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AlertsController.php similarity index 87% rename from src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php rename to src/PrestaShopBundle/Controller/Admin/Improve/Modules/AlertsController.php index 072badcadcd41..1cd98c83c8f69 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAlertsController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/AlertsController.php @@ -32,7 +32,7 @@ /** * Responsible of "Improve > Modules > Modules & Services > Alerts" page display */ -class ModuleAlertsController extends ModuleAbstractController +class AlertsController extends ModuleAbstractController { /** * @return Response @@ -50,7 +50,9 @@ public function indexAction() */ public function notificationsCountAction() { - $moduleManager = $this->container->get('prestashop.module.manager'); - return new JsonResponse($moduleManager->countModulesWithNotificationsDetailed()); + return new JsonResponse( + $this->get('prestashop.module.manager') + ->countModulesWithNotificationsDetailed() + ); } } diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php index 1d3f6f618ab00..ba2a11faa8b1b 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleAbstractController.php @@ -1,9 +1,9 @@ * @copyright 2007-2018 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) @@ -49,33 +49,30 @@ protected function getNotificationPageData($type) $moduleManager = $this->get('prestashop.module.manager'); $modules = $moduleManager->getModulesWithNotifications($modulesPresenterCallback); - $layoutTitle = $this->trans('Module notifications', 'Admin.Modules.Feature'); - $errorMessage = $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'); - - return array( + return [ 'enableSidebar' => true, 'layoutHeaderToolbarBtn' => $this->getToolbarButtons(), - 'layoutTitle' => $layoutTitle, + 'layoutTitle' => $this->trans('Module notifications', 'Admin.Modules.Feature'), 'help_link' => $this->generateSidebarLink('AdminModules'), 'modules' => $modules->{$type}, 'requireAddonsSearch' => false, 'requireBulkActions' => false, 'requireFilterStatus' => false, 'level' => $this->authorizationLevel($this::CONTROLLER_NAME), - 'errorMessage' => $errorMessage, - ); + 'errorMessage' => $this->trans('You do not have permission to add this.', 'Admin.Notifications.Error'), + ]; } /** * Common method for all module related controller for getting the header buttons - * + * * @return array */ protected function getToolbarButtons() { // toolbarButtons - $toolbarButtons = array(); + $toolbarButtons = []; if (!in_array( $this->authorizationLevel($this::CONTROLLER_NAME), @@ -84,12 +81,12 @@ protected function getToolbarButtons() PageVoter::LEVEL_UPDATE, ) )) { - $toolbarButtons['add_module'] = array( + $toolbarButtons['add_module'] = [ 'href' => '#', 'desc' => $this->trans('Upload a module', 'Admin.Modules.Feature'), 'icon' => 'cloud_upload', 'help' => $this->trans('Upload a module', 'Admin.Modules.Feature'), - ); + ]; } return array_merge($toolbarButtons, $this->getAddonsConnectToolbar()); @@ -100,28 +97,28 @@ protected function getToolbarButtons() * * @return array */ - private function getAddonsConnectToolbar() + protected function getAddonsConnectToolbar() { $addonsProvider = $this->get('prestashop.core.admin.data_provider.addons_interface'); - $addonsConnect = array(); - if ($addonsProvider->isAddonsAuthenticated()) { $addonsEmail = $addonsProvider->getAddonsEmail(); - $addonsConnect['addons_logout'] = array( - 'href' => '#', - 'desc' => $addonsEmail['username_addons'], - 'icon' => 'exit_to_app', - 'help' => $this->trans('Synchronized with Addons marketplace!', 'Admin.Modules.Notification'), - ); - } else { - $addonsConnect['addons_connect'] = array( + return [ + 'addons_logout' => [ + 'href' => '#', + 'desc' => $addonsEmail['username_addons'], + 'icon' => 'exit_to_app', + 'help' => $this->trans('Synchronized with Addons marketplace!', 'Admin.Modules.Notification'), + ] + ]; + } + + return [ + 'addons_connect' => [ 'href' => '#', 'desc' => $this->trans('Connect to Addons marketplace', 'Admin.Modules.Feature'), 'icon' => 'vpn_key', 'help' => $this->trans('Connect to Addons marketplace', 'Admin.Modules.Feature'), - ); - } - - return $addonsConnect; + ] + ]; } } diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/UpdatesController.php similarity index 95% rename from src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php rename to src/PrestaShopBundle/Controller/Admin/Improve/Modules/UpdatesController.php index 2ebd22a84bbe5..ac2ac6060787a 100644 --- a/src/PrestaShopBundle/Controller/Admin/Improve/Modules/ModuleUpdatesController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/Modules/UpdatesController.php @@ -31,7 +31,7 @@ /** * Responsible of "Improve > Modules > Modules & Services > Updates" page display */ -class ModuleUpdatesController extends ModuleAbstractController +class UpdatesController extends ModuleAbstractController { /** * @return Response 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 582975afefccf..9adad5444bb52 100644 --- a/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/_modules.yml +++ b/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/_modules.yml @@ -6,7 +6,7 @@ admin_module_cart: path: /cart/{moduleId} methods: [GET] defaults: - _controller: PrestaShopBundle:Admin/Module:getModuleCart + _controller: PrestaShopBundle:Admin/Improve/Module:getModuleCart requirements: moduleId: \d+ @@ -14,7 +14,7 @@ admin_module_catalog: path: /catalog methods: [GET] defaults: - _controller: PrestaShopBundle:Admin/Module:catalog + _controller: PrestaShopBundle:Admin/Improve/Module:catalog _legacy_controller: AdminModulesCatalog admin_module_catalog_refresh: @@ -23,14 +23,14 @@ admin_module_catalog_refresh: defaults: category: keyword: - _controller: PrestaShopBundle:Admin/Module:refreshCatalog + _controller: PrestaShopBundle:Admin/Improve/Module:refreshCatalog _legacy_controller: AdminModulesCatalog admin_module_catalog_post: path: /catalog/recommended methods: [GET] defaults: - _controller: PrestaShopBundle:Admin/Module:getPreferredModules + _controller: PrestaShopBundle:Admin/Improve/Module:getPreferredModules _legacy_controller: AdminModulesCatalog admin_module_manage: @@ -39,14 +39,14 @@ admin_module_manage: defaults: category: keyword: - _controller: PrestaShopBundle:Admin/Module:manage + _controller: PrestaShopBundle:Admin/Improve/Module:manage _legacy_controller: AdminModulesManage admin_module_manage_action: path: /manage/action/{action}/{module_name} methods: [POST] defaults: - _controller: PrestaShopBundle:Admin/Module:module + _controller: PrestaShopBundle:Admin/Improve/Module:module requirements: action: install|uninstall|enable|disable|enable_mobile|disable_mobile|reset|upgrade @@ -54,14 +54,14 @@ admin_module_configure_action: path: /manage/action/configure/{module_name} methods: [GET, POST] defaults: - _controller: PrestaShopBundle:Admin/Module:configureModule + _controller: PrestaShopBundle:Admin/Improve/Module:configureModule _legacy_controller: AdminModules admin_module_manage_action_bulk: path: /manage/bulk/{action} methods: [POST] defaults: - _controller: PrestaShopBundle:Admin/Module:module + _controller: PrestaShopBundle:Admin/Improve/Module:module requirements: action: install|uninstall|configure|enable|disable|reset|upgrade @@ -69,25 +69,25 @@ admin_module_manage_update_all: path: /manage/update/all methods: [POST] defaults: - _controller: PrestaShopBundle:Admin/Module:module + _controller: PrestaShopBundle:Admin/Improve/Module:module admin_module_import: path: /import methods: [POST] defaults: module_name: - _controller: PrestaShopBundle:Admin/Module:importModule + _controller: PrestaShopBundle:Admin/Improve/Module:importModule admin_module_notification: path: /alerts methods: [GET] defaults: - _controller: PrestaShopBundle:Admin/Improve/Modules/ModuleAlerts:index + _controller: PrestaShopBundle:Admin/Improve/Modules/Alerts:index _legacy_controller: AdminModulesNotifications admin_module_notification_count: path: /alerts/count methods: [GET] defaults: - _controller: PrestaShopBundle:Admin\Improve\Modules\ModuleAlerts:notificationsCount + _controller: PrestaShopBundle:Admin\Improve\Modules\Alerts:notificationsCount _legacy_controller: AdminModulesNotifications From c79a0b13d80d2542734a5ab95f8e8fd47eebb70f Mon Sep 17 00:00:00 2001 From: Pierre RAMBAUD Date: Thu, 16 Aug 2018 15:34:53 +0200 Subject: [PATCH 17/21] Fix undefined routes --- .../Admin/Improve/ModuleController.php | 16 +++++++++++----- .../routing/admin/improve/modules/_modules.yml | 7 +++++++ .../routing/admin/improve/modules/addons.yml | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php index c88c4aecf44d9..514ff871e93f0 100755 --- a/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php @@ -31,6 +31,7 @@ use PrestaShop\PrestaShop\Core\Addon\AddonListFilterStatus; use PrestaShop\PrestaShop\Core\Addon\AddonListFilterType; use PrestaShop\PrestaShop\Core\Addon\AddonsCollection; +use PrestaShop\PrestaShop\Adapter\Module\Module as ApiModule; use PrestaShop\PrestaShop\Core\Addon\Module\ModuleRepository; use PrestaShop\PrestaShop\Core\Addon\Module\Exception\UnconfirmedModuleActionException; use PrestaShopBundle\Controller\Admin\Improve\Modules\ModuleAbstractController; @@ -55,7 +56,8 @@ class ModuleController extends ModuleAbstractController const CONTROLLER_NAME = 'ADMINMODULESSF'; /** - * @AdminSecurity("is_granted(['read', 'create'], 'ADMINMODULESSF_')") + * @AdminSecurity("is_granted(['read', 'create', 'update', 'delete'], 'ADMINMODULESSF_')") + * * @return Response */ public function catalogAction() @@ -83,7 +85,7 @@ public function catalogAction() /** * Controller responsible for displaying "Catalog Module Grid" section of Module management pages with ajax. * - * @AdminSecurity("is_granted(['read', 'create'], 'ADMINMODULESSF_')") + * @AdminSecurity("is_granted(['read', 'create', 'update', 'delete'], 'ADMINMODULESSF_')") * * @param Request $request * @@ -148,7 +150,7 @@ public function manageAction() } /** - * @AdminSecurity("is_granted(['read', 'create'], 'ADMINMODULESSF_')") + * @AdminSecurity("is_granted(['read', 'create', 'update', 'delete'], 'ADMINMODULESSF_')") * * @param Request $request * @return Response @@ -302,7 +304,9 @@ public function refreshCatalogAction(Request $request) $deniedAccess = $this->checkPermissions( [ PageVoter::LEVEL_READ, - PageVoter::LEVEL_CREATE + PageVoter::LEVEL_CREATE, + PageVoter::LEVEL_DELETE, + PageVoter::LEVEL_UPDATE ] ); if (null !== $deniedAccess) { @@ -727,8 +731,10 @@ private function constructJsonCatalogCategoriesMenuResponse($categoriesMenu) /** * Find module type * + * @param ApiModule $installedProduct Installed product + * @param array $modulesTheme Modules theme */ - private function findModuleType(object $installedProduct, $modulesTheme) + private function findModuleType(ApiModule $installedProduct, array $modulesTheme) { if (in_array($installedProduct->attributes->get('name'), $modulesTheme)) { return 'theme_bundle'; 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 9adad5444bb52..42ee4064736a0 100644 --- a/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/_modules.yml +++ b/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/_modules.yml @@ -91,3 +91,10 @@ admin_module_notification_count: defaults: _controller: PrestaShopBundle:Admin\Improve\Modules\Alerts:notificationsCount _legacy_controller: AdminModulesNotifications + +admin_module_updates: + path: /updates + methods: [GET] + defaults: + _controller: PrestaShopBundle:Admin/Improve/Modules/Updates:index + _legacy_controller: AdminModulesUpdates diff --git a/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/addons.yml b/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/addons.yml index 9a779a8325ff9..2fdcc78f03e51 100644 --- a/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/addons.yml +++ b/src/PrestaShopBundle/Resources/config/routing/admin/improve/modules/addons.yml @@ -3,7 +3,7 @@ admin_addons_login: methods: [POST] defaults: _controller: PrestaShopBundle:Admin/Addons:login - + admin_addons_logout: path: /logout methods: [GET] From 407be44b3eb083b1e1d5215d5bd58ef9b2b3674e Mon Sep 17 00:00:00 2001 From: Pierre RAMBAUD Date: Fri, 17 Aug 2018 09:36:55 +0200 Subject: [PATCH 18/21] Address @tomlev comments --- .../php/ps_1750_update_module_tabs.php | 28 +++++++++-------- .../Admin/Improve/ModuleController.php | 30 +++++++++++-------- 2 files changed, 33 insertions(+), 25 deletions(-) diff --git a/install-dev/upgrade/php/ps_1750_update_module_tabs.php b/install-dev/upgrade/php/ps_1750_update_module_tabs.php index 4d3238d705fb9..279392b8da5ee 100644 --- a/install-dev/upgrade/php/ps_1750_update_module_tabs.php +++ b/install-dev/upgrade/php/ps_1750_update_module_tabs.php @@ -1,9 +1,9 @@ * @copyright 2007-2018 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) @@ -34,20 +34,24 @@ function ps_1750_update_module_tabs() 'AdminModulesUpdates' => 'en:Updates|fr:Mises à jour|es:Actualizaciones|de:Aktualisierung|it:Aggiornamenti', ); - include_once('add_new_tab.php'); + include_once 'add_new_tab.php'; foreach ($moduleTabsToBeAdded as $className => $translations) { add_new_tab_17($className, $translations, 0, false, 'AdminModulesSf'); - Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'tab` SET `active`= 1 WHERE `class_name` = "' . $className . '"'); + Db::getInstance()->execute( + 'UPDATE `'._DB_PREFIX_.'tab` SET `active`= 1 WHERE `class_name` = "' . $className . '"' + ); } - + // STEP 2: Rename Notifications as Alerts - $adminModulesNotificationsTabId = Db::getInstance()->getValue('SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE class_name = "AdminModulesNotifications"'); + $adminModulesNotificationsTabId = Db::getInstance()->getValue( + 'SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE class_name = "AdminModulesNotifications"' + ); if (empty($adminModulesNotificationsTabId)) { return; } - - include_once('clean_tabs_15.php'); + + include_once 'clean_tabs_15.php'; renameTab( $adminModulesNotificationsTabId, [ diff --git a/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php index 514ff871e93f0..7db06f9d61a8d 100755 --- a/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php +++ b/src/PrestaShopBundle/Controller/Admin/Improve/ModuleController.php @@ -26,27 +26,28 @@ namespace PrestaShopBundle\Controller\Admin\Improve; +use DateTime; use Exception; +use Module; +use PrestaShopBundle\Controller\Admin\Improve\Modules\ModuleAbstractController; +use PrestaShopBundle\Entity\ModuleHistory; +use PrestaShopBundle\Security\Annotation\AdminSecurity; +use PrestaShopBundle\Security\Voter\PageVoter; +use PrestaShop\PrestaShop\Adapter\Module\AdminModuleDataProvider; +use PrestaShop\PrestaShop\Adapter\Module\Module as ApiModule; use PrestaShop\PrestaShop\Core\Addon\AddonListFilter; +use PrestaShop\PrestaShop\Core\Addon\AddonListFilterOrigin; use PrestaShop\PrestaShop\Core\Addon\AddonListFilterStatus; use PrestaShop\PrestaShop\Core\Addon\AddonListFilterType; use PrestaShop\PrestaShop\Core\Addon\AddonsCollection; -use PrestaShop\PrestaShop\Adapter\Module\Module as ApiModule; -use PrestaShop\PrestaShop\Core\Addon\Module\ModuleRepository; use PrestaShop\PrestaShop\Core\Addon\Module\Exception\UnconfirmedModuleActionException; -use PrestaShopBundle\Controller\Admin\Improve\Modules\ModuleAbstractController; -use PrestaShopBundle\Security\Voter\PageVoter; -use PrestaShopBundle\Entity\ModuleHistory; +use PrestaShop\PrestaShop\Core\Addon\Module\ModuleRepository; +use Profile; +use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Validator\Constraints as Assert; -use PrestaShop\PrestaShop\Core\Addon\AddonListFilterOrigin; -use PrestaShopBundle\Security\Annotation\AdminSecurity; -use Module; -use Profile; use stdClass; -use DateTime; /** * Responsible of "Improve > Modules > Modules & Services > Catalog / Manage" page display @@ -683,9 +684,12 @@ private function getDisabledFunctionalityResponse(Request $request) } /** - * @param TODO + * @param AdminModuleDataProvider $modulesProvider + * @param array $modules + * + * @return array */ - private function constructJsonCatalogBodyResponse($modulesProvider, $modules) + private function constructJsonCatalogBodyResponse(AdminModuleDataProvider $modulesProvider, array $modules) { $collection = AddonsCollection::createFrom($modules); $modules = $modulesProvider->generateAddonsUrls($collection); From b89f3432668b5ed5bc1ae5d0d94cacd3942e165b Mon Sep 17 00:00:00 2001 From: Pierre RAMBAUD Date: Fri, 17 Aug 2018 11:49:06 +0200 Subject: [PATCH 19/21] Fix tests --- src/Adapter/Hosting/HostingInformation.php | 2 +- src/Adapter/Module/Presenter/PaymentModulesPresenter.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapter/Hosting/HostingInformation.php b/src/Adapter/Hosting/HostingInformation.php index 9ede12ac9dcf5..a891c11a44d78 100644 --- a/src/Adapter/Hosting/HostingInformation.php +++ b/src/Adapter/Hosting/HostingInformation.php @@ -56,7 +56,7 @@ public function getDatabaseInformation() public function getServerInformation() { return array( - 'version' => $_SERVER['SERVER_SOFTWARE'], + 'version' => isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null, 'php' => $this->getPhpInformation(), ); } diff --git a/src/Adapter/Module/Presenter/PaymentModulesPresenter.php b/src/Adapter/Module/Presenter/PaymentModulesPresenter.php index 151cf22495ef1..0036ebc31ff84 100644 --- a/src/Adapter/Module/Presenter/PaymentModulesPresenter.php +++ b/src/Adapter/Module/Presenter/PaymentModulesPresenter.php @@ -28,7 +28,7 @@ use PrestaShop\PrestaShop\Adapter\Module\ModuleDataProvider; use PrestaShop\PrestaShop\Core\Addon\Module\ModuleRepository; -use PrestaShop\PrestaShop\Core\Foundation\Templating\PresenterInterface; +use PrestaShop\PrestaShop\Adapter\Presenter\PresenterInterface; use PrestaShop\PrestaShop\Core\Module\DataProvider\TabModuleListProviderInterface; /** From bfa2aa565a0e446f7bcd5728a8e0a7f9d45905a9 Mon Sep 17 00:00:00 2001 From: Pierre RAMBAUD Date: Fri, 24 Aug 2018 17:30:04 +0200 Subject: [PATCH 20/21] Rename all tabs --- classes/lang/KeysReference/TabLang.php | 7 ++- install-dev/data/xml/tab.xml | 6 +- install-dev/langs/en/data/tab.xml | 4 +- .../php/ps_1750_update_module_tabs.php | 58 ++++++++++++++----- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/classes/lang/KeysReference/TabLang.php b/classes/lang/KeysReference/TabLang.php index 424d07c580625..ffd71f77d90e3 100644 --- a/classes/lang/KeysReference/TabLang.php +++ b/classes/lang/KeysReference/TabLang.php @@ -134,6 +134,7 @@ trans('Modules Catalog', 'Admin.Navigation.Menu'); // subtab -trans('Selection', 'Admin.Navigation.Menu'); -trans('Installed modules', 'Admin.Navigation.Menu'); -trans('Notifications', 'Admin.Navigation.Menu'); +trans('Catalog', 'Admin.Navigation.Menu'); +trans('Modules', 'Admin.Navigation.Menu'); +trans('Updates', 'Admin.Navigation.Menu'); +trans('Alerts', 'Admin.Navigation.Menu'); diff --git a/install-dev/data/xml/tab.xml b/install-dev/data/xml/tab.xml index a0e05c07f7309..e18a241001c16 100644 --- a/install-dev/data/xml/tab.xml +++ b/install-dev/data/xml/tab.xml @@ -172,12 +172,12 @@ AdminModulesSf - - AdminModulesManage - AdminModulesCatalog + + AdminModulesManage + AdminModulesNotifications diff --git a/install-dev/langs/en/data/tab.xml b/install-dev/langs/en/data/tab.xml index 19118b256386a..af3b8a9272f72 100644 --- a/install-dev/langs/en/data/tab.xml +++ b/install-dev/langs/en/data/tab.xml @@ -7,8 +7,8 @@ - - + + diff --git a/install-dev/upgrade/php/ps_1750_update_module_tabs.php b/install-dev/upgrade/php/ps_1750_update_module_tabs.php index 279392b8da5ee..8e7f88164780e 100644 --- a/install-dev/upgrade/php/ps_1750_update_module_tabs.php +++ b/install-dev/upgrade/php/ps_1750_update_module_tabs.php @@ -44,23 +44,55 @@ function ps_1750_update_module_tabs() // STEP 2: Rename Notifications as Alerts + include_once 'clean_tabs_15.php'; $adminModulesNotificationsTabId = Db::getInstance()->getValue( 'SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE class_name = "AdminModulesNotifications"' ); - if (empty($adminModulesNotificationsTabId)) { - return; + if (!empty($adminModulesNotificationsTabId)) { + renameTab( + $adminModulesNotificationsTabId, + [ + 'fr' => 'Alertes', + 'es' => 'Alertas', + 'en' => 'Alerts', + 'gb' => 'Alerts', + 'de' => 'Benachrichtigungen', + 'it' => 'Avvisi', + ] + ); } - include_once 'clean_tabs_15.php'; - renameTab( - $adminModulesNotificationsTabId, - [ - 'fr' => 'Alertes', - 'es' => 'Alertas', - 'en' => 'Alerts', - 'gb' => 'Alerts', - 'de' => 'Benachrichtigungen', - 'it' => 'Avvisi', - ] + $adminModulesCatalogTabId = Db::getInstance()->getValue( + 'SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE class_name = "AdminModulesCatalog"' ); + if (!empty($adminModulesCatalogTabId)) { + renameTab( + $adminModulesCatalogTabId, + [ + 'fr' => 'Catalogue', + 'es' => 'Catálogo', + 'en' => 'Catalog', + 'gb' => 'Catalog', + 'de' => 'Catalogus', + 'it' => 'Catalogo', + ] + ); + } + + $adminModulesManageTabId = Db::getInstance()->getValue( + 'SELECT id_tab FROM '._DB_PREFIX_.'tab WHERE class_name = "AdminModulesManage"' + ); + if (!empty($adminModulesManageTabId)) { + renameTab( + $adminModulesManageTabId, + [ + 'fr' => 'Modules', + 'es' => 'módulos', + 'en' => 'Modules', + 'gb' => 'Modules', + 'de' => 'Modules', + 'it' => 'Moduli', + ] + ); + } } From 6d87a6c5efbdf7d6898da10885d119483c51107b Mon Sep 17 00:00:00 2001 From: Pierre RAMBAUD Date: Mon, 27 Aug 2018 15:04:17 +0200 Subject: [PATCH 21/21] Change menu order & names --- classes/lang/KeysReference/TabLang.php | 4 +-- install-dev/data/xml/tab.xml | 25 +++++++++---------- install-dev/langs/en/data/tab.xml | 4 +-- install-dev/upgrade/sql/1.7.5.0.sql | 7 ------ .../Presenter/Module/ModulePresenter.php | 2 +- src/Core/Addon/Module/ModuleManager.php | 2 +- 6 files changed, 18 insertions(+), 26 deletions(-) delete mode 100644 install-dev/upgrade/sql/1.7.5.0.sql diff --git a/classes/lang/KeysReference/TabLang.php b/classes/lang/KeysReference/TabLang.php index ffd71f77d90e3..49e9a2377fea5 100644 --- a/classes/lang/KeysReference/TabLang.php +++ b/classes/lang/KeysReference/TabLang.php @@ -38,7 +38,7 @@ trans('Carrier', 'Admin.Navigation.Menu'); trans('Cart Rules', 'Admin.Navigation.Menu'); trans('Catalog Price Rules', 'Admin.Navigation.Menu'); -trans('Catalog', 'Admin.Navigation.Menu'); +trans('Module Catalog', 'Admin.Navigation.Menu'); trans('Categories', 'Admin.Navigation.Menu'); trans('Page Categories', 'Admin.Navigation.Menu'); trans('Pages', 'Admin.Navigation.Menu'); @@ -132,9 +132,9 @@ trans('Webservice', 'Admin.Navigation.Menu'); trans('Zones', 'Admin.Navigation.Menu'); trans('Modules Catalog', 'Admin.Navigation.Menu'); +trans('Module manager', 'Admin.Navigation.Menu'); // subtab -trans('Catalog', 'Admin.Navigation.Menu'); trans('Modules', 'Admin.Navigation.Menu'); trans('Updates', 'Admin.Navigation.Menu'); trans('Alerts', 'Admin.Navigation.Menu'); diff --git a/install-dev/data/xml/tab.xml b/install-dev/data/xml/tab.xml index e18a241001c16..fc4af4d52a442 100644 --- a/install-dev/data/xml/tab.xml +++ b/install-dev/data/xml/tab.xml @@ -168,22 +168,21 @@ AdminParentModulesSf - + + AdminModulesCatalog + AdminModulesSf - - AdminModulesCatalog - - - AdminModulesManage - - - AdminModulesNotifications - - - AdminModulesUpdates - + + AdminModulesManage + + + AdminModulesNotifications + + + AdminModulesUpdates + AdminModules diff --git a/install-dev/langs/en/data/tab.xml b/install-dev/langs/en/data/tab.xml index af3b8a9272f72..411837d75098f 100644 --- a/install-dev/langs/en/data/tab.xml +++ b/install-dev/langs/en/data/tab.xml @@ -6,8 +6,8 @@ - - + + diff --git a/install-dev/upgrade/sql/1.7.5.0.sql b/install-dev/upgrade/sql/1.7.5.0.sql deleted file mode 100644 index 8b7f9c133e828..0000000000000 --- a/install-dev/upgrade/sql/1.7.5.0.sql +++ /dev/null @@ -1,7 +0,0 @@ -SET SESSION sql_mode = ''; -SET NAMES 'utf8'; - -/* PHP:ps_1750_update_module_tabs(); */; -DELETE FROM `PREFIX_tab_lang` WHERE `id_tab` = (SELECT `id_tab` FROM `PREFIX_tab` WHERE `class_name` = 'AdminAddonsCatalog'); - -DELETE FROM `PREFIX_tab` where `class_name` = 'AdminAddonsCatalog'; diff --git a/src/Adapter/Presenter/Module/ModulePresenter.php b/src/Adapter/Presenter/Module/ModulePresenter.php index 7c344dbe77571..0bfc379c6fce6 100644 --- a/src/Adapter/Presenter/Module/ModulePresenter.php +++ b/src/Adapter/Presenter/Module/ModulePresenter.php @@ -94,7 +94,7 @@ private function getModulePrice($prices) */ public function presentCollection($modules) { - $presentedProducts = array(); + $presentedProducts = []; foreach ($modules as $name => $product) { $presentedProducts[$name] = $this->present($product); } diff --git a/src/Core/Addon/Module/ModuleManager.php b/src/Core/Addon/Module/ModuleManager.php index 8844aac607fb7..2ceee62a6fabd 100644 --- a/src/Core/Addon/Module/ModuleManager.php +++ b/src/Core/Addon/Module/ModuleManager.php @@ -163,7 +163,7 @@ public function getModulesWithNotifications(callable $modulesPresenter) * * @return int * - * @deprecated since 1.7.4.0 + * @deprecated since 1.7.5.0 */ public function countModulesWithNotifications() {