0

I just wrote a Magento module, but it's not being loaded and I'd like to debug it.

Dustin Oprea
  • 9,673
  • 13
  • 65
  • 105
  • 2
    Please add the code of your module. It's impossible to help you without any details. – Fabrizio D'Ammassa Jul 14 '11 at 14:39
  • I was fully intending to answer my question, but there's a mandatory wait period, friend. – Dustin Oprea Jul 14 '11 at 14:50
  • Do you see your module under Admin --> Configuration --> Advanced --> Advanced ? – user487772 Jul 14 '11 at 18:55
  • If anyone who voted me down could reverse their vote, that'd be much appreciated. This was intended to be asked and answered by myself. – Dustin Oprea Sep 06 '11 at 21:53
  • You need to provide enough information for people to answer the question. If you intend to continue asking questions without enough information, only to answer them yourself, I suggest you start your own blog. – Bill the Lizard Sep 07 '11 at 00:51
  • 2
    Seems like a real question to me. They guy is just posting a tutorial for a legitimate Magento issue. I believe this to be valid and at the very core of what SO is all about. – Diego Sep 08 '11 at 18:56
  • 1
    That's correct. If you actually look at the purpose of the site, they encourage this. Stop using your ridiculous rating to bully others. – Dustin Oprea Sep 12 '11 at 08:04
  • yep! check for errors in the log, and make sure you don't have an XML error in the /etc/modules config-load file. Those are the two most common issues. – ppostma1 May 13 '13 at 19:09
  • This was an already-answered question from two years ago. Please don't comment on old questions. – Dustin Oprea May 14 '13 at 19:45
  • http://stackoverflow.com/questions/32188034/magento-1-9-2-1-custom-module-404/34288942#34288942 – Micromega Dec 15 '15 at 16:09

1 Answers1

15

Here are a couple of classes and the methods that are responsible for various stages of loading.

Mage_Core_Model_Config

Called for each module (returns a Mage_Core_Model_Config representing the module's XML block in the main config directory (enabled, version, etc..)):

/**
 * Get module config node
 *
 * @param string $moduleName
 * @return Varien_Simplexml_Object
 */
function getModuleConfig($moduleName='')
{
    $modules = $this->getNode('modules');
    if (''===$moduleName) {
        return $modules;
    } else {
        return $modules->$moduleName;
    }
}

Called for each module, but just builds a structure still without including the individual module configs:

/**
 * Load declared modules configuration
 *
 * @param   null $mergeConfig depricated
 * @return  Mage_Core_Model_Config
 */
protected function _loadDeclaredModules($mergeConfig = null)
{
    $moduleFiles = $this->_getDeclaredModuleFiles();
    if (!$moduleFiles) {
        return ;
    }

    Varien_Profiler::start('config/load-modules-declaration');

    $unsortedConfig = new Mage_Core_Model_Config_Base();
    $unsortedConfig->loadString('<config/>');
    $fileConfig = new Mage_Core_Model_Config_Base();

    // load modules declarations
    foreach ($moduleFiles as $file) {
        $fileConfig->loadFile($file);
        $unsortedConfig->extend($fileConfig);
    }

    $moduleDepends = array();
    foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) {
        if (!$this->_isAllowedModule($moduleName)) {
            continue;
        }

        $depends = array();
        if ($moduleNode->depends) {
            foreach ($moduleNode->depends->children() as $depend) {
                $depends[$depend->getName()] = true;
            }
        }
        $moduleDepends[$moduleName] = array(
            'module'    => $moduleName,
            'depends'   => $depends,
            'active'    => ('true' === (string)$moduleNode->active ? true : false),
        );
    }

    // check and sort module dependence
    $moduleDepends = $this->_sortModuleDepends($moduleDepends);

    // create sorted config
    $sortedConfig = new Mage_Core_Model_Config_Base();
    $sortedConfig->loadString('<config><modules/></config>');

    foreach ($unsortedConfig->getNode()->children() as $nodeName => $node) {
        if ($nodeName != 'modules') {
            $sortedConfig->getNode()->appendChild($node);
        }
    }

    foreach ($moduleDepends as $moduleProp) {
        $node = $unsortedConfig->getNode('modules/'.$moduleProp['module']);
        $sortedConfig->getNode('modules')->appendChild($node);
    }

    $this->extend($sortedConfig);

    Varien_Profiler::stop('config/load-modules-declaration');
    return $this;
}

Loads config.xml, enterprise.xml, local.xml, etc..:

/**
 * Load base system configuration (config.xml and local.xml files)
 *
 * @return Mage_Core_Model_Config
 */
public function loadBase()
{
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    return $this;
}

Loads the individual module configs:

/**
 * Iterate all active modules "etc" folders and combine data from
 * specidied xml file name to one object
 *
 * @param   string $fileName
 * @param   null|Mage_Core_Model_Config_Base $mergeToObject
 * @return  Mage_Core_Model_Config_Base
 */
public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
{
    $disableLocalModules = !$this->_canUseLocalModules();

    if ($mergeToObject === null) {
        $mergeToObject = clone $this->_prototype;
        $mergeToObject->loadString('<config/>');
    }
    if ($mergeModel === null) {
        $mergeModel = clone $this->_prototype;
    }
    $modules = $this->getNode('modules')->children();
    foreach ($modules as $modName=>$module) {
        if ($module->is('active')) {
            if ($disableLocalModules && ('local' === (string)$module->codePool)) {
                continue;
            }
            $configFile = $this->getModuleDir('etc', $modName).DS.$fileName;
            if ($mergeModel->loadFile($configFile)) {
                $mergeToObject->extend($mergeModel, true);
            }
        }
    }
    return $mergeToObject;
}

Varien_Simplexml_Config (lib/Varien/Simplexml/Config.php)

What actually reads the individual module configs:

/**
 * Imports XML file
 *
 * @param string $filePath
 * @return boolean
 */
public function loadFile($filePath)
{
    if (!is_readable($filePath)) {
        //throw new Exception('Can not read xml file '.$filePath);
        return false;
    }

    $fileData = file_get_contents($filePath);
    $fileData = $this->processFileData($fileData);
    return $this->loadString($fileData, $this->_elementClass);
}

Dustin Oprea

Dustin Oprea
  • 9,673
  • 13
  • 65
  • 105