From fa34c99154ff2d11045e7be8ff593c8c99d907a6 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Tue, 6 Feb 2024 16:11:48 +0100 Subject: [PATCH 1/6] Add missing index.php protection files --- src/Adapter/index.php | 11 +++++++++++ src/Constraint/index.php | 11 +++++++++++ src/Definition/index.php | 11 +++++++++++ src/Filters/index.php | 11 +++++++++++ src/Form/Feature/index.php | 11 +++++++++++ src/Form/FeatureValue/index.php | 11 +++++++++++ src/Form/index.php | 11 +++++++++++ src/Hook/index.php | 11 +++++++++++ src/Product/index.php | 11 +++++++++++ src/index.php | 11 +++++++++++ upgrade/index.php | 11 +++++++++++ views/templates/admin/_functions/index.php | 11 +++++++++++ views/templates/admin/_partials/index.php | 11 +++++++++++ views/templates/front/catalog/index.php | 11 +++++++++++ 14 files changed, 154 insertions(+) create mode 100644 src/Adapter/index.php create mode 100644 src/Constraint/index.php create mode 100644 src/Definition/index.php create mode 100644 src/Filters/index.php create mode 100644 src/Form/Feature/index.php create mode 100644 src/Form/FeatureValue/index.php create mode 100644 src/Form/index.php create mode 100644 src/Hook/index.php create mode 100644 src/Product/index.php create mode 100644 src/index.php create mode 100644 upgrade/index.php create mode 100644 views/templates/admin/_functions/index.php create mode 100644 views/templates/admin/_partials/index.php create mode 100644 views/templates/front/catalog/index.php diff --git a/src/Adapter/index.php b/src/Adapter/index.php new file mode 100644 index 000000000..88355f610 --- /dev/null +++ b/src/Adapter/index.php @@ -0,0 +1,11 @@ + Date: Tue, 6 Feb 2024 17:53:12 +0100 Subject: [PATCH 2/6] Handle AttributeGroup hooks to integrate the module into the migrate AttributeGroup form --- src/Form/AttributeGroup/FormDataProvider.php | 93 ++++++++++++ src/Form/AttributeGroup/FormModifier.php | 121 +++++++++++++++ src/Hook/AttributeGroup.php | 148 +++++++++++++++---- 3 files changed, 335 insertions(+), 27 deletions(-) create mode 100644 src/Form/AttributeGroup/FormDataProvider.php create mode 100644 src/Form/AttributeGroup/FormModifier.php diff --git a/src/Form/AttributeGroup/FormDataProvider.php b/src/Form/AttributeGroup/FormDataProvider.php new file mode 100644 index 000000000..38afb5a5e --- /dev/null +++ b/src/Form/AttributeGroup/FormDataProvider.php @@ -0,0 +1,93 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\FacetedSearch\Form\AttributeGroup; + +use Db; +use PrestaShopDatabaseException; + +class FormDataProvider +{ + /** + * @var Db + */ + private $database; + + public function __construct(Db $database) + { + $this->database = $database; + } + + /** + * Fills form data + * + * @param array $params + * + * @return array + * + * @throws PrestaShopDatabaseException + */ + public function getData(array $params) + { + $defaultUrl = []; + $defaultMetaTitle = []; + $isIndexable = false; + + // if params contains id, gets data for edit form + if (!empty($params['id'])) { + $attributeGroupId = (int) $params['id']; + + // returns false if request failed. + $queryIndexable = $this->database->getValue( + 'SELECT `indexable` ' . + 'FROM ' . _DB_PREFIX_ . 'layered_indexable_attribute_group ' . + 'WHERE `id_attribute_group` = ' . $attributeGroupId + ); + + $isIndexable = (bool) $queryIndexable; + $result = $this->database->executeS( + 'SELECT `url_name`, `meta_title`, `id_lang` ' . + 'FROM ' . _DB_PREFIX_ . 'layered_indexable_attribute_group_lang_value ' . + 'WHERE `id_attribute_group` = ' . $attributeGroupId + ); + + if (!empty($result) && is_array($result)) { + foreach ($result as $data) { + $defaultUrl[$data['id_lang']] = $data['url_name']; + $defaultMetaTitle[$data['id_lang']] = $data['meta_title']; + } + } + } + + return [ + 'url_name' => $defaultUrl, + 'meta_title' => $defaultMetaTitle, + 'is_indexable' => $isIndexable, + ]; + } +} diff --git a/src/Form/AttributeGroup/FormModifier.php b/src/Form/AttributeGroup/FormModifier.php new file mode 100644 index 000000000..e7a8d6cce --- /dev/null +++ b/src/Form/AttributeGroup/FormModifier.php @@ -0,0 +1,121 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\FacetedSearch\Form\AttributeGroup; + +use PrestaShop\Module\FacetedSearch\Constraint\UrlSegment; +use PrestaShop\PrestaShop\Core\Exception\CoreException; +use PrestaShopBundle\Form\Admin\Type\SwitchType; +use PrestaShopBundle\Form\Admin\Type\TranslatableType; +use PrestaShopBundle\Translation\TranslatorComponent; +use Symfony\Component\Form\FormBuilderInterface; + +class FormModifier +{ + /** + * @var TranslatorComponent + */ + private $translator; + + public function __construct(TranslatorComponent $translator) + { + $this->translator = $translator; + } + + public function modify(FormBuilderInterface $formBuilder) + { + // Dynamically check the class and instanciate it, this avoids the module from requiring PrestaShop 1.7.8 minimum, + // besides this code is not supposed to be called in older versions + if (!class_exists('\PrestaShopBundle\Form\FormBuilderModifier')) { + throw new CoreException('FormBuilderModifier class was not found, it is only available in PrestaShop 1.7.8 and more'); + } + $formBuilderModifier = new \PrestaShopBundle\Form\FormBuilderModifier(); + + $invalidCharsHint = $this->translator->trans( + 'Invalid characters: <>;=#{}_', + [], + 'Modules.Facetedsearch.Admin' + ); + + $urlTip = $this->translator->trans( + 'When the Faceted Search module is enabled, you can get more detailed URLs by choosing the word that best represent this attribute. By default, PrestaShop uses the attribute\'s name, but you can change that setting using this field.', + [], + 'Modules.Facetedsearch.Admin' + ); + $metaTitleTip = $this->translator->trans( + 'When the Faceted Search module is enabled, you can get more detailed page titles by choosing the word that best represent this attribute. By default, PrestaShop uses the attribute\'s name, but you can change that setting using this field.', + [], + 'Modules.Facetedsearch.Admin' + ); + + $formBuilderModifier->addBefore( + $formBuilder, + 'group_type', + 'url_name', + TranslatableType::class, + [ + 'required' => false, + 'label' => $this->translator->trans('URL', [], 'Modules.Facetedsearch.Admin'), + 'help' => $urlTip . ' ' . $invalidCharsHint, + 'options' => [ + 'constraints' => [ + new UrlSegment([ + 'message' => $this->translator->trans('%s is invalid.', [], 'Admin.Notifications.Error'), + ]), + ], + ], + ] + ); + $formBuilderModifier->addBefore( + $formBuilder, + 'group_type', + 'meta_title', + TranslatableType::class, + [ + 'required' => false, + 'label' => $this->translator->trans('Meta title', [], 'Modules.Facetedsearch.Admin'), + 'help' => $metaTitleTip, + ] + ); + $formBuilderModifier->addBefore( + $formBuilder, + 'group_type', + 'is_indexable', + SwitchType::class, + [ + 'required' => false, + 'label' => $this->translator->trans('Indexable', [], 'Modules.Facetedsearch.Admin'), + 'help' => $this->translator->trans( + 'Use this attribute in URL generated by the Faceted Search module.', + [], + 'Modules.Facetedsearch.Admin' + ), + ] + ); + } +} diff --git a/src/Hook/AttributeGroup.php b/src/Hook/AttributeGroup.php index 2d91b6e8a..ff4b539c7 100644 --- a/src/Hook/AttributeGroup.php +++ b/src/Hook/AttributeGroup.php @@ -21,6 +21,8 @@ namespace PrestaShop\Module\FacetedSearch\Hook; use Language; +use PrestaShop\Module\FacetedSearch\Form\AttributeGroup\FormDataProvider; +use PrestaShop\Module\FacetedSearch\Form\AttributeGroup\FormModifier; use Tools; class AttributeGroup extends AbstractHook @@ -30,8 +32,65 @@ class AttributeGroup extends AbstractHook 'actionAttributeGroupSave', 'displayAttributeGroupForm', 'displayAttributeGroupPostProcess', + // Hooks for migrated page + 'actionAttributeGroupFormBuilderModifier', + 'actionAttributeGroupFormDataProviderData', + 'actionAfterCreateAttributeGroupFormHandler', + 'actionAfterUpdateAttributeGroupFormHandler', ]; + /** + * Hook for modifying attribute group form formBuilder + * + * @since PrestaShop 9.0.0 + * + * @param array $params + */ + public function actionAttributeGroupFormBuilderModifier(array $params) + { + $formModifier = new FormModifier($this->context->getTranslator()); + $formModifier->modify($params['form_builder']); + } + + /** + * Hook that provides extra data in the form. + * + * @since PrestaShop 9.0.0 + * + * @param array $params + */ + public function actionAttributeGroupFormDataProviderData(array $params) + { + $formDataProvider = new FormDataProvider($this->database); + $attributeGroupData = $formDataProvider->getData($params); + // Update data field in params which is passed by reference + $params['data'] = array_merge($params['data'], $attributeGroupData); + } + + /** + * Hook after creation form is handled in migrated page. + * + * @since PrestaShop 9.0.0 + * + * @param array $params + */ + public function actionAfterCreateAttributeGroupFormHandler(array $params): void + { + $this->save(array_merge(['id_attribute_group' => $params['id']], $params['form_data'])); + } + + /** + * Hook after edition form is handled in migrated page. + * + * @since PrestaShop 9.0.0 + * + * @param array $params + */ + public function actionAfterUpdateAttributeGroupFormHandler(array $params): void + { + $this->save(array_merge(['id_attribute_group' => $params['id']], $params['form_data'])); + } + /** * After save Attributes group * @@ -43,37 +102,23 @@ public function actionAttributeGroupSave(array $params) return; } - $this->database->execute( - 'DELETE FROM ' . _DB_PREFIX_ . 'layered_indexable_attribute_group - WHERE `id_attribute_group` = ' . (int) $params['id_attribute_group'] - ); - $this->database->execute( - 'DELETE FROM ' . _DB_PREFIX_ . 'layered_indexable_attribute_group_lang_value - WHERE `id_attribute_group` = ' . (int) $params['id_attribute_group'] - ); - - $this->database->execute( - 'INSERT INTO ' . _DB_PREFIX_ . 'layered_indexable_attribute_group (`id_attribute_group`, `indexable`) -VALUES (' . (int) $params['id_attribute_group'] . ', ' . (int) Tools::getValue('layered_indexable') . ')' - ); + $formData = [ + 'id_attribute_group' => (int) $params['id_attribute_group'], + 'is_indexable' => (int) Tools::getValue('layered_indexable'), + ]; foreach (Language::getLanguages(false) as $language) { - $seoUrl = Tools::getValue('url_name_' . (int) $language['id_lang']); - $metaTitle = Tools::getValue('meta_title_' . (int) $language['id_lang']); - if (empty($seoUrl) && empty($metaTitle)) { - continue; + $langId = (int) $language['id_lang']; + $seoUrl = Tools::getValue('url_name_' . $langId); + if (!empty($seoUrl)) { + $formData['url_name'][$langId] = $seoUrl; + } + $metaTitle = Tools::getValue('meta_title_' . $langId); + if (!empty($metaTitle)) { + $formData['meta_title'][$langId] = $metaTitle; } - - $this->database->execute( - 'INSERT INTO ' . _DB_PREFIX_ . 'layered_indexable_attribute_group_lang_value - (`id_attribute_group`, `id_lang`, `url_name`, `meta_title`) - VALUES ( - ' . (int) $params['id_attribute_group'] . ', ' . (int) $language['id_lang'] . ', - \'' . pSQL(Tools::str2url($seoUrl)) . '\', - \'' . pSQL($metaTitle, true) . '\')' - ); } - $this->module->invalidateLayeredFilterBlockCache(); + $this->save($formData); } /** @@ -142,4 +187,53 @@ public function displayAttributeGroupForm(array $params) return $this->module->render('attribute_group_form.tpl'); } + + /** + * This is the common save method, the calling methods just need to format the form data appropriately + * depending on the page being migrated or not. + * + * @param array $formData + */ + private function save(array $formData): void + { + if (empty($formData['id_attribute_group'])) { + return; + } + + $attributeGroupId = $formData['id_attribute_group']; + + // First clean all existing data + $this->database->execute( + 'DELETE FROM ' . _DB_PREFIX_ . 'layered_indexable_attribute_group + WHERE `id_attribute_group` = ' . $attributeGroupId + ); + $this->database->execute( + 'DELETE FROM ' . _DB_PREFIX_ . 'layered_indexable_attribute_group_lang_value + WHERE `id_attribute_group` = ' . $attributeGroupId + ); + + $this->database->execute( + 'INSERT INTO ' . _DB_PREFIX_ . 'layered_indexable_attribute_group (`id_attribute_group`, `indexable`) +VALUES (' . $attributeGroupId . ', ' . (int) $formData['is_indexable'] . ')' + ); + + $landIds = array_unique(array_merge(array_keys($formData['meta_title'] ?? []), array_keys($formData['url_name'] ?? []))); + foreach ($landIds as $langId) { + $seoUrl = $formData['url_name'][$langId] ?? null; + $metaTitle = $formData['meta_title'][$langId] ?? null; + if (empty($seoUrl) && empty($metaTitle)) { + continue; + } + + $this->database->execute( + 'INSERT INTO ' . _DB_PREFIX_ . 'layered_indexable_attribute_group_lang_value + (`id_attribute_group`, `id_lang`, `url_name`, `meta_title`) + VALUES ( + ' . $attributeGroupId . ', ' . $langId . ', + \'' . pSQL(Tools::str2url($seoUrl)) . '\', + \'' . pSQL($metaTitle, true) . '\')' + ); + } + $this->module->invalidateLayeredFilterBlockCache(); + } } From 7f19960f6f03859d871d8f522c8c0aa3c703f514 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Tue, 6 Feb 2024 18:16:42 +0100 Subject: [PATCH 3/6] Handle Attribute hooks to integrate the module into the migrate Attribute form --- src/Form/Attribute/FormDataProvider.php | 82 +++++++++++++++ src/Form/Attribute/FormModifier.php | 95 ++++++++++++++++++ src/Hook/Attribute.php | 128 ++++++++++++++++++++---- 3 files changed, 286 insertions(+), 19 deletions(-) create mode 100644 src/Form/Attribute/FormDataProvider.php create mode 100644 src/Form/Attribute/FormModifier.php diff --git a/src/Form/Attribute/FormDataProvider.php b/src/Form/Attribute/FormDataProvider.php new file mode 100644 index 000000000..61f71ca28 --- /dev/null +++ b/src/Form/Attribute/FormDataProvider.php @@ -0,0 +1,82 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\FacetedSearch\Form\Attribute; + +use Db; +use PrestaShopDatabaseException; + +class FormDataProvider +{ + /** + * @var Db + */ + private $database; + + public function __construct(Db $database) + { + $this->database = $database; + } + + /** + * Fills form data + * + * @param array $params + * + * @return array + * + * @throws PrestaShopDatabaseException + */ + public function getData(array $params) + { + $defaultUrl = []; + $defaultMetaTitle = []; + + // if params contains id, gets data for edit form + if (!empty($params['id'])) { + $attributeId = (int) $params['id']; + $result = $this->database->executeS( + 'SELECT `url_name`, `meta_title`, `id_lang` ' . + 'FROM ' . _DB_PREFIX_ . 'layered_indexable_attribute_lang_value ' . + 'WHERE `id_attribute` = ' . $attributeId + ); + + if (!empty($result) && is_array($result)) { + foreach ($result as $data) { + $defaultUrl[$data['id_lang']] = $data['url_name']; + $defaultMetaTitle[$data['id_lang']] = $data['meta_title']; + } + } + } + + return [ + 'url_name' => $defaultUrl, + 'meta_title' => $defaultMetaTitle, + ]; + } +} diff --git a/src/Form/Attribute/FormModifier.php b/src/Form/Attribute/FormModifier.php new file mode 100644 index 000000000..dec8431fc --- /dev/null +++ b/src/Form/Attribute/FormModifier.php @@ -0,0 +1,95 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\FacetedSearch\Form\Attribute; + +use PrestaShop\Module\FacetedSearch\Constraint\UrlSegment; +use PrestaShopBundle\Form\Admin\Type\TranslatableType; +use PrestaShopBundle\Translation\TranslatorComponent; +use Symfony\Component\Form\FormBuilderInterface; + +class FormModifier +{ + /** + * @var TranslatorComponent + */ + private $translator; + + public function __construct(TranslatorComponent $translator) + { + $this->translator = $translator; + } + + public function modify(FormBuilderInterface $formBuilder) + { + $invalidCharsHint = $this->translator->trans( + 'Invalid characters: <>;=#{}_', + [], + 'Modules.Facetedsearch.Admin' + ); + + $urlTip = $this->translator->trans( + 'When the Faceted Search module is enabled, you can get more detailed URLs by choosing the word that best represent this attribute. By default, PrestaShop uses the attribute\'s name, but you can change that setting using this field.', + [], + 'Modules.Facetedsearch.Admin' + ); + $metaTitleTip = $this->translator->trans( + 'When the Faceted Search module is enabled, you can get more detailed page titles by choosing the word that best represent this attribute. By default, PrestaShop uses the attribute\'s name, but you can change that setting using this field.', + [], + 'Modules.Facetedsearch.Admin' + ); + + $formBuilder + ->add( + 'url_name', + TranslatableType::class, + [ + 'required' => false, + 'label' => $this->translator->trans('URL', [], 'Modules.Facetedsearch.Admin'), + 'help' => $urlTip . ' ' . $invalidCharsHint, + 'options' => [ + 'constraints' => [ + new UrlSegment([ + 'message' => $this->translator->trans('%s is invalid.', [], 'Admin.Notifications.Error'), + ]), + ], + ], + ] + ) + ->add( + 'meta_title', + TranslatableType::class, + [ + 'required' => false, + 'label' => $this->translator->trans('Meta title', [], 'Modules.Facetedsearch.Admin'), + 'help' => $metaTitleTip, + ] + ) + ; + } +} diff --git a/src/Hook/Attribute.php b/src/Hook/Attribute.php index 32efac430..0a8864dfb 100644 --- a/src/Hook/Attribute.php +++ b/src/Hook/Attribute.php @@ -21,6 +21,8 @@ namespace PrestaShop\Module\FacetedSearch\Hook; use Language; +use PrestaShop\Module\FacetedSearch\Form\Attribute\FormDataProvider; +use PrestaShop\Module\FacetedSearch\Form\Attribute\FormModifier; use Tools; class Attribute extends AbstractHook @@ -30,8 +32,65 @@ class Attribute extends AbstractHook 'actionAttributeSave', 'displayAttributeForm', 'actionAttributePostProcess', + // Hooks for migrated page + 'actionAttributeFormBuilderModifier', + 'actionAttributeFormDataProviderData', + 'actionAfterCreateAttributeFormHandler', + 'actionAfterUpdateAttributeFormHandler', ]; + /** + * Hook for modifying attribute form formBuilder + * + * @since PrestaShop 9.0.0 + * + * @param array $params + */ + public function actionAttributeFormBuilderModifier(array $params) + { + $formModifier = new FormModifier($this->context->getTranslator()); + $formModifier->modify($params['form_builder']); + } + + /** + * Hook that provides extra data in the form. + * + * @since PrestaShop 9.0.0 + * + * @param array $params + */ + public function actionAttributeFormDataProviderData(array $params) + { + $formDataProvider = new FormDataProvider($this->database); + $attributeData = $formDataProvider->getData($params); + // Update data field in params which is passed by reference + $params['data'] = array_merge($params['data'], $attributeData); + } + + /** + * Hook after creation form is handled in migrated page. + * + * @since PrestaShop 9.0.0 + * + * @param array $params + */ + public function actionAfterCreateAttributeFormHandler(array $params): void + { + $this->save(array_merge(['id_attribute' => $params['id']], $params['form_data'])); + } + + /** + * Hook after edition form is handled in migrated page. + * + * @since PrestaShop 9.0.0 + * + * @param array $params + */ + public function actionAfterUpdateAttributeFormHandler(array $params): void + { + $this->save(array_merge(['id_attribute' => $params['id']], $params['form_data'])); + } + /** * After save attribute * @@ -43,28 +102,21 @@ public function actionAttributeSave(array $params) return; } - $this->database->execute( - 'DELETE FROM ' . _DB_PREFIX_ . 'layered_indexable_attribute_lang_value - WHERE `id_attribute` = ' . (int) $params['id_attribute'] - ); - + $formData = [ + 'id_attribute' => (int) $params['id_attribute'], + ]; foreach (Language::getLanguages(false) as $language) { - $seoUrl = Tools::getValue('url_name_' . (int) $language['id_lang']); - $metaTitle = Tools::getValue('meta_title_' . (int) $language['id_lang']); - if (empty($seoUrl) && empty($metaTitle)) { - continue; + $langId = (int) $language['id_lang']; + $seoUrl = Tools::getValue('url_name_' . $langId); + if (!empty($seoUrl)) { + $formData['url_name'][$langId] = $seoUrl; + } + $metaTitle = Tools::getValue('meta_title_' . $langId); + if (!empty($metaTitle)) { + $formData['meta_title'][$langId] = $metaTitle; } - - $this->database->execute( - 'INSERT INTO ' . _DB_PREFIX_ . 'layered_indexable_attribute_lang_value - (`id_attribute`, `id_lang`, `url_name`, `meta_title`) - VALUES ( - ' . (int) $params['id_attribute'] . ', ' . (int) $language['id_lang'] . ', - \'' . pSQL(Tools::str2url($seoUrl)) . '\', - \'' . pSQL($metaTitle, true) . '\')' - ); } - $this->module->invalidateLayeredFilterBlockCache(); + $this->save($formData); } /** @@ -122,4 +174,42 @@ public function displayAttributeForm(array $params) return $this->module->render('attribute_form.tpl'); } + + /** + * This is the common save method, the calling methods just need to format the form data appropriately + * depending on the page being migrated or not. + * + * @param array $formData + */ + private function save(array $formData): void + { + if (empty($formData['id_attribute'])) { + return; + } + + $attributeId = (int) $formData['id_attribute']; + $this->database->execute( + 'DELETE FROM ' . _DB_PREFIX_ . 'layered_indexable_attribute_lang_value + WHERE `id_attribute` = ' . $attributeId + ); + + $landIds = array_unique(array_merge(array_keys($formData['meta_title'] ?? []), array_keys($formData['url_name'] ?? []))); + foreach ($landIds as $langId) { + $seoUrl = $formData['url_name'][$langId] ?? null; + $metaTitle = $formData['meta_title'][$langId] ?? null; + if (empty($seoUrl) && empty($metaTitle)) { + continue; + } + + $this->database->execute( + 'INSERT INTO ' . _DB_PREFIX_ . 'layered_indexable_attribute_lang_value + (`id_attribute`, `id_lang`, `url_name`, `meta_title`) + VALUES ( + ' . $attributeId . ', ' . $langId . ', + \'' . pSQL(Tools::str2url($seoUrl)) . '\', + \'' . pSQL($metaTitle, true) . '\')' + ); + } + $this->module->invalidateLayeredFilterBlockCache(); + } } From bdfdf069219bff732db6c8c2e9de41e17ae8b151 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Tue, 6 Feb 2024 18:27:48 +0100 Subject: [PATCH 4/6] Update hook dispatcher tests --- tests/php/FacetedSearch/HookDispatcherTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/php/FacetedSearch/HookDispatcherTest.php b/tests/php/FacetedSearch/HookDispatcherTest.php index ccf5e3c32..e55b928e8 100644 --- a/tests/php/FacetedSearch/HookDispatcherTest.php +++ b/tests/php/FacetedSearch/HookDispatcherTest.php @@ -47,17 +47,25 @@ protected function setUp() public function testGetAvailableHooks() { - $this->assertCount(31, $this->dispatcher->getAvailableHooks()); + $this->assertCount(39, $this->dispatcher->getAvailableHooks()); $this->assertEquals( [ 'actionAttributeGroupDelete', 'actionAttributeSave', 'displayAttributeForm', 'actionAttributePostProcess', + 'actionAttributeFormBuilderModifier', + 'actionAttributeFormDataProviderData', + 'actionAfterCreateAttributeFormHandler', + 'actionAfterUpdateAttributeFormHandler', 'actionAttributeGroupDelete', 'actionAttributeGroupSave', 'displayAttributeGroupForm', 'displayAttributeGroupPostProcess', + 'actionAttributeGroupFormBuilderModifier', + 'actionAttributeGroupFormDataProviderData', + 'actionAfterCreateAttributeGroupFormHandler', + 'actionAfterUpdateAttributeGroupFormHandler', 'actionCategoryAdd', 'actionCategoryDelete', 'actionCategoryUpdate', From 5d9a46bf291d5cbc84e0c2920a294a3ec0641659 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Tue, 6 Feb 2024 18:29:14 +0100 Subject: [PATCH 5/6] Bump version 3.15.0 --- config.xml | 2 +- ps_facetedsearch.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config.xml b/config.xml index 07a332015..b32333baa 100644 --- a/config.xml +++ b/config.xml @@ -2,7 +2,7 @@ ps_facetedsearch - + diff --git a/ps_facetedsearch.php b/ps_facetedsearch.php index c3e618e43..f3e1d12e5 100644 --- a/ps_facetedsearch.php +++ b/ps_facetedsearch.php @@ -96,7 +96,7 @@ public function __construct() { $this->name = 'ps_facetedsearch'; $this->tab = 'front_office_features'; - $this->version = '3.14.1'; + $this->version = '3.15.0'; $this->author = 'PrestaShop'; $this->need_instance = 0; $this->bootstrap = true; From cb724260875ce91fa03c4899c8dddfe8231a22c5 Mon Sep 17 00:00:00 2001 From: Jonathan Lelievre Date: Wed, 7 Feb 2024 11:04:58 +0100 Subject: [PATCH 6/6] Add upgrade script to register to new hooks for attribute migrated page --- upgrade/upgrade-3.15.0.php | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 upgrade/upgrade-3.15.0.php diff --git a/upgrade/upgrade-3.15.0.php b/upgrade/upgrade-3.15.0.php new file mode 100644 index 000000000..d62e25c1e --- /dev/null +++ b/upgrade/upgrade-3.15.0.php @@ -0,0 +1,39 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +function upgrade_module_3_15_0(Ps_Facetedsearch $module) +{ + // New hooks for migrated attribute page + $newHooks = [ + 'actionAttributeFormBuilderModifier', + 'actionAttributeFormDataProviderData', + 'actionAfterCreateAttributeFormHandler', + 'actionAfterUpdateAttributeFormHandler', + 'actionAttributeGroupFormBuilderModifier', + 'actionAttributeGroupFormDataProviderData', + 'actionAfterCreateAttributeGroupFormHandler', + 'actionAfterUpdateAttributeGroupFormHandler', + ]; + + return $module->registerHook($newHooks); +}