function getRewritesList() { $moduleFiles = glob(Mage::getBaseDir('etc') . DS . 'modules' . DS . '*.xml'); if (!$moduleFiles) { return false; } // load file contents $unsortedConfig = new Varien_Simplexml_Config(); $unsortedConfig->loadString('<config/>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($moduleFiles as $filePath) { $fileConfig->loadFile($filePath); $unsortedConfig->extend($fileConfig); } // create sorted config [only active modules] $sortedConfig = new Varien_Simplexml_Config(); $sortedConfig->loadString('<config><modules/></config>'); foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if ('true' === (string) $moduleNode->active) { $sortedConfig->getNode('modules')->appendChild($moduleNode); } } $fileConfig = new Varien_Simplexml_Config(); $_finalResult = array(); foreach ($sortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { $codePool = (string) $moduleNode->codePool; $configPath = BP . DS . 'app' . DS . 'code' . DS . $codePool . DS . uc_words($moduleName, DS) . DS . 'etc' . DS . 'config.xml'; $fileConfig->loadFile($configPath); $rewriteBlocks = array('blocks', 'models', 'helpers'); foreach ($rewriteBlocks as $param) { if (!isset($_finalResult[$param])) { $_finalResult[$param] = array(); } if ($rewrites = $fileConfig->getXpath('global/' . $param . '/*/rewrite')) { foreach ($rewrites as $rewrite) { $parentElement = $rewrite->xpath('../..'); foreach ($parentElement[0] as $moduleKey => $moduleItems) { $moduleItemsArray['rewrite'] = array(); $moduleItemsArray['codePool'] = array(); foreach ($moduleItems->rewrite as $rewriteLine) { foreach ($rewriteLine as $key => $value) { $moduleItemsArray['rewrite'][$key] = (string) $value; $moduleItemsArray['codePool'][$key] = $codePool; } } if ($moduleItems->rewrite) { $_finalResult[$param] = array_merge_recursive($_finalResult[$param], array($moduleKey => $moduleItemsArray)); } } } } } } return $_finalResult; }
private function __construct() { $moduleFiles = glob(BP . '/app/etc/modules/*.xml'); $unsortedConfig = new Varien_Simplexml_Config(); $unsortedConfig->loadString('<config/>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($moduleFiles as $filePath) { $fileConfig->loadFile($filePath); $unsortedConfig->extend($fileConfig); } // create sorted config [only active modules] #$sortedConfig = new Varien_Simplexml_Config(); #$sortedConfig->loadString('<config><modules/></config>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if ('true' === (string) $moduleNode->active) { $codePool = (string) $moduleNode->codePool; $configPath = BP . '/app/code/' . $codePool . '/' . uc_words($moduleName, '/') . '/etc/config.xml'; $fileConfig->loadFile($configPath); $unsortedConfig->extend($fileConfig); } } $this->_config = $unsortedConfig; }
public function injectCronjobsIntoConfig($cronExecution = false) { try { if (Mage::registry('xt_orderexport_cron_injected') !== null) { return $this; } Mage::register('xt_orderexport_cron_injected', true); if ($cronExecution) { // Dispatch "cron has been executed" event if (Mage::registry('xtento_cronjob_execution_called') === null) { Mage::dispatchEvent('xtento_cronjob_execution', array()); Mage::register('xtento_cronjob_execution_called', true); } } if (!Mage::helper('xtento_orderexport')->getModuleEnabled() || !Mage::helper('xtento_orderexport')->isModuleProperlyInstalled()) { return $this; } $newJobs = new SimpleXMLElement('<?xml version="1.0"?><config><crontab><jobs></jobs></crontab></config>'); $jobs = $newJobs->crontab->jobs; // Load profiles and add cronjobs $profileCollection = Mage::getModel('xtento_orderexport/profile')->getCollection(); $profileCollection->addFieldToFilter('enabled', 1); // Profile enabled $profileCollection->addFieldToFilter('cronjob_enabled', 1); // Cronjob enabled foreach ($profileCollection as $profile) { if ($profile->getCronjobFrequency() == Xtento_OrderExport_Model_Observer_Cronjob::CRON_CUSTOM || $profile->getCronjobFrequency() == '' && $profile->getCronjobCustomFrequency() !== '') { // Custom cron expression $cronFrequencies = $profile->getCronjobCustomFrequency(); if (empty($cronFrequencies)) { continue; } $cronFrequencies = array_unique(explode(";", $cronFrequencies)); $cronCounter = 0; foreach ($cronFrequencies as $cronFrequency) { if (empty($cronFrequency)) { continue; } $cronCounter++; $job = $jobs->addChild('xtento_orderexport_profile_' . $profile->getId() . '_cron_' . $cronCounter); $job->addChild('schedule')->addChild('cron_expr', $cronFrequency); $job->addChild('run')->addChild('model', 'xtento_orderexport/observer_cronjob::export'); } } else { // No custom cron expression $cronFrequency = $profile->getCronjobFrequency(); if (empty($cronFrequency)) { continue; } $job = $jobs->addChild('xtento_orderexport_profile_' . $profile->getId()); $job->addChild('schedule')->addChild('cron_expr', $cronFrequency); $job->addChild('run')->addChild('model', 'xtento_orderexport/observer_cronjob::export'); } } // Done adding cronjobs, extend original cron config $origJobs = new Varien_Simplexml_Config('<?xml version="1.0"?><config><crontab>' . Mage::getConfig()->getNode('crontab/jobs')->asXML() . '</crontab></config>'); $newCronConfig = new Varien_Simplexml_Config($newJobs->asXML()); $newCronConfig->extend($origJobs); } catch (Exception $e) { Mage::log('Exception for _addCronjobsToConfig(): ' . $e->getMessage(), null, 'xtento_orderexport_cron.log', true); return $this; } // Reset original cronjobs and inject our custom cron config with our cronjobs on first position $node = Mage::getConfig()->getNode('crontab'); unset($node->jobs); Mage::getConfig()->extend($newCronConfig, true); // Double check cronjob configuration $jobNode = Mage::getConfig()->getNode('crontab/jobs'); if (!$jobNode || !$jobNode->children() || method_exists($jobNode->children(), 'count') && $jobNode->children()->count() === 0) { // There was a problem extending the config, restore original config. Mage::getConfig()->extend($origJobs, true); } }
/** * Retrive possible conflicts list * * @return array */ public function getConflictList() { $moduleFiles = glob($this->_etcDir . 'modules' . DIRECTORY_SEPARATOR . '*.xml'); if (!$moduleFiles) { return false; } // load file contents $unsortedConfig = new Varien_Simplexml_Config(); $unsortedConfig->loadString('<config/>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($moduleFiles as $filePath) { $fileConfig->loadFile($filePath); $unsortedConfig->extend($fileConfig); } // create sorted config [only active modules] $sortedConfig = new Varien_Simplexml_Config(); $sortedConfig->loadString('<config><modules/></config>'); foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if ('true' === (string) $moduleNode->active) { $sortedConfig->getNode('modules')->appendChild($moduleNode); } } $fileConfig = new Varien_Simplexml_Config(); $_finalResult = array(); $_finalResultAbstract = array(); foreach ($sortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { $codePool = (string) $moduleNode->codePool; $configPath = $this->_codeDir . $codePool . DIRECTORY_SEPARATOR . uc_words($moduleName, DS) . DIRECTORY_SEPARATOR . 'etc' . DS . 'config.xml'; $fileConfig->loadFile($configPath); $rewriteBlocks = array('blocks', 'models', 'helpers'); foreach ($rewriteBlocks as $param) { if (!isset($_finalResult[$param])) { $_finalResult[$param] = array(); } if ($rewrites = $fileConfig->getXpath('global/' . $param . '/*/rewrite')) { foreach ($rewrites as $rewrite) { $parentElement = $rewrite->xpath('../..'); foreach ($parentElement[0] as $moduleKey => $moduleItems) { $moduleItemsArray['rewrite'] = array(); foreach ($moduleItems->rewrite as $rewriteLine) { foreach ($rewriteLine as $key => $value) { $moduleItemsArray['rewrite'][$key] = (string) $value; } #$moduleItemsArray['rewrite'] += $rewriteLine->asArray(); #echo "<pre>".print_r($moduleItemsArray['rewrite'],1)."</pre>"; } if ($moduleItems->rewrite) { // $_finalResult[$param] = array_merge_recursive($_finalResult[$param], array($moduleKey => $moduleItems->asArray())); $_finalResult[$param] = array_merge_recursive($_finalResult[$param], array($moduleKey => $moduleItemsArray)); } } } } #echo "<pre>".print_r($_finalResult,1)."</pre>"; if ($rewrites = $fileConfig->getXpath('global/' . $param . '/*/rewriteabstract')) { foreach ($rewrites as $rewrite) { $parentElement = $rewrite->xpath('../..'); foreach ($parentElement[0] as $moduleKey => $moduleItems) { if ($moduleItems->rewriteabstract) { // $_finalResultAbstract[$param] = array_merge_recursive($_finalResultAbstract[$param], array($moduleKey => $moduleItems->asArray())); $list = array(); foreach ($moduleItems->rewriteabstract->children() as $key => $value) { $list[$key] = (string) $value; } #echo "<pre>--".print_r($list,1)."</pre>"; #echo "<pre>++".print_r($moduleItems->asArray(),1)."</pre>"; $_finalResultAbstract[$param] = array($moduleKey => array('rewriteabstract' => $list)); } } } } } } foreach (array_keys($_finalResult) as $groupType) { foreach (array_keys($_finalResult[$groupType]) as $key) { // remove some repeating elements after merging all parents foreach ($_finalResult[$groupType][$key]['rewrite'] as $key1 => $value) { if (is_array($value)) { $_finalResult[$groupType][$key]['rewrite'][$key1] = array_unique($value); } // if rewrites count < 2 - no conflicts - remove if (gettype($_finalResult[$groupType][$key]['rewrite'][$key1]) == 'array' && count($_finalResult[$groupType][$key]['rewrite'][$key1]) < 2 || gettype($_finalResult[$groupType][$key]['rewrite'][$key1]) == 'string') { unset($_finalResult[$groupType][$key]['rewrite'][$key1]); } } // clear empty elements if (count($_finalResult[$groupType][$key]['rewrite']) < 1) { unset($_finalResult[$groupType][$key]); } } // clear empty elements if (count($_finalResult[$groupType]) < 1) { unset($_finalResult[$groupType]); } } foreach (array_keys($_finalResultAbstract) as $groupType) { foreach (array_keys($_finalResultAbstract[$groupType]) as $key) { // remove some repeating elements after merging all parents foreach ($_finalResultAbstract[$groupType][$key]['rewriteabstract'] as $key1 => $value) { if (is_array($value)) { $_finalResultAbstract[$groupType][$key]['rewriteabstract'][$key1] = array_unique($value); } } // clear empty elements if (count($_finalResultAbstract[$groupType][$key]['rewriteabstract']) < 1) { unset($_finalResultAbstract[$groupType][$key]); } } // clear empty elements if (count($_finalResultAbstract[$groupType]) < 1) { unset($_finalResultAbstract[$groupType]); } } // filter aitoc modules foreach ($_finalResult as $type => $data) { foreach ($data as $module => $data) { foreach ($data['rewrite'] as $model => $classes) { $remove = true; foreach ($classes as $class) { if (strstr($class, 'Aitoc') || strstr($class, 'AdjustWare')) { $remove = false; break; } } if ($remove) { unset($_finalResult[$type][$module]['rewrite'][$model]); } } if (!$_finalResult[$type][$module]['rewrite']) { unset($_finalResult[$type][$module]); } } } return array($_finalResult, $_finalResultAbstract); }
/** * Retrive possible conflicts list * * @return array */ protected function _getPossibleConflictsList() { $moduleFiles = glob($this->_etcDir . DS . 'modules' . DS . '*.xml'); if (!$moduleFiles) { return false; } // load file contents $unsortedConfig = new Varien_Simplexml_Config(); $unsortedConfig->loadString('<config/>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($moduleFiles as $filePath) { $fileConfig->loadFile($filePath); $unsortedConfig->extend($fileConfig); } // create sorted config [only active modules] $sortedConfig = new Varien_Simplexml_Config(); $sortedConfig->loadString('<config><modules/></config>'); foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if ('true' === (string) $moduleNode->active) { $sortedConfig->getNode('modules')->appendChild($moduleNode); } } $fileConfig = new Varien_Simplexml_Config(); $_finalResult = array(); foreach ($sortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { $codePool = (string) $moduleNode->codePool; $configPath = $this->_codeDir . DS . $codePool . DS . uc_words($moduleName, DS) . DS . 'etc' . DS . 'config.xml'; $fileConfig->loadFile($configPath); $rewriteBlocks = array('blocks', 'models', 'helpers'); foreach ($rewriteBlocks as $param) { if (!isset($_finalResult[$param])) { $_finalResult[$param] = array(); } if ($rewrites = $fileConfig->getXpath('global/' . $param . '/*/rewrite')) { foreach ($rewrites as $rewrite) { $parentElement = $rewrite->xpath('../..'); foreach ($parentElement[0] as $moduleKey => $moduleItems) { if ($moduleItems->rewrite) { $_finalResult[$param] = array_merge_recursive($_finalResult[$param], array($moduleKey => $moduleItems->asArray())); } } } } } } foreach (array_keys($_finalResult) as $groupType) { foreach (array_keys($_finalResult[$groupType]) as $key) { // remove some repeating elements after merging all parents foreach ($_finalResult[$groupType][$key]['rewrite'] as $key1 => $value) { if (is_array($value)) { $_finalResult[$groupType][$key]['rewrite'][$key1] = array_unique($value); } // if rewrites count < 2 - no conflicts - remove if (gettype($_finalResult[$groupType][$key]['rewrite'][$key1]) == 'array' && count($_finalResult[$groupType][$key]['rewrite'][$key1]) < 2 || gettype($_finalResult[$groupType][$key]['rewrite'][$key1]) == 'string') { unset($_finalResult[$groupType][$key]['rewrite'][$key1]); } } // clear empty elements if (count($_finalResult[$groupType][$key]['rewrite']) < 1) { unset($_finalResult[$groupType][$key]); } } // clear empty elements if (count($_finalResult[$groupType]) < 1) { unset($_finalResult[$groupType]); } } return $_finalResult; }
protected function getModulesList() { $ret = array(); $moduleFiles = glob($this->_etcDir . DS . 'modules' . DS . '*.xml'); if ($moduleFiles) { // load file contents $unsortedConfig = new Varien_Simplexml_Config(); $unsortedConfig->loadString('<config/>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($moduleFiles as $filePath) { $fileConfig->loadFile($filePath); $unsortedConfig->extend($fileConfig); } // create sorted config [only active modules] $sortedConfig = new Varien_Simplexml_Config(); $sortedConfig->loadString('<config><modules/></config>'); foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if ('true' === (string) $moduleNode->active) { $sortedConfig->getNode('modules')->appendChild($moduleNode); } } $fileConfig = new Varien_Simplexml_Config(); foreach ($sortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if (strpos($moduleName, "Mage_") === FALSE) { $codePool = (string) $moduleNode->codePool; $configPath = $this->_codeDir . DS . $codePool . DS . uc_words($moduleName, DS) . DS . 'etc' . DS . 'config.xml'; $fileConfig->loadFile($configPath); $version = $fileConfig->getXpath('modules/' . $moduleName . '/version'); $ret[] = array('version' => $version && $version[0] ? (string) $version[0] : NULL, 'key' => $moduleName); } } } return $ret; }
public function getExtensionConflict($all_conflicts = false) { $all_rewrite_classes = array(); $node_type_list = array('model', 'helper', 'block'); foreach ($node_type_list as $node_type) { foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module) { if ($module->codePool == 'core' || $module->active != 'true') { continue; } $config_file_path = Mage::getConfig()->getModuleDir('etc', $name) . DS . 'config.xml'; $config = new Varien_Simplexml_Config(); $config->loadString('<config/>'); $config->loadFile($config_file_path); $config->extend($config, true); $nodes = $config->getNode()->global->{$node_type . 's'}; if (!$nodes) { continue; } foreach ($nodes->children() as $node_name => $config) { if ($config->rewrite) { // there is rewrite for current config foreach ($config->rewrite->children() as $class_tag => $derived_class) { $base_class_name = $this->_getMageBaseClass($node_type, $node_name, $class_tag); $lead_derived_class = ''; $conf = Mage::getConfig()->getNode()->global->{$node_type . 's'}->{$node_name}; if (isset($conf->rewrite->{$class_tag})) { $lead_derived_class = (string) $conf->rewrite->{$class_tag}; } if ($derived_class == '') { $derived_class = $lead_derived_class; } if (empty($all_rewrite_classes[$base_class_name])) { $all_rewrite_classes[$base_class_name] = array('derived' => array((string) $derived_class), 'lead' => (string) $lead_derived_class, 'tag' => $class_tag, 'name' => array((string) $name)); } else { array_push($all_rewrite_classes[$base_class_name]['derived'], (string) $derived_class); array_push($all_rewrite_classes[$base_class_name]['name'], (string) $name); } } } } } } if ($all_conflicts) { return $all_rewrite_classes; } $isp_rewrite_classes = array(); $isp_module_name = 'Autocompleteplus_Autosuggest'; foreach ($all_rewrite_classes as $base => $conflict_info) { if (in_array($isp_module_name, $conflict_info['name'])) { // if isp extension rewrite this base class if (count($conflict_info['derived']) > 1) { // more then 1 class rewrite this base class => there is a conflict $isp_rewrite_classes[$base] = $conflict_info; } } } return $isp_rewrite_classes; }
/** * Retrive possible conflicts list * * @return array */ public function getConflictList() { $moduleFiles = glob($this->_etcDir . 'modules' . DIRECTORY_SEPARATOR . '*.xml'); if (!$moduleFiles) { return false; } // load file contents $unsortedConfig = new Varien_Simplexml_Config(); $unsortedConfig->loadString('<config/>'); $fileConfig = new Varien_Simplexml_Config(); foreach ($moduleFiles as $filePath) { $fileConfig->loadFile($filePath); $unsortedConfig->extend($fileConfig); } // create sorted config [only active modules] $sortedConfig = new Varien_Simplexml_Config(); $sortedConfig->loadString('<config><modules/></config>'); foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { if ('true' === (string) $moduleNode->active) { $sortedConfig->getNode('modules')->appendChild($moduleNode); } } $fileConfig = new Varien_Simplexml_Config(); $_finalResult = array(); foreach ($sortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) { $codePool = (string) $moduleNode->codePool; $configPath = $this->_codeDir . $codePool . DIRECTORY_SEPARATOR . uc_words($moduleName, DS) . DIRECTORY_SEPARATOR . 'etc' . DS . 'config.xml'; $fileConfig->loadFile($configPath); $rewriteBlocks = array('blocks', 'models', 'helpers'); foreach ($rewriteBlocks as $param) { if (!isset($_finalResult[$param])) { $_finalResult[$param] = array(); } if ($rewrites = $fileConfig->getXpath('global/' . $param . '/*/rewrite')) { foreach ($rewrites as $rewrite) { $parentElement = $rewrite->xpath('../..'); foreach ($parentElement[0] as $moduleKey => $moduleItems) { $moduleItemsArray['rewrite'] = array(); foreach ($moduleItems->rewrite as $rewriteLine) { foreach ($rewriteLine as $key => $value) { $moduleItemsArray['rewrite'][$key] = (string) $value; } #echo "<pre>".print_r($moduleItemsArray['rewrite'],1)."</pre>"; } if ($moduleItems->rewrite) { $_finalResult[$param] = array_merge_recursive($_finalResult[$param], array($moduleKey => $moduleItemsArray)); } } } } } } $_finalResult = $this->_fillAllClassesToRewrite($_finalResult); $_finalResult = $this->_clearEmptyRows($_finalResult); $_finalResult = $this->_recoverDeletedClassRewrites($_finalResult); // filter aitoc modules foreach ($_finalResult as $type => $data) { foreach ($data as $module => $data) { foreach ($data['rewrite'] as $model => $classes) { $remove = true; foreach ($classes as $class) { if (strstr($class, 'Aitoc') || strstr($class, 'AdjustWare')) { $remove = false; break; } } if ($remove) { unset($_finalResult[$type][$module]['rewrite'][$model]); } } if (!$_finalResult[$type][$module]['rewrite']) { unset($_finalResult[$type][$module]); } } } return $_finalResult; }
public function loadFromXmlFiles() { $path = Mage::getConfig()->getOptions()->getCodeDir() . DS . 'local' . DS . 'AW' . DS . 'Featured' . DS . 'etc' . DS . 'representations'; $files = glob($path . DS . '*.xml'); $rprConfig = new Varien_Simplexml_Config(); foreach ($files as $file) { if (!$rprConfig->getNode()) { $rprConfig = new Varien_Simplexml_Config($file); } else { $tmpConfig = new Varien_Simplexml_Config($file); $rprConfig->extend($tmpConfig); } } $this->_config = $rprConfig; return $this->_config; }