ltsecurityinc安防产品在线商城代码
This commit is contained in:
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization\Data;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Magento\Framework\Model\Context;
|
||||
use Magento\Framework\Registry;
|
||||
use Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface;
|
||||
use Plumrocket\Base\Helper\Config;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class ExtensionAuthorization extends AbstractModel implements ExtensionAuthorizationInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\Model\Context $context
|
||||
* @param \Magento\Framework\Registry $registry
|
||||
* @param \Plumrocket\Base\Helper\Config $config
|
||||
* @param string $name
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
Registry $registry,
|
||||
Config $config,
|
||||
string $name,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $registry, null, null, $data);
|
||||
$this->name = $name;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize resource model
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(\Plumrocket\Base\Model\ResourceModel\ExtensionAuthorization::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getModuleName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isAuthorized(): bool
|
||||
{
|
||||
return $this->getStatus() && ($this->getStatus() % 100 === 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getStatus(): int
|
||||
{
|
||||
return (int) $this->_getData(self::STATUS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setStatus(int $status): ExtensionAuthorizationInterface
|
||||
{
|
||||
return $this->setData(self::STATUS, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSignature(string $signature): ExtensionAuthorizationInterface
|
||||
{
|
||||
return $this->setData(self::SIGNATURE, $signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDate(): string
|
||||
{
|
||||
return (string) $this->_getData(self::DATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setDate(string $date): ExtensionAuthorizationInterface
|
||||
{
|
||||
return $this->setData(self::DATE, $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function isCached(): bool
|
||||
{
|
||||
if ($this->config->isDebugMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->getDate() > date('Y-m-d H:i:s')
|
||||
&& $this->getDate() < date('Y-m-d H:i:s', time() + 30 * 86400);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2020 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization;
|
||||
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Factory
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\ObjectManagerInterface $objectManager
|
||||
*/
|
||||
public function __construct(ObjectManagerInterface $objectManager)
|
||||
{
|
||||
$this->objectManager = $objectManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $moduleName
|
||||
* @return \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface|Data\ExtensionAuthorization
|
||||
*/
|
||||
public function create(string $moduleName): ExtensionAuthorizationInterface
|
||||
{
|
||||
return $this->objectManager->create(ExtensionAuthorizationInterface::class, ['name' => $moduleName]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization;
|
||||
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Plumrocket\Base\Api\GetExtensionInformationInterface;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Key
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $keyCache = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $keyPathCache = [];
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
|
||||
*/
|
||||
private $getExtensionInformation;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Config\ScopeConfigInterface
|
||||
*/
|
||||
private $scopeConfig;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
|
||||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
|
||||
*/
|
||||
public function __construct(
|
||||
GetExtensionInformationInterface $getExtensionInformation,
|
||||
ScopeConfigInterface $scopeConfig
|
||||
) {
|
||||
$this->getExtensionInformation = $getExtensionInformation;
|
||||
$this->scopeConfig = $scopeConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve key from config
|
||||
*
|
||||
* @param string $moduleName
|
||||
* @return string
|
||||
*/
|
||||
public function get(string $moduleName): string
|
||||
{
|
||||
if (! isset($this->keyCache[$moduleName]) || ! $this->keyCache[$moduleName]) {
|
||||
$this->keyCache[$moduleName] = (string) $this->scopeConfig->getValue(
|
||||
$this->getPath($moduleName),
|
||||
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
return $this->keyCache[$moduleName];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set key to cache.
|
||||
*
|
||||
* @param string $moduleName
|
||||
* @param string $key
|
||||
* @return $this
|
||||
*/
|
||||
public function set(string $moduleName, string $key): Key
|
||||
{
|
||||
$this->keyCache[$moduleName] = $key;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve config path to key
|
||||
*
|
||||
* @param string $moduleName
|
||||
* @return string
|
||||
*/
|
||||
public function getPath(string $moduleName): string
|
||||
{
|
||||
if (! isset($this->keyPathCache[$moduleName])) {
|
||||
$info = $this->getExtensionInformation->execute($moduleName);
|
||||
if ($configSection = $info->getConfigSection()) {
|
||||
$path = "$configSection/general/serial";
|
||||
} else {
|
||||
$path = 'custom/general/serial';
|
||||
}
|
||||
$this->keyPathCache[$moduleName] = $path;
|
||||
}
|
||||
|
||||
return $this->keyPathCache[$moduleName];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization\Key;
|
||||
|
||||
use Exception;
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface;
|
||||
use Plumrocket\Base\Api\GetExtensionInformationInterface;
|
||||
use Plumrocket\Base\Helper\Config;
|
||||
use Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey;
|
||||
use Plumrocket\Base\Model\External\Connector;
|
||||
use Plumrocket\Base\Model\External\Urls;
|
||||
use Plumrocket\Base\Model\Utils\GetEnabledStoresUrls;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Load
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Utils\GetEnabledStoresUrls
|
||||
*/
|
||||
private $getEnabledStoresUrls;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
|
||||
*/
|
||||
private $getExtensionInformation;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey
|
||||
*/
|
||||
private $getTrueCustomerKey;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ProductMetadataInterface
|
||||
*/
|
||||
private $productMetadata;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\External\Connector
|
||||
*/
|
||||
private $externalConnector;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Utils\GetEnabledStoresUrls $getEnabledStoresUrls
|
||||
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
|
||||
* @param \Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey $getTrueCustomerKey
|
||||
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
|
||||
* @param \Plumrocket\Base\Model\External\Connector $externalConnector
|
||||
* @param \Plumrocket\Base\Helper\Config $config
|
||||
*/
|
||||
public function __construct(
|
||||
GetEnabledStoresUrls $getEnabledStoresUrls,
|
||||
GetExtensionInformationInterface $getExtensionInformation,
|
||||
GetTrueCustomerKey $getTrueCustomerKey,
|
||||
ProductMetadataInterface $productMetadata,
|
||||
Connector $externalConnector,
|
||||
Config $config
|
||||
) {
|
||||
$this->getEnabledStoresUrls = $getEnabledStoresUrls;
|
||||
$this->getExtensionInformation = $getExtensionInformation;
|
||||
$this->getTrueCustomerKey = $getTrueCustomerKey;
|
||||
$this->productMetadata = $productMetadata;
|
||||
$this->externalConnector = $externalConnector;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load extension key.
|
||||
*
|
||||
* @param \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface $extension
|
||||
* @return array
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function execute(ExtensionAuthorizationInterface $extension): array
|
||||
{
|
||||
$extensionInformation = $this->getExtensionInformation->execute($extension->getModuleName());
|
||||
$key = '';
|
||||
$expiration = 0;
|
||||
try {
|
||||
$data = [
|
||||
'edition' => $this->productMetadata->getEdition(),
|
||||
'base_urls' => $this->getEnabledStoresUrls->execute(),
|
||||
'name' => $extensionInformation->getModuleName(),
|
||||
'name_version' => $extensionInformation->getInstalledVersion(),
|
||||
'customer' => $this->getTrueCustomerKey->execute($extension->getModuleName()),
|
||||
'title' => $extensionInformation->getTitle(),
|
||||
'platform' => 'm2',
|
||||
];
|
||||
|
||||
$xml = $this->externalConnector->connect('https://' . Urls::PINGBACK_URL . '/session/', $data);
|
||||
$cacheTime = (int) ($res['cache_time'] ?? 0);
|
||||
if ($cacheTime > 0) {
|
||||
$expiration = $cacheTime;
|
||||
}
|
||||
$key = $xml['data'] ?? '';
|
||||
} catch (Exception $e) {
|
||||
if ($this->config->isDebugMode()) {
|
||||
throw new LocalizedException(__($e->getMessage()), null, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return [$key, $expiration];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization\Key;
|
||||
|
||||
use Magento\Config\Model\ResourceModel\Config;
|
||||
use Magento\Framework\App\Cache\TypeListInterface;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface;
|
||||
use Plumrocket\Base\Model\Extension\Authorization\Key;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Update
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Key\Load
|
||||
*/
|
||||
private $loadKey;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Status\Update
|
||||
*/
|
||||
private $updateStatus;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Key
|
||||
*/
|
||||
private $key;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\Cache\TypeListInterface
|
||||
*/
|
||||
private $cacheTypeList;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Event\ManagerInterface
|
||||
*/
|
||||
private $eventManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Config\Model\ResourceModel\Config
|
||||
*/
|
||||
private $resourceModelConfig;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Key\Load $loadKey
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Status\Update $updateStatus
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Key $key
|
||||
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
|
||||
* @param \Magento\Framework\Event\ManagerInterface $eventManager
|
||||
* @param \Magento\Config\Model\ResourceModel\Config $resourceModelConfig
|
||||
* @param \Plumrocket\Base\Helper\Config $config\
|
||||
*/
|
||||
public function __construct(
|
||||
Load $loadKey,
|
||||
\Plumrocket\Base\Model\Extension\Authorization\Status\Update $updateStatus,
|
||||
Key $key,
|
||||
TypeListInterface $cacheTypeList,
|
||||
ManagerInterface $eventManager,
|
||||
Config $resourceModelConfig,
|
||||
\Plumrocket\Base\Helper\Config $config
|
||||
) {
|
||||
$this->loadKey = $loadKey;
|
||||
$this->updateStatus = $updateStatus;
|
||||
$this->key = $key;
|
||||
$this->cacheTypeList = $cacheTypeList;
|
||||
$this->eventManager = $eventManager;
|
||||
$this->resourceModelConfig = $resourceModelConfig;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load new key and update status
|
||||
*
|
||||
* @param \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface $extension
|
||||
* @return \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface
|
||||
*/
|
||||
public function execute(ExtensionAuthorizationInterface $extension): ExtensionAuthorizationInterface
|
||||
{
|
||||
try {
|
||||
list($key, $expirationDays) = $this->loadKey->execute($extension);
|
||||
$this->key->set($extension->getModuleName(), $key);
|
||||
|
||||
$this->resourceModelConfig->saveConfig(
|
||||
$this->key->getPath($extension->getModuleName()),
|
||||
$key,
|
||||
'default',
|
||||
0
|
||||
);
|
||||
|
||||
// clear the config cache
|
||||
$this->cacheTypeList->cleanType('config');
|
||||
$this->eventManager->dispatch('adminhtml_cache_refresh_type', ['type' => 'config']);
|
||||
|
||||
return $this->updateStatus->execute($extension, null, $expirationDays);
|
||||
} catch (LocalizedException $localizedException) {
|
||||
if ($this->config->isDebugMode()) {
|
||||
throw $localizedException;
|
||||
}
|
||||
}
|
||||
|
||||
return $extension;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization;
|
||||
|
||||
use Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Message
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Key
|
||||
*/
|
||||
private $authorizationKey;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Key $authorizationKey
|
||||
*/
|
||||
public function __construct(Key $authorizationKey)
|
||||
{
|
||||
$this->authorizationKey = $authorizationKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive product description
|
||||
*
|
||||
* @param \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface $authorization
|
||||
* @return string
|
||||
*/
|
||||
public function get(ExtensionAuthorizationInterface $authorization): string
|
||||
{
|
||||
if ($authorization->isAuthorized()) {
|
||||
return 'Congratulations! Your serial key is now activated. ' .
|
||||
'Thank you for choosing Plumrocket Inc as your Magento extension provider!';
|
||||
}
|
||||
|
||||
if (! $this->authorizationKey->get($authorization->getModuleName())) {
|
||||
return 'Serial key is missing. Please login to your account at ' .
|
||||
'<a target="_blank" href="https://plumrocket.com/downloadable/customer/products">' .
|
||||
'https://plumrocket.com' .
|
||||
'</a> to copy your serial key for this product. ' .
|
||||
'Read this <a target="_blank" href="https://plumrocket.com/docs/general/magento-license-installation">' .
|
||||
'wiki article</a> for more info.';
|
||||
}
|
||||
|
||||
if (! $authorization->isAuthorized()) {
|
||||
if ($authorization->getStatus() === 503) {
|
||||
return 'Your serial key is not valid for Magento Enterprise Edition. ' .
|
||||
'Please purchase Magento Enterprise Edition license for this product at ' .
|
||||
'<a href="https://plumrocket.com" target="_blank">https://plumrocket.com</a>';
|
||||
}
|
||||
|
||||
return 'Serial key is not valid for this domain. Please go to ' .
|
||||
'<a href="https://plumrocket.com" target="_blank">https://plumrocket.com</a> ' .
|
||||
'to purchase new license for live site. ' .
|
||||
'Testing or development subdomains can be added to your license free of charge. Read this ' .
|
||||
'<a href="https://plumrocket.com/docs/general/updating-license-domains" target="_blank">wiki ' .
|
||||
'article</a> for more info.';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization;
|
||||
|
||||
use Exception;
|
||||
use Magento\Backend\Model\Auth\Session;
|
||||
use Magento\Framework\App\CacheInterface;
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Magento\Framework\Util;
|
||||
use Plumrocket\Base\Model\Extension\GetInstallationType;
|
||||
use Plumrocket\Base\Api\ExtensionAuthorizationRepositoryInterface;
|
||||
use Plumrocket\Base\Api\ExtensionInformationListInterface;
|
||||
use Plumrocket\Base\Helper\Config;
|
||||
use Plumrocket\Base\Model\Extension\Authorization\Status\Calculate;
|
||||
use Plumrocket\Base\Model\Extension\Authorization\Status\Update;
|
||||
use Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey;
|
||||
use Plumrocket\Base\Model\Extension\Status\Disable;
|
||||
use Plumrocket\Base\Model\Extension\Status\IsEnabledOnAnyStoreView;
|
||||
use Plumrocket\Base\Model\External\Connector;
|
||||
use Plumrocket\Base\Model\External\Urls;
|
||||
use Plumrocket\Base\Model\Utils\GetEnabledStoresUrls;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Reindex
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Backend\Model\Auth\Session
|
||||
*/
|
||||
private $backendAuthSession;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\CacheInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ProductMetadataInterface
|
||||
*/
|
||||
private $productMetadata;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Utils\GetEnabledStoresUrls
|
||||
*/
|
||||
private $getEnabledStoresUrls;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\ExtensionInformationListInterface
|
||||
*/
|
||||
private $extensionInformationList;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\ExtensionAuthorizationRepositoryInterface
|
||||
*/
|
||||
private $extensionAuthorizationRepository;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Status\IsEnabledOnAnyStoreView
|
||||
*/
|
||||
private $isEnabledOnAnyStoreView;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey
|
||||
*/
|
||||
private $getTrueCustomerKey;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Key
|
||||
*/
|
||||
private $authorizationKey;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\External\Connector
|
||||
*/
|
||||
private $externalConnector;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Status\Calculate
|
||||
*/
|
||||
private $calculateStatus;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Factory
|
||||
*/
|
||||
private $extensionAuthorizationFactory;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Status\Update
|
||||
*/
|
||||
private $updateStatus;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Status\Disable
|
||||
*/
|
||||
private $disableExtension;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\GetInstallationType
|
||||
*/
|
||||
private $getInstallType;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Util
|
||||
*/
|
||||
private $magentoUtil;
|
||||
|
||||
/**
|
||||
* @param \Magento\Backend\Model\Auth\Session $backendAuthSession
|
||||
* @param \Plumrocket\Base\Helper\Config $config
|
||||
* @param \Magento\Framework\App\CacheInterface $cache
|
||||
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
|
||||
* @param \Plumrocket\Base\Model\Utils\GetEnabledStoresUrls $getEnabledStoresUrls
|
||||
* @param \Plumrocket\Base\Api\ExtensionInformationListInterface $extensionInformationList
|
||||
* @param \Plumrocket\Base\Api\ExtensionAuthorizationRepositoryInterface $extensionAuthorizationRepository
|
||||
* @param \Plumrocket\Base\Model\Extension\Status\IsEnabledOnAnyStoreView $isEnabledOnAnyStoreView
|
||||
* @param \Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey $getTrueCustomerKey
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Key $authorizationKey
|
||||
* @param \Plumrocket\Base\Model\External\Connector $externalConnector
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Status\Calculate $calculateStatus
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Factory $extensionAuthorizationFactory
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Status\Update $updateStatus
|
||||
* @param \Plumrocket\Base\Model\Extension\Status\Disable $disableExtension
|
||||
* @param \Plumrocket\Base\Model\Extension\GetInstallationType $getInstallType
|
||||
* @param \Magento\Framework\Util $magentoUtil
|
||||
*/
|
||||
public function __construct(
|
||||
Session $backendAuthSession,
|
||||
Config $config,
|
||||
CacheInterface $cache,
|
||||
ProductMetadataInterface $productMetadata,
|
||||
GetEnabledStoresUrls $getEnabledStoresUrls,
|
||||
ExtensionInformationListInterface $extensionInformationList,
|
||||
ExtensionAuthorizationRepositoryInterface $extensionAuthorizationRepository,
|
||||
IsEnabledOnAnyStoreView $isEnabledOnAnyStoreView,
|
||||
GetTrueCustomerKey $getTrueCustomerKey,
|
||||
Key $authorizationKey,
|
||||
Connector $externalConnector,
|
||||
Calculate $calculateStatus,
|
||||
Factory $extensionAuthorizationFactory,
|
||||
Update $updateStatus,
|
||||
Disable $disableExtension,
|
||||
GetInstallationType $getInstallType,
|
||||
Util $magentoUtil
|
||||
) {
|
||||
$this->backendAuthSession = $backendAuthSession;
|
||||
$this->config = $config;
|
||||
$this->cache = $cache;
|
||||
$this->productMetadata = $productMetadata;
|
||||
$this->getEnabledStoresUrls = $getEnabledStoresUrls;
|
||||
$this->extensionInformationList = $extensionInformationList;
|
||||
$this->extensionAuthorizationRepository = $extensionAuthorizationRepository;
|
||||
$this->isEnabledOnAnyStoreView = $isEnabledOnAnyStoreView;
|
||||
$this->getTrueCustomerKey = $getTrueCustomerKey;
|
||||
$this->authorizationKey = $authorizationKey;
|
||||
$this->externalConnector = $externalConnector;
|
||||
$this->calculateStatus = $calculateStatus;
|
||||
$this->extensionAuthorizationFactory = $extensionAuthorizationFactory;
|
||||
$this->updateStatus = $updateStatus;
|
||||
$this->disableExtension = $disableExtension;
|
||||
$this->getInstallType = $getInstallType;
|
||||
$this->magentoUtil = $magentoUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reindex installed extensions.
|
||||
*
|
||||
* @return void
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function execute(): void
|
||||
{
|
||||
$time = time();
|
||||
$session = $this->backendAuthSession;
|
||||
|
||||
$cacheKey = 'Plumrocket_base_reindex';
|
||||
|
||||
if (! $session->isLoggedIn()
|
||||
|| (86400 + $session->getPBProductReindex() > $time)
|
||||
|| (86400 + ((int) $this->cache->load($cacheKey)) > $time)
|
||||
) {
|
||||
if (! $this->config->isDebugMode()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
'edition' => $this->productMetadata->getEdition(),
|
||||
'products' => [],
|
||||
'base_urls' => $this->getEnabledStoresUrls->execute(),
|
||||
'platform' => 'm2',
|
||||
'magento_version' => $this->productMetadata->getVersion(),
|
||||
'php_version' => $this->magentoUtil->getTrimmedPhpVersion(),
|
||||
];
|
||||
$activeModules = [];
|
||||
foreach ($this->extensionInformationList->getList()->getItems() as $extensionInformation) {
|
||||
$moduleName = $extensionInformation->getModuleName();
|
||||
try {
|
||||
$isCached = $this->extensionAuthorizationRepository->get($moduleName)->isCached();
|
||||
} catch (NoSuchEntityException $e) {
|
||||
$isCached = false;
|
||||
}
|
||||
|
||||
if ($isCached || ! $this->isEnabledOnAnyStoreView->execute($moduleName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$activeModules[$moduleName] = $moduleName;
|
||||
$data['products'][$moduleName] = [
|
||||
$moduleName,
|
||||
$extensionInformation->getInstalledVersion(),
|
||||
$this->getTrueCustomerKey->execute($moduleName) ?: 0,
|
||||
$this->authorizationKey->get($moduleName) ?: 0,
|
||||
$extensionInformation->getTitle(),
|
||||
$this->getInstallType->execute($moduleName),
|
||||
];
|
||||
}
|
||||
|
||||
if (count($activeModules)) {
|
||||
try {
|
||||
$xml = $this->externalConnector->connect('https://' . Urls::PINGBACK_URL . '/extensions/', $data);
|
||||
if (! isset($xml['statuses'])) {
|
||||
throw new LocalizedException(__('Statuses are missing.'), null, 1);
|
||||
}
|
||||
$statuses = $xml['statuses'];
|
||||
} catch (Exception $e) {
|
||||
if ($this->config->isDebugMode()) {
|
||||
throw new LocalizedException(__($e->getMessage()), null, 1);
|
||||
}
|
||||
$statuses = [];
|
||||
foreach ($activeModules as $moduleName) {
|
||||
$statuses[$moduleName] = $this->calculateStatus->execute($moduleName);
|
||||
}
|
||||
}
|
||||
foreach ($activeModules as $moduleName) {
|
||||
try {
|
||||
$authorization = $this->extensionAuthorizationRepository->get($moduleName);
|
||||
} catch (NoSuchEntityException $e) {
|
||||
$authorization = $this->extensionAuthorizationFactory->create($moduleName);
|
||||
}
|
||||
|
||||
$status = $statuses[$moduleName] ?? 301;
|
||||
$authorization = $this->updateStatus->execute($authorization, $status);
|
||||
if (! $authorization->isAuthorized()) {
|
||||
$this->disableExtension->execute($authorization->getModuleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->cache->save($time, $cacheKey);
|
||||
$session->setPBProductReindex($time);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization;
|
||||
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface;
|
||||
use Plumrocket\Base\Api\ExtensionAuthorizationRepositoryInterface;
|
||||
use Plumrocket\Base\Model\ResourceModel\ExtensionAuthorization;
|
||||
|
||||
class Repository implements ExtensionAuthorizationRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var ExtensionAuthorizationInterface[]
|
||||
*/
|
||||
private $cache = [];
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Signature
|
||||
*/
|
||||
private $signature;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Factory
|
||||
*/
|
||||
private $extensionAuthorizationFactory;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\ResourceModel\ExtensionAuthorization
|
||||
*/
|
||||
private $resourceModel;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Signature $signature
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Factory $extensionAuthorizationFactory
|
||||
* @param \Plumrocket\Base\Model\ResourceModel\ExtensionAuthorization $resourceModel
|
||||
*/
|
||||
public function __construct(
|
||||
Signature $signature,
|
||||
Factory $extensionAuthorizationFactory,
|
||||
ExtensionAuthorization $resourceModel
|
||||
) {
|
||||
$this->signature = $signature;
|
||||
$this->extensionAuthorizationFactory = $extensionAuthorizationFactory;
|
||||
$this->resourceModel = $resourceModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(string $moduleName): ExtensionAuthorizationInterface
|
||||
{
|
||||
if (! isset($this->cache[$moduleName])) {
|
||||
$this->resourceModel->deleteOld(); // remove old records before loading
|
||||
$signature = $this->signature->create($moduleName);
|
||||
$authorization = $this->extensionAuthorizationFactory->create($moduleName);
|
||||
$this->resourceModel->load($authorization, $signature, ExtensionAuthorizationInterface::SIGNATURE);
|
||||
if (! $authorization->getId()) {
|
||||
throw new NoSuchEntityException(
|
||||
__("The extension authorization that was requested doesn't exist. Verify the module and try again.")
|
||||
);
|
||||
}
|
||||
|
||||
$this->cache[$moduleName] = $authorization;
|
||||
}
|
||||
return $this->cache[$moduleName];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface|Data\ExtensionAuthorization $extension
|
||||
* @return \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface
|
||||
* @throws \Magento\Framework\Exception\AlreadyExistsException
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
*/
|
||||
public function save(ExtensionAuthorizationInterface $extension): ExtensionAuthorizationInterface
|
||||
{
|
||||
unset($this->cache[$extension->getModuleName()]);
|
||||
$this->resourceModel->save($extension);
|
||||
return $this->get($extension->getModuleName());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization;
|
||||
|
||||
use Magento\Framework\Encryption\Encryptor;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Signature
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Key
|
||||
*/
|
||||
private $key;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Encryption\Encryptor
|
||||
*/
|
||||
private $encryptor;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Key $key
|
||||
* @param \Magento\Framework\Encryption\Encryptor $encryptor
|
||||
*/
|
||||
public function __construct(Key $key, Encryptor $encryptor)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->encryptor = $encryptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $moduleName
|
||||
* @return string
|
||||
*/
|
||||
public function create(string $moduleName): string
|
||||
{
|
||||
return $this->encryptor->hash(
|
||||
$moduleName . $this->key->get($moduleName),
|
||||
Encryptor::HASH_VERSION_MD5
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization\Status;
|
||||
|
||||
use Plumrocket\Base\Model\Extension\Authorization\Key;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Calculate
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Key
|
||||
*/
|
||||
private $key;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Key $key
|
||||
*/
|
||||
public function __construct(Key $key)
|
||||
{
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check key.
|
||||
*
|
||||
* @param string $moduleName
|
||||
* @return int
|
||||
*/
|
||||
public function execute(string $moduleName): int
|
||||
{
|
||||
return strlen($this->key->get($moduleName)) === 32 ? 500 : 201;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization\Status;
|
||||
|
||||
use Exception;
|
||||
use Magento\Framework\App\ProductMetadataInterface;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Util;
|
||||
use Plumrocket\Base\Api\GetExtensionInformationInterface;
|
||||
use Plumrocket\Base\Helper\Config;
|
||||
use Plumrocket\Base\Model\Extension\Authorization\Key;
|
||||
use Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey;
|
||||
use Plumrocket\Base\Model\External\Connector;
|
||||
use Plumrocket\Base\Model\External\Urls;
|
||||
use Plumrocket\Base\Model\Utils\GetEnabledStoresUrls;
|
||||
use Plumrocket\Base\Model\Extension\GetInstallationType;
|
||||
|
||||
/**
|
||||
* Get status from store
|
||||
*
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Load
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Utils\GetEnabledStoresUrls
|
||||
*/
|
||||
private $getEnabledStoresUrls;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
|
||||
*/
|
||||
private $getExtensionInformation;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey
|
||||
*/
|
||||
private $getTrueCustomerKey;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ProductMetadataInterface
|
||||
*/
|
||||
private $productMetadata;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\External\Connector
|
||||
*/
|
||||
private $externalConnector;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Helper\Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Key
|
||||
*/
|
||||
private $authorizationKey;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Status\Calculate
|
||||
*/
|
||||
private $calculateStatus;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\GetInstallationType
|
||||
*/
|
||||
private $getInstallType;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Util
|
||||
*/
|
||||
private $magentoUtil;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Utils\GetEnabledStoresUrls $getEnabledStoresUrls
|
||||
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
|
||||
* @param \Plumrocket\Base\Model\Extension\Customer\GetTrueCustomerKey $getTrueCustomerKey
|
||||
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
|
||||
* @param \Plumrocket\Base\Model\External\Connector $externalConnector
|
||||
* @param \Plumrocket\Base\Helper\Config $config
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Key $authorizationKey
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Status\Calculate $calculateStatus
|
||||
* @param \Plumrocket\Base\Model\Extension\GetInstallationType $getInstallType
|
||||
* @param \Magento\Framework\Util $magentoUtil
|
||||
*/
|
||||
public function __construct(
|
||||
GetEnabledStoresUrls $getEnabledStoresUrls,
|
||||
GetExtensionInformationInterface $getExtensionInformation,
|
||||
GetTrueCustomerKey $getTrueCustomerKey,
|
||||
ProductMetadataInterface $productMetadata,
|
||||
Connector $externalConnector,
|
||||
Config $config,
|
||||
Key $authorizationKey,
|
||||
Calculate $calculateStatus,
|
||||
GetInstallationType $getInstallType,
|
||||
Util $magentoUtil
|
||||
) {
|
||||
$this->getEnabledStoresUrls = $getEnabledStoresUrls;
|
||||
$this->getExtensionInformation = $getExtensionInformation;
|
||||
$this->getTrueCustomerKey = $getTrueCustomerKey;
|
||||
$this->productMetadata = $productMetadata;
|
||||
$this->externalConnector = $externalConnector;
|
||||
$this->config = $config;
|
||||
$this->authorizationKey = $authorizationKey;
|
||||
$this->calculateStatus = $calculateStatus;
|
||||
$this->getInstallType = $getInstallType;
|
||||
$this->magentoUtil = $magentoUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load extension status.
|
||||
*
|
||||
* @param string $moduleName
|
||||
* @return int
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function execute(string $moduleName): int
|
||||
{
|
||||
$extensionInformation = $this->getExtensionInformation->execute($moduleName);
|
||||
try {
|
||||
$params = [
|
||||
'edition' => $this->productMetadata->getEdition(),
|
||||
'session' => $this->authorizationKey->get($moduleName),
|
||||
'base_urls' => $this->getEnabledStoresUrls->execute(),
|
||||
'name' => $extensionInformation->getModuleName(),
|
||||
'name_version' => $extensionInformation->getInstalledVersion(),
|
||||
'customer' => $this->getTrueCustomerKey->execute($moduleName),
|
||||
'title' => $extensionInformation->getTitle(),
|
||||
'platform' => 'm2',
|
||||
'magento_version' => $this->productMetadata->getVersion(),
|
||||
'installation' => $this->getInstallType->execute($moduleName),
|
||||
'php_version' => $this->magentoUtil->getTrimmedPhpVersion(),
|
||||
];
|
||||
|
||||
$xml = $this->externalConnector->connect('https://' . Urls::PINGBACK_URL . '/extension/', $params);
|
||||
if (empty($xml['status'])) {
|
||||
throw new LocalizedException(__('Status is missing.'), null, 1);
|
||||
}
|
||||
$status = (int) $xml['status'];
|
||||
} catch (Exception $e) {
|
||||
if ($this->config->isDebugMode()) {
|
||||
throw new LocalizedException(__($e->getMessage()), null, 1);
|
||||
}
|
||||
$status = $this->calculateStatus->execute($moduleName);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization\Status;
|
||||
|
||||
use Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface;
|
||||
|
||||
/**
|
||||
* Get new status from store
|
||||
*
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Refresh
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Status\Load
|
||||
*/
|
||||
private $loadStatus;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Status\Update
|
||||
*/
|
||||
private $updateStatus;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Status\Load $loadStatus
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Status\Update $updateStatus
|
||||
*/
|
||||
public function __construct(
|
||||
Load $loadStatus,
|
||||
Update $updateStatus
|
||||
) {
|
||||
$this->loadStatus = $loadStatus;
|
||||
$this->updateStatus = $updateStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface $extensionAuthorization
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function execute(ExtensionAuthorizationInterface $extensionAuthorization)
|
||||
{
|
||||
$status = $this->loadStatus->execute($extensionAuthorization->getModuleName());
|
||||
if ($extensionAuthorization->getStatus() !== $status) {
|
||||
$this->updateStatus->execute($extensionAuthorization, $status);
|
||||
}
|
||||
|
||||
return $extensionAuthorization;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_Base
|
||||
* @copyright Copyright (c) 2021 Plumrocket Inc. (https://plumrocket.com)
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\Base\Model\Extension\Authorization\Status;
|
||||
|
||||
use Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface;
|
||||
use Plumrocket\Base\Api\ExtensionAuthorizationRepositoryInterface;
|
||||
use Plumrocket\Base\Model\Extension\Authorization\Signature;
|
||||
|
||||
/**
|
||||
* @since 2.5.0
|
||||
*/
|
||||
class Update
|
||||
{
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Signature
|
||||
*/
|
||||
private $signature;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\ExtensionAuthorizationRepositoryInterface
|
||||
*/
|
||||
private $extensionAuthorizationRepository;
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Model\Extension\Authorization\Status\Calculate
|
||||
*/
|
||||
private $calculateStatus;
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Signature $signature
|
||||
* @param \Plumrocket\Base\Api\ExtensionAuthorizationRepositoryInterface $extensionAuthorizationRepository
|
||||
* @param \Plumrocket\Base\Model\Extension\Authorization\Status\Calculate $calculateStatus
|
||||
*/
|
||||
public function __construct(
|
||||
Signature $signature,
|
||||
ExtensionAuthorizationRepositoryInterface $extensionAuthorizationRepository,
|
||||
Calculate $calculateStatus
|
||||
) {
|
||||
$this->signature = $signature;
|
||||
$this->extensionAuthorizationRepository = $extensionAuthorizationRepository;
|
||||
$this->calculateStatus = $calculateStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface $authorization
|
||||
* @param int $cacheLifetime
|
||||
* @param int|null $status
|
||||
* @return \Plumrocket\Base\Api\Data\ExtensionAuthorizationInterface
|
||||
*/
|
||||
public function execute(
|
||||
ExtensionAuthorizationInterface $authorization,
|
||||
?int $status = null,
|
||||
int $cacheLifetime = 3
|
||||
): ExtensionAuthorizationInterface {
|
||||
$authorization->setSignature($this->signature->create($authorization->getModuleName()));
|
||||
$authorization->setStatus($status ?? $this->calculateStatus->execute($authorization->getModuleName()));
|
||||
$authorization->setDate(date('Y-m-d H:i:s', time() + $cacheLifetime * 86400));
|
||||
return $this->extensionAuthorizationRepository->save($authorization);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user