Skip to content

Commit

Permalink
feat: install on dashboard & module catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
jinpresta committed Aug 30, 2024
1 parent 77ccdf2 commit 74b55d4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/services/eventbus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
arguments:
- "ps_eventbus"
- "3.0.8"
- false
- true
6 changes: 0 additions & 6 deletions ps_mbo.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,6 @@ public function install(): bool
ErrorHelper::reportError($e);
}

try {
$this->getService('mbo.ps_eventbus.installer')->install();
} catch (Exception $e) {
ErrorHelper::reportError($e);
}

$this->installTables();
if (parent::install() && $this->registerHook($this->getHooksNames())) {
// Do come extra operations on modules' registration like modifying orders
Expand Down
14 changes: 8 additions & 6 deletions src/Controller/Admin/ModuleCatalogController.php
100644 → 100755
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();
$this->ensurePsAccountIsEnabled();
if ($this->ensurePsAccountIsEnabled()) $this->get('mbo.ps_eventbus.installer')->install();
} 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 @@ -132,13 +132,15 @@ public function cdcErrorAction(): Response
);
}

private function ensurePsAccountIsEnabled(): void
private function ensurePsAccountIsEnabled(): bool
{
$accountsInstaller = $this->get('mbo.ps_accounts.installer');
if (!$accountsInstaller) return false;

if (null !== $accountsInstaller && !$accountsInstaller->isModuleEnabled()) {
$moduleManager = $this->get('prestashop.module.manager');
$moduleManager->enable($accountsInstaller->getModuleName());
}
$accountsEnabled = $accountsInstaller->isModuleEnabled();
if ($accountsEnabled) return true;

$moduleManager = $this->get('prestashop.module.manager');
return $moduleManager->enable($accountsInstaller->getModuleName());
}
}
4 changes: 4 additions & 0 deletions src/Service/ModuleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public function isShopVersion17()
* @return boolean
*/
public function isModuleInstalled() {
if (false === $this->isShopVersion17()) {
return \Module::isInstalled($this->moduleName);
}

return $this->moduleManager->isInstalled($this->moduleName);
}

Expand Down
18 changes: 18 additions & 0 deletions src/Traits/Hooks/UseDashboardZoneOne.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +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();
} catch (\PrestaShop\PsAccountsInstaller\Installer\Exception\InstallerException $e) {
ErrorHelper::reportError($e);
}
Expand All @@ -113,4 +114,21 @@ protected function loadPsAccounts(): string

return $urlAccountsCdn;
}

/**
* Return true if ps_account is enabled
*
* @return bool
*/
private function ensurePsAccountIsEnabled(): bool {
$accountsInstaller = $this->get('mbo.ps_accounts.installer');
if (!$accountsInstaller) return false;

$accountsEnabled = $accountsInstaller->isModuleEnabled();
if ($accountsEnabled) return true;

$moduleManager = $this->get('prestashop.module.manager');
return $moduleManager->enable($accountsInstaller->getModuleName());
}

}

0 comments on commit 74b55d4

Please sign in to comment.