Skip to content

Commit

Permalink
Prevent local.xml from being loaded from installed packages
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbeaty committed Dec 6, 2024
1 parent 170c73a commit 9339f89
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions app/code/core/Mage/Core/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
*/
protected $_prototype;

/**
* Reference to the Varien_Simplexml_Config object where local.xml was loaded in to
*/
protected Mage_Core_Model_Config_Base $_refLocalConfigObject;

/**
* Flag which identify what local configuration is loaded
*
Expand Down Expand Up @@ -323,6 +328,11 @@ public function init($options = [])
*/
public function loadBase()
{
// Prevent double loading of base config
if ($this->getNode() !== false) {
return;

Check failure on line 333 in app/code/core/Mage/Core/Model/Config.php

View workflow job for this annotation

GitHub Actions / Analyze PHP 8.2 (main)

Method Mage_Core_Model_Config::loadBase() should return $this(Mage_Core_Model_Config) but empty return statement found.

Check failure on line 333 in app/code/core/Mage/Core/Model/Config.php

View workflow job for this annotation

GitHub Actions / Analyze PHP 8.3 (main)

Method Mage_Core_Model_Config::loadBase() should return $this(Mage_Core_Model_Config) but empty return statement found.

Check failure on line 333 in app/code/core/Mage/Core/Model/Config.php

View workflow job for this annotation

GitHub Actions / Analyze PHP 8.4 (main)

Method Mage_Core_Model_Config::loadBase() should return $this(Mage_Core_Model_Config) but empty return statement found.

Check failure on line 333 in app/code/core/Mage/Core/Model/Config.php

View workflow job for this annotation

GitHub Actions / Analyze PHP 8.2 (topic-composer-plugin-v3)

Method Mage_Core_Model_Config::loadBase() should return $this(Mage_Core_Model_Config) but empty return statement found.

Check failure on line 333 in app/code/core/Mage/Core/Model/Config.php

View workflow job for this annotation

GitHub Actions / Analyze PHP 8.3 (topic-composer-plugin-v3)

Method Mage_Core_Model_Config::loadBase() should return $this(Mage_Core_Model_Config) but empty return statement found.

Check failure on line 333 in app/code/core/Mage/Core/Model/Config.php

View workflow job for this annotation

GitHub Actions / Analyze PHP 8.4 (topic-composer-plugin-v3)

Method Mage_Core_Model_Config::loadBase() should return $this(Mage_Core_Model_Config) but empty return statement found.
}

$files = [];

foreach (Maho::getInstalledPackages() as $package => $info) {
Expand All @@ -336,17 +346,17 @@ public function loadBase()
}

// Merge all config files
$this->loadFile(current($files));
while ($file = next($files)) {
$this->loadString('<?xml version="1.0"?><config></config>');
foreach ($files as $basename => $file) {
$merge = clone $this->_prototype;
$merge->loadFile($file);
if ($basename === 'local.xml') {
$this->_isLocalConfigLoaded = true;
$this->_refLocalConfigObject = $merge;
}
$this->extend($merge);
}

if (isset($files['local.xml'])) {
$this->_isLocalConfigLoaded = true;
}

return $this;
}

Expand Down Expand Up @@ -382,13 +392,9 @@ public function loadModules()
$resourceConfig = sprintf('config.%s.xml', $this->_getResourceConnectionModel('core'));
$this->loadModulesConfiguration(['config.xml', $resourceConfig], $this);

/**
* Prevent local.xml directives overwriting
*/
$mergeConfig = clone $this->_prototype;
$this->_isLocalConfigLoaded = $mergeConfig->loadFile($this->getOptions()->getEtcDir() . DS . 'local.xml');
// Prevent local.xml directives overwriting
if ($this->_isLocalConfigLoaded) {
$this->extend($mergeConfig);
$this->extend($this->_refLocalConfigObject);
}

$this->applyExtends();
Expand Down

0 comments on commit 9339f89

Please sign in to comment.