/** * @return string */ public static function getPatchesCacheDir() { if (!self::$_patchesCacheDir) { self::$_patchesCacheDir = BP . DS . Aitoc_Aitsys_Model_Platform::getInstance()->getVarPath() . self::PATCH_DIR; } return self::$_patchesCacheDir; }
/** * @param $observer */ public function pathTemplateReplaceBeforeToHtml($observer) { if (($block = $observer->getBlock()) instanceof Mage_Core_Block_Template) { if (!Mage::registry('design_path_aitoc')) { $currentViewDirAll = Mage::getBaseDir('design'); Mage::register('design_path_aitoc', $currentViewDirAll); } $currentViewDir = Mage::registry('design_path_aitoc'); $fileName = $block->getTemplateFile(); //save base dir before this block if (Mage::registry('design_path_for_' . get_class($block) . '_' . $block->getId())) { Mage::unregister('design_path_for_' . get_class($block) . '_' . $block->getId()); } Mage::register('design_path_for_' . get_class($block) . '_' . $block->getId(), Mage::getBaseDir('design')); if (false !== strpos($fileName, 'aitcommonfiles')) { if (Mage::getStoreConfigFlag('aitsys/settings/use_dynamic_patches') || !file_exists($currentViewDir . DS . $fileName)) { $newViewDir = Aitoc_Aitsys_Model_Aitpatch::getPatchesCacheDir() . 'design'; if (file_exists($newViewDir . DS . $fileName)) { $currentViewDir = $newViewDir; // replacing view dir } else { // also trying with 'default' folder instead of 'base' (for compatibility with 1.3 and 1.4 in one version) $fileNameDef = str_replace(DS . 'base' . DS, DS . 'default' . DS, $fileName); if (file_exists($newViewDir . DS . $fileNameDef)) { $currentViewDir = $newViewDir; // replacing view dir $fileName = $fileNameDef; // forcing use 'default' instead of 'base' } } } } $block->setTemplateFile($fileName); Mage::getConfig()->getOptions()->setData('design_dir', $currentViewDir); } else { if (Mage::registry('design_path_aitoc') && Mage::registry('design_path_aitoc') != Mage::getBaseDir('design')) { Mage::getConfig()->getOptions()->setData('design_dir', Mage::registry('design_path_aitoc')); } } }
/** * @return string */ public function getDestinationFile() { $destinationFile = str_replace(Mage::getBaseDir('app'), Aitoc_Aitsys_Model_Aitpatch::getPatchesCacheDir(), $this->getSourceFile(true)); $destinationFile = substr($destinationFile, 0, strrpos($destinationFile, DS) + 1); $destinationFile = str_replace(strstr($destinationFile, 'template'), '', $destinationFile); $destinationFile .= 'template' . DS . 'aitcommonfiles' . DS . str_replace('.patch', '', $this->getPatchFile()); $destinationFile = $this->_removeBasedir($destinationFile); return $destinationFile; }
public function fetchView($fileName) { $currentViewDir = $this->_viewDir; if (false !== strpos($fileName, 'aitcommonfiles')) { if (Mage::getStoreConfigFlag('aitsys/settings/use_dynamic_patches') || !file_exists($currentViewDir . DS . $fileName)) { $newViewDir = Aitoc_Aitsys_Model_Aitpatch::getPatchesCacheDir() . 'design'; if (file_exists($newViewDir . DS . $fileName)) { $this->_viewDir = $newViewDir; // replacing view dir } else { // also trying with 'default' folder instead of 'base' (for compatibility with 1.3 and 1.4 in one version) $fileNameDef = str_replace(DS . 'base' . DS, DS . 'default' . DS, $fileName); if (file_exists($newViewDir . DS . $fileNameDef)) { $this->_viewDir = $newViewDir; // replacing view dir $fileName = $fileNameDef; // forcing use 'default' instead of 'base' } } } } Varien_Profiler::start($fileName); extract($this->_viewVars); $do = $this->getDirectOutput(); if (!$do) { ob_start(); } if ($this->getShowTemplateHints()) { echo '<div style="position:relative; border:1px dotted red; margin:6px 2px; padding:18px 2px 2px 2px; zoom:1;"><div style="position:absolute; left:0; top:0; padding:2px 5px; background:red; color:white; font:normal 11px Arial; text-align:left !important; z-index:998;" onmouseover="this.style.zIndex=\'999\'" onmouseout="this.style.zIndex=\'998\'" title="' . $fileName . '">' . $fileName . '</div>'; if (self::$_showTemplateHintsBlocks) { $thisClass = get_class($this); echo '<div style="position:absolute; right:0; top:0; padding:2px 5px; background:red; color:blue; font:normal 11px Arial; text-align:left !important; z-index:998;" onmouseover="this.style.zIndex=\'999\'" onmouseout="this.style.zIndex=\'998\'" title="' . $thisClass . '">' . $thisClass . '</div>'; } } try { $includeFilePath = realpath($this->_viewDir . DS . $fileName); if (strpos($includeFilePath, realpath($this->_viewDir)) === 0 || $this->_checkAllowSymlinks()) { include $includeFilePath; } else { Mage::log('Not valid template file:' . $fileName, Zend_Log::CRIT, null, null, true); } } catch (Exception $e) { ob_get_clean(); Mage::log('Failed to load template:' . $this->_viewDir . DS . $fileName); throw $e; } //include $this->_viewDir.DS.$fileName; if ($this->getShowTemplateHints()) { echo '</div>'; } if (!$do) { $html = ob_get_clean(); } else { $html = ''; } Varien_Profiler::stop($fileName); #$html = parent::fetchView($fileName); $this->_viewDir = $currentViewDir; // returning default dir back return $html; }
/** * @return array */ public function getSubsystemsDirs() { if (empty($this->_subsystemsDirs)) { $this->_subsystemsDirs[] = Aitoc_Aitsys_Model_Rewriter_Abstract::getRewritesCacheDir(); $this->_subsystemsDirs[] = Aitoc_Aitsys_Model_Aitpatch::getPatchesCacheDir(); } return $this->_subsystemsDirs; }
public function saveData($aData, $aModuleHash = array(), $clearCache = true, $hideEvents = false) { if (!$aData) { return false; } if (!$aModuleHash) { $aModuleHash = $this->_getModuleHash(); } $sModuleEtcDir = $this->_getEtcDir(); // dispatching pre-disable event $aStatusHash = $this->getModulesStatusHash(); if ($this->_isCorrection) { // For correction $aData is an array of modules to be corrected, not a list of all modules with new statuses. // To prevent status changes of all other modules we are re-creating $aData from $aStatusHash. // Then in $sStatusHash we change current statuses of modules that require correction to an opposite one to simulate // normal process of enabling/disabling of modules. $newData = array(); foreach ($aStatusHash as $module => $oldStatus) { $newData[$module] = $oldStatus; $aStatusHash[$module] = isset($aData[$module]) ? !$oldStatus : $oldStatus; } $aData = $newData; } if ($aModuleHash) { foreach ($aModuleHash as $sFile => $sFullPath) { if (!file_exists($sFullPath)) { continue; } $oModuleBaseConfigCheck = simplexml_load_file($sFullPath); $this->checkModulesCompatibility($aData, $oModuleBaseConfigCheck, $aModuleHash); } } $eventArg = array('aitsys' => $this, 'data' => $aData, 'module_hash' => $aModuleHash, 'status_hash' => $aStatusHash); if (!$hideEvents) { $this->tool()->event('aitoc_module_save_data_before', $eventArg); } foreach ($aStatusHash as $sModule => $bIsActive) { if (!isset($aData[$sModule]) or !$aData[$sModule]) { $aEventParams = array('object' => $this, 'aitocmodulename' => $sModule); if (!$hideEvents) { Mage::dispatchEvent('aitoc_module_disable_before', $aEventParams); } } } // checking if we got any error from events $aErrors = $this->_getErrorList(); if (!empty($aErrors)) { return $aErrors; } if ($aModuleHash) { foreach ($aModuleHash as $sFile => $sFullPath) { if (!file_exists($sFullPath)) { continue; } $sModuleName = substr($sFile, 0, strpos($sFile, '.')); if (!$hideEvents) { $this->tool()->event('aitoc_module_modify_before', array('aitsys' => $this, 'key' => $sModuleName)); } $sModuleDir = $this->_getModuleDir($sModuleName); // get main module config $oModuleMainConfig = $this->_getModuleConfig($sModuleDir); // set module status if (isset($aData[$sModuleName]) and $aData[$sModuleName]) { $sModuleActive = 'true'; //$this->_addModuleClassRewrite($oModuleMainConfig, $sModuleName); //deprecated since 2.19.0 } else { $sModuleActive = 'false'; } // get base module config $oModuleCustomConfig = $this->_getModuleConfig($sModuleDir, true); $this->_setFileMergeData($oModuleCustomConfig, $sModuleDir); $oModuleBaseConfig = simplexml_load_file($sFullPath); $oModuleBaseConfig->modules->{$sModuleName}->active = $sModuleActive; if ($iPriority = $oModuleBaseConfig->modules->{$sModuleName}->priority) { $this->_aModulePriority[$sModuleName] = (int) $iPriority; } else { $this->_aModulePriority[$sModuleName] = 0; } $sFileContent = $oModuleBaseConfig->asXML(); if ($this->_isCorrection || $this->_checkFileSaveWithContent($sFullPath, $sFileContent)) { // check if module's status was changed // check if module has license helper // launch module's specific install/uninstall methods from license helper if (array_key_exists($sModuleName, $aData) && array_key_exists($sModuleName, $aStatusHash) && $aData[$sModuleName] != $aStatusHash[$sModuleName]) { if ($sModuleActive == 'false') { $this->tool()->getLicenseHelper($sModuleName)->uninstallBefore(); } else { $this->tool()->getLicenseHelper($sModuleName)->installBefore(); } } // check if module has resource setup files // also if it has version in `core_resource` // run 'activate' or 'uninstall' scripts if ($oModuleMainConfig and isset($oModuleMainConfig->global->resources)) { $resourceName = ''; foreach ($oModuleMainConfig->global->resources->children() as $key => $object) { if ($object->setup) { $resourceName = $key; break; } } if ($resourceName) { // check if module has version in `core_resource`, so it was previously enabled $dbVersion = Mage::getResourceModel('core/resource')->getDBVersion($resourceName); if ($dbVersion && array_key_exists($sModuleName, $aData) && array_key_exists($sModuleName, $aStatusHash) && $aData[$sModuleName] != $aStatusHash[$sModuleName]) { if ($sModuleActive == 'false') { $aitsysSetup = new Aitoc_Aitsys_Model_Mysql4_Setup('core_setup'); $aitsysSetup->applyAitocModuleUninstall($sModuleName); } else { $aitsysSetup = new Aitoc_Aitsys_Model_Mysql4_Setup('core_setup'); $aitsysSetup->applyAitocModuleActivate($sModuleName); } } } } // save module status in the database for future correction checks Aitoc_Aitsys_Model_Module_Status::updateStatus($sModuleName, $sModuleActive != 'false'); } } $this->_clearFileMergeData($aData, $aModuleHash, $aStatusHash); // set new php class inheritance /* deprecated since 2.19.0 if ($this->_aModuleClassRewrite) { $aModuleOrder = $this->_getModuleOrder(); foreach ($this->_aModuleClassRewrite as $sKey => $aData) { $aReplaceHash = $this->_setRewriteClass($sKey, $aData, $aModuleOrder); if ($aReplaceHash) { foreach ($aReplaceHash as $sModuleName => $aReplace) { if ($aReplace['extends']) // must change inheritance { // modify class inheritance $sExtends = ' extends '; $aReplaceData = array ( 'search' => array($sExtends . $aReplace['original']), 'replace' => array($sExtends . $aReplace['extends']), ); } else { $aReplaceData = array(); } $this->_checkFileSaveWithBackup($aReplace['path'], 'php', $aReplaceData); $this->_aConfigReplace[$sModuleName][$aReplace['module']] = $aReplace['config']; } } } } */ // checking write permissions to var $this->_checkFileWritePermissions(Mage::getBaseDir('var')); // save updated config modules files /* deprecated since 2.19.0 if ($this->_aConfigReplace) { foreach ($this->_aConfigReplace as $sModuleName => $aData) { $aReplaceData = array(); foreach ($aData as $sKey => $sVal) { $aReplaceData['search'][] = $sKey; $aReplaceData['replace'][] = $sVal; } $sModuleDir = $this->_getModuleDir($sModuleName); $sConfigFilePath = $sModuleDir . '/etc/config'; $this->_checkFileSaveWithBackup($sConfigFilePath, 'xml', $aReplaceData); } } */ if (!$this->_aErrorList) { if ($this->_aFileMerge) { $oPatch = new Aitoc_Aitsys_Model_Aitpatch(); $oPatch->setPatchFiles($this->_aFileMerge); $aErrorList = $oPatch->applyPatchDryrun(); if ($aErrorList) { foreach ($aErrorList as $aError) { $this->_addError($aError['file'], $aError['type']); } } else { $oPatch->applyPatch(); } } if (!$this->_aErrorList) { $this->_saveAllFileContent(); $this->_deleteFiles(); } } } if ($clearCache) { $this->tool()->clearCache(); } if (!$hideEvents) { $this->tool()->event('aitoc_module_save_data_after', $eventArg); } return $this->_getErrorList(); }