ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user