/** * Implements Rollback functionality for Db * * @return bool */ public function rollback() { set_time_limit(0); ignore_user_abort(true); $this->_lastOperationSucceed = false; $archiveManager = new Mage_Archive(); $source = $archiveManager->unpack($this->getBackupPath(), $this->getBackupsDir()); $file = new Mage_Backup_Filesystem_Iterator_File($source); foreach ($file as $statement) { $this->getResourceModel()->runCommand($statement); } @unlink($source); $this->_lastOperationSucceed = true; return true; }
public function rollback() { set_time_limit(0); ignore_user_abort(true); $this->_lastOperationSucceed = false; $unsecureBaseUrl = Mage::getStoreConfig('web/unsecure/base_url'); $secureBaseUrl = Mage::getStoreConfig('web/secure/base_url'); $archiveManager = new Mage_Archive(); $source = $archiveManager->unpack($this->getBackupPath(), $this->getBackupsDir()); $file = new Mage_Backup_Filesystem_Iterator_File($source); foreach ($file as $statement) { $updateStatement = ''; //if(strpos($statement, '`admin_assert`')){ continue; } //if(strpos($statement, '`admin_role`')){ continue; } //if(strpos($statement, '`admin_rule`')){ continue; } //if(strpos($statement, '`admin_user`')){ continue; } //if(strpos($statement, '`adminnotification_inbox`')){ continue; } //if(strpos($statement, '`api2_acl_attribute`')){ continue; } //if(strpos($statement, '`api2_acl_role`')){ continue; } //if(strpos($statement, '`api2_acl_rule`')){ continue; } //if(strpos($statement, '`api2_acl_user`')){ continue; } //if(strpos($statement, '`api_assert`')){ continue; } //if(strpos($statement, '`api_role`')){ continue; } //if(strpos($statement, '`api_rule`')){ continue; } //if(strpos($statement, '`api_session`')){ continue; } //if(strpos($statement, '`api_user`')){ continue; } if (strpos($statement, '`core_cache_option`')) { continue; } //if(strpos($statement, '`oauth_consumer`')){ continue; } //if(strpos($statement, '`oauth_nonce`')){ continue; } //if(strpos($statement, '`oauth_token`')){ continue; } if (strpos($statement, '`core_resource`')) { continue; } $this->getResourceModel()->runCommand($statement); if (strpos($statement, '`core_config_data`')) { if (strpos($statement, 'INSERT INTO `core_config_data`') === 0) { $updateStatement = "UPDATE `core_config_data` set value = '{$unsecureBaseUrl}' where path = 'web/unsecure/base_url';"; $updateStatement .= "UPDATE `core_config_data` set value = '{$secureBaseUrl}' where path = 'web/secure/base_url';"; $this->getResourceModel()->runCommand($updateStatement); } } } @unlink($source); $this->_lastOperationSucceed = true; return true; }
/** * Files rollback implementation via local filesystem * * @see Mage_Backup_Filesystem_Rollback_Abstract::run() * @throws Mage_Exception */ public function run() { $snapshotPath = $this->_snapshot->getBackupPath(); if (!is_file($snapshotPath) || !is_readable($snapshotPath)) { throw new Mage_Backup_Exception_CantLoadSnapshot('Cant load snapshot archive'); } $fsHelper = new Mage_Backup_Filesystem_Helper(); $filesInfo = $fsHelper->getInfo($this->_snapshot->getRootDir(), Mage_Backup_Filesystem_Helper::INFO_WRITABLE, $this->_snapshot->getIgnorePaths()); if (!$filesInfo['writable']) { throw new Mage_Backup_Exception_NotEnoughPermissions('Unable to make rollback because not all files are writable'); } $archiver = new Mage_Archive(); /** * we need these fake initializations because all magento's files in filesystem will be deleted and autoloader * wont be able to load classes that we need for unpacking */ new Mage_Archive_Tar(); new Mage_Archive_Gz(); new Mage_Archive_Helper_File(''); new Mage_Archive_Helper_File_Gz(''); $fsHelper->rm($this->_snapshot->getRootDir(), $this->_snapshot->getIgnorePaths()); $archiver->unpack($snapshotPath, $this->_snapshot->getRootDir()); }
/** * Unpack snapshot * * @param string $tmpDir */ protected function _unpackSnapshot($tmpDir) { $snapshotPath = $this->_snapshot->getBackupPath(); $archiver = new Mage_Archive(); $archiver->unpack($snapshotPath, $tmpDir); }