diff --git a/src/Profiler/Console/Command/EnableCommand.php b/src/Profiler/Console/Command/EnableCommand.php index 95291e0..6f371b1 100644 --- a/src/Profiler/Console/Command/EnableCommand.php +++ b/src/Profiler/Console/Command/EnableCommand.php @@ -47,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $this->config->enableProfiler(); - + $output->writeln('Status: ' . ($this->config->isEnabled() ? 'Enabled' : 'Disabled') . ''); } } diff --git a/src/Profiler/Console/Command/StatusCommand.php b/src/Profiler/Console/Command/StatusCommand.php index 2d8e6ce..e6901f5 100644 --- a/src/Profiler/Console/Command/StatusCommand.php +++ b/src/Profiler/Console/Command/StatusCommand.php @@ -46,6 +46,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->appState->setAreaCode('empty'); }catch (LocalizedException $e){} + $output->writeln('Clearing cache...'); + $this->config->clearCache(); + $output->writeln('Status: ' . ($this->config->isEnabled() ? 'Enabled' : 'Disabled') . ''); $output->writeln('IPs: ' . implode(', ', $this->config->getAddressInfo()) . ''); } diff --git a/src/Profiler/Model/Config.php b/src/Profiler/Model/Config.php index 9174907..53645a7 100644 --- a/src/Profiler/Model/Config.php +++ b/src/Profiler/Model/Config.php @@ -7,6 +7,7 @@ use Magento\Framework\Config\File\ConfigFilePool; use Magento\Config\Model\Config\Factory as ConfigFactory; use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\App\ResourceConnection; class Config { @@ -36,19 +37,26 @@ class Config * @var DirectoryList */ private $directoryList; + private $_configWriter; + + protected $resourceConnection; public function __construct( DeploymentConfigWriter $deploymentConfigWriter, DeploymentConfigReader $deploymentConfigReader, ScopeConfigInterface $scopeConfig, ConfigFactory $configFactory, - DirectoryList $directoryList + DirectoryList $directoryList, + \Magento\Framework\App\Config\Storage\WriterInterface $configWriter, + ResourceConnection $resourceConnection ) { $this->deploymentConfigWriter = $deploymentConfigWriter; $this->deploymentConfigReader = $deploymentConfigReader; $this->scopeConfig = $scopeConfig; $this->configFactory = $configFactory; $this->directoryList = $directoryList; + $this->_configWriter = $configWriter; + $this->resourceConnection = $resourceConnection; } /** @@ -56,18 +64,23 @@ public function __construct( */ public function isEnabled() { - return (bool)$this->scopeConfig->getValue('profiler/general/enable'); + $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT; + $scopeId = 0; + + $connection = $this->resourceConnection->getConnection(); + $table = $connection->getTableName('core_config_data'); + $query = sprintf("SELECT value FROM `%s` WHERE path = 'profiler/general/enable' and scope = '%s' and scope_id = '%d'", $table, $scope, $scopeId); + $result = $connection->fetchOne($query); + + return (bool)$result; } /** * @return bool */ public function enableProfiler() - { - $config = $this->configFactory->create(); - $config->setDataByPath('profiler/general/enable', true); - $config->save(); - + { + $this->_configWriter->save('profiler/general/enable', '1', $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); $this->enableDbProfiler(); return true; @@ -77,11 +90,8 @@ public function enableProfiler() * @return bool */ public function disableProfiler() - { - $config = $this->configFactory->create(); - $config->setDataByPath('profiler/general/enable', false); - $config->save(); - + { + $this->_configWriter->save('profiler/general/enable', '0', $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); $this->disableDbProfiler(); return true; @@ -139,7 +149,7 @@ public function getAddressInfo() { $addresses = $this->scopeConfig->getValue('profiler/general/addresses'); - return array_filter(explode(',', $addresses)); + return array_filter(explode(',', $addresses ?? '')); } public function getDumpPath() @@ -150,5 +160,5 @@ public function getDumpPath() } return $path; - } + } } \ No newline at end of file