Skip to content

Commit

Permalink
[FEATURE] add option to mask fields and modify export
Browse files Browse the repository at this point in the history
Fixes #1
  • Loading branch information
kaystrobach committed May 31, 2015
1 parent eafeffa commit 9ef0099
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
15 changes: 8 additions & 7 deletions Classes/KayStrobach/Backup/Command/BackupCommandController.php
Expand Up @@ -47,9 +47,10 @@ public function setBackupFolder($name = NULL) {
* @param bool $database
* @param bool $settings
* @param bool $composer
* @param string $preset
* @throws \TYPO3\Flow\Utility\Exception
*/
public function createCommand($database = TRUE, $settings = TRUE, $composer = TRUE) {
public function createCommand($database = TRUE, $settings = TRUE, $composer = TRUE, $preset = 'default') {
$this->setBackupFolder();
Files::createDirectoryRecursively($this->backupFolder);
if($composer) {
Expand All @@ -68,9 +69,9 @@ public function createCommand($database = TRUE, $settings = TRUE, $composer = TR
}
if($database) {
Files::createDirectoryRecursively($this->backupFolder . 'Database');
$this->emitCreateDbBackup($this->backupFolder . 'Database/');
$this->emitCreateDbBackup($this->backupFolder . 'Database/', $preset);
}
$this->emitBeforeCompression($this->backupFolder);
$this->emitBeforeCompression($this->backupFolder, $preset);
}

/**
Expand Down Expand Up @@ -124,23 +125,23 @@ public function listCommand() {
* @return void
* @Flow\Signal
*/
protected function emitCreateDbBackup($backupPath) {}
protected function emitCreateDbBackup($backupPath, $exportName = 'default') {}

/**
* @return void
* @Flow\Signal
*/
protected function emitRestoreDbBackup($backupPath) {}
protected function emitRestoreDbBackup($backupPath, $exportName = 'default') {}

/**
* @return void
* @Flow\Signal
*/
protected function emitBeforeCompression($backupPath) {}
protected function emitBeforeCompression($backupPath, $exportName = 'default') {}

/**
* @return void
* @Flow\Signal
*/
protected function emitAfterDecompression($backupPath) {}
protected function emitAfterDecompression($backupPath, $exportName = 'default') {}
}
27 changes: 22 additions & 5 deletions Classes/KayStrobach/Backup/Driver/Database/AbtractDriver.php
Expand Up @@ -18,6 +18,11 @@ abstract class AbtractDriver {
*/
protected $settings = array();

/**
* @var array
*/
protected $processingSettings = array();

/**
* @var string
*/
Expand All @@ -33,34 +38,46 @@ abstract class AbtractDriver {

/**
* inits some of the needed internal variables and triggers the backup if needed
*
* @param string $path
* @param string $exportName
*/
public function catchBackupSignal($path) {
public function catchBackupSignal($path, $exportName = 'default') {
$this->backupPath = $path;
$this->fetchSettings();
$this->fetchSettings($exportName);
if($this->drivername === $this->settings['driver']) {
$this->backup();
}
}

/**
* inits some of the needed internal variables and triggers the restore if needed
*
* @param string $path
* @param string $exportName
*/
public function catchRestoreSignal($path) {
public function catchRestoreSignal($path, $exportName = 'default') {
$this->backupPath = $path;
$this->fetchSettings();
$this->fetchSettings($exportName);
if($this->drivername === $this->settings['driver']) {
$this->restore();
}
}

/**
* provide the settings needed to configure the driver
*
* @param string $exportName
*/
protected function fetchSettings() {
protected function fetchSettings($exportName = 'default') {
$this->settings = $this->configurationManager->getConfiguration(
\TYPO3\FLOW\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
'TYPO3.Flow.persistence.backendOptions'
);
$this->processingSettings = $this->configurationManager->getConfiguration(
'KayStrobach.Backup',
'Backup.' . $exportName
);
}

/**
Expand Down
21 changes: 17 additions & 4 deletions Classes/KayStrobach/Backup/Driver/Database/PdoMysqlDriver.php
Expand Up @@ -48,14 +48,27 @@ protected function restore() {
}

protected function buildMySqlDumpCommand($username, $password, $database, $host, $charset, $dumpFilename) {
$command = 'mysqldump --user=' . $username . ' --password=' . $password . ' --host=' . $host .
$tables = $this->processingSettings['database']['tables'];
$ignoreTables = '';
$specialCommands = '';
if(is_array($tables)) {
foreach($tables as $table => $options) {
$ignoreTables .= ' --ignore-table=' . $this->settings['dbname'] . '.' . $table . ' ';
$specialCommands .= 'MYSQL_PWD=' . $password . ' mysqldump --user=' . $username . ' --host=' . $host .
' -c -e --default-character-set=' . $charset .
' --single-transaction --skip-set-charset --where="' . $options['mysqldump']['where'] . '" ' . $database . ' ' . $table . ' >> ' . $dumpFilename . ';';
}
}

$command = 'MYSQL_PWD=' . $password . ' mysqldump --user=' . $username . ' --host=' . $host .
' -c -e --default-character-set=' . $charset .
' --single-transaction --skip-set-charset ' . $database . '> ' . $dumpFilename;
return $command;
' --single-transaction --skip-set-charset ' . $ignoreTables . $database . '> ' . $dumpFilename . ';';

return $command . $specialCommands;
}

protected function buildMysqlImportCommand($username, $password, $database, $host, $charset, $dumpFilename) {
$command = 'mysql --user=' . $username .' --password=' . $password . ' --host=' . $host .
$command = 'MYSQL_PWD=' . $password . ' mysql --user=' . $username . ' --host=' . $host .
' --default-character-set=' . $charset . ' ' . $database . ' < ' . $dumpFilename;
return $command;
}
Expand Down
9 changes: 9 additions & 0 deletions Classes/KayStrobach/Backup/Package.php
Expand Up @@ -28,5 +28,14 @@ public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap) {
'KayStrobach\Backup\Command\BackupCommandController', 'restoreDbBackup',
'KayStrobach\Backup\Driver\Database\PdoMysqlDriver', 'catchRestoreSignal'
);

//register Configuration Type Menu
$dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect('TYPO3\Flow\Configuration\ConfigurationManager', 'configurationManagerReady',
function ($configurationManager) {
$configurationManager->registerConfigurationType('KayStrobach.Backup');
}
);

}
}
6 changes: 6 additions & 0 deletions Configuration/KayStrobach.Backup.yaml
@@ -0,0 +1,6 @@
# Backup:
# default:
# settings:
# composer:
# database:
# tables:

0 comments on commit 9ef0099

Please sign in to comment.