Exemple #1
0
 public function applyPatch($bDryRun = false)
 {
     $oConfig = Mage::getConfig();
     $aPatchFiles = $this->_getPatchFiles();
     $oPatcher = new Aitoc_Aitsys_Model_Aitfilepatcher();
     $oFileSys = new Aitoc_Aitsys_Model_Aitfilesystem();
     $aErrors = array();
     $uncompatibleList = array();
     foreach ($aPatchFiles as $sFile => $aParams) {
         $sPatch = '';
         $aModules = $aParams['modules'];
         $currentModulePath = '';
         $currentModuleName = '';
         foreach ($aModules as $sMod => $sModPathToFile) {
             $patchFile = $oFileSys->getPatchFilePath($sFile, $sMod . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR);
             if (!$patchFile->getIsError()) {
                 $sPatch .= file_get_contents($patchFile->getFilePath());
             }
             $currentModulePath = $sMod;
             $currentModuleName = str_replace(array('/', '\\'), '_', substr($sMod, 6 + strrpos($sMod, 'local')));
         }
         $oPatcher->parsePatch($sPatch);
         // now will check if we can patch current file
         $sFileNameToPatch = str_replace('--', '/', $sFile);
         $sFileToPatch = $oConfig->getOptions()->getAppDir() . '/' . substr($sFileNameToPatch, 0, strpos($sFileNameToPatch, '.patch'));
         if (!file_exists($sFileToPatch) && $aParams['optional']) {
             continue;
         }
         if (!$oPatcher->canApplyChanges($sFileToPatch)) {
             $aErrors[] = array('file' => $sFileToPatch, 'type' => 'file_uncompatible');
             // adding session data for instructions page
             $uncompatibleList[$currentModuleName][] = array('file' => $sFileToPatch, 'mod' => $currentModulePath, 'patchfile' => $sFile, 'modkey' => $this->_getModuleKey($currentModuleName));
         }
         if (!$bDryRun) {
             // apply patch
             $sApplyPatchTo = $oFileSys->makeTemporary($sFileToPatch);
             $oPatcher->applyPatch($sApplyPatchTo);
             foreach ($aModules as $sMod => $sModPathToFile) {
                 $oFileSys->cpFile($sApplyPatchTo, $this->_patchedTemplatesDir . $sModPathToFile);
             }
             $oFileSys->rmFile($sApplyPatchTo);
         }
     }
     if ($bDryRun) {
         if ($uncompatibleList) {
             Mage::getSingleton('adminhtml/session')->setData('aitsys_patch_incompatible_files', $uncompatibleList);
             Mage::unregister('aitsys_patch_incompatible_files');
             Mage::register('aitsys_patch_incompatible_files', $uncompatibleList);
         }
         return $aErrors;
     }
     return true;
 }
Exemple #2
0
 /**
  * Clearing current rewrites
  */
 public function clear()
 {
     $filesystem = new Aitoc_Aitsys_Model_Aitfilesystem();
     $filesystem->rmFile($this->_rewriteDir . 'config.php');
 }