ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -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);
}
}
@@ -0,0 +1,88 @@
<?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\Config;
use Magento\Framework\Config\ConverterInterface;
use Magento\Framework\Data\Argument\Interpreter\Boolean as BooleanInterpreter;
use Plumrocket\Base\Api\Data\ExtensionInformationInterface;
class Converter implements ConverterInterface
{
/**
* @var BooleanInterpreter
*/
private $booleanInterpreter;
/**
* @param \Magento\Framework\Data\Argument\Interpreter\Boolean $booleanInterpreter
*/
public function __construct(BooleanInterpreter $booleanInterpreter)
{
$this->booleanInterpreter = $booleanInterpreter;
}
/**
* Convert dom node tree to array
*
* @param \DOMDocument $source
* @return array
*/
public function convert($source)
{
$output = [];
/** @var \DOMNodeList $extensions */
$extensions = $source->getElementsByTagName('extension');
/** @var \DOMNode $extension */
foreach ($extensions as $extension) {
$extensionConfig = [
ExtensionInformationInterface::FIELD_CONFIG_SECTION => '',
ExtensionInformationInterface::FIELD_IS_ENABLED_PATH => '',
ExtensionInformationInterface::FIELD_DOCUMENTATION => '',
ExtensionInformationInterface::FIELD_WIKI => '',
ExtensionInformationInterface::FIELD_IS_SERVICE => false,
ExtensionInformationInterface::FIELD_URL => '',
ExtensionInformationInterface::FIELD_MARKETPLACE_URL => '',
'customer' => ['key' => ''],
'metapackage' => ['composer_name' => '', 'directory' => ''],
];
/** @var \DOMAttr $attribute */
foreach ($extension->attributes as $attribute) {
$value = $attribute->nodeValue;
if ($attribute->nodeName === ExtensionInformationInterface::FIELD_IS_SERVICE) {
$value = $this->booleanInterpreter->evaluate(['value' => $value]);
}
$extensionConfig[$attribute->nodeName] = $value;
}
$extensionConfig = $this->addCustomerData($extension, $extensionConfig);
$output[$extension->attributes->getNamedItem('name')->nodeValue] = $extensionConfig;
}
return $output;
}
private function addCustomerData(\DOMNode $extension, array $extensionConfig): array
{
if ($extension->hasChildNodes()) {
/** @var \DOMNode $childNode */
foreach ($extension->childNodes as $childNode) {
if ($childNode->nodeType === XML_ELEMENT_NODE) {
/** @var \DOMAttr $attribute */
foreach ($childNode->attributes as $attribute) {
$extensionConfig[$childNode->nodeName][$attribute->nodeName] = $attribute->nodeValue;
}
}
}
}
return $extensionConfig;
}
}
@@ -0,0 +1,45 @@
<?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\Customer;
use Magento\Framework\Config\DataInterface;
/**
* Reads customer key from pr_extensions.xml
*
* @since 2.5.0
*/
class GetKey
{
/**
* @var \Magento\Framework\Config\DataInterface
*/
private $extensionsConfig;
/**
* @param \Magento\Framework\Config\DataInterface $extensionsConfig
*/
public function __construct(
DataInterface $extensionsConfig
) {
$this->extensionsConfig = $extensionsConfig;
}
/**
* Get customer key.
*
* @param string $moduleName e.g. SocialLoginFree
* @return string
*/
public function execute(string $moduleName): string
{
return (string) $this->extensionsConfig->get("$moduleName/customer/key");
}
}
@@ -0,0 +1,83 @@
<?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\Customer;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Plumrocket\Base\Model\Extension\GetModuleName;
/**
* Retrieve true customer key when customer had bought extension from marketplace
*
* @since 2.5.0
*/
class GetTrueCustomerKey
{
/**
* @var \Plumrocket\Base\Model\Extension\Customer\GetKey
*/
private $getKey;
/**
* @var \Plumrocket\Base\Model\Extension\Customer\IsMarketplaceKey
*/
private $isMarketplaceKey;
/**
* @var \Plumrocket\Base\Model\Extension\GetModuleName
*/
private $getModuleName;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;
/**
* @param \Plumrocket\Base\Model\Extension\Customer\GetKey $getKey
* @param \Plumrocket\Base\Model\Extension\Customer\IsMarketplaceKey $isMarketplaceKey
* @param \Plumrocket\Base\Model\Extension\GetModuleName $getModuleName
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
GetKey $getKey,
IsMarketplaceKey $isMarketplaceKey,
GetModuleName $getModuleName,
ScopeConfigInterface $scopeConfig
) {
$this->getKey = $getKey;
$this->isMarketplaceKey = $isMarketplaceKey;
$this->getModuleName = $getModuleName;
$this->scopeConfig = $scopeConfig;
}
/**
* @param string $moduleName e.g. SocialLoginFree or Plumrocket_SocialLoginFree
* @return string
*/
public function execute(string $moduleName): string
{
$moduleName = $this->getModuleName->execute($moduleName);
$customerKey = $this->getKey->execute($moduleName);
if ($this->isMarketplaceKey->execute($customerKey)) {
$customerKey = $this->getFromConfig($moduleName) ?: $customerKey;
}
return $customerKey;
}
/**
* @param string $moduleName e.g. SocialLoginFree
* @return string
*/
private function getFromConfig(string $moduleName): string
{
return (string) $this->scopeConfig->getValue("$moduleName/module/data");
}
}
@@ -0,0 +1,25 @@
<?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\Customer;
/**
* Check whether customer key is marketplace
*
* @since 2.5.0
*/
class IsMarketplaceKey
{
const MARKETPLACE_CUSTOMER_KEY = '532416486b540ea2a1e50c4070b671611b44f52718';
public function execute(string $customerKey): bool
{
return self::MARKETPLACE_CUSTOMER_KEY === $customerKey;
}
}
@@ -0,0 +1,62 @@
<?php
/**
* @package Plumrocket_Base
* @copyright Copyright (c) 2022 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\Base\Model\Extension;
use Magento\Framework\Module\Dir\Reader;
use Magento\Framework\Module\Dir;
/**
* @since 2.8.4
*/
class GetInstallationType
{
public const NON_COMPOSER_EXTENSION_PATH = 'app/code/Plumrocket';
public const NON_COMPOSER_INSTALL_TYPE = 'non-composer';
public const COMPOSER_INSTALL_TYPE = 'composer';
/**
* @var Reader
*/
private $moduleDirReader;
/**
* @var \Plumrocket\Base\Model\Extension\GetModuleName
*/
private $getModuleName;
/**
* @param Reader $moduleDirReader
* @param \Plumrocket\Base\Model\Extension\GetModuleName $getModuleName
*/
public function __construct(
Reader $moduleDirReader,
GetModuleName $getModuleName
) {
$this->moduleDirReader = $moduleDirReader;
$this->getModuleName = $getModuleName;
}
/**
* Detect installation type of the Plumrocket extensions
*
* @param string $moduleName
* @return string
*/
public function execute(string $moduleName): string
{
$moduleName = 'Plumrocket_' . $this->getModuleName->execute($moduleName);
$etcDirPath = $this->moduleDirReader->getModuleDir(Dir::MODULE_ETC_DIR, $moduleName);
return strpos($etcDirPath, self::NON_COMPOSER_EXTENSION_PATH) !== false
? self::NON_COMPOSER_INSTALL_TYPE : self::COMPOSER_INSTALL_TYPE;
}
}
@@ -0,0 +1,56 @@
<?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;
use Magento\Framework\Module\ModuleListInterface;
/**
* Retrieve names of installed plumrocket extensions
* For example ['Base', 'SocialLoginFree']
*
* @since 2.3.0
*/
class GetListOfInstalled
{
/**
* @var \Magento\Framework\Module\ModuleListInterface
*/
private $moduleList;
/**
* GetPlumrocketInstalledExtensions constructor.
*
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
*/
public function __construct(ModuleListInterface $moduleList)
{
$this->moduleList = $moduleList;
}
/**
* Get list of installed plumrocket extensions.
*
* @return string[] only module name, without vendor name
*/
public function execute(): array
{
$plumrocketModuleNames = [];
foreach ($this->moduleList->getNames() as $moduleFullName) {
[$vendor, $module] = explode('_', $moduleFullName);
if ('Plumrocket' !== $vendor) {
continue;
}
$plumrocketModuleNames[] = $module;
}
return $plumrocketModuleNames;
}
}
@@ -0,0 +1,33 @@
<?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;
/**
* Get name "SocialLoginFree" from "Plumrocket_SocialLoginFree" or "SocialLoginFree"
*
* @since 2.3.7
*/
class GetModuleName
{
/**
* Remove Plumrocket_ from Plumrocket_ModuleName.
*
* @param string $maybeModuleFullName
* @return string
*/
public function execute(string $maybeModuleFullName): string
{
if (false === strpos($maybeModuleFullName, '_')) {
return $maybeModuleFullName;
}
return explode('_', $maybeModuleFullName)[1];
}
}
@@ -0,0 +1,202 @@
<?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\Information;
use Magento\Framework\DataObject;
use Plumrocket\Base\Api\Data\ExtensionInformationInterface;
use Plumrocket\Base\Api\GetModuleVersionInterface;
/**
* Container for information about extension that parsed from "pr_extensions.xml"
*
* Can be used for old extension which has not xml file
* and does not realize \Plumrocket\Base\Api\ModuleInformationInterface
*
* @since 2.5.0
*/
class Container extends DataObject implements ExtensionInformationInterface
{
/**
* @var \Plumrocket\Base\Api\GetModuleVersionInterface
*/
private $getModuleVersion;
/**
* @param \Plumrocket\Base\Api\GetModuleVersionInterface $getModuleVersion
* @param array $data
*/
public function __construct(
GetModuleVersionInterface $getModuleVersion,
array $data = []
) {
parent::__construct($data);
$this->getModuleVersion = $getModuleVersion;
}
/**
* @inheritDoc
*/
public function isService(): bool
{
return (bool) $this->_getData(self::FIELD_IS_SERVICE);
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return (string) $this->_getData(self::FIELD_TITLE);
}
/**
* @inheritDoc
*/
public function getDocumentationLink(): string
{
return (string) ($this->_getData(self::FIELD_DOCUMENTATION) ?: $this->_getData(self::FIELD_WIKI));
}
/**
* @inheritDoc
*/
public function getWikiLink(): string
{
return $this->getDocumentationLink();
}
/**
* @inheritDoc
*/
public function getUrl(): string
{
return (string) $this->_getData(self::FIELD_URL);
}
/**
* @inheritDoc
*/
public function getMarketplaceUrl(): string
{
return (string) $this->_getData(self::FIELD_MARKETPLACE_URL);
}
/**
* @inheritDoc
*/
public function getConfigSection(): string
{
return (string) $this->_getData(self::FIELD_CONFIG_SECTION);
}
/**
* @inheritDoc
*/
public function getIsEnabledFieldConfigPath(): string
{
return (string) $this->_getData(self::FIELD_IS_ENABLED_PATH);
}
/**
* @inheritDoc
*/
public function getModuleName(): string
{
return (string) $this->_getData(self::FIELD_MODULE_NAME);
}
/**
* @inheritDoc
*/
public function getVendorAndModuleName(): string
{
return "Plumrocket_{$this->getModuleName()}";
}
/**
* @inheritDoc
*/
public function getInstalledVersion(): string
{
return $this->getModuleVersion->execute($this->getVendorAndModuleName());
}
/**
* @inheritDoc
*/
public function setIsService(bool $isService): ExtensionInformationInterface
{
return $this->setData(self::FIELD_IS_SERVICE, $isService);
}
/**
* @inheritDoc
*/
public function setTitle(string $title): ExtensionInformationInterface
{
return $this->setData(self::FIELD_TITLE, $title);
}
/**
* @inheritDoc
*/
public function setConfigSection(string $configSection): ExtensionInformationInterface
{
return $this->setData(self::FIELD_CONFIG_SECTION, $configSection);
}
/**
* @inheritDoc
*/
public function setDocumentationLink(string $documentationLink): ExtensionInformationInterface
{
return $this->setData(self::FIELD_DOCUMENTATION, $documentationLink);
}
/**
* @inheritDoc
*/
public function setWikiLink(string $wikiLink): ExtensionInformationInterface
{
return $this->setDocumentationLink($wikiLink);
}
/**
* @inheritDoc
*/
public function setUrl(string $extensionUrl): ExtensionInformationInterface
{
return $this->setData(self::FIELD_URL, $extensionUrl);
}
/**
* @inheritDoc
*/
public function setMarketplaceUrl(string $extensionMarketplaceUrl): ExtensionInformationInterface
{
return $this->setData(self::FIELD_MARKETPLACE_URL, $extensionMarketplaceUrl);
}
/**
* @inheritDoc
*/
public function setModuleName(string $moduleName): ExtensionInformationInterface
{
return $this->setData(self::FIELD_MODULE_NAME, $moduleName);
}
/**
* @inheritDoc
*/
public function setIsEnabledFieldConfigPath(string $configPath): ExtensionInformationInterface
{
return $this->setData(self::FIELD_IS_ENABLED_PATH, $configPath);
}
}
@@ -0,0 +1,113 @@
<?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\Information;
use Magento\Framework\Config\DataInterface;
use Magento\Framework\Module\ModuleListInterface;
use Plumrocket\Base\Api\Data\ExtensionInformationInterface;
use Plumrocket\Base\Api\GetExtensionInformationInterface;
use Plumrocket\Base\Model\Extension\GetModuleName;
use Plumrocket\Base\Model\Extension\Information\ContainerFactory;
/**
* @since 2.3.0
*/
class Get implements GetExtensionInformationInterface
{
/**
* @var string[]
*/
private $services = [
'Base',
'Token',
'AmpEmailApi',
];
/**
* @var \Plumrocket\Base\Api\Data\ExtensionInformationInterface[]
*/
private $extensions;
/**
* @var \Plumrocket\Base\Model\Extension\Information\ContainerFactory
*/
private $informationContainerFactory;
/**
* @var \Plumrocket\Base\Model\Extension\GetModuleName
*/
private $getExtensionName;
/**
* @var \Magento\Framework\Config\DataInterface
*/
private $extensionsConfig;
/**
* @var \Magento\Framework\Module\ModuleListInterface
*/
private $moduleList;
/**
* @param \Plumrocket\Base\Model\Extension\Information\ContainerFactory $informationContainerFactory
* @param \Plumrocket\Base\Model\Extension\GetModuleName $getExtensionName
* @param \Magento\Framework\Config\DataInterface $extensionsConfig
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* @param array $extensions
*/
public function __construct(
ContainerFactory $informationContainerFactory,
GetModuleName $getExtensionName,
DataInterface $extensionsConfig,
ModuleListInterface $moduleList,
array $extensions = []
) {
$this->extensions = $extensions;
$this->informationContainerFactory = $informationContainerFactory;
$this->getExtensionName = $getExtensionName;
$this->extensionsConfig = $extensionsConfig;
$this->moduleList = $moduleList;
}
/**
* @inheritDoc
*/
public function execute(string $moduleName): ExtensionInformationInterface
{
$moduleName = $this->getExtensionName->execute($moduleName);
if (! isset($this->extensions[$moduleName])) {
/** @var \Plumrocket\Base\Model\Extension\Information\Container $infoContainer */
$infoContainer = $this->informationContainerFactory->create();
$infoContainer->setModuleName($moduleName);
if ($extensionConfig = $this->extensionsConfig->get($moduleName)) {
$infoContainer->setIsService($extensionConfig[ExtensionInformationInterface::FIELD_IS_SERVICE])
->setModuleName($extensionConfig['name'])
->setTitle($extensionConfig['title'])
->setConfigSection($extensionConfig['config_section'])
->setIsEnabledFieldConfigPath($extensionConfig['is_enabled_path'])
->setDocumentationLink($extensionConfig['documentation'] ?: $extensionConfig['wiki'])
->setUrl($extensionConfig[ExtensionInformationInterface::FIELD_URL] ?? '')
->setMarketplaceUrl(
$extensionConfig[ExtensionInformationInterface::FIELD_MARKETPLACE_URL] ?? ''
);
} else {
if ($this->moduleList->has("Plumrocket_$moduleName")) {
$infoContainer->setIsService(in_array($moduleName, $this->services, true));
}
}
$this->extensions[$moduleName] = $infoContainer;
}
return $this->extensions[$moduleName];
}
}
@@ -0,0 +1,88 @@
<?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\Information;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Api\SearchResultsInterface;
use Plumrocket\Base\Api\Data\ExtensionInformationSearchResultsInterfaceFactory;
use Plumrocket\Base\Api\ExtensionInformationListInterface;
use Plumrocket\Base\Api\GetExtensionInformationInterface;
use Plumrocket\Base\Model\Extension\GetListOfInstalled;
/**
* @since 2.5.0
*/
class ListProvider implements ExtensionInformationListInterface
{
/**
* @var \Magento\Framework\Api\SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;
/**
* @var \Plumrocket\Base\Api\Data\ExtensionInformationSearchResultsInterfaceFactory
*/
private $searchResultsFactory;
/**
* @var \Plumrocket\Base\Model\Extension\GetListOfInstalled
*/
private $getListOfInstalledExtensions;
/**
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
*/
private $getExtensionInformation;
/**
* @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder
* @param \Plumrocket\Base\Api\Data\ExtensionInformationSearchResultsInterfaceFactory $searchResultsFactory
* @param \Plumrocket\Base\Model\Extension\GetListOfInstalled $getListOfInstalledExtensions
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
*/
public function __construct(
SearchCriteriaBuilder $searchCriteriaBuilder,
ExtensionInformationSearchResultsInterfaceFactory $searchResultsFactory,
GetListOfInstalled $getListOfInstalledExtensions,
GetExtensionInformationInterface $getExtensionInformation
) {
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->searchResultsFactory = $searchResultsFactory;
$this->getListOfInstalledExtensions = $getListOfInstalledExtensions;
$this->getExtensionInformation = $getExtensionInformation;
}
/**
* @inheritDoc
*/
public function getList(?SearchCriteriaInterface $searchCriteria = null): SearchResultsInterface
{
if (null === $searchCriteria) {
$searchCriteria = $this->searchCriteriaBuilder->create();
}
$extensionsNames = $this->getListOfInstalledExtensions->execute();
$informationList = [];
foreach ($extensionsNames as $extensionsName) {
$informationList[] = $this->getExtensionInformation->execute($extensionsName);
}
/** @var \Plumrocket\Base\Api\Data\ExtensionInformationSearchResultsInterface $searchResults */
$searchResults = $this->searchResultsFactory->create();
$searchResults->setItems($informationList);
$searchResults->setTotalCount(count($informationList));
$searchResults->setSearchCriteria($searchCriteria);
return $searchResults;
}
}
@@ -0,0 +1,93 @@
<?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;
use Magento\Config\Model\Config\Structure\Data as ConfigStructureData;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
use Plumrocket\Base\Api\Data\ExtensionInformationInterface;
use Plumrocket\Base\Api\GetExtensionInformationInterface;
/**
* @since 2.5.0
*/
class IsPaid
{
/**
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
*/
private $getExtensionInformation;
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var ConfigStructureData
*/
private $systemXmlStructure;
/**
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param ConfigStructureData $configStructureData
*/
public function __construct(
GetExtensionInformationInterface $getExtensionInformation,
ScopeConfigInterface $scopeConfig,
ConfigStructureData $configStructureData
) {
$this->getExtensionInformation = $getExtensionInformation;
$this->scopeConfig = $scopeConfig;
$this->systemXmlStructure = $configStructureData;
}
/**
* Check if the extension is paid.
*
* @param string $moduleName
* @return bool
*/
public function execute(string $moduleName): bool
{
$extensionInformation = $this->getExtensionInformation->execute($moduleName);
return $this->hasSerialKey($extensionInformation) || $this->hasDeclaredSerialKeyField($extensionInformation);
}
/**
* Check if the extension has empty or not serial key value.
*
* @param \Plumrocket\Base\Api\Data\ExtensionInformationInterface $extensionInformation
* @return bool
*/
private function hasSerialKey(ExtensionInformationInterface $extensionInformation): bool
{
$generalConfigurations = $this->scopeConfig->getValue(
"{$extensionInformation->getConfigSection()}/general",
ScopeInterface::SCOPE_STORE,
0
);
return is_array($generalConfigurations) && array_key_exists('serial', $generalConfigurations);
}
/**
* Check if the serial key field is exists in system.xml
*
* @param \Plumrocket\Base\Api\Data\ExtensionInformationInterface $extensionInformation
* @return bool
*/
private function hasDeclaredSerialKeyField(ExtensionInformationInterface $extensionInformation): bool
{
return (bool) $this->systemXmlStructure->get(
"sections/{$extensionInformation->getConfigSection()}/children/general/children/serial"
);
}
}
@@ -0,0 +1,123 @@
<?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\Status;
use Magento\Config\Model\Config;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\ObjectManagerInterface;
use Plumrocket\Base\Api\GetExtensionInformationInterface;
use Plumrocket\Base\Model\Extension\Status\Disable\Logger;
/**
* @since 2.3.7
*/
class Disable
{
/**
* @var \Magento\Config\Model\Config
*/
private $config;
/**
* @var \Magento\Framework\App\ResourceConnection
*/
private $resourceConnection;
/**
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
*/
private $getExtensionInformation;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* @var \Plumrocket\Base\Model\Extension\Status\Disable\Logger
*/
private $disableExtensionLogger;
/**
* @param \Magento\Config\Model\Config $config
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param \Plumrocket\Base\Model\Extension\Status\Disable\Logger $disableExtensionLogger
*/
public function __construct(
Config $config,
ResourceConnection $resourceConnection,
GetExtensionInformationInterface $getExtensionInformation,
ObjectManagerInterface $objectManager,
Logger $disableExtensionLogger
) {
$this->config = $config;
$this->resourceConnection = $resourceConnection;
$this->getExtensionInformation = $getExtensionInformation;
$this->objectManager = $objectManager;
$this->disableExtensionLogger = $disableExtensionLogger;
}
/**
* @param string $moduleName
* @param string $description
* @return bool
*/
public function execute(string $moduleName, string $description = ''): bool
{
// TODO: remove usage of 'disableExtension' after finished integration with all extensions
$helper = $this->getHelper($moduleName);
if ($helper && method_exists($helper, 'disableExtension')) {
$helper->disableExtension();
$this->disableExtensionLogger->log($moduleName, $description);
return true;
}
$configPath = $this->getExtensionInformation->execute($moduleName)->getIsEnabledFieldConfigPath();
if (! $configPath) {
return false;
}
$connection = $this->resourceConnection->getConnection('core_write');
$connection->delete(
$this->resourceConnection->getTableName('core_config_data'),
[
$connection->quoteInto('path = ?', $configPath)
]
);
$this->disableExtensionLogger->log($moduleName, $description);
try {
$this->config->setDataByPath($configPath, 0);
$this->config->save();
return true;
} catch (\Exception $e) {
return false;
}
}
/**
* Receive data helper
*
* @param string $moduleName
* @return \Magento\Framework\App\Helper\AbstractHelper|false
*/
private function getHelper(string $moduleName)
{
$type = "Plumrocket\\{$moduleName}\Helper\Data";
try {
return $this->objectManager->get($type);
} catch (\ReflectionException $reflectionException) {
return false;
}
}
}
@@ -0,0 +1,58 @@
<?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\Status\Disable;
use Plumrocket\Base\Model\External\LastRequests;
use Psr\Log\LoggerInterface;
/**
* Logger for the extension disabling reason.
*
* If one of the plumrocket extensions disabled, we need have the opportunity to get know who have done it.
* So we add logger that track all disabling due to bad licence, store problem, etc.
*
* @since 2.5.7
*/
class Logger
{
/**
* @var \Plumrocket\Base\Model\External\LastRequests
*/
private $lastRequests;
/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;
/**
* @param \Plumrocket\Base\Model\External\LastRequests $lastRequests
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(
LastRequests $lastRequests,
LoggerInterface $logger
) {
$this->lastRequests = $lastRequests;
$this->logger = $logger;
}
public function log(string $moduleName, string $description = '')
{
$logMessage = "$moduleName was disabled, for details see the request data and the backtrace below";
$logMessage .= $description ? "\nDescription: $description" : '';
$logMessage .= "\nConnector Requests Data: " . json_encode($this->lastRequests->getList());
$logMessage .= "\n" . (new \Exception)->getTraceAsString();
/** Use exception.log as module disabling is critical */
$this->logger->critical(new \Exception($logMessage));
// TODO: add admin notification
}
}
@@ -0,0 +1,99 @@
<?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\Status;
use Magento\Framework\Module\Manager as ModuleManager;
use Magento\Framework\Module\ModuleListInterface;
use Plumrocket\Base\Api\ExtensionStatusInterface;
use Plumrocket\Base\Api\GetExtensionInformationInterface;
use Plumrocket\Base\Api\GetExtensionStatusInterface;
use Plumrocket\Base\Model\ConfigUtils;
use Plumrocket\Base\Model\Extension\GetModuleName;
/**
* Class GetModuleVersion
*
* @since 2.3.9
*/
class Get implements GetExtensionStatusInterface
{
/**
* @var ModuleManager
*/
private $moduleManager;
/**
* @var \Magento\Framework\Module\ModuleListInterface
*/
private $fullModuleList;
/**
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
*/
private $getExtensionInformation;
/**
* @var \Plumrocket\Base\Model\ConfigUtils
*/
private $configUtils;
/**
* @var \Plumrocket\Base\Model\Extension\GetModuleName
*/
private $getModuleName;
/**
* @param \Magento\Framework\Module\Manager $moduleManager
* @param \Magento\Framework\Module\ModuleListInterface $fullModuleList
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
* @param \Plumrocket\Base\Model\ConfigUtils $configUtils
* @param \Plumrocket\Base\Model\Extension\GetModuleName $getModuleName
*/
public function __construct(
ModuleManager $moduleManager,
ModuleListInterface $fullModuleList,
GetExtensionInformationInterface $getExtensionInformation,
ConfigUtils $configUtils,
GetModuleName $getModuleName
) {
$this->moduleManager = $moduleManager;
$this->fullModuleList = $fullModuleList;
$this->getExtensionInformation = $getExtensionInformation;
$this->configUtils = $configUtils;
$this->getModuleName = $getModuleName;
}
/**
* Retrieve status of Plumrocket module
*
* @param string $moduleName
* @return int
*/
public function execute(string $moduleName): int
{
$moduleName = $this->getModuleName->execute($moduleName);
$hasModule = $this->moduleManager->isEnabled("Plumrocket_$moduleName");
if (! $hasModule) {
return $this->fullModuleList->has("Plumrocket_$moduleName")
? ExtensionStatusInterface::DISABLED_FROM_CLI
: ExtensionStatusInterface::NOT_INSTALLED;
}
$extensionInformation = $this->getExtensionInformation->execute($moduleName);
if ($isEnabledConfigPath = $extensionInformation->getIsEnabledFieldConfigPath()) {
return $this->configUtils->isSetFlag($isEnabledConfigPath)
? ExtensionStatusInterface::ENABLED
: ExtensionStatusInterface::DISABLED;
}
return ExtensionStatusInterface::ENABLED;
}
}
@@ -0,0 +1,86 @@
<?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\Status;
use Magento\Store\Model\StoreManager;
use Plumrocket\Base\Api\GetExtensionInformationInterface;
use Plumrocket\Base\Model\ConfigUtils;
use Plumrocket\Base\Model\Extension\GetModuleName;
/**
* Check if module is enabled in configurations on any store view
*
* @since 2.5.0
*/
class IsEnabledOnAnyStoreView
{
/**
* @var \Magento\Store\Model\StoreManager
*/
private $storeManager;
/**
* @var \Plumrocket\Base\Model\Extension\GetModuleName
*/
private $getExtensionName;
/**
* @var \Plumrocket\Base\Api\GetExtensionInformationInterface
*/
private $getExtensionInformation;
/**
* @var \Plumrocket\Base\Model\ConfigUtils
*/
private $configUtils;
/**
* @param \Magento\Store\Model\StoreManager $storeManager
* @param \Plumrocket\Base\Model\Extension\GetModuleName $getExtensionName
* @param \Plumrocket\Base\Api\GetExtensionInformationInterface $getExtensionInformation
* @param \Plumrocket\Base\Model\ConfigUtils $configUtils
*/
public function __construct(
StoreManager $storeManager,
GetModuleName $getExtensionName,
GetExtensionInformationInterface $getExtensionInformation,
ConfigUtils $configUtils
) {
$this->storeManager = $storeManager;
$this->getExtensionName = $getExtensionName;
$this->getExtensionInformation = $getExtensionInformation;
$this->configUtils = $configUtils;
}
/**
* Check if module is enabled on any store view.
*
* @param string $moduleName
* @return bool
*/
public function execute(string $moduleName): bool
{
$moduleName = $this->getExtensionName->execute($moduleName);
$configPath = $this->getExtensionInformation->execute($moduleName)->getIsEnabledFieldConfigPath();
foreach ($this->storeManager->getStores() as $store) {
if (! $store->getIsActive()) {
continue;
}
if ($configPath && $this->configUtils->getStoreConfig($configPath, $store->getId())) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,76 @@
<?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\Status;
use Plumrocket\Base\Api\ExtensionStatusInterface;
use Plumrocket\Base\Model\Extension\GetModuleName;
/**
* @since 2.4.1
*/
class Provider implements ExtensionStatusInterface
{
/**
* @var \Plumrocket\Base\Model\Extension\Status\Get
*/
private $getExtensionStatus;
/**
* @var \Plumrocket\Base\Model\Extension\GetModuleName
*/
private $getExtensionName;
/**
* @param \Plumrocket\Base\Model\Extension\Status\Get $getExtensionStatus
* @param \Plumrocket\Base\Model\Extension\GetModuleName $getExtensionName
*/
public function __construct(
Get $getExtensionStatus,
GetModuleName $getExtensionName
) {
$this->getExtensionStatus = $getExtensionStatus;
$this->getExtensionName = $getExtensionName;
}
/**
* @inheritDoc
*/
public function isEnabled(string $moduleName): bool
{
return self::ENABLED === $this->getExtensionStatus->execute($this->getExtensionName->execute($moduleName));
}
/**
* @inheritDoc
*/
public function isDisabled(string $moduleName): bool
{
return self::DISABLED === $this->getExtensionStatus->execute($this->getExtensionName->execute($moduleName));
}
/**
* @inheritDoc
*/
public function isDisabledFromCli(string $moduleName): bool
{
$status = $this->getExtensionStatus->execute($this->getExtensionName->execute($moduleName));
return self::DISABLED_FROM_CLI === $status;
}
/**
* @inheritDoc
*/
public function isNotInstalled(string $moduleName): bool
{
$status = $this->getExtensionStatus->execute($this->getExtensionName->execute($moduleName));
return self::NOT_INSTALLED === $status;
}
}
@@ -0,0 +1,159 @@
<?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\Updates;
use Magento\Framework\Config\DataInterface;
use Plumrocket\Base\Api\GetModuleVersionInterface;
use Plumrocket\Base\Model\Extension\Updates\Load as LoadUpdates;
/**
* @since 2.3.0
*/
class Get
{
/**
* @var \Plumrocket\Base\Api\GetModuleVersionInterface
*/
private $getModuleVersion;
/**
* @var LoadUpdates
*/
private $loadUpdates;
/**
* @var \Magento\Framework\Config\DataInterface
*/
private $extensionsConfig;
/**
* GetUpdates constructor.
*
* @param \Plumrocket\Base\Api\GetModuleVersionInterface $getModuleVersion
* @param \Plumrocket\Base\Model\Extension\Updates\Load $loadUpdates
* @param \Magento\Framework\Config\DataInterface $extensionsConfig
*/
public function __construct(
GetModuleVersionInterface $getModuleVersion,
LoadUpdates $loadUpdates,
DataInterface $extensionsConfig
) {
$this->getModuleVersion = $getModuleVersion;
$this->loadUpdates = $loadUpdates;
$this->extensionsConfig = $extensionsConfig;
}
/**
* Get available updates with changelogs.
*
* @param array $extensions
* @return array
* @throws \Magento\Framework\Exception\NotFoundException if we cannot fetch file with updates
*/
public function execute(array $extensions): array
{
$result = [];
$updates = $this->loadUpdates->execute();
foreach ($extensions as $extensionName) {
if (($metapackageName = $this->getMetapackageName($extensionName)) && isset($updates[$metapackageName])) {
$changeLogSource = $metapackageName;
} else {
$changeLogSource = $extensionName;
}
if (isset($updates[$extensionName])) {
$extensionUpdates = $this->fixBrokenStructure($updates[$changeLogSource]);
$result[$extensionName] = $this->extractNewReleases(
$this->getModuleVersion->execute("Plumrocket_{$extensionName}"),
$extensionUpdates
);
} else {
$result[$extensionName] = [];
}
}
return $result;
}
/**
* Filter installed versions.
*
* @param string $currentVersion
* @param array $updatesInfo
* @return array
*/
private function extractNewReleases(string $currentVersion, array $updatesInfo): array
{
return array_filter(
$updatesInfo['changelogs'],
static function ($changelog) use ($currentVersion) {
return version_compare($currentVersion, $changelog['version'], '<');
}
);
}
/**
* Fix xml structure.
*
* When new version has only one changelog, xml can be broken during convert from array.
* We detect and fix it here.
*
* @param array $updatesInfo
* @return array
*/
public function fixBrokenStructure(array $updatesInfo): array
{
if (! isset($updatesInfo['changelogs'])) {
$updatesInfo['changelogs'] = [];
return $updatesInfo;
}
if (isset($updatesInfo['changelogs']['version'])) {
$updatesInfo['changelogs'] = [$updatesInfo['changelogs']];
}
$updatesInfo['changelogs'] = $this->fixChangelogsStructure($updatesInfo['changelogs']);
return $updatesInfo;
}
/**
* Fix xml structure.
*
* @param array $changelogs
* @return array
*/
private function fixChangelogsStructure(array $changelogs): array
{
return array_map(
static function ($changelog) {
if (isset($changelog['changes']['type'])) {
$changelog['changes'] = [$changelog['changes']];
}
return $changelog;
},
$changelogs
);
}
/**
* Get metapackage name.
*
* @param string $moduleName
* @return string
*/
private function getMetapackageName(string $moduleName): string
{
return (string) $this->extensionsConfig->get("$moduleName/metapackage/directory");
}
}
@@ -0,0 +1,68 @@
<?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\Updates;
use Plumrocket\Base\Model\Extension\GetModuleName;
use Plumrocket\Base\Model\External\Urls;
/**
* @since 2.5.0
* @deprecated since 2.8.0 - no more used
*/
class GetLastVersionMessage
{
/**
* @var \Plumrocket\Base\Model\Extension\GetModuleName
*/
private $getModuleName;
/**
* @param \Plumrocket\Base\Model\Extension\GetModuleName $getModuleName
*/
public function __construct(GetModuleName $getModuleName)
{
$this->getModuleName = $getModuleName;
}
public function execute(string $moduleName): array
{
$moduleName = $this->getModuleName->execute($moduleName);
$xmlPath = 'https://' . Urls::VERSIONS_URL;
$message = '';
$version = '';
try {
$context = stream_context_create(
[
'http' => [
'timeout' => 2,
'ignore_errors' => true,
],
]
);
$string = file_get_contents($xmlPath, false, $context);
if ($string && $moduleName) {
$xml = simplexml_load_string($string);
if ($xml && isset($xml->Magento2->{$moduleName})) {
$extData = $xml->Magento2->{$moduleName} ?? null;
if ($extData !== null && isset($extData->message, $extData->version)) {
$message = (string)$extData->message;
$version = (string)$extData->version;
}
}
}
} catch (\Exception $e) {}
return ['message' => $message, 'newv' => $version];
}
}
@@ -0,0 +1,92 @@
<?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\Updates;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NotFoundException;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Framework\Xml\Parser;
use Plumrocket\Base\Model\External\Urls;
/**
* Retrieve information in format
* [moduleName => data]
*
* @since 2.3.0
*/
class Load
{
/**
* @var \Magento\Framework\Filesystem\DriverInterface
*/
private $httpsDriver;
/**
* @var array[]
*/
private $updates;
/**
* @var \Magento\Framework\Xml\Parser
*/
private $xmlParser;
/**
* Load constructor.
*
* @param \Magento\Framework\Filesystem\DriverInterface $httpsDriver
* @param \Magento\Framework\Xml\Parser $xmlParser
*/
public function __construct(DriverInterface $httpsDriver, Parser $xmlParser)
{
$this->httpsDriver = $httpsDriver;
$this->xmlParser = $xmlParser;
}
/**
* @return array|array[]|string
* @throws \Magento\Framework\Exception\NotFoundException
*/
public function execute()
{
if (null === $this->updates) {
$this->updates = [];
if ($fileContent = $this->readInternalFile()) {
try {
$updates = $this->xmlParser->loadXML($fileContent)->xmlToArray();
if (isset($updates['modules'])) {
$this->updates = $updates['modules'];
}
} catch (LocalizedException $e) {
$this->updates = [];
}
}
}
return $this->updates;
}
/**
* @return string
* @throws \Magento\Framework\Exception\NotFoundException
*/
private function readInternalFile() : string
{
try {
$fileContent = $this->httpsDriver->fileGetContents(Urls::CHANGELOGS_URL, null, stream_context_create(['ssl'=>['verify_peer'=>false,'verify_peer_name'=>false]]));
} catch (FileSystemException $e) {
throw new NotFoundException(__('Fail to fetch latest versions of Plumrocket extensions.'));
}
return $fileContent;
}
}