From fe7881200f1347e5dfd6372ec1803f09bdc639be Mon Sep 17 00:00:00 2001 From: Michael Mussulis Date: Sun, 16 Apr 2023 11:23:44 -0400 Subject: [PATCH 1/2] Fixed php 8.1 compatiblity and added clearing cache function --- src/Profiler/Model/Config.php | 51 +++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Profiler/Model/Config.php b/src/Profiler/Model/Config.php index 9174907..0ab7a4d 100644 --- a/src/Profiler/Model/Config.php +++ b/src/Profiler/Model/Config.php @@ -1,6 +1,10 @@ deploymentConfigWriter = $deploymentConfigWriter; $this->deploymentConfigReader = $deploymentConfigReader; $this->scopeConfig = $scopeConfig; $this->configFactory = $configFactory; $this->directoryList = $directoryList; + $this->_configWriter = $configWriter; + $this->cacheTypeList = $cacheTypeList; + $this->cacheFrontendPool = $cacheFrontendPool; } /** @@ -67,8 +81,11 @@ public function enableProfiler() $config = $this->configFactory->create(); $config->setDataByPath('profiler/general/enable', true); $config->save(); + + //$this->_configWriter->save('profiler/general/enable', true, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); $this->enableDbProfiler(); + $this->clearCache(); return true; } @@ -82,7 +99,10 @@ public function disableProfiler() $config->setDataByPath('profiler/general/enable', false); $config->save(); + //$this->_configWriter->save('profiler/general/enable', false, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); + $this->disableDbProfiler(); + $this->clearCache(); return true; } @@ -139,7 +159,7 @@ public function getAddressInfo() { $addresses = $this->scopeConfig->getValue('profiler/general/addresses'); - return array_filter(explode(',', $addresses)); + return array_filter(explode(',', $addresses ?? '')); } public function getDumpPath() @@ -151,4 +171,31 @@ public function getDumpPath() return $path; } + + public function clearCache() + { + echo "Clearing cache...\n"; + + $_types = [ + 'config', + 'layout', + 'block_html', + 'collections', + 'reflection', + 'db_ddl', + 'eav', + 'config_integration', + 'config_integration_api', + 'full_page', + 'translate', + 'config_webservice' + ]; + + foreach ($_types as $type) { + $this->cacheTypeList->cleanType($type); + } + foreach ($this->cacheFrontendPool as $cacheFrontend) { + $cacheFrontend->getBackend()->clean(); + } + } } \ No newline at end of file From 1d2e2470b6b827b9c3872ebd4dd37b05b3c4721d Mon Sep 17 00:00:00 2001 From: Michael Mussulis Date: Mon, 17 Apr 2023 14:14:03 -0400 Subject: [PATCH 2/2] Fixed config variable caching --- .../Console/Command/EnableCommand.php | 2 +- .../Console/Command/StatusCommand.php | 3 + src/Profiler/Model/Config.php | 73 +++++-------------- 3 files changed, 22 insertions(+), 56 deletions(-) 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 0ab7a4d..53645a7 100644 --- a/src/Profiler/Model/Config.php +++ b/src/Profiler/Model/Config.php @@ -1,16 +1,13 @@ deploymentConfigWriter = $deploymentConfigWriter; $this->deploymentConfigReader = $deploymentConfigReader; @@ -61,8 +56,7 @@ public function __construct( $this->configFactory = $configFactory; $this->directoryList = $directoryList; $this->_configWriter = $configWriter; - $this->cacheTypeList = $cacheTypeList; - $this->cacheFrontendPool = $cacheFrontendPool; + $this->resourceConnection = $resourceConnection; } /** @@ -70,22 +64,24 @@ 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', true, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); - + { + $this->_configWriter->save('profiler/general/enable', '1', $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); $this->enableDbProfiler(); - $this->clearCache(); return true; } @@ -94,15 +90,9 @@ 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', false, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); - + { + $this->_configWriter->save('profiler/general/enable', '0', $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0); $this->disableDbProfiler(); - $this->clearCache(); return true; } @@ -170,32 +160,5 @@ public function getDumpPath() } return $path; - } - - public function clearCache() - { - echo "Clearing cache...\n"; - - $_types = [ - 'config', - 'layout', - 'block_html', - 'collections', - 'reflection', - 'db_ddl', - 'eav', - 'config_integration', - 'config_integration_api', - 'full_page', - 'translate', - 'config_webservice' - ]; - - foreach ($_types as $type) { - $this->cacheTypeList->cleanType($type); - } - foreach ($this->cacheFrontendPool as $cacheFrontend) { - $cacheFrontend->getBackend()->clean(); - } - } + } } \ No newline at end of file