Magento: Static blocks and configuration settings migration
deployment, e-commerce, magento, php
Solution
You are right, values specified in the config xml files are overwritten by values from the `core_config_data` table. As B00MER pointed out, the code in question is in `Mage_Core_Model_Config::init()`:
public function init($options=array())
{
$this->setCacheChecksum(null);
$this->_cacheLoadedSections = array();
$this->setOptions($options);
$this->loadBase();
$cacheLoad = $this->loadModulesCache();
if ($cacheLoad) {
return $this;
}
$this->loadModules();
$this->loadDb();
$this->saveCache();
return $this;
}
Notice that `loadDb()` is called after `loadModules()`. The actual merging logic is in the config resource model `Mage_Core_Model_Resource_Config::loadToXml()`.
For each global setting this is called:
$xmlConfig->setNode('default/' . $r['path'], $value);
For each website scope setting this is called:
$nodePath = sprintf('websites/%s/%s', $websites[$r['scope_id']]['code'], $r['path']);
$xmlConfig->setNode($nodePath, $value);
For each website scope setting this is called:
$nodePath = sprintf('stores/%s/%s', $stores[$r['scope_id']]['code'], $r['path']);
$xmlConfig->setNode($nodePath, $value);
This is slightly simplified, but if you need more detail you can look at the source.
Problem
To migrate all changes to all environments I use database upgrade scripts. I use them to create different instances(customer, tax settings etc.) but usually to migrate static blocks and config settings. To migrate static blocks: ``` <?php $block = Mage::getModel('cms/block'); $data = array( 'title' => 'Block title', 'identifier' => 'block_identifier', 'content' => 'block content', 'is_active' => 1, 'stores' => array(0 => Mage_Core_Model_App::ADMIN_STORE_ID), ); $block->addData($data); $block->save(); ?> ``` To migrate settings: ``` <?php Mage::getModel('core/config')->saveConfig('design/theme/default', 'theme'); ?> ``` I know that we can modify Magento settings via config.xml: ``` <default> <general> <store_information> <name>My Store</name> </store_information> <content_staging> <block_frontend_stub>home</block_frontend_stub> </content_staging> </general> </default> ``` But as far as I understand we can modify settings in such way only if paths: general/store_information/name and general/content_staging/block_frontend_stub don't exists at db or their values equal NULL, if value not NULL we can't modify it via xml. I tested it on my local environment and I think I'm right but can't find a code at Magento which is responsible for setting configuration via xml. Am I right? Can you show me the part of code which is responsible for it? And what is your best migration practices for Magento? Maybe I don't know something :)