public function tearDown() { if (file_exists(__DIR__ . '/_files/output/pack')) { $helper = new \Magento\Framework\Backup\Filesystem\Helper(); $helper->rm(__DIR__ . '/_files/output/pack', [], true); } }
private function removeCsv($module) { if (file_exists(__DIR__ . "/_files/root/app/code/Magento/{$module}/i18n")) { $helper = new \Magento\Framework\Backup\Filesystem\Helper(); $helper->rm(__DIR__ . "/_files/root/app/code/Magento/{$module}/i18n", [], true); } }
/** * Implementation Create Backup functionality for Filesystem * * @throws \Magento\Framework\Exception\LocalizedException * @return boolean */ public function create() { set_time_limit(0); ignore_user_abort(true); $this->_lastOperationSucceed = false; $this->_checkBackupsDir(); $fsHelper = new \Magento\Framework\Backup\Filesystem\Helper(); $filesInfo = $fsHelper->getInfo($this->getRootDir(), \Magento\Framework\Backup\Filesystem\Helper::INFO_READABLE | \Magento\Framework\Backup\Filesystem\Helper::INFO_SIZE, $this->getIgnorePaths()); if (!$filesInfo['readable']) { throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions(new \Magento\Framework\Phrase('Not enough permissions to read files for backup')); } $this->validateAvailableDiscSpace($this->getBackupsDir(), $filesInfo['size']); $tarTmpPath = $this->_getTarTmpPath(); $tarPacker = new \Magento\Framework\Backup\Archive\Tar(); $tarPacker->setSkipFiles($this->getIgnorePaths())->pack($this->getRootDir(), $tarTmpPath, true); if (!is_file($tarTmpPath) || filesize($tarTmpPath) == 0) { throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Failed to create backup')); } $backupPath = $this->getBackupPath(); $gzPacker = new \Magento\Framework\Archive\Gz(); $gzPacker->pack($tarTmpPath, $backupPath); if (!is_file($backupPath) || filesize($backupPath) == 0) { throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Failed to create backup')); } @unlink($tarTmpPath); $this->_lastOperationSucceed = true; return $this->_lastOperationSucceed; }
/** * Files rollback implementation via ftp * * @return void * @throws \Magento\Framework\Exception\LocalizedException * * @see AbstractRollback::run() */ public function run() { $snapshotPath = $this->_snapshot->getBackupPath(); if (!is_file($snapshotPath) || !is_readable($snapshotPath)) { throw new \Magento\Framework\Backup\Exception\CantLoadSnapshot(new \Magento\Framework\Phrase('Can\'t load snapshot archive')); } $this->_initFtpClient(); $this->_validateFtp(); $tmpDir = $this->_createTmpDir(); $this->_unpackSnapshot($tmpDir); $fsHelper = new \Magento\Framework\Backup\Filesystem\Helper(); $this->_cleanupFtp(); $this->_uploadBackupToFtp($tmpDir); $fsHelper->rm($tmpDir, [], true); }
/** * Files rollback implementation via local filesystem * * @return void * @throws \Magento\Framework\Exception\LocalizedException * * @see AbstractRollback::run() */ public function run() { $snapshotPath = $this->_snapshot->getBackupPath(); if (!is_file($snapshotPath) || !is_readable($snapshotPath)) { throw new \Magento\Framework\Backup\Exception\CantLoadSnapshot(new \Magento\Framework\Phrase('Can\'t load snapshot archive')); } $fsHelper = new \Magento\Framework\Backup\Filesystem\Helper(); $filesInfo = $fsHelper->getInfo($this->_snapshot->getRootDir(), \Magento\Framework\Backup\Filesystem\Helper::INFO_WRITABLE, $this->_snapshot->getIgnorePaths()); if (!$filesInfo['writable']) { throw new \Magento\Framework\Backup\Exception\NotEnoughPermissions(new \Magento\Framework\Phrase('Unable to make rollback because not all files are writable')); } $archiver = new \Magento\Framework\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 \Magento\Framework\Archive\Tar(); new \Magento\Framework\Archive\Gz(); new \Magento\Framework\Archive\Helper\File(''); new \Magento\Framework\Archive\Helper\File\Gz(''); $fsHelper->rm($this->_snapshot->getRootDir(), $this->_snapshot->getIgnorePaths()); $archiver->unpack($snapshotPath, $this->_snapshot->getRootDir()); }