From b1da62e55d825af64f9bb1b038dc81d8458e1944 Mon Sep 17 00:00:00 2001 From: GuillaumeKadolis Date: Tue, 5 Sep 2017 09:36:42 +0200 Subject: [PATCH 1/8] [fix] custom link id --- src/Presenter/LinkBlockPresenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Presenter/LinkBlockPresenter.php b/src/Presenter/LinkBlockPresenter.php index ff8069d5..62383258 100644 --- a/src/Presenter/LinkBlockPresenter.php +++ b/src/Presenter/LinkBlockPresenter.php @@ -209,7 +209,7 @@ private function makeCustomLinks($customContent) $self = $this; $customLinks = array_map(function ($el) use ($self) { return array( - 'id' => 'link-custom-page-' . $el['title'], + 'id' => 'link-custom-page-' . Tools::link_rewrite($el['title']), 'class' => 'custom-page-link', 'title' => $el['title'], 'description' => '', From 91c696ad58b306450b487e292996ac8af4f72621 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Tue, 20 Nov 2018 18:26:16 +0100 Subject: [PATCH 2/8] Fix update when table cms_block_page does not exist --- upgrade/upgrade-3.0.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/upgrade/upgrade-3.0.php b/upgrade/upgrade-3.0.php index 4ee6d2b9..eaa7f3bb 100644 --- a/upgrade/upgrade-3.0.php +++ b/upgrade/upgrade-3.0.php @@ -41,7 +41,11 @@ function upgrade_module_3_0($object) Configuration::deleteByName('FOOTER_CONTACT'); Configuration::deleteByName('FOOTER_SITEMAP'); - Db::getInstance()->execute('DROP TABLE `' . _DB_PREFIX_ . 'cms_block_page`'); + try { + Db::getInstance()->execute('DROP TABLE `' . _DB_PREFIX_ . 'cms_block_page`'); + } catch (PrestaShopDatabaseException $e) { + //Do nothing, table does not exist + } $object->reset(); From 0beee3895d507ff43d0e8cfdbf219c244487c907 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Thu, 29 Nov 2018 15:37:36 +0100 Subject: [PATCH 3/8] Remove call to reset, and cache clearing as it must be done in PrestaShop core --- upgrade/upgrade-3.0.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/upgrade/upgrade-3.0.php b/upgrade/upgrade-3.0.php index eaa7f3bb..8ac20ebc 100644 --- a/upgrade/upgrade-3.0.php +++ b/upgrade/upgrade-3.0.php @@ -27,9 +27,6 @@ exit; } -use PrestaShop\PrestaShop\Adapter\SymfonyContainer; -use PrestaShop\PrestaShop\Adapter\Cache\CacheClearer; - function upgrade_module_3_0($object) { Configuration::deleteByName('FOOTER_CMS'); @@ -47,10 +44,5 @@ function upgrade_module_3_0($object) //Do nothing, table does not exist } - $object->reset(); - - //Clear Symfony cache to update routing rules - Tools::clearSf2Cache(); - return true; } From 84e6b21036c1985f8127fdc5d23b3683d424fc13 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Fri, 30 Nov 2018 10:51:52 +0100 Subject: [PATCH 4/8] Removing cache clear since it is managed in core now, remove useless security annotation, add installTab on enable --- config/services.yml | 4 +++ ps_linklist.php | 36 ++++++++++--------- .../Improve/Design/LinkBlockController.php | 11 ------ upgrade/upgrade-3.0.php | 6 +--- 4 files changed, 24 insertions(+), 33 deletions(-) diff --git a/config/services.yml b/config/services.yml index 8acafb63..fe8d02ef 100644 --- a/config/services.yml +++ b/config/services.yml @@ -1,4 +1,7 @@ services: + _defaults: + public: true + prestashop.module.link_block.cache: class: PrestaShop\Module\LinkList\Cache\LegacyLinkBlockCache arguments: @@ -122,6 +125,7 @@ services: prestashop.module.link_block.custom_url_type: class: PrestaShop\Module\LinkList\Form\Type\CustomUrlType parent: 'form.type.translatable.aware' + public: true tags: - { name: form.type } diff --git a/ps_linklist.php b/ps_linklist.php index 2102934c..08e690fc 100644 --- a/ps_linklist.php +++ b/ps_linklist.php @@ -70,6 +70,14 @@ public function __construct() $this->version = '3.0.1'; $this->need_instance = 0; $this->tab = 'front_office_features'; + $this->tabs = [ + [ + 'class_name' => 'AdminLinkWidget', + 'visible' => true, + 'name' => 'Link Widget', + 'parent_class_name' => 'AdminParentThemes', + ] + ]; $this->bootstrap = true; parent::__construct(); @@ -90,7 +98,7 @@ public function install() if (!parent::install()) { return false; } - $installed = true; + if (null !== $this->getRepository()) { $installed = $this->installFixtures(); } else { @@ -101,17 +109,23 @@ public function install() && $this->registerHook('displayFooter') && $this->registerHook('actionUpdateLangAfter') && $this->installTab()) { - //Clear Symfony cache to update routing rules - Tools::clearSf2Cache(); - return true; } - parent::uninstall(); + $this->uninstall(); return false; } + public function enable($force_all = false) + { + if (!$this->installTab()) { + return false; + } + + return parent::enable($force_all); + } + /** * @return bool * @@ -146,10 +160,6 @@ private function installLegacyFixtures() public function uninstall() { $uninstalled = true; - if (!$this->uninstallTab()) { - $this->_errors[] = $this->trans('Could not remove Tab.', array(), 'Admin.Modules.Notification'); - $uninstalled = false; - } $errors = $this->getRepository()->dropTables(); if (!empty($errors)) { $this->addModuleErrors($errors); @@ -174,14 +184,6 @@ public function installTab() return $tab->add(); } - public function uninstallTab() - { - $id_tab = (int) Tab::getIdFromClassName('AdminLinkWidget'); - $tab = new Tab($id_tab); - - return $tab->delete(); - } - public function hookActionUpdateLangAfter($params) { if (!empty($params['lang']) && $params['lang'] instanceof Language) { diff --git a/src/Controller/Admin/Improve/Design/LinkBlockController.php b/src/Controller/Admin/Improve/Design/LinkBlockController.php index 0dfe3195..9006497e 100644 --- a/src/Controller/Admin/Improve/Design/LinkBlockController.php +++ b/src/Controller/Admin/Improve/Design/LinkBlockController.php @@ -39,7 +39,6 @@ use PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinition; use PrestaShop\PrestaShop\Core\Grid\Position\PositionUpdate; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; -use PrestaShopBundle\Security\Annotation\AdminSecurity; use PrestaShopBundle\Security\Annotation\ModuleActivated; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -53,8 +52,6 @@ class LinkBlockController extends FrameworkBundleAdminController { /** - * @AdminSecurity("is_granted('read', request.get('_legacy_controller'))", message="Access denied.") - * * @param Request $request * * @return Response @@ -86,8 +83,6 @@ public function listAction(Request $request) } /** - * @AdminSecurity("is_granted('create', request.get('_legacy_controller'))", message="Access denied.") - * * @param Request $request * * @return Response @@ -108,8 +103,6 @@ public function createAction(Request $request) } /** - * @AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message="Access denied.") - * * @param Request $request * @param int $linkBlockId * @@ -131,8 +124,6 @@ public function editAction(Request $request, $linkBlockId) } /** - * @AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message="Access denied.") - * * @param Request $request * * @return RedirectResponse|Response @@ -145,8 +136,6 @@ public function createProcessAction(Request $request) } /** - * @AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message="Access denied.") - * * @param Request $request * @param int $linkBlockId * diff --git a/upgrade/upgrade-3.0.php b/upgrade/upgrade-3.0.php index 8ac20ebc..7b5b3153 100644 --- a/upgrade/upgrade-3.0.php +++ b/upgrade/upgrade-3.0.php @@ -38,11 +38,7 @@ function upgrade_module_3_0($object) Configuration::deleteByName('FOOTER_CONTACT'); Configuration::deleteByName('FOOTER_SITEMAP'); - try { - Db::getInstance()->execute('DROP TABLE `' . _DB_PREFIX_ . 'cms_block_page`'); - } catch (PrestaShopDatabaseException $e) { - //Do nothing, table does not exist - } + Db::getInstance()->execute('DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'cms_block_page`'); return true; } From 9f3cb6c9b0a9a6d2fad1caf053ebb04c70a6227e Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Fri, 30 Nov 2018 14:41:14 +0100 Subject: [PATCH 5/8] Avoid adding the tab twice --- ps_linklist.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ps_linklist.php b/ps_linklist.php index 08e690fc..3c79f76c 100644 --- a/ps_linklist.php +++ b/ps_linklist.php @@ -169,8 +169,20 @@ public function uninstall() return $uninstalled && parent::uninstall(); } + /** + * The Core is supposed to register the tabs automatically thanks to the getTabs() return. + * However in 1.7.5 it only works when the module contains a AdminLinkWidgetController file, + * this works fine when module has been upgraded and the former file is still present however + * for a fresh install we need to install it manually until the core is able to manage new modules. + * + * @return bool + */ public function installTab() { + if (Tab::getIdFromClassName('AdminLinkWidget')) { + return true; + } + $tab = new Tab(); $tab->active = 1; $tab->class_name = 'AdminLinkWidget'; From e4fcf3c8a1bd106be6486dd02f84b6dd4c9ee199 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Fri, 30 Nov 2018 15:14:18 +0100 Subject: [PATCH 6/8] Set the AdminSecurity annotations back --- .../Admin/Improve/Design/LinkBlockController.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Controller/Admin/Improve/Design/LinkBlockController.php b/src/Controller/Admin/Improve/Design/LinkBlockController.php index 9006497e..ae64b424 100644 --- a/src/Controller/Admin/Improve/Design/LinkBlockController.php +++ b/src/Controller/Admin/Improve/Design/LinkBlockController.php @@ -39,6 +39,7 @@ use PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinition; use PrestaShop\PrestaShop\Core\Grid\Position\PositionUpdate; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; +use PrestaShopBundle\Security\Annotation\AdminSecurity; use PrestaShopBundle\Security\Annotation\ModuleActivated; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -52,6 +53,8 @@ class LinkBlockController extends FrameworkBundleAdminController { /** + * @AdminSecurity("is_granted('read', request.get('_legacy_controller'))", message="Access denied.") + * * @param Request $request * * @return Response @@ -83,6 +86,8 @@ public function listAction(Request $request) } /** + * @AdminSecurity("is_granted('create', request.get('_legacy_controller'))", message="Access denied.") + * * @param Request $request * * @return Response @@ -103,6 +108,8 @@ public function createAction(Request $request) } /** + * @AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message="Access denied.") + * * @param Request $request * @param int $linkBlockId * @@ -124,6 +131,8 @@ public function editAction(Request $request, $linkBlockId) } /** + * @AdminSecurity("is_granted('create', request.get('_legacy_controller'))", message="Access denied.") + * * @param Request $request * * @return RedirectResponse|Response @@ -136,6 +145,8 @@ public function createProcessAction(Request $request) } /** + * @AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message="Access denied.") + * * @param Request $request * @param int $linkBlockId * @@ -149,6 +160,8 @@ public function editProcessAction(Request $request, $linkBlockId) } /** + * @AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", message="Access denied.") + * * @param int $linkBlockId * * @return RedirectResponse @@ -178,6 +191,8 @@ public function deleteAction($linkBlockId) } /** + * @AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message="Access denied.") + * * @param Request $request * @param int $hookId * From 76bce8d1c42a510a4790c48a05f943e6314562e4 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Fri, 30 Nov 2018 15:21:04 +0100 Subject: [PATCH 7/8] Cs fixer --- ps_linklist.php | 3 +-- .../Grid/Definition/Factory/LinkBlockDefinitionFactory.php | 2 +- src/Form/LinkBlockFormDataProvider.php | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ps_linklist.php b/ps_linklist.php index 3c79f76c..b12d76e7 100644 --- a/ps_linklist.php +++ b/ps_linklist.php @@ -35,7 +35,6 @@ use PrestaShop\Module\LinkList\Model\LinkBlockLang; use PrestaShop\Module\LinkList\Repository\LinkBlockRepository; use PrestaShop\PrestaShop\Adapter\SymfonyContainer; -use PrestaShop\PrestaShop\Adapter\Cache\CacheClearer; use PrestaShop\PrestaShop\Adapter\LegacyContext; use PrestaShop\PrestaShop\Adapter\Shop\Context; @@ -76,7 +75,7 @@ public function __construct() 'visible' => true, 'name' => 'Link Widget', 'parent_class_name' => 'AdminParentThemes', - ] + ], ]; $this->bootstrap = true; diff --git a/src/Core/Grid/Definition/Factory/LinkBlockDefinitionFactory.php b/src/Core/Grid/Definition/Factory/LinkBlockDefinitionFactory.php index 07400e77..b0067235 100644 --- a/src/Core/Grid/Definition/Factory/LinkBlockDefinitionFactory.php +++ b/src/Core/Grid/Definition/Factory/LinkBlockDefinitionFactory.php @@ -100,7 +100,7 @@ protected function getColumns() 'update_method' => 'POST', 'record_route_params' => [ 'id_hook' => 'hookId', - ] + ], ]) ) ->add((new ActionColumn('actions')) diff --git a/src/Form/LinkBlockFormDataProvider.php b/src/Form/LinkBlockFormDataProvider.php index c30e6345..9178df07 100644 --- a/src/Form/LinkBlockFormDataProvider.php +++ b/src/Form/LinkBlockFormDataProvider.php @@ -264,6 +264,7 @@ private function validateLinkBlock(array $data) /** * @param array $custom + * * @return bool */ private function isEmptyCustom(array $custom) From eb863be4ca47b888618314659946fe6e70bcf463 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Tue, 11 Dec 2018 18:10:40 +0100 Subject: [PATCH 8/8] update version --- composer.json | 1 + config.xml | 2 +- ps_linklist.php | 2 +- views/package.json | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 1cdbd782..3fba4221 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "description": "PrestaShop - Link list", "homepage": "https://github.com/PrestaShop/ps_linklist", "license": "AFL-3.0", + "version": "3.0.2", "authors": [ { "name": "PrestaShop SA", diff --git a/config.xml b/config.xml index eaf8be93..bcb01366 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_linklist - + diff --git a/ps_linklist.php b/ps_linklist.php index b12d76e7..7522a458 100644 --- a/ps_linklist.php +++ b/ps_linklist.php @@ -66,7 +66,7 @@ public function __construct() { $this->name = 'ps_linklist'; $this->author = 'PrestaShop'; - $this->version = '3.0.1'; + $this->version = '3.0.2'; $this->need_instance = 0; $this->tab = 'front_office_features'; $this->tabs = [ diff --git a/views/package.json b/views/package.json index f77ee3f0..0ab3355e 100644 --- a/views/package.json +++ b/views/package.json @@ -1,6 +1,6 @@ { "name": "ps_linklist", - "version": "3.0.1", + "version": "3.0.2", "description": "", "scripts": { "build": "NODE_ENV=production webpack --progress --colors --debug --display-chunks",