ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -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