Skip to content

Commit 37f866e

Browse files
fix: restore install/upgrade on PS 9.0.x
Two bugs broke ps_mbo install/upgrade on PrestaShop 9.0.x: - ResolvesServices was used inside the UseHooks trait, so getTraitNames() (class_uses(UseHooks::class)) turned it into a bogus "ResolvesServices" hook and registration failed. Move the trait onto the ps_mbo class so getRequiredService() stays available without being scanned as a hook. - The 'upload' action on route admin_module_manage_action only exists since PS 9.1.0; generating its URL threw InvalidParameterException on 9.0.x. Add the 'upload' action URL only when _PS_VERSION_ >= 9.1.0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent abc39b4 commit 37f866e

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

ps_mbo.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class ps_mbo extends Module
4141
use PrestaShop\Module\Mbo\Traits\HaveTabs;
4242
use PrestaShop\Module\Mbo\Traits\UseHooks;
4343
use PrestaShop\Module\Mbo\Traits\HaveConfigurationPage;
44+
use PrestaShop\Module\Mbo\Traits\ResolvesServices;
4445

4546
public const MODULE_NAME = 'ps_mbo';
4647

src/Service/View/ContextBuilder.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,33 @@ private function getCommonContextContent(): array
184184
'shop_business_sector' => $shopActivity['name'],
185185
'overrides_on_shop' => $overrideChecker->listOverridesFromPsDirectory(),
186186
'actions_token' => UrlHelper::getQueryParameterValue($mboResetUrl, '_token'),
187-
'actions_url' => [
188-
'install' => $this->generateActionUrl('install'),
189-
'uninstall' => $this->generateActionUrl('uninstall'),
190-
'delete' => $this->generateActionUrl('delete'),
191-
'enable' => $this->generateActionUrl('enable'),
192-
'disable' => $this->generateActionUrl('disable'),
193-
'reset' => $this->generateActionUrl('reset'),
194-
'upgrade' => $this->generateActionUrl('upgrade'),
195-
'upload' => $this->generateActionUrl('upload'),
196-
],
187+
'actions_url' => $this->getActionsUrl(),
197188
];
198189
}
199190

191+
/**
192+
* @return array<string, string>
193+
*/
194+
private function getActionsUrl(): array
195+
{
196+
$actionsUrl = [
197+
'install' => $this->generateActionUrl('install'),
198+
'uninstall' => $this->generateActionUrl('uninstall'),
199+
'delete' => $this->generateActionUrl('delete'),
200+
'enable' => $this->generateActionUrl('enable'),
201+
'disable' => $this->generateActionUrl('disable'),
202+
'reset' => $this->generateActionUrl('reset'),
203+
'upgrade' => $this->generateActionUrl('upgrade'),
204+
];
205+
206+
// The 'upload' action on route admin_module_manage_action exists only since PS 9.1.0
207+
if (version_compare(_PS_VERSION_, '9.1.0', '>=')) {
208+
$actionsUrl['upload'] = $this->generateActionUrl('upload');
209+
}
210+
211+
return $actionsUrl;
212+
}
213+
200214
private function generateActionUrl(string $action): string
201215
{
202216
$params = [

src/Traits/UseHooks.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
trait UseHooks
3232
{
33-
use ResolvesServices;
3433
use Hooks\UseDashboardZoneOne;
3534
use Hooks\UseDashboardZoneThree {
3635
Hooks\UseDashboardZoneOne::smartyDisplayTpl insteadof \PrestaShop\Module\Mbo\Traits\Hooks\UseDashboardZoneThree;

0 commit comments

Comments
 (0)