Magento - load local.xml based on the environment

I want to have 3 app/etc/local.xmlfiles - name them local.xml staging.xml and live.xml.

I want to load them based on an environment variable that I set in either vhosts or htaccess. This way, I can have separate databases, etc., but one code base that I can save under svn.

What would be the best way to achieve this?

+3
source share
1 answer

local.xml hardcoded in multiple Magento files.

So, if you want to implement your own choice of file name for this, you will have to redefine a few basic classes / methods / functions accordingly.

local.xml * , , , /app/Mage.php. , Mage ( final).

, /app/Mage.php, Magento .

,

Mage_Core_Model_Config
Mage_Core_Model_Layout_Update

, ,

Mage_Install_Model_Installer_Config
Mage_Adminhtml_Block_Notification_Security (1.5.1)

.

, . :

class Mynamespace_Mymodule_Helper_Data extends Mage_Core_Helper_Data
{
    public function getLocalXMLFileName()
    {
        return getenv('MY_XML') . 'xml';
    }    
}

, .

$updateFiles[] = 'local.xml';

$updateFiles[] = Mage::helper('mymodule')->getLocalXMLFileName();

* 1.3.2.x, 1.5.1 1.8.1.0. / .

1.3.2.x:

./app/code/core/Mage/Install/Model/Installer/Config.php:49:
    $this->_localConfigFile = Mage::getBaseDir('etc').DS.'local.xml';

./app/code/core/Mage/Core/Model/Layout/Update.php:283:
    $updateFiles[] = 'local.xml';

./app/code/core/Mage/Core/Model/Config.php:214:
    $localConfigLoaded  = $this->loadFile($etcDir.DS.'local.xml');

./app/code/core/Mage/Core/Model/Config.php:248:
    $configFile  = $etcDir.DS.'local.xml';

./app/Mage.php:521:
    $localConfigFile = self::getRoot() . DS . $etcDir . DS . 'local.xml';

1.5.1

./app/code/core/Mage/Install/Model/Installer/Config.php:49:
    $this->_localConfigFile = Mage::getBaseDir('etc').DS.'local.xml';

./app/code/core/Mage/Core/Model/Layout/Update.php:418:
    $updateFiles[] = 'local.xml';

./app/code/core/Mage/Core/Model/Config.php:280:
    if (in_array($etcDir.DS.'local.xml', $files)) {

./app/code/core/Mage/Core/Model/Config.php:322:
    $this->_isLocalConfigLoaded = $mergeConfig->
        loadFile($this->getOptions()->getEtcDir().DS.'local.xml');

./app/code/core/Mage/Adminhtml/Block/Notification/Security.php:36:
    private $_filePath = 'app/etc/local.xml';

./app/Mage.php:671:
    $localConfigFile = self::getRoot() . DS . $etcDir . DS . 'local.xml';

./errors/processor.php:34:
    const MAGE_ERRORS_LOCAL_XML = 'local.xml';

1.8.1.0:

./app/code/core/Mage/Install/Model/Installer/Config.php:49:
    $this->_localConfigFile = Mage::getBaseDir('etc') . DS . 'local.xml';

./app/code/core/Mage/Install/Model/Installer/Config.php:103:
    $template = file_get_contents(Mage::getBaseDir('etc') . DS . 'local.xml.template');

./app/code/core/Mage/Core/Model/Config.php:280:
    if (in_array($etcDir.DS.'local.xml', $files)) {

./app/code/core/Mage/Core/Model/Config.php:324:
    $this->_isLocalConfigLoaded =
        $mergeConfig->loadFile($this->getOptions()->getEtcDir().DS.'local.xml');

./app/code/core/Mage/Core/Model/Layout/Update.php:311:
    // $updateFiles[] = 'local.xml';

./app/code/core/Mage/Core/Model/Layout/Update.php:431:
    $updateFiles[] = 'local.xml';

./app/code/core/Mage/Adminhtml/Block/Notification/Security.php:36:
    private $_filePath = 'app/etc/local.xml';

./app/Mage.php:762:
    $localConfigFile = $etcDir . DS . 'local.xml';

./errors/processor.php:34:
   const MAGE_ERRORS_LOCAL_XML = 'local.xml';

>

+5

All Articles