Skip to content

Commit

Permalink
[MBO-1170] Check if container is set before calling method (#603)
Browse files Browse the repository at this point in the history
* Check if container is set before calling method

* Use simple SQL query to get MBO Api user
  • Loading branch information
sowbiba authored Jul 24, 2023
1 parent 760c668 commit 02165a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ps_mbo.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public function getAdminAuthenticationProvider(): AdminAuthenticationProvider
$this->container = SymfonyContainer::getInstance();
}

return $this->container->has('mbo.security.admin_authentication.provider') ?
return null !== $this->container && $this->container->has('mbo.security.admin_authentication.provider') ?
$this->get('mbo.security.admin_authentication.provider') :
new AdminAuthenticationProvider(
$this->get('doctrine.dbal.default_connection'),
Expand Down
17 changes: 16 additions & 1 deletion src/Traits/Hooks/UseActionObjectEmployeeUpdateBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

namespace PrestaShop\Module\Mbo\Traits\Hooks;

use PrestaShop\Module\Mbo\Helpers\Config;

trait UseActionObjectEmployeeUpdateBefore
{
/**
Expand All @@ -31,7 +33,7 @@ public function hookActionObjectEmployeeUpdateBefore($params): void
if (empty($params) || empty($params['object']) || !$params['object'] instanceof \Employee) {
return;
}
$currentApiUser = $this->getAdminAuthenticationProvider()->getApiUser();
$currentApiUser = $this->getApiUser();
if (!$currentApiUser) {
return;
}
Expand All @@ -44,4 +46,17 @@ public function hookActionObjectEmployeeUpdateBefore($params): void
$params['object']->active = true;
}
}

private function getApiUser()
{
$apiUserId = \Db::getInstance()->getValue(
'SELECT `id_employee` FROM `' . _DB_PREFIX_ . 'employee` WHERE `email` = "' . pSQL(Config::getShopMboAdminMail()) . '" AND active = 1'
);

if (!$apiUserId) {
return null;
}

return new \Employee((int) $apiUserId);
}
}

0 comments on commit 02165a0

Please sign in to comment.