Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Profiler/Console/Command/EnableCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$this->config->enableProfiler();

$output->writeln('<info>Status: ' . ($this->config->isEnabled() ? 'Enabled' : 'Disabled') . '</info>');
}
}
3 changes: 3 additions & 0 deletions src/Profiler/Console/Command/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->appState->setAreaCode('empty');
}catch (LocalizedException $e){}

$output->writeln('<info>Clearing cache...</info>');
$this->config->clearCache();

$output->writeln('<info>Status: ' . ($this->config->isEnabled() ? 'Enabled' : 'Disabled') . '</info>');
$output->writeln('<info>IPs: ' . implode(', ', $this->config->getAddressInfo()) . '</info>');
}
Expand Down
38 changes: 24 additions & 14 deletions src/Profiler/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -36,38 +37,50 @@ 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;
}

/**
* @return bool
*/
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -150,5 +160,5 @@ public function getDumpPath()
}

return $path;
}
}
}