Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to keep Files in Rollback #11750

Merged
merged 2 commits into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions lib/internal/Magento/Framework/Backup/AbstractBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
*/
namespace Magento\Framework\Backup;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;

/**
* Class to work with archives
*
* @api
*/
abstract class AbstractBackup implements BackupInterface
abstract class AbstractBackup implements BackupInterface, SourceFileInterface
{
/**
* Backup name
Expand Down Expand Up @@ -68,6 +71,13 @@ abstract class AbstractBackup implements BackupInterface
*/
protected $_lastErrorMessage;

/**
* Keep Source files in Backup
*
* @var boolean
*/
private $keepSourceFile;

/**
* Set Backup Extension
*
Expand Down Expand Up @@ -138,14 +148,14 @@ public function getTime()
* Set root directory of Magento installation
*
* @param string $rootDir
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
* @return $this
*/
public function setRootDir($rootDir)
{
if (!is_dir($rootDir)) {
throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase('Bad root directory')
throw new LocalizedException(
new Phrase('Bad root directory')
);
}

Expand Down Expand Up @@ -296,4 +306,26 @@ protected function _filterName($name)

return $name;
}

/**
* Check if keep files of backup
*
* @return bool
*/
public function keepSourceFile()
{
return $this->keepSourceFile;
}

/**
* Set if keep files of backup
*
* @param bool $keepSourceFile
* @return $this
*/
public function setKeepSourceFile(bool $keepSourceFile)
{
$this->keepSourceFile = $keepSourceFile;
return $this;
}
}
12 changes: 8 additions & 4 deletions lib/internal/Magento/Framework/Backup/Archive/Tar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
namespace Magento\Framework\Backup\Archive;

use Magento\Framework\Backup\Filesystem\Iterator\Filter;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;

class Tar extends \Magento\Framework\Archive\Tar
{
/**
Expand All @@ -35,12 +39,12 @@ protected function _createTar($skipRoot = false, $finalize = false)
{
$path = $this->_getCurrentFile();

$filesystemIterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($path),
\RecursiveIteratorIterator::SELF_FIRST
$filesystemIterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST
);

$iterator = new \Magento\Framework\Backup\Filesystem\Iterator\Filter(
$iterator = new Filter(
$filesystemIterator,
$this->_skipFiles
);
Expand Down
18 changes: 12 additions & 6 deletions lib/internal/Magento/Framework/Backup/Db.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/
namespace Magento\Framework\Backup;

use Magento\Framework\Archive;
use Magento\Framework\Backup\Db\BackupFactory;
use Magento\Framework\Backup\Filesystem\Iterator\File;

/**
* Class to work with database backups
*
Expand All @@ -14,14 +18,14 @@
class Db extends AbstractBackup
{
/**
* @var \Magento\Framework\Backup\Db\BackupFactory
* @var BackupFactory
*/
protected $_backupFactory;

/**
* @param \Magento\Framework\Backup\Db\BackupFactory $backupFactory
* @param BackupFactory $backupFactory
*/
public function __construct(\Magento\Framework\Backup\Db\BackupFactory $backupFactory)
public function __construct(BackupFactory $backupFactory)
{
$this->_backupFactory = $backupFactory;
}
Expand All @@ -38,14 +42,16 @@ public function rollback()

$this->_lastOperationSucceed = false;

$archiveManager = new \Magento\Framework\Archive();
$archiveManager = new Archive();
$source = $archiveManager->unpack($this->getBackupPath(), $this->getBackupsDir());

$file = new \Magento\Framework\Backup\Filesystem\Iterator\File($source);
$file = new File($source);
foreach ($file as $statement) {
$this->getResourceModel()->runCommand($statement);
}
@unlink($source);
if ($this->keepSourceFile() === false) {
@unlink($source);
}

$this->_lastOperationSucceed = true;

Expand Down
24 changes: 13 additions & 11 deletions lib/internal/Magento/Framework/Backup/Db/BackupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\Framework\Backup\Db;

use Magento\Framework\ObjectManagerInterface;

/**
* @api
*/
Expand All @@ -14,33 +16,33 @@ class BackupFactory
/**
* Object manager
*
* @var \Magento\Framework\ObjectManagerInterface
* @var ObjectManagerInterface
*/
private $_objectManager;
private $objectManager;

/**
* @var string
*/
private $_backupInstanceName;
private $backupInstanceName;

/**
* @var string
*/
private $_backupDbInstanceName;
private $backupDbInstanceName;

/**
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param ObjectManagerInterface $objectManager
* @param string $backupInstanceName
* @param string $backupDbInstanceName
*/
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
ObjectManagerInterface $objectManager,
$backupInstanceName,
$backupDbInstanceName
) {
$this->_objectManager = $objectManager;
$this->_backupInstanceName = $backupInstanceName;
$this->_backupDbInstanceName = $backupDbInstanceName;
$this->objectManager = $objectManager;
$this->backupInstanceName = $backupInstanceName;
$this->backupDbInstanceName = $backupDbInstanceName;
}

/**
Expand All @@ -51,7 +53,7 @@ public function __construct(
*/
public function createBackupModel(array $arguments = [])
{
return $this->_objectManager->create($this->_backupInstanceName, $arguments);
return $this->objectManager->create($this->backupInstanceName, $arguments);
}

/**
Expand All @@ -62,6 +64,6 @@ public function createBackupModel(array $arguments = [])
*/
public function createBackupDbModel(array $arguments = [])
{
return $this->_objectManager->create($this->_backupDbInstanceName, $arguments);
return $this->objectManager->create($this->backupDbInstanceName, $arguments);
}
}
16 changes: 10 additions & 6 deletions lib/internal/Magento/Framework/Backup/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*/
namespace Magento\Framework\Backup;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Phrase;

/**
* @api
*/
Expand All @@ -17,7 +21,7 @@ class Factory
/**
* Object manager
*
* @var \Magento\Framework\ObjectManagerInterface
* @var ObjectManagerInterface
*/
private $_objectManager;

Expand Down Expand Up @@ -54,9 +58,9 @@ class Factory
protected $_allowedTypes;

/**
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param ObjectManagerInterface $objectManager
*/
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
public function __construct(ObjectManagerInterface $objectManager)
{
$this->_objectManager = $objectManager;
$this->_allowedTypes = [
Expand All @@ -73,13 +77,13 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan
*
* @param string $type
* @return BackupInterface
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
*/
public function create($type)
{
if (!in_array($type, $this->_allowedTypes)) {
throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase(
throw new LocalizedException(
new Phrase(
'Current implementation not supported this type (%1) of backup.',
[$type]
)
Expand Down
Loading