Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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\CleanupIdentityCommand;
class CleanupIdentityHandler
{
/**
* @param CleanupIdentityCommand $command
*
* @return void
*/
public function handle(CleanupIdentityCommand $command)
{
$id_shop = $command->shopId;
\Db::getInstance()->execute(
'DELETE FROM `' . _DB_PREFIX_ . bqSQL('configuration') . '`'
. ' WHERE (name like \'PS_ACCOUNTS%\' or name = \'PSX_UUID_V4\' or name = \'PS_CHECKOUT_SHOP_UUID_V4\')'
. ' AND ' . ($id_shop ? 'id_shop = ' . (int) $id_shop : 'id_shop IS NULL')
);
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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\CreateIdentitiesCommand;
use PrestaShop\Module\PsAccounts\Account\Command\CreateIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
class CreateIdentitiesHandler extends MultiShopHandler
{
/**
* @param CreateIdentitiesCommand $command
*
* @return void
*/
public function handle(CreateIdentitiesCommand $command)
{
$this->handleMulti(function ($multiShopId) use ($command) {
try {
$this->commandBus->handle(
(new CreateIdentityCommand($multiShopId, false))
->withOrigin($command->origin)
->withSource($command->source)
);
} catch (RefreshTokenException $e) {
Logger::getInstance()->error($e->getMessage());
} catch (AccountsException $e) {
Logger::getInstance()->error($e->getMessage());
}
});
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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\CreateIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Command\VerifyIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Client;
class CreateIdentityHandler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var OAuth2Client
*/
private $oAuth2Client;
/**
* @var ShopProvider
*/
private $shopProvider;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var CommandBus
*/
private $commandBus;
/**
* @param AccountsService $accountsService
* @param ShopProvider $shopProvider
* @param OAuth2Client $oauth2Client
* @param StatusManager $shopStatus
* @param CommandBus $commandBus
*/
public function __construct(
AccountsService $accountsService,
ShopProvider $shopProvider,
OAuth2Client $oauth2Client,
StatusManager $shopStatus,
CommandBus $commandBus
) {
$this->accountsService = $accountsService;
$this->shopProvider = $shopProvider;
$this->oAuth2Client = $oauth2Client;
$this->statusManager = $shopStatus;
$this->commandBus = $commandBus;
}
/**
* @param CreateIdentityCommand $command
*
* @return void
*
* @throws RefreshTokenException
* @throws UnknownStatusException
* @throws AccountsException
*/
public function handle(CreateIdentityCommand $command)
{
if ($command->renew || !$this->isAlreadyCreated()) {
$shopId = $command->shopId;
$identityCreated = $this->accountsService
->withSource($command->source)
->withOrigin($command->origin)
->createShopIdentity(
$this->shopProvider->getUrl($shopId),
$this->shopProvider->getName($shopId)
);
$this->oAuth2Client->update(
$identityCreated->clientId,
$identityCreated->clientSecret
);
$this->statusManager->setCloudShopId($identityCreated->cloudShopId);
$this->statusManager->setIsVerified(false);
$this->statusManager->invalidateCache();
$this->commandBus->handle(
(new VerifyIdentityCommand($shopId, true))
->withOrigin($command->origin)
->withSource($command->source)
);
} else {
$this->commandBus->handle(
(new VerifyIdentityCommand($command->shopId))
->withOrigin($command->origin)
->withSource($command->source)
);
}
}
/**
* Idempotency check
*
* @return bool
*/
private function isAlreadyCreated()
{
// FIXME: define where this code belongs
return $this->oAuth2Client->exists() && $this->statusManager->identityCreated();
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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\IdentifyContactCommand;
use PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession;
use PrestaShop\Module\PsAccounts\Account\Session\ShopSession;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
class IdentifyContactHandler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var ShopSession
*/
private $shopSession;
/**
* @var OwnerSession
*/
private $ownerSession;
/**
* @param AccountsService $accountsService
* @param StatusManager $statusManager
* @param ShopSession $shopSession
* @param OwnerSession $ownerSession
*/
public function __construct(
AccountsService $accountsService,
StatusManager $statusManager,
ShopSession $shopSession,
OwnerSession $ownerSession
) {
$this->accountsService = $accountsService;
$this->statusManager = $statusManager;
$this->shopSession = $shopSession;
$this->ownerSession = $ownerSession;
}
/**
* @param IdentifyContactCommand $command
*
* @return void
*
* @throws AccountsException
*/
public function handle(IdentifyContactCommand $command)
{
$status = $this->statusManager->withSource($command->source)->getStatus();
if (!$status->isVerified) {
return;
}
$this->accountsService
->withSource($command->source)
->setPointOfContact(
$this->statusManager->getCloudShopId(),
$this->shopSession->getValidToken(),
$command->accessToken->access_token
);
// cleanup user token
$this->ownerSession->cleanup();
// optimistic update cached status
$this->statusManager->setPointOfContactUuid($command->userInfo->sub);
$this->statusManager->setPointOfContactEmail($command->userInfo->email);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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 Exception;
use PrestaShop\Module\PsAccounts\Account\Command\MigrateOrCreateIdentitiesV8Command;
use PrestaShop\Module\PsAccounts\Account\Command\MigrateOrCreateIdentityV8Command;
use PrestaShop\Module\PsAccounts\Log\Logger;
class MigrateOrCreateIdentitiesV8Handler extends MultiShopHandler
{
/**
* @param MigrateOrCreateIdentitiesV8Command $command
*
* @return void
*/
public function handle(MigrateOrCreateIdentitiesV8Command $command)
{
$this->handleMulti(function ($multiShopId) use ($command) {
try {
$this->commandBus->handle(
(new MigrateOrCreateIdentityV8Command($multiShopId))
->withOrigin($command->origin)
->withSource($command->source)
);
} catch (Exception $e) {
Logger::getInstance()->error($e->getMessage());
}
});
}
}

View File

@@ -0,0 +1,274 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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 InvalidArgumentException;
use PrestaShop\Module\PsAccounts\Account\Command\CreateIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Command\MigrateOrCreateIdentityV8Command;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Account\ProofManager;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
use PrestaShop\Module\PsAccounts\Service\Accounts\Exception\StoreLegacyNotFoundException;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Exception;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Service;
use PrestaShop\Module\PsAccounts\Service\UpgradeService;
class MigrateOrCreateIdentityV8Handler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var OAuth2Service
*/
protected $oAuth2Service;
/**
* @var ShopProvider
*/
private $shopProvider;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var ProofManager
*/
protected $proofManager;
/**
* @var ConfigurationRepository
*/
private $configurationRepository;
/**
* @var CommandBus
*/
private $commandBus;
/**
* @var UpgradeService
*/
private $upgradeService;
/**
* @param AccountsService $accountsService
* @param OAuth2Service $oAuth2Service
* @param ShopProvider $shopProvider
* @param StatusManager $shopStatus
* @param ProofManager $proofManager
* @param ConfigurationRepository $configurationRepository
* @param CommandBus $commandBus
* @param UpgradeService $upgradeService
*/
public function __construct(
AccountsService $accountsService,
OAuth2Service $oAuth2Service,
ShopProvider $shopProvider,
StatusManager $shopStatus,
ProofManager $proofManager,
ConfigurationRepository $configurationRepository,
CommandBus $commandBus,
UpgradeService $upgradeService
) {
$this->accountsService = $accountsService;
$this->oAuth2Service = $oAuth2Service;
$this->shopProvider = $shopProvider;
$this->statusManager = $shopStatus;
$this->proofManager = $proofManager;
$this->configurationRepository = $configurationRepository;
$this->commandBus = $commandBus;
$this->upgradeService = $upgradeService;
}
/**
* @param MigrateOrCreateIdentityV8Command $command
*
* @return void
*
* @throws AccountsException
* @throws RefreshTokenException
* @throws UnknownStatusException
*/
public function handle(MigrateOrCreateIdentityV8Command $command)
{
$shopId = $command->shopId;
$shopUuid = $this->configurationRepository->getShopUuid();
// FIXME: command can hold that property depending on context
$fromVersion = $this->upgradeService->getRegisteredVersion();
$migratedToV8 = version_compare($fromVersion, '8', '>=');
$notIdentified = !$shopUuid;
// FIXME: shouldn't this condition be a specific flag
if ($notIdentified || $migratedToV8) {
$this->registerLatestVersion();
$this->createOrVerifyIdentity($command);
return;
}
try {
// Register cloudShopId locally
$this->statusManager->setCloudShopId($shopUuid);
$identityCreated = $this->accountsService
->withSource($command->source)
->migrateShopIdentity(
$shopUuid,
$this->getTokenV6OrV7($shopUuid),
$this->shopProvider->getUrl($shopId),
$this->shopProvider->getName($shopId),
$fromVersion,
$this->proofManager->generateProof()
);
if (!empty($identityCreated->clientId) &&
!empty($identityCreated->clientSecret)) {
$this->oAuth2Service->getOAuth2Client()->update(
$identityCreated->clientId,
$identityCreated->clientSecret
);
}
$this->clearTokens();
$this->statusManager->invalidateCache();
$this->registerLatestVersion();
} catch (StoreLegacyNotFoundException $e) {
if ($command->origin !== AccountsService::ORIGIN_ADVANCED_SETTINGS) {
$this->registerLatestVersion();
$this->cleanupIdentity();
$this->createOrVerifyIdentity($command);
return;
} else {
throw $e;
}
}
}
/**
* @param string $shopUuid
*
* @return string
*
* @throws OAuth2Exception
*/
private function getAccessTokenV7($shopUuid)
{
return $this->oAuth2Service->getAccessTokenByClientCredentials([], [
// audience v7
'shop_' . $shopUuid,
])->access_token;
}
/**
* @param string $shopUuid
*
* @return string
*
* @throws AccountsException
* @throws InvalidArgumentException
*/
private function getFirebaseTokenV6($shopUuid)
{
return $this->accountsService->refreshShopToken(
$this->configurationRepository->getFirebaseRefreshToken(),
$shopUuid
)->token;
}
/**
* @param string $shopUuid
*
* @return string
*
* @throws AccountsException
*/
private function getTokenV6OrV7($shopUuid)
{
try {
return $this->getAccessTokenV7($shopUuid);
} catch (OAuth2Exception $e) {
return $this->getFirebaseTokenV6($shopUuid);
}
}
/**
* @return void
*/
private function cleanupIdentity()
{
// Will trigger reset banner
//$this->upgradeService->setVersion('');
$this->statusManager->clearStatus();
$this->oAuth2Service->getOAuth2Client()->delete();
$this->clearTokens();
}
/**
* Create Or Verify Or Do Nothing
*
* @param MigrateOrCreateIdentityV8Command $command
*
* @return void
*
* @throws RefreshTokenException
* @throws UnknownStatusException
* @throws AccountsException
*/
private function createOrVerifyIdentity(MigrateOrCreateIdentityV8Command $command)
{
$this->commandBus->handle(
(new CreateIdentityCommand($command->shopId, false))
->withOrigin($command->origin)
->withSource($command->source)
);
}
/**
* @return void
*/
private function clearTokens()
{
$this->configurationRepository->updateAccessToken('');
$this->configurationRepository->updateFirebaseIdAndRefreshTokens('', '');
$this->configurationRepository->updateUserFirebaseIdAndRefreshToken('', '');
}
/**
* @return void
*/
private function registerLatestVersion()
{
$this->upgradeService->setVersion();
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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\Context\ShopContext;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
abstract class MultiShopHandler
{
/**
* @var ShopContext
*/
protected $shopContext;
/**
* @var CommandBus
*/
protected $commandBus;
public function __construct(
ShopContext $shopContext,
CommandBus $commandBus
) {
$this->shopContext = $shopContext;
$this->commandBus = $commandBus;
}
/**
* @param \Closure $handler
*
* @return void
*/
protected function handleMulti($handler)
{
foreach ($this->getShopIds() as $multiShopId) {
$this->shopContext->execInShopContext($multiShopId, function () use ($handler, $multiShopId) {
$handler($multiShopId);
});
}
}
/**
* @return int[]
*/
protected function getShopIds()
{
if ($this->shopContext->isMultishopActive()) {
return $this->shopContext->getMultiShopIds();
}
//return [\Shop::getContextShopID(true)];
return [\Shop::getContextShopID()];
}
}

View File

@@ -0,0 +1,158 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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 Exception;
use PrestaShop\Module\PsAccounts\Account\Command\MigrateOrCreateIdentityV8Command;
use PrestaShop\Module\PsAccounts\Account\Command\RestoreIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Command\VerifyIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Service\Accounts\Resource\ShopStatus;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Client;
use PrestaShop\Module\PsAccounts\Service\UpgradeService;
use Throwable;
class RestoreIdentityHandler
{
/**
* @var OAuth2Client
*/
private $oAuth2Client;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var UpgradeService
*/
private $upgradeService;
/**
* @var CommandBus
*/
private $commandBus;
/**
* @param OAuth2Client $oauth2Client
* @param StatusManager $shopStatus
* @param UpgradeService $upgradeService
* @param CommandBus $commandBus
*/
public function __construct(
OAuth2Client $oauth2Client,
StatusManager $shopStatus,
UpgradeService $upgradeService,
CommandBus $commandBus
) {
$this->oAuth2Client = $oauth2Client;
$this->statusManager = $shopStatus;
$this->upgradeService = $upgradeService;
$this->commandBus = $commandBus;
}
/**
* @param RestoreIdentityCommand $command
*
* @return void
*
* @throws Exception|Throwable
*/
public function handle(RestoreIdentityCommand $command)
{
try {
$currentStatus = $this->statusManager->getStatus(true);
} catch (UnknownStatusException $e) {
$currentStatus = null;
}
$registeredVersion = $this->upgradeService->getRegisteredVersion();
$shopId = $command->shopId ?: \Shop::getContextShopID();
try {
$this->statusManager->clearStatus();
// Update OAuth client
$this->oAuth2Client->update(
$command->clientId,
$command->clientSecret ?: $this->oAuth2Client->getClientSecret()
);
// Update cloudShopId
$this->statusManager->setCloudShopId($command->cloudShopId);
// Fix version number when not set
$this->upgradeService->setVersion();
if ($command->migrate) {
// this will trigger migration
$this->upgradeService->setVersion($command->migrateFrom);
}
$this->commandBus->handle(
// FIXME: $cloudShopId (should not be necessary to read it from db)
(new MigrateOrCreateIdentityV8Command($shopId))
->withOrigin($command->origin)
->withSource($command->source)
);
if ($command->verify) {
// force verify
$this->commandBus->handle(
(new VerifyIdentityCommand($shopId, true))
->withOrigin($command->origin)
->withSource($command->source)
);
}
//$this->statusManager->invalidateCache();
} catch (Exception $e) {
$this->handleError($currentStatus, $registeredVersion, $e);
} catch (Throwable $e) {
$this->handleError($currentStatus, $registeredVersion, $e);
}
}
/**
* @param ShopStatus|null $currentStatus
* @param string $registeredVersion
* @param Exception|Throwable $e
*
* @return void
*
* @throws Exception|Throwable
*/
private function handleError($currentStatus, $registeredVersion, $e)
{
if (isset($currentStatus)) {
$this->statusManager->restoreStatus($currentStatus);
}
$this->upgradeService->setVersion($registeredVersion);
Logger::getInstance()->error($e);
throw $e;
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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\UpdateBackOfficeUrlCommand;
use PrestaShop\Module\PsAccounts\Account\Session\ShopSession;
use PrestaShop\Module\PsAccounts\Account\ShopUrl;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
class UpdateBackOfficeUrlHandler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var ShopProvider
*/
private $shopProvider;
/**
* @var ShopSession
*/
private $shopSession;
/**
* @var ConfigurationRepository
*/
private $configurationRepository;
/**
* @param AccountsService $accountsService
* @param StatusManager $statusManager
* @param ShopProvider $shopProvider
* @param ShopSession $shopSession
* @param ConfigurationRepository $configurationRepository
*/
public function __construct(
AccountsService $accountsService,
StatusManager $statusManager,
ShopProvider $shopProvider,
ShopSession $shopSession,
ConfigurationRepository $configurationRepository
) {
$this->accountsService = $accountsService;
$this->statusManager = $statusManager;
$this->shopProvider = $shopProvider;
$this->shopSession = $shopSession;
$this->configurationRepository = $configurationRepository;
}
/**
* @param UpdateBackOfficeUrlCommand $command
*
* @return void
*/
public function handle(UpdateBackOfficeUrlCommand $command)
{
// On disconnected context with single shop mode, the contextual shop id is not defined.
$shopId = $command->shopId ?: $this->configurationRepository->getMainShopId();
// TODO: rework parameters priority
$status = $this->statusManager->withSource('ps_accounts')->getStatus();
$cloudShopUrl = ShopUrl::createFromStatus($status, $shopId);
$localShopUrl = $this->shopProvider->getUrl($shopId);
try {
// Check if BO url changed and urls aren't empty
if (!$cloudShopUrl->backOfficeUrlEquals($localShopUrl)) {
$this->accountsService->updateBackOfficeUrl(
$status->cloudShopId,
$this->shopSession->getValidToken(),
$localShopUrl
);
}
} catch (\InvalidArgumentException $e) {
Logger::getInstance()->error($e->getMessage());
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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 Exception;
use PrestaShop\Module\PsAccounts\Account\Command\UpdateBackOfficeUrlCommand;
use PrestaShop\Module\PsAccounts\Account\Command\UpdateBackOfficeUrlsCommand;
use PrestaShop\Module\PsAccounts\Log\Logger;
use Throwable;
class UpdateBackOfficeUrlsHandler extends MultiShopHandler
{
/**
* @param UpdateBackOfficeUrlsCommand $command
*
* @return void
*/
public function handle(UpdateBackOfficeUrlsCommand $command)
{
$this->handleMulti(function ($multiShopId) {
try {
$updateBackOfficeUrlCommand = new UpdateBackOfficeUrlCommand($multiShopId);
$this->commandBus->handle($updateBackOfficeUrlCommand);
} catch (Exception $e) {
Logger::getInstance()->error($e->getMessage());
} catch (Throwable $e) {
Logger::getInstance()->error($e->getMessage());
}
});
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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\VerifyIdentitiesCommand;
use PrestaShop\Module\PsAccounts\Account\Command\VerifyIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
class VerifyIdentitiesHandler extends MultiShopHandler
{
/**
* @param VerifyIdentitiesCommand $command
*
* @return void
*/
public function handle(VerifyIdentitiesCommand $command)
{
$this->handleMulti(function ($multiShopId) use ($command) {
try {
$this->commandBus->handle(
(new VerifyIdentityCommand($multiShopId, false))
->withOrigin($command->origin)
->withSource($command->source)
);
} catch (RefreshTokenException $e) {
Logger::getInstance()->error($e->getMessage());
} catch (AccountsException $e) {
Logger::getInstance()->error($e->getMessage());
} catch (UnknownStatusException $e) {
Logger::getInstance()->error($e->getMessage());
}
});
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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\VerifyIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Account\ProofManager;
use PrestaShop\Module\PsAccounts\Account\Session\ShopSession;
use PrestaShop\Module\PsAccounts\Account\ShopUrl;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
class VerifyIdentityHandler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var ShopProvider
*/
private $shopProvider;
/**
* @var ShopSession
*/
private $shopSession;
/**
* @var ProofManager
*/
private $proofManager;
/**
* @param AccountsService $accountsService
* @param ShopProvider $shopProvider
* @param StatusManager $statusManager
* @param ShopSession $shopSession
* @param ProofManager $proofManager
*/
public function __construct(
AccountsService $accountsService,
ShopProvider $shopProvider,
StatusManager $statusManager,
ShopSession $shopSession,
ProofManager $proofManager
) {
$this->accountsService = $accountsService;
$this->shopProvider = $shopProvider;
$this->statusManager = $statusManager;
$this->shopSession = $shopSession;
$this->proofManager = $proofManager;
}
/**
* @param VerifyIdentityCommand $command
*
* @return void
*
* @throws RefreshTokenException
* @throws UnknownStatusException
* @throws AccountsException
*/
public function handle(VerifyIdentityCommand $command)
{
$shopId = $command->shopId;
$status = $this->statusManager->withSource($command->source)->getStatus();
$cloudShopUrl = ShopUrl::createFromStatus($status, $shopId);
if (!$command->force && $status->isVerified) {
return;
}
try {
if (!$command->force && !$cloudShopUrl->frontendUrlEquals($this->shopProvider->getUrl($shopId))) {
return;
}
} catch (\InvalidArgumentException $e) {
Logger::getInstance()->error($e->getMessage());
return;
}
$this->accountsService
->withOrigin($command->origin)
->withSource($command->source)
->verifyShopIdentity(
$this->statusManager->getCloudShopId(),
$this->shopSession->getValidToken(),
$this->shopProvider->getUrl($shopId),
$this->shopProvider->getName($shopId),
$this->proofManager->generateProof()
);
$this->statusManager->invalidateCache();
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;