public function prepare() { $merge = new Aitoc_Aitsys_Model_Rewriter_Merge(); $rewriterConfig = new Aitoc_Aitsys_Model_Rewriter_Config(); // first clearing current class rewrites Aitoc_Aitsys_Model_Rewriter_Autoload::instance()->clearConfig(); $merge->clear(); $conflict = new Aitoc_Aitsys_Model_Rewriter_Conflict(); list($conflicts, $rewritesAbstract) = $conflict->getConflictList(); /** * FOR NORMAL REWRITES */ // will combine rewrites by alias groups if (!empty($conflicts)) { foreach ($conflicts as $groupType => $modules) { $groupType = substr($groupType, 0, -1); foreach ($modules as $moduleName => $moduleRewrites) { foreach ($moduleRewrites['rewrite'] as $moduleClass => $rewriteClasses) { /* * $rewriteClasses is an array of class names for one rewrite alias * for example: * Array * ( * [0] => AdjustWare_Deliverydate_Model_Rewrite_AdminhtmlSalesOrderCreate * [4] => Aitoc_Aitcheckoutfields_Model_Rewrite_AdminSalesOrderCreate * [10] => Aitoc_Aitorderedit_Model_Rewrite_AdminSalesOrderCreate * ) */ // building inheritance tree $alias = $moduleName . '/' . $moduleClass; $classModel = new Aitoc_Aitsys_Model_Rewriter_Class(); $inheritanceModel = new Aitoc_Aitsys_Model_Rewriter_Inheritance(); $baseClass = $classModel->getBaseClass($groupType, $alias); $inheritedClasses = $inheritanceModel->build($rewriteClasses, $baseClass); // don't create rewrites for excluded Magento base classes if (in_array($baseClass, $this->tool()->db()->getConfigValue('aitsys_rewriter_exclude_classes', array()))) { continue; } $mergedFilename = $merge->merge($inheritedClasses); if ($mergedFilename) { $rewriterConfig->add($mergedFilename, $rewriteClasses); $rewriterConfig->add(serialize($merge->getLatestMergedFiles()), 'file:' . $mergedFilename); } } } } } /** * FOR ABSTRACT REWRITES (AITOC REALIZATION) */ if (!empty($rewritesAbstract)) { foreach ($rewritesAbstract as $groupType => $modules) { $groupType = substr($groupType, 0, -1); foreach ($modules as $moduleName => $moduleRewrites) { foreach ($moduleRewrites['rewriteabstract'] as $moduleClass => $rewriteClass) { // building inheritance tree $alias = $moduleName . '/' . $moduleClass; $classModel = new Aitoc_Aitsys_Model_Rewriter_Class(); $inheritanceModel = new Aitoc_Aitsys_Model_Rewriter_Inheritance(); $baseClass = $classModel->getBaseClass($groupType, $alias); $inheritedClasses = $inheritanceModel->buildAbstract($rewriteClass, $baseClass); $mergedFilename = $merge->merge($inheritedClasses); if ($mergedFilename) { $rewriterConfig->add($mergedFilename, array($rewriteClass, $baseClass)); } } } } } $rewriterConfig->commit(); Aitoc_Aitsys_Model_Rewriter_Autoload::instance()->setupConfig(); }
protected function _prepareConflictGroups() { $allExtensions = array(); $currentExtension = Mage::app()->getRequest()->getParam('extension'); $rewriterConflictModel = new Aitoc_Aitsys_Model_Rewriter_Conflict(); list($conflicts, ) = $rewriterConflictModel->getConflictList(); // will combine rewrites by alias groups $groups = array(); if (!empty($conflicts)) { $rewriterClassModel = new Aitoc_Aitsys_Model_Rewriter_Class(); $rewriterinheritanceModel = new Aitoc_Aitsys_Model_Rewriter_Inheritance(); foreach ($conflicts as $groupType => $modules) { $groupType = substr($groupType, 0, -1); foreach ($modules as $moduleName => $moduleRewrites) { foreach ($moduleRewrites['rewrite'] as $moduleClass => $rewriteClasses) { // building inheritance tree $alias = $moduleName . '/' . $moduleClass; $baseClass = $rewriterClassModel->getBaseClass($groupType, $alias); $inheritedClasses = $rewriterinheritanceModel->build($rewriteClasses, $baseClass, false); $groups[$baseClass] = array_keys($inheritedClasses); ksort($groups[$baseClass]); $groups[$baseClass] = array_values($groups[$baseClass]); } } } $order = $this->_aithelper('Rewriter')->getOrderConfig(); foreach ($groups as $baseClass => $group) { $groups[$baseClass] = array_flip($group); $isCurrentFound = !(bool) $currentExtension; $savedRewritesValid = $this->_aithelper('Rewriter')->validateSavedClassConfig(isset($order[$baseClass]) ? $order[$baseClass] : array(), array_keys($groups[$baseClass])); foreach ($groups[$baseClass] as $class => $i) { if (isset($order[$baseClass][$class]) && $savedRewritesValid) { $groups[$baseClass][$class] = $order[$baseClass][$class]; } // adding class to the list of all extensions $key = substr($class, 0, strpos($class, '_', 1 + strpos($class, '_'))); // ^^^^^^^^^^^^^^^^^^^^^ --- this is offset, so start searching second "_" $allExtensions[] = $key; if ($key == $currentExtension) { $isCurrentFound = true; } } $groups[$baseClass] = array_flip($groups[$baseClass]); ksort($groups[$baseClass]); if (!$isCurrentFound || in_array($baseClass, $this->_aithelper('Rewriter')->getExcludeClassesConfig())) { // will display conflicts only for groups where current selected extension presents // exclude conflicts for excluded base Magento classes unset($groups[$baseClass]); } } } $aModuleList = $this->tool()->platform()->getModules(); $allExtensions = array_unique($allExtensions); foreach ($allExtensions as $key) { $moduleName = $key; foreach ($aModuleList as $moduleItem) { if ($key == $moduleItem->getKey()) { $moduleName = (string) $moduleItem->getLabel(); } } $this->_extensions[$this->getExtensionUrl($key)] = $moduleName; } $this->_groups = $groups; }
/** * Found all Inherited Classes and run method for analysis * * @param $object * @param $method * @param array $params * @param bool $useOrdering * @return bool */ public function analysisInheritedClasses($object, $method, &$params = array(), $useOrdering = true) { $rewriterConflictModel = new Aitoc_Aitsys_Model_Rewriter_Conflict(); $conflicts = $rewriterConflictModel->getConflictList(); // will combine rewrites by alias groups if (!empty($conflicts)) { $rewriterClassModel = new Aitoc_Aitsys_Model_Rewriter_Class(); $rewriterInheritanceModel = new Aitoc_Aitsys_Model_Rewriter_Inheritance(); $result = false; foreach ($conflicts as $groupType => $modules) { $groupType = substr($groupType, 0, -1); foreach ($modules as $moduleName => $moduleRewrites) { foreach ($moduleRewrites['rewrite'] as $moduleClass => $rewriteClasses) { // building inheritance tree $alias = $moduleName . '/' . $moduleClass; $baseClass = $rewriterClassModel->getBaseClass($groupType, $alias); $inheritedClasses = $rewriterInheritanceModel->build($rewriteClasses, $baseClass, $useOrdering); if ($inheritedClasses == false) { continue; } $paramsMethod = array('rewriteClasses' => $rewriteClasses, 'alias' => $alias, 'baseClass' => $baseClass, 'inheritedClasses' => $inheritedClasses, 'params' => &$params); $result = $object->{$method}($paramsMethod) ? true : $result; } } } return $result; } return false; }