1

Magento will consider any declared module dependencies in app/etc/modules/Namespace_Module.xml when calculating runtime configuration values such as rewrites, events, etc. however it does not follow a similar process when sequencing module setup scripts. The setup scripts are executed in alphabetical order, which can cause issues when one module depends on setup scripts defined in a module that comes later in the alphabet.

The relevant code is in applyAllDataUpdates method of Mage_Core_Model_Resource_Setup:

    $resources = Mage::getConfig()->getNode('global/resources')->children();
    foreach ($resources as $resName => $resource) {
        <snip/>
        $setupClass->applyDataUpdates();
    }

Is there a safe/preferred/recommended option to ensure that necessary setup scripts have been executed prior to running the required scripts?

1
  • You mentioned on Twitter that the version was 1.5 - updated my answer with complete POC. Check your dependency argument? Commented Nov 30, 2012 at 12:16

1 Answer 1

3

I'm curious to know the use case, but I see module dependencies having effect in this area, which is to be expected, as all of the config files are loaded according to module declaration entry + dependency specification.

POC

Verified in 1.5.1.1:

app/etc/modules/a.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Foo_Module>
            <active>true</active>
            <codePool>local</codePool>
        </Foo_Module>
        <Mage_Eav>
            <depends>
                <Foo_Module />
            </depends>
        </Mage_Eav>
    </modules>
</config>

app/code/local/Foo/Module/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Foo_Module>
            <version>0.1</version>
        </Foo_Module>
    </modules>
    <global>
        <resources>
            <foo_module_setup>
                <setup>
                    <module>Foo_Module</module>
                </setup>
            </foo_module_setup>
        </resources>
    </global>
</config>

Mage_Core_Model_App:

public function run($params)
{
    $options = isset($params['options']) ? $params['options'] : array();
    $this->baseInit($options);

    if ($this->_cache->processRequest()) {
        $this->getResponse()->sendResponse();
    } else {
        $this->_initModules();
        $this->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);

        if ($this->_config->isLocalConfigLoaded()) {
            $scopeCode = isset($params['scope_code']) ? $params['scope_code'] : '';
            $scopeType = isset($params['scope_type']) ? $params['scope_type'] : 'store';
            $this->_initCurrentStore($scopeCode, $scopeType);
            $this->_initRequest();
    /*Dump resource node here: */
            var_dump(Mage::getConfig()->getNode('global/resources')->children()); die;
            Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
        }

        $this->getFrontController()->dispatch();
    }
    return $this;
}
Sign up to request clarification or add additional context in comments.

3 Comments

thx Ben. can you confirm which version? This was observed in Community 1.5.x, sorry should have specified in the question.
agree with Ben, setups are run in the same order as etc/config.xml gets merged. E.g. in the same way as events, layouts, rewrites, etc. There is no difference.
Curious whether you've ended up confirming this, Jonathan.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.