-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9105d45
commit e711dfd
Showing
41 changed files
with
201 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
|
||
use Db; | ||
use Exception; | ||
use PrestaShop\Module\PsAccounts\Repository\UserTokenRepository; | ||
use Module; | ||
use PrestaShop\PrestaShop\Adapter\ServiceLocator; | ||
use PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleNotInstalledException; | ||
use PrestaShop\PsAccountsInstaller\Installer\Exception\ModuleVersionException; | ||
|
@@ -49,16 +49,22 @@ public function getAccountsToken(): string | |
return ''; | ||
} | ||
|
||
if (!class_exists(\PrestaShop\Module\PsAccounts\Repository\UserTokenRepository::class)) { | ||
return ''; | ||
} | ||
|
||
/** @var Module|null $psAccountsModule */ | ||
$psAccountsModule = ServiceLocator::get('ps_accounts'); | ||
if (null === $psAccountsModule || !method_exists($psAccountsModule, 'getService')) { | ||
return ''; | ||
} | ||
|
||
if (null === $psAccountsModule) { | ||
/** @var \PrestaShop\Module\PsAccounts\Repository\UserTokenRepository|null $accountsUserTokenRepository */ | ||
$accountsUserTokenRepository = $psAccountsModule->getService(\PrestaShop\Module\PsAccounts\Repository\UserTokenRepository::class); | ||
Check failure on line 63 in src/Accounts/Provider/AccountsDataProvider.php GitHub Actions / PHPStan (9.0.x)
Check failure on line 63 in src/Accounts/Provider/AccountsDataProvider.php GitHub Actions / PHPStan (9.0.x)
|
||
if (!$accountsUserTokenRepository) { | ||
return ''; | ||
} | ||
|
||
/** | ||
* @var UserTokenRepository $accountsUserTokenRepository | ||
*/ | ||
$accountsUserTokenRepository = $psAccountsModule->getService(UserTokenRepository::class); | ||
try { | ||
$token = $accountsUserTokenRepository->getOrRefreshToken(); | ||
} catch (Exception $e) { | ||
|
@@ -115,8 +121,6 @@ private function isAccountLinked(): bool | |
} | ||
|
||
/** | ||
* @param string $serviceName | ||
* | ||
* @return mixed | ||
* | ||
* @throws ModuleNotInstalledException | ||
|
@@ -126,8 +130,10 @@ public function getAccountsService() | |
{ | ||
if ($this->isPsAccountsInstalled()) { | ||
if ($this->checkPsAccountsVersion()) { | ||
return \Module::getInstanceByName(Installer::PS_ACCOUNTS_MODULE_NAME) | ||
->getService(PsAccounts::PS_ACCOUNTS_SERVICE); | ||
$module = \Module::getInstanceByName(Installer::PS_ACCOUNTS_MODULE_NAME); | ||
if ($module && method_exists($module, 'getService')) { | ||
return $module->getService(PsAccounts::PS_ACCOUNTS_SERVICE); | ||
} | ||
} | ||
throw new ModuleVersionException('Module version expected : ' . $this->psAccountsVersion); | ||
} | ||
|
@@ -152,6 +158,10 @@ private function isPsAccountsInstalled() | |
|
||
private function checkPsAccountsVersion() | ||
{ | ||
if (!class_exists('Ps_accounts')) { | ||
return false; | ||
} | ||
|
||
$moduleName = Installer::PS_ACCOUNTS_MODULE_NAME; | ||
|
||
$module = \Module::getInstanceByName($moduleName); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.