@@ -51,7 +51,7 @@ class ps_mbo extends Module
5151 /**
5252 * @var string
5353 */
54- public const VERSION = '4.14.1 ' ;
54+ public const VERSION = '4.14.2 ' ;
5555
5656 public const CONTROLLERS_WITH_CONNECTION_TOOLBAR = [
5757 'AdminModulesManage ' ,
@@ -90,13 +90,18 @@ class ps_mbo extends Module
9090 */
9191 public $ moduleCacheDir ;
9292
93+ /**
94+ * @var bool
95+ */
96+ private static $ subscriberRegistered = false ;
97+
9398 /**
9499 * Constructor.
95100 */
96101 public function __construct ()
97102 {
98103 $ this ->name = 'ps_mbo ' ;
99- $ this ->version = '4.14.1 ' ;
104+ $ this ->version = '4.14.2 ' ;
100105 $ this ->author = 'PrestaShop ' ;
101106 $ this ->tab = 'administration ' ;
102107 $ this ->module_key = '6cad5414354fbef755c7df4ef1ab74eb ' ;
@@ -123,6 +128,11 @@ public function __construct()
123128 }
124129
125130 $ this ->loadEnv ();
131+
132+ if (!self ::$ subscriberRegistered && $ this ->isAdminContext () && $ this ->shouldRegisterSubscriber ()) {
133+ $ this ->registerModuleManagementSubscriber ();
134+ self ::$ subscriberRegistered = true ;
135+ }
126136 }
127137
128138 /**
@@ -470,4 +480,48 @@ private function isPsAccountEnabled(): bool
470480
471481 return $ accountsInstaller ->isModuleEnabled ();
472482 }
483+
484+ private function isAdminContext (): bool
485+ {
486+ return defined ('_PS_ADMIN_DIR_ ' );
487+ }
488+
489+ private function shouldRegisterSubscriber (): bool
490+ {
491+ $ values = \ToolsCore::getAllValues ();
492+ // Value is present when updating a module
493+ if (empty ($ values ['source ' ])) {
494+ return false ;
495+ }
496+
497+ // If updating MBO, we don't want to register the subscriber
498+ if (strpos ($ values ['source ' ], '&id_module=39574& ' ) !== false ) {
499+ return false ;
500+ }
501+
502+ return self ::checkModuleStatus ();
503+ }
504+
505+ private function registerModuleManagementSubscriber (): void
506+ {
507+ try {
508+ /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
509+ $ dispatcher = $ this ->get ('event_dispatcher ' );
510+
511+ $ subscriber = new \PrestaShop \Module \Mbo \Addons \Subscriber \ModuleManagementEventSubscriber (
512+ $ this ->get ('logger ' ),
513+ $ this ->get ('mbo.modules.repository ' ),
514+ $ this ->get ('mbo.tab.collection.provider ' ),
515+ $ this ->get ('mbo.cdc.context_builder ' ),
516+ $ this ->get ('mbo.cdc.client.distribution_api ' ),
517+ $ this ->get ('mbo.security.admin_authentication.provider ' ),
518+ $ this ->get ('mbo.distribution.api_version_change_config_apply_handler ' ),
519+ $ this ->get ('mbo.symfony_cache_clearer ' )
520+ );
521+
522+ $ dispatcher ->addSubscriber ($ subscriber );
523+ } catch (\Throwable $ e ) {
524+ //Do nothing here
525+ }
526+ }
473527}
0 commit comments