Skip to content

Commit

Permalink
Fix env.php sync issue when enabling/disabling the profiler on Magent…
Browse files Browse the repository at this point in the history
…o 2.4.4
  • Loading branch information
guvra committed Jul 6, 2022
1 parent 5b29704 commit ccfecbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## WIP

- Fix env.php sync issue when enabling/disabling the profiler on Magento 2.4.4

## [5.2.0] - 2022-04-15
[5.2.0]: https://github.com/Smile-SA/magento2-module-debug-toolbar/compare/5.1.2...5.2.0

Expand Down
20 changes: 10 additions & 10 deletions Observer/EnableDbProfiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ public function __construct(
* @inheritdoc
* @throws FileSystemException
* @throws RuntimeException
* @SuppressWarnings(PHPMD.ElseExpression)
*/
public function execute(Observer $observer)
{
$env = $this->deploymentConfigReader->load(ConfigFilePool::APP_ENV);
$defaultConnection = $env['db']['connection']['default'];
$enabled = $this->configHelper->isEnabled();

// We still have the old value before the config was saved, so if it was modified, we reverse it
$changedPaths = $observer->getEvent()->getData('changed_paths');
if (in_array(ConfigHelper::KEY_CONFIG_ENABLE, $changedPaths, true)) {
$enabled = !$enabled;
}

unset($env['db']['connection']['default']['profiler']);

if ($enabled) {
$env['db']['connection']['default']['profiler'] = [
$defaultConnection['profiler'] = [
'class' => DbProfiler::class,
'enabled' => true,
];
} else {
unset($defaultConnection['profiler']);
}

$this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_ENV => $env], true);
// Update deployment config only if it was modified
if ($defaultConnection !== $env['db']['connection']['default']) {
$env['db']['connection']['default'] = $defaultConnection;
$this->deploymentConfigWriter->saveConfig([ConfigFilePool::APP_ENV => $env], true);
}
}
}

0 comments on commit ccfecbd

Please sign in to comment.