From 9a85fd314e801b986a0f22224db44d690913b118 Mon Sep 17 00:00:00 2001 From: Jonathan Renard <1273438+fox-john@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:51:53 +0100 Subject: [PATCH] fix: missing hooks (employees and translations) (#270) --- ps_eventbus.php | 82 +++++++++++++++++++++++++++++++++++++++ upgrade/Upgrade-3.0.5.php | 13 +++++++ 2 files changed, 95 insertions(+) create mode 100644 upgrade/Upgrade-3.0.5.php diff --git a/ps_eventbus.php b/ps_eventbus.php index 02687477..20a0b566 100644 --- a/ps_eventbus.php +++ b/ps_eventbus.php @@ -25,6 +25,7 @@ */ use PrestaShop\Module\PsEventbus\Config\Config; +use PrestaShopBundle\EventListener\ActionDispatcherLegacyHooksSubscriber; if (!defined('_PS_VERSION_')) { exit; @@ -124,6 +125,12 @@ class Ps_eventbus extends Module 'actionObjectZoneDeleteAfter', 'actionObjectZoneUpdateAfter', 'actionShippingPreferencesPageSave', + + 'actionObjectEmployeeAddAfter', + 'actionObjectEmployeeDeleteAfter', + 'actionObjectEmployeeUpdateAfter', + + 'actionDispatcherBefore', ]; /** @@ -1348,6 +1355,81 @@ public function hookActionShippingPreferencesPageSave() ); } + /** + * @return void + */ + public function hookActionObjectEmployeeAddAfter() + { + $this->insertIncrementalSyncObject( + 0, + Config::COLLECTION_EMPLOYEES, + date(DATE_ATOM), + $this->shopId + ); + } + + /** + * @return void + */ + public function hookActionObjectEmployeeDeleteAfter() + { + $this->insertIncrementalSyncObject( + 0, + Config::COLLECTION_EMPLOYEES, + date(DATE_ATOM), + $this->shopId + ); + } + + /** + * @return void + */ + public function hookActionObjectEmployeeUpdateAfter() + { + $this->insertIncrementalSyncObject( + 0, + Config::COLLECTION_EMPLOYEES, + date(DATE_ATOM), + $this->shopId + ); + } + + /** + * This is global hook. This hook is called at the beginning of the dispatch method of the Dispatcher + * It's possible to use this hook all time when we don't have specific hook. + * Available since: 1.7.1 + * + * Unable to use hookActionDispatcherAfter. Seem to be have a strange effect. When i use + * this hook and try to dump() the content, no dump appears in the symfony debugger, and no more hooks appear. + * For security reasons, I like to use the before hook, and put it in a try/catch + * + * @param array $parameters + * + * @return void + */ + public function hookActionDispatcherBefore($parameters) + { + try { + if ($parameters['controller_type'] != ActionDispatcherLegacyHooksSubscriber::BACK_OFFICE_CONTROLLER) { + return; + } + + $route = $parameters['route']; + + // when translation is edited or reset, add to incremental sync + if ($route == 'api_translation_value_edit' || $route == 'api_translation_value_reset') { + $this->insertIncrementalSyncObject( + 0, + Config::COLLECTION_TRANSLATIONS, + date(DATE_ATOM), + $this->shopId + ); + } + } catch (\Exception $e) { + return; + } + } + /** * @param array $parameters * diff --git a/upgrade/Upgrade-3.0.5.php b/upgrade/Upgrade-3.0.5.php new file mode 100644 index 00000000..8f7b8488 --- /dev/null +++ b/upgrade/Upgrade-3.0.5.php @@ -0,0 +1,13 @@ +registerhook('actionObjectEmployeeAddAfter'); + $module->registerhook('actionObjectEmployeeDeleteAfter'); + $module->registerhook('actionObjectEmployeeUpdateAfter'); + + return true; +}