From e9bac9afb012abac445f10e038708589f07c937a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Schoenenberger?= <54308193+hschoenenberger@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:43:21 +0100 Subject: [PATCH] [ACCOUNT-2742] fix: deprecation warnings (#448) * fix: finer grained scoping * fix: hookable trait & shop provider * fix: log level compat v9 * chore: remove useless confusing tags * chore: cleanup unused code * fix: catch throwable --- .dir-scoped | 4 +- composer.json | 15 +- config/command.yml | 10 -- config/common.yml | 4 +- ps_accounts.php | 21 +-- scoper.inc.php | 17 ++- .../Command/MigrateAndLinkV4ShopCommand.php | 44 ------ .../MigrateAndLinkV4ShopHandler.php | 75 ---------- src/Account/Session/ShopSession.php | 3 +- src/Api/Client/AccountsClient.php | 20 --- src/Api/Controller/AbstractRestController.php | 5 +- src/Context/ShopContext.php | 5 +- src/DependencyInjection/ContainerProvider.php | 4 +- src/Hook/Hook.php | 2 +- src/Hook/HookableTrait.php | 2 +- src/Log/Logger.php | 131 +++++++++++++----- src/Presenter/PsAccountsPresenter.php | 19 +-- src/Provider/ShopProvider.php | 3 +- src/Service/AnalyticsService.php | 2 +- src/Service/PsAccountsService.php | 61 -------- 20 files changed, 138 insertions(+), 309 deletions(-) delete mode 100644 src/Account/Command/MigrateAndLinkV4ShopCommand.php delete mode 100644 src/Account/CommandHandler/MigrateAndLinkV4ShopHandler.php diff --git a/.dir-scoped b/.dir-scoped index 7f1fd74db..ebde8b403 100644 --- a/.dir-scoped +++ b/.dir-scoped @@ -5,13 +5,13 @@ symfony/expression-language symfony/filesystem symfony/yaml psr +monolog guzzlehttp league -prestashopcorp +prestashopcorp/oauth2-prestashop lcobucci prestashop/module-lib-service-container prestashop/module-lib-cache-directory-provider -monolog ramsey/uuid ralouphie/getallheaders phpseclib/phpseclib/phpseclib diff --git a/composer.json b/composer.json index 20eb213b5..98dd6f7de 100644 --- a/composer.json +++ b/composer.json @@ -27,9 +27,6 @@ "PrestaShop\\Module\\PsAccounts\\Vendor\\GuzzleHttp\\Psr7\\": "vendor/guzzlehttp/psr7/src", "PrestaShop\\Module\\PsAccounts\\Vendor\\League\\OAuth2\\Client\\": "vendor/league/oauth2-client/src", "PrestaShop\\Module\\PsAccounts\\Vendor\\Lcobucci\\JWT\\": "vendor/lcobucci/jwt/src", - "PrestaShop\\Module\\PsAccounts\\Vendor\\Monolog\\": "vendor/monolog/monolog/src/Monolog", - "PrestaShop\\Module\\PsAccounts\\Vendor\\PhpCsFixer\\": "vendor/friendsofphp/php-cs-fixer/src", - "PrestaShop\\Module\\PsAccounts\\Vendor\\PhpCsFixer\\Tests\\": "vendor/friendsofphp/php-cs-fixer/tests", "PrestaShop\\Module\\PsAccounts\\Vendor\\phpseclib\\": "vendor/phpseclib/phpseclib/phpseclib", "PrestaShop\\Module\\PsAccounts\\Vendor\\Psr\\Cache\\": "vendor/psr/cache/src", "PrestaShop\\Module\\PsAccounts\\Vendor\\Psr\\Container\\": "vendor/psr/container/src", @@ -37,20 +34,14 @@ "PrestaShop\\Module\\PsAccounts\\Vendor\\Psr\\Log\\": "vendor/psr/log/Psr/Log", "PrestaShop\\Module\\PsAccounts\\Vendor\\Psr\\SimpleCache\\": "vendor/psr/simple-cache/src", "PrestaShop\\Module\\PsAccounts\\Vendor\\Ramsey\\Uuid\\": "vendor/ramsey/uuid/src", + "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Cache\\": "vendor/symfony/cache", - "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Config\\": "vendor/symfony/config", - "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Console\\": "vendor/symfony/console", - "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Debug\\": "vendor/symfony/debug", "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\DependencyInjection\\": "vendor/symfony/dependency-injection", - "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\EventDispatcher\\": "vendor/symfony/event-dispatcher", "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\ExpressionLanguage\\": "vendor/symfony/expression-language", "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Filesystem\\": "vendor/symfony/filesystem", - "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Finder\\": "vendor/symfony/finder", - "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\OptionsResolver\\": "vendor/symfony/options-resolver", - "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Process\\": "vendor/symfony/process", - "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Stopwatch\\": "vendor/symfony/stopwatch", "PrestaShop\\Module\\PsAccounts\\Vendor\\Symfony\\Component\\Yaml\\": "vendor/symfony/yaml", - "PrestaShop\\Module\\PsAccounts\\Vendor\\PrestaShop\\ModuleLibServiceContainer\\": "vendor/prestashop/module-lib-service-container/src,", + + "PrestaShop\\Module\\PsAccounts\\Vendor\\PrestaShop\\ModuleLibServiceContainer\\": "vendor/prestashop/module-lib-service-container/src", "PrestaShop\\Module\\PsAccounts\\Vendor\\PrestaShop\\ModuleLibCacheDirectoryProvider\\": "vendor/prestashop/module-lib-cache-directory-provider/src" }, "classmap": [ diff --git a/config/command.yml b/config/command.yml index 4bd679e10..334520c91 100644 --- a/config/command.yml +++ b/config/command.yml @@ -2,16 +2,12 @@ services: PrestaShop\Module\PsAccounts\Account\CommandHandler\LinkShopHandler: class: PrestaShop\Module\PsAccounts\Account\CommandHandler\LinkShopHandler public: true - tags: - - { name: tactician.handler, command: 'PrestaShop\Module\PsAccounts\Domain\Shop\Command\LinkShopCommand' } arguments: - '@PrestaShop\Module\PsAccounts\Account\LinkShop' PrestaShop\Module\PsAccounts\Account\CommandHandler\MigrateAndLinkV4ShopHandler: class: PrestaShop\Module\PsAccounts\Account\CommandHandler\MigrateAndLinkV4ShopHandler public: true - tags: - - { name: tactician.handler, command: 'PrestaShop\Module\PsAccounts\Domain\Shop\Command\MigrateAndLinkV4ShopCommand' } arguments: - '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient' - '@PrestaShop\Module\PsAccounts\Context\ShopContext' @@ -20,8 +16,6 @@ services: PrestaShop\Module\PsAccounts\Account\CommandHandler\DeleteUserShopHandler: class: PrestaShop\Module\PsAccounts\Account\CommandHandler\DeleteUserShopHandler public: true - tags: - - { name: tactician.handler, command: 'PrestaShop\Module\PsAccounts\Domain\Shop\Command\DeleteUserShopCommand' } arguments: - '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient' - '@PrestaShop\Module\PsAccounts\Context\ShopContext' @@ -31,8 +25,6 @@ services: PrestaShop\Module\PsAccounts\Account\CommandHandler\UnlinkShopHandler: class: PrestaShop\Module\PsAccounts\Account\CommandHandler\UnlinkShopHandler public: true - tags: - - { name: tactician.handler, command: 'PrestaShop\Module\PsAccounts\Domain\Shop\Command\UnlinkShopCommand' } arguments: - '@PrestaShop\Module\PsAccounts\Account\LinkShop' - '@PrestaShop\Module\PsAccounts\Service\AnalyticsService' @@ -41,8 +33,6 @@ services: PrestaShop\Module\PsAccounts\Account\CommandHandler\UpdateUserShopHandler: class: PrestaShop\Module\PsAccounts\Account\CommandHandler\UpdateUserShopHandler public: true - tags: - - { name: tactician.handler, command: 'PrestaShop\Module\PsAccounts\Domain\Shop\Command\UpdateShopCommand' } arguments: - '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient' - '@PrestaShop\Module\PsAccounts\Context\ShopContext' diff --git a/config/common.yml b/config/common.yml index adf37dd99..d682e8ce2 100644 --- a/config/common.yml +++ b/config/common.yml @@ -18,8 +18,8 @@ services: class: PrestaShop\Module\PsAccounts\Vendor\Monolog\Logger public: true factory: [ 'PrestaShop\Module\PsAccounts\Log\Logger', 'create' ] -# arguments: -# - '%ps_accounts.log_level%' + arguments: + - '%ps_accounts.log_level%' PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider: class: PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider diff --git a/ps_accounts.php b/ps_accounts.php index 8f72891c4..bebcc34e7 100644 --- a/ps_accounts.php +++ b/ps_accounts.php @@ -157,7 +157,7 @@ public function __construct() } /** - * @return \PrestaShop\Module\PsAccounts\Vendor\Monolog\Logger + * @return \Monolog\Logger */ public function getLogger() { @@ -487,22 +487,6 @@ public function getSession() throw new \Exception('Feature not available'); } - /** - * @deprecated - * - * @return void - * - * @throws PrestaShopException - * - * @phpstan-ignore-next-line - */ - private function autoReonboardOnV5() - { - /** @var \PrestaShop\Module\PsAccounts\Service\PsAccountsService $psAccountsService */ - $psAccountsService = $this->getService(\PrestaShop\Module\PsAccounts\Service\PsAccountsService::class); - $psAccountsService->autoReonboardOnV5(); - } - /** * @return void * @@ -521,9 +505,6 @@ public function onModuleReset() // FIXME: this wont prevent from re-implanting override on reset of module $uninstaller = new PrestaShop\Module\PsAccounts\Module\Uninstall($this, Db::getInstance()); $uninstaller->deleteAdminTab('AdminLogin'); - -// $this->installEventBus(); -// $this->autoReonboardOnV5(); } } diff --git a/scoper.inc.php b/scoper.inc.php index 961428cad..d15fa7b28 100644 --- a/scoper.inc.php +++ b/scoper.inc.php @@ -145,13 +145,16 @@ static function ($filePath, $prefix, $contents) { 'exclude-namespaces' => [ '~^PrestaShop\\\\OAuth2\\\\Client~', '~^Composer\\\\~', - '~^Symfony\\Polyfill\\Apcu\\', - '~^Symfony\\Polyfill\\Ctype\\', - '~^Symfony\\Polyfill\\IntlIdn\\', - '~^Symfony\\Polyfill\\IntlNormalizer\\', - '~^Symfony\\Polyfill\\Mbstring\\', - '~^Symfony\\Polyfill\\Php70\\', - '~^Symfony\\Polyfill\\Php72\\', + 'Monolog\\', + //'~^Symfony\\\\Component\\\\Config~', + 'Symfony\\Component\\Config\\', + 'Symfony\\Polyfill\\Apcu\\', + 'Symfony\\Polyfill\\Ctype\\', + 'Symfony\\Polyfill\\IntlIdn\\', + 'Symfony\\Polyfill\\IntlNormalizer\\', + 'Symfony\\Polyfill\\Mbstring\\', + 'Symfony\\Polyfill\\Php70\\', + 'Symfony\\Polyfill\\Php72\\', ], 'exclude-classes' => [], 'exclude-functions' => [ diff --git a/src/Account/Command/MigrateAndLinkV4ShopCommand.php b/src/Account/Command/MigrateAndLinkV4ShopCommand.php deleted file mode 100644 index c6786befd..000000000 --- a/src/Account/Command/MigrateAndLinkV4ShopCommand.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 - */ - -namespace PrestaShop\Module\PsAccounts\Account\Command; - -class MigrateAndLinkV4ShopCommand -{ - /** - * @var int - */ - public $shopId; - - /** - * @var array - */ - public $payload; - - /** - * @param int $shopId - * @param array $payload - */ - public function __construct($shopId, array $payload) - { - $this->shopId = $shopId; - $this->payload = $payload; - } -} diff --git a/src/Account/CommandHandler/MigrateAndLinkV4ShopHandler.php b/src/Account/CommandHandler/MigrateAndLinkV4ShopHandler.php deleted file mode 100644 index 806bd59c7..000000000 --- a/src/Account/CommandHandler/MigrateAndLinkV4ShopHandler.php +++ /dev/null @@ -1,75 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 - */ - -namespace PrestaShop\Module\PsAccounts\Account\CommandHandler; - -use PrestaShop\Module\PsAccounts\Account\Command\MigrateAndLinkV4ShopCommand; -use PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession; -use PrestaShop\Module\PsAccounts\Api\Client\AccountsClient; -use PrestaShop\Module\PsAccounts\Context\ShopContext; -use PrestaShop\Module\PsAccounts\Exception\RefreshTokenException; - -class MigrateAndLinkV4ShopHandler -{ - /** - * @var AccountsClient - */ - private $accountClient; - - /** - * @var ShopContext - */ - private $shopContext; - - /** - * @var ShopSession - */ - private $shopSession; - - public function __construct( - AccountsClient $accountClient, - ShopContext $shopContext, - ShopSession $shopSession - ) { - $this->accountClient = $accountClient; - $this->shopContext = $shopContext; - $this->shopSession = $shopSession; - } - - /** - * @param MigrateAndLinkV4ShopCommand $command - * - * @return array - * - * @throws RefreshTokenException - */ - public function handle(MigrateAndLinkV4ShopCommand $command) - { - return $this->shopContext->execInShopContext((int) $command->shopId, function () use ($command) { - $shopToken = $this->shopSession->getValidToken(); - - return $this->accountClient->reonboardShop( - $shopToken->getUuid(), - $shopToken->getJwt(), - $command->payload - ); - }); - } -} diff --git a/src/Account/Session/ShopSession.php b/src/Account/Session/ShopSession.php index fb94ad396..10b1a0273 100644 --- a/src/Account/Session/ShopSession.php +++ b/src/Account/Session/ShopSession.php @@ -110,7 +110,8 @@ public function refreshToken($refreshToken = null) $e->getMessage() )); } catch (IdentityProviderException $e) { - } catch (\Error $e) { + } catch (\Throwable $e) { + /* @phpstan-ignore-next-line */ } catch (\Exception $e) { } throw new RefreshTokenException('Unable to refresh shop token : ' . $e->getMessage()); diff --git a/src/Api/Client/AccountsClient.php b/src/Api/Client/AccountsClient.php index 3dd35116b..7d398ee2b 100644 --- a/src/Api/Client/AccountsClient.php +++ b/src/Api/Client/AccountsClient.php @@ -152,26 +152,6 @@ public function deleteUserShop($ownerUid, $shopUid, $ownerToken) ]); } - /** - * @param string $shopUid - * @param string $shopToken - * @param array $payload - * - * @return array - */ - public function reonboardShop($shopUid, $shopToken, $payload) - { - $this->getClient()->setRoute('v1/shop/' . $shopUid . '/reonboard'); - - return $this->getClient()->post([ - 'headers' => $this->getHeaders([ - 'Authorization' => 'Bearer ' . $shopToken, - 'X-Shop-Id' => $shopUid, - ]), - 'json' => $payload, - ]); - } - /** * @param string $ownerUid * @param string $shopUid diff --git a/src/Api/Controller/AbstractRestController.php b/src/Api/Controller/AbstractRestController.php index 4501235b1..c41721666 100644 --- a/src/Api/Controller/AbstractRestController.php +++ b/src/Api/Controller/AbstractRestController.php @@ -90,8 +90,9 @@ public function postProcess() 'error' => true, 'message' => $e->getMessage(), ], $e->getStatusCode()); - } catch (\Error $e) { + } catch (\Throwable $e) { $this->handleError($e); + /* @phpstan-ignore-next-line */ } catch (\Exception $e) { $this->handleError($e); } @@ -362,7 +363,7 @@ protected function geolocationManagement($defaultCountry) } /** - * @param \Error|\Exception $e + * @param \Throwable|\Exception $e * * @return void * diff --git a/src/Context/ShopContext.php b/src/Context/ShopContext.php index 6b1e8c382..0d1874499 100644 --- a/src/Context/ShopContext.php +++ b/src/Context/ShopContext.php @@ -165,7 +165,7 @@ public function getConfiguration() * * @return mixed * - * @throws \Exception + * @throws \Throwable|\Exception */ public function execInShopContext($shopId, $closure) { @@ -177,7 +177,8 @@ public function execInShopContext($shopId, $closure) try { $result = $closure(); - } catch (\Error $e) { + } catch (\Throwable $e) { + /* @phpstan-ignore-next-line */ } catch (\Exception $e) { } $this->configuration->setShopId($backup); diff --git a/src/DependencyInjection/ContainerProvider.php b/src/DependencyInjection/ContainerProvider.php index aa79ec3d3..e67a2369c 100644 --- a/src/DependencyInjection/ContainerProvider.php +++ b/src/DependencyInjection/ContainerProvider.php @@ -21,12 +21,12 @@ namespace PrestaShop\Module\PsAccounts\DependencyInjection; use PrestaShop\Module\PsAccounts\Vendor\PrestaShop\ModuleLibCacheDirectoryProvider\Cache\CacheDirectoryProvider; -use PrestaShop\Module\PsAccounts\Vendor\Symfony\Component\Config\ConfigCache; -use PrestaShop\Module\PsAccounts\Vendor\Symfony\Component\Config\FileLocator; use PrestaShop\Module\PsAccounts\Vendor\Symfony\Component\DependencyInjection\ContainerBuilder; use PrestaShop\Module\PsAccounts\Vendor\Symfony\Component\DependencyInjection\ContainerInterface; use PrestaShop\Module\PsAccounts\Vendor\Symfony\Component\DependencyInjection\Dumper\PhpDumper; use PrestaShop\Module\PsAccounts\Vendor\Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\Config\ConfigCache; +use Symfony\Component\Config\FileLocator; class ContainerProvider { diff --git a/src/Hook/Hook.php b/src/Hook/Hook.php index bf5b1bd89..b345a9a8c 100644 --- a/src/Hook/Hook.php +++ b/src/Hook/Hook.php @@ -20,8 +20,8 @@ namespace PrestaShop\Module\PsAccounts\Hook; +use Monolog\Logger; use PrestaShop\Module\PsAccounts\Cqrs\CommandBus; -use PrestaShop\Module\PsAccounts\Vendor\Monolog\Logger; use Ps_accounts; abstract class Hook diff --git a/src/Hook/HookableTrait.php b/src/Hook/HookableTrait.php index 3dc09ff50..c9fb8fd84 100644 --- a/src/Hook/HookableTrait.php +++ b/src/Hook/HookableTrait.php @@ -58,6 +58,6 @@ private function executeHook($methodName, array $params = []) */ public function __call($name, array $arguments) { - return $this->executeHook($name, $arguments[0]); + return $this->executeHook($name, is_array($arguments[0]) ? $arguments[0] : []); } } diff --git a/src/Log/Logger.php b/src/Log/Logger.php index e14be4890..525fff1e9 100644 --- a/src/Log/Logger.php +++ b/src/Log/Logger.php @@ -20,52 +20,100 @@ namespace PrestaShop\Module\PsAccounts\Log; -use PrestaShop\Module\PsAccounts\Vendor\Monolog\Handler\RotatingFileHandler; -use PrestaShop\Module\PsAccounts\Vendor\Monolog\Logger as MonoLogger; +use Monolog\Handler\RotatingFileHandler; +use Monolog\Logger as MonologLogger; use Ps_accounts; class Logger { + /** + * Detailed debug information + * + * @var string + */ const DEBUG = 'DEBUG'; + + /** + * Interesting events + * + * @var string + */ const INFO = 'INFO'; + + /** + * Uncommon events + * + * @var string + */ const NOTICE = 'NOTICE'; + + /** + * Exceptional occurrences that are not errors + * + * @var string + */ const WARNING = 'WARNING'; + + /** + * Runtime errors + * + * @var string + */ const ERROR = 'ERROR'; + + /** + * Critical conditions + * + * @var string + */ const CRITICAL = 'CRITICAL'; - const ALERT = 'ALERT'; - const EMERGENCY = 'EMERGENCY'; - const MAX_FILES = 15; /** - * @param string|null $logLevel + * Action must be taken immediately * - * @return MonoLogger + * @var string */ - public static function create($logLevel = null) - { - $logLevel = self::getLevel($logLevel); - $monologLevel = MonoLogger::toMonologLevel($logLevel); - if (!is_int($monologLevel)) { - $monologLevel = MonoLogger::ERROR; - } + const ALERT = 'ALERT'; - $path = _PS_ROOT_DIR_ . '/var/logs/ps_accounts'; + /** + * Urgent alert. + * + * @var string + */ + const EMERGENCY = 'EMERGENCY'; - if (version_compare(_PS_VERSION_, '1.7', '<')) { - $path = _PS_ROOT_DIR_ . '/log/ps_accounts'; - } elseif (version_compare(_PS_VERSION_, '1.7.4', '<')) { - $path = _PS_ROOT_DIR_ . '/app/logs/ps_accounts'; - } + /** + * Number of files to rotate + * + * @var int + */ + const MAX_FILES = 15; - $rotatingFileHandler = new RotatingFileHandler($path, static::MAX_FILES, $monologLevel); - $logger = new MonoLogger('ps_accounts'); - $logger->pushHandler($rotatingFileHandler); + /** + * @var int + */ + const DEFAULT_MONOLOG_LEVEL = MonologLogger::ERROR; - return $logger; + /** + * @param string $level + * + * @return MonologLogger + */ + public static function create($level = '') + { + return (new MonologLogger('ps_accounts'))->pushHandler( + new RotatingFileHandler( + self::getPath(), + static::MAX_FILES, + self::getMonologLevel($level) + ) + ); } /** - * @return Monologger + * FIXME: misnamed method + * + * @return MonologLogger */ public static function getInstance() { @@ -76,21 +124,30 @@ public static function getInstance() } /** - * @param string|null $logLevel - * @param string $parameter - * - * @return mixed + * @return string */ - public static function getLevel($logLevel, $parameter = 'ps_accounts.log_level') + protected static function getPath() { - if ($logLevel === null) { - /** @var Ps_accounts $psAccounts */ - $psAccounts = \Module::getInstanceByName('ps_accounts'); - if ($psAccounts->hasParameter($parameter)) { - $logLevel = $psAccounts->getParameter($parameter); - } + $path = _PS_ROOT_DIR_ . '/var/logs/ps_accounts'; + if (version_compare(_PS_VERSION_, '1.7', '<')) { + $path = _PS_ROOT_DIR_ . '/log/ps_accounts'; + } elseif (version_compare(_PS_VERSION_, '1.7.4', '<')) { + $path = _PS_ROOT_DIR_ . '/app/logs/ps_accounts'; } - return $logLevel; + return $path; + } + + /** + * @param string $level + * @param int $default + * + * @return int + */ + protected static function getMonologLevel($level, $default = self::DEFAULT_MONOLOG_LEVEL) + { + $logLevel = MonologLogger::toMonologLevel($level); + /* @phpstan-ignore-next-line */ + return is_int($logLevel) ? $logLevel : $default; } } diff --git a/src/Presenter/PsAccountsPresenter.php b/src/Presenter/PsAccountsPresenter.php index d2b54ccbe..4167d3459 100644 --- a/src/Presenter/PsAccountsPresenter.php +++ b/src/Presenter/PsAccountsPresenter.php @@ -95,10 +95,13 @@ public function present($psxName = 'ps_accounts') $moduleName = (string) $this->module->name; - $unlinkedShops = $this->shopProvider->getUnlinkedShops( - $psxName, - $shopContext->getContext()->employee->id - ); + $employee = $shopContext->getContext()->employee; + /* @phpstan-ignore-next-line */ + if (!$employee) { + $employee = new \Employee(); + } + + $unlinkedShops = $this->shopProvider->getUnlinkedShops($psxName, (int) $employee->id); $shopBase64 = base64_encode( (string) json_encode(array_values($unlinkedShops)) ); @@ -136,12 +139,12 @@ public function present($psxName = 'ps_accounts') 'uuid' => $this->psAccountsService->getUserUuid() ?: null, 'email' => $this->psAccountsService->getEmail() ?: null, 'emailIsValidated' => $this->psAccountsService->isEmailValidated(), - 'isSuperAdmin' => $shopContext->getContext()->employee->isSuperAdmin(), + 'isSuperAdmin' => $employee->isSuperAdmin(), ], 'backendUser' => [ - 'email' => $shopContext->getContext()->employee->email, - 'employeeId' => $shopContext->getContext()->employee->id, - 'isSuperAdmin' => $shopContext->getContext()->employee->isSuperAdmin(), + 'email' => $employee->email, + 'employeeId' => $employee->id, + 'isSuperAdmin' => $employee->isSuperAdmin(), ], 'currentShop' => $this->shopProvider->getCurrentShop($psxName), 'isShopContext' => $shopContext->isShopContext(), diff --git a/src/Provider/ShopProvider.php b/src/Provider/ShopProvider.php index 5baf221f6..ff9d8c41e 100644 --- a/src/Provider/ShopProvider.php +++ b/src/Provider/ShopProvider.php @@ -99,6 +99,7 @@ public function formatShopData(array $shopData, $psxName = '', $refreshTokens = true, [], [ + 'module_name' => $psxName, 'configure' => $psxName, 'setShopContext' => 's-' . $shopData['id_shop'], ] @@ -123,7 +124,7 @@ public function formatShopData(array $shopData, $psxName = '', $refreshTokens = * * @throws \PrestaShopException|\Exception */ - public function getCurrentShop($psxName = '') + public function getCurrentShop($psxName = 'ps_accounts') { $shop = $this->formatShopData((array) \Shop::getShop($this->shopContext->getContext()->shop->id), $psxName); diff --git a/src/Service/AnalyticsService.php b/src/Service/AnalyticsService.php index 9006852a9..aca6f975b 100644 --- a/src/Service/AnalyticsService.php +++ b/src/Service/AnalyticsService.php @@ -20,7 +20,7 @@ namespace PrestaShop\Module\PsAccounts\Service; -use PrestaShop\Module\PsAccounts\Vendor\Monolog\Logger; +use Monolog\Logger; use PrestaShop\Module\PsAccounts\Vendor\Ramsey\Uuid\Uuid; use Segment; diff --git a/src/Service/PsAccountsService.php b/src/Service/PsAccountsService.php index 99ce5cc85..bfce1ccdf 100644 --- a/src/Service/PsAccountsService.php +++ b/src/Service/PsAccountsService.php @@ -20,16 +20,12 @@ namespace PrestaShop\Module\PsAccounts\Service; -use PrestaShop\Module\PsAccounts\Account\Command\MigrateAndLinkV4ShopCommand; -use PrestaShop\Module\PsAccounts\Account\Command\UnlinkShopCommand; use PrestaShop\Module\PsAccounts\Account\LinkShop; use PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession; use PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession; use PrestaShop\Module\PsAccounts\Adapter\Link; -use PrestaShop\Module\PsAccounts\Cqrs\CommandBus; use PrestaShop\Module\PsAccounts\Entity\EmployeeAccount; use PrestaShop\Module\PsAccounts\Exception\RefreshTokenException; -use PrestaShop\Module\PsAccounts\Provider\ShopProvider; use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository; use PrestaShop\Module\PsAccounts\Repository\EmployeeAccountRepository; @@ -237,63 +233,6 @@ public function getAccountsCdn() return $this->module->getParameter('ps_accounts.accounts_cdn_url'); } - /** - * @return void - * - * @throws \PrestaShopException - * @throws \Exception - */ - public function autoReonboardOnV5() - { - /** @var ShopProvider $shopProvider */ - $shopProvider = $this->module->getService(ShopProvider::class); - - /** @var ConfigurationRepository $conf */ - $conf = $this->module->getService(ConfigurationRepository::class); - - /** @var LinkShop $linkShop */ - $linkShop = $this->module->getService(LinkShop::class); - - /** @var CommandBus $commandBus */ - $commandBus = $this->module->getService(CommandBus::class); - - $allShops = $shopProvider->getShopsTree((string) $this->module->name); - - $flattenShops = []; - - foreach ($allShops as $shopGroup) { - foreach ($shopGroup['shops'] as $shop) { - $shop['multishop'] = (bool) $shopGroup['multishop']; - $flattenShops[] = $shop; - } - } - - $isAlreadyReonboard = false; - - usort($flattenShops, function ($firstShop, $secondShop) { - return (int) $firstShop['id'] - (int) $secondShop['id']; - }); - - foreach ($flattenShops as $shop) { - if ($shop['isLinkedV4']) { - $id = $conf->getShopId(); - if ($isAlreadyReonboard) { - $conf->setShopId((int) $shop['id']); - - $commandBus->handle(new UnlinkShopCommand($shop['id'])); - - $conf->setShopId($id); - } else { - $shop['employeeId'] = null; - - $commandBus->handle(new MigrateAndLinkV4ShopCommand($id, $shop)); - - $isAlreadyReonboard = true; - } - } - } - } - /** * @return bool *