Skip to content

Commit 14a2644

Browse files
⚗️ Try to fix self updates issues
1 parent c2fc4b0 commit 14a2644

File tree

4 files changed

+111
-49
lines changed

4 files changed

+111
-49
lines changed

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<module>
33
<name>ps_mbo</name>
44
<displayName><![CDATA[PrestaShop Marketplace in your Back Office]]></displayName>
5-
<version><![CDATA[4.14.1]]></version>
5+
<version><![CDATA[4.14.2]]></version>
66
<description><![CDATA[Discover the best PrestaShop modules to optimize your online store.]]></description>
77
<author><![CDATA[PrestaShop]]></author>
88
<tab><![CDATA[administration]]></tab>

config/services/addons.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

ps_mbo.php

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

upgrade/upgrade-4.14.2.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright since 2007 PrestaShop SA and Contributors
4+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5+
*
6+
* NOTICE OF LICENSE
7+
*
8+
* This source file is subject to the Academic Free License version 3.0
9+
* that is bundled with this package in the file LICENSE.md.
10+
* It is also available through the world-wide-web at this URL:
11+
* https://opensource.org/licenses/AFL-3.0
12+
* If you did not receive a copy of the license and are unable to
13+
* obtain it through the world-wide-web, please send an email
14+
* to license@prestashop.com so we can send you a copy immediately.
15+
*
16+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
17+
* @copyright Since 2007 PrestaShop SA and Contributors
18+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
19+
*/
20+
if (!defined('_PS_VERSION_')) {
21+
exit;
22+
}
23+
$rootDir = defined('_PS_ROOT_DIR_') ? _PS_ROOT_DIR_ : getenv('_PS_ROOT_DIR_');
24+
if (!$rootDir) {
25+
$rootDir = __DIR__ . '/../../../';
26+
}
27+
28+
require_once $rootDir . '/vendor/autoload.php';
29+
30+
if (!function_exists('safeUnlink')) {
31+
32+
function safeUnlink(string $filePath): void
33+
{
34+
if (file_exists($filePath) && is_file($filePath)) {
35+
@unlink($filePath);
36+
}
37+
}
38+
}
39+
40+
/**
41+
* @return bool
42+
*/
43+
function upgrade_module_4_14_2()
44+
{
45+
$moduleDir = _PS_MODULE_DIR_ . 'ps_mbo';
46+
47+
try {
48+
safeUnlink($moduleDir . '/config/services/addons.php');
49+
50+
return true;
51+
} catch (Exception $e) {
52+
return true;
53+
}
54+
}

0 commit comments

Comments
 (0)