Skip to content

Commit

Permalink
feat: enable ps_eventbus if not
Browse files Browse the repository at this point in the history
  • Loading branch information
jinpresta committed Sep 5, 2024
1 parent 364c572 commit faa43b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Controller/Admin/ModuleCatalogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function indexAction(): Response
try {
$accountsFacade = $this->get('mbo.ps_accounts.facade');
$accountsService = $accountsFacade->getPsAccountsService();
if ($this->ensurePsAccountIsEnabled()) $this->get('mbo.ps_eventbus.installer')->install();
if ($this->ensurePsAccountIsEnabled()) $this->ensurePsEventbusEnabled();
} catch (\PrestaShop\PsAccountsInstaller\Installer\Exception\InstallerException $e) {
$accountsInstaller = $this->get('mbo.ps_accounts.installer');
// Seems the module is not here, try to install it
Expand Down Expand Up @@ -143,4 +143,12 @@ private function ensurePsAccountIsEnabled(): bool
$moduleManager = $this->get('prestashop.module.manager');
return $moduleManager->enable($accountsInstaller->getModuleName());
}

private function ensurePsEventbusEnabled()
{
$installer = $this->get('mbo.ps_eventbus.installer');
if ($installer->install()) {
$installer->enable();
}
}
}
12 changes: 12 additions & 0 deletions src/Service/ModuleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ public function install() {
return $this->moduleManager->install($this->moduleName);
}

/**
* @return bool
*/
public function enable()
{
if (!$this->moduleManager->isEnabled($this->moduleName)) {
return $this->moduleManager->enable($this->moduleName);
}

return true;
}

/**
* @return bool
*/
Expand Down
9 changes: 8 additions & 1 deletion src/Traits/Hooks/UseDashboardZoneOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function loadPsAccounts(): string
try {
$accountsFacade = $this->get('mbo.ps_accounts.facade');
$accountsService = $accountsFacade->getPsAccountsService();
if ($this->ensurePsAccountIsEnabled()) $this->get('mbo.ps_eventbus.installer')->install();
if ($this->ensurePsAccountIsEnabled()) $this->ensurePsEventbusEnabled();
} catch (\PrestaShop\PsAccountsInstaller\Installer\Exception\InstallerException $e) {
$accountsInstaller = $this->get('mbo.ps_accounts.installer');
// Seems the module is not here, try to install it
Expand Down Expand Up @@ -141,4 +141,11 @@ private function ensurePsAccountIsEnabled(): bool {
return $moduleManager->enable($accountsInstaller->getModuleName());
}

private function ensurePsEventbusEnabled()
{
$installer = $this->get('mbo.ps_eventbus.installer');
if ($installer->install()) {
$installer->enable();
}
}
}

0 comments on commit faa43b4

Please sign in to comment.