Skip to content

Commit

Permalink
Merge branch 'configurableDumpCommand'
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.json
  • Loading branch information
mficzel committed Jan 13, 2022
2 parents 90a395f + 1857956 commit e0c2a9c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
7 changes: 6 additions & 1 deletion Classes/Command/CloneCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function presetCommand($presetName, $yes = false, $keepDb = false)
$yes,
$keepDb,
$configuration['flowCommand'] ?? null,
$configuration['dumpCommand'] ?? null,
$configuration['sshOptions'] ?? ''
);
} else {
Expand All @@ -128,7 +129,8 @@ public function presetCommand($presetName, $yes = false, $keepDb = false)
* @param null $postClone command or array of commands to be executed after cloning
* @param boolean $yes confirm execution without further input
* @param boolean $keepDb skip dropping of database during sync
* @param null $remoteFlowCommand the flow command to execute on the remote system
* @param string|null $remoteFlowCommand the flow command to execute on the remote system
* @param string|null $remoteDumpCommand the dump command to execute on the remote system
* @param string $sshOptions additional options for the ssh command
* @throws StopCommandException
* @throws StopActionException
Expand All @@ -144,6 +146,7 @@ protected function cloneRemoteHost(
$yes = false,
$keepDb = false,
$remoteFlowCommand = null,
$remoteDumpCommand = null,
$sshOptions = ''
)
{
Expand Down Expand Up @@ -283,6 +286,7 @@ protected function cloneRemoteHost(
$remotePersistenceConfiguration['user'],
escapeshellcmd($remotePersistenceConfiguration['password']),
$remotePersistenceConfiguration['dbname'],
$remoteDumpCommand,
$tableContentToSkip
),
$this->dbal->buildCmd(
Expand Down Expand Up @@ -311,6 +315,7 @@ protected function cloneRemoteHost(
$remotePersistenceConfiguration['user'],
escapeshellcmd($remotePersistenceConfiguration['password']),
$remotePersistenceConfiguration['dbname'],
$remoteDumpCommand,
$tableContentToSkip
),
$this->dbal->buildCmd(
Expand Down
4 changes: 3 additions & 1 deletion Classes/Command/StashCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function createCommand($name)
$this->renderHeadLine('Write Manifest');
$presetName = $this->configurationService->getCurrentPreset();
$presetConfiguration = $this->configurationService->getCurrentConfiguration();
$remoteDumpCommand = $presetConfiguration['dumpCommand'] ?? null;
$cloneTimestamp = $this->configurationService->getMostRecentCloneTimeStamp();
$stashTimestamp = time();

Expand All @@ -96,7 +97,8 @@ public function createCommand($name)
(int)$this->databaseConfiguration['port'],
$this->databaseConfiguration['user'],
$this->databaseConfiguration['password'],
$this->databaseConfiguration['dbname']
$this->databaseConfiguration['dbname'],
$remoteDumpCommand
) . ' > ' . $databaseDestination
);

Expand Down
34 changes: 26 additions & 8 deletions Classes/DBAL/SimpleDBAL.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,30 @@ public function buildCmd(string $driver, ?string $host, int $port, string $usern
* @param string $username
* @param string $password
* @param string $database
* @param string|null $dumpCommand
* @param array $excludeTables
* @return string
*/
public function buildDataDumpCmd(string $driver, ?string $host, int $port, string $username, string $password, string $database, array $excludeTables = []): string
{
public function buildDataDumpCmd(
string $driver,
?string $host,
int $port,
string $username,
string $password,
string $database,
?string $dumpCommand = null,
array $excludeTables = []
): string {
$buildExcludeTableParameters = static function (string $parameterName) use ($excludeTables, $database) {
return implode(' ', array_map(static function (string $excludeTable) use ($parameterName, $database) {
return sprintf('%s %s.%s', $parameterName, $database, $excludeTable);
}, $excludeTables));
};

if ($driver === 'pdo_mysql') {
return sprintf('mysqldump --single-transaction --add-drop-table --no-tablespaces --host=%s --port=%s --user=%s --password=%s %s %s', escapeshellarg($host), escapeshellarg($port), escapeshellarg($username), escapeshellarg($password), $buildExcludeTableParameters('--ignore-table'), escapeshellarg($database));
return sprintf(($dumpCommand ?: 'mysqldump') . ' --single-transaction --add-drop-table --no-tablespaces --host=%s --port=%s --user=%s --password=%s %s %s', escapeshellarg($host), escapeshellarg($port), escapeshellarg($username), escapeshellarg($password), $buildExcludeTableParameters('--ignore-table'), escapeshellarg($database));
} else if ($driver === 'pdo_pgsql') {
return sprintf('PGPASSWORD=%s pg_dump --host=%s --port=%s --username=%s %s --dbname=%s --schema=public --no-owner --no-privileges', escapeshellarg($password), escapeshellarg($host), escapeshellarg($port), escapeshellarg($username), $buildExcludeTableParameters('--exclude-table'), escapeshellarg($database));
return sprintf('PGPASSWORD=%s ' . ($dumpCommand ?: 'pg_dump') . ' --host=%s --port=%s --username=%s %s --dbname=%s --schema=public --no-owner --no-privileges', escapeshellarg($password), escapeshellarg($host), escapeshellarg($port), escapeshellarg($username), $buildExcludeTableParameters('--exclude-table'), escapeshellarg($database));
}
}

Expand All @@ -61,21 +70,30 @@ public function buildDataDumpCmd(string $driver, ?string $host, int $port, strin
* @param string $username
* @param string $password
* @param string $database
* @param ?string $dumpCommand
* @param array $tables
* @return string
*/
public function buildSchemaDumpCmd(string $driver, ?string $host, int $port, string $username, string $password, string $database, array $tables = []): string
{
public function buildSchemaDumpCmd(
string $driver,
?string $host,
int $port,
string $username,
string $password,
string $database,
?string $dumpCommand = null,
array $tables = []
): string {
$buildOnlyTableParameters = static function (string $parameterName = '') use ($tables) {
return implode(' ', array_map(static function (string $table) use ($parameterName) {
return trim($parameterName . ' ' . $table);
}, $tables));
};

if ($driver === 'pdo_mysql') {
return sprintf('mysqldump --single-transaction --add-drop-table --no-tablespaces --no-data --host=%s --port=%s --user=%s --password=%s %s %s', escapeshellarg($host), escapeshellarg($port), escapeshellarg($username), escapeshellarg($password), escapeshellarg($database), $buildOnlyTableParameters());
return sprintf(($dumpCommand ?: 'mysqldump') . ' --single-transaction --add-drop-table --no-tablespaces --no-data --host=%s --port=%s --user=%s --password=%s %s %s', escapeshellarg($host), escapeshellarg($port), escapeshellarg($username), escapeshellarg($password), escapeshellarg($database), $buildOnlyTableParameters());
} else if ($driver === 'pdo_pgsql') {
return sprintf('PGPASSWORD=%s pg_dump --host=%s --port=%s --username=%s --dbname=%s --schema=public --no-owner --no-privileges --schema-only %s', escapeshellarg($password), escapeshellarg($host), escapeshellarg($port), escapeshellarg($username), escapeshellarg($database), $buildOnlyTableParameters('-t'));
return sprintf('PGPASSWORD=%s ' . ($dumpCommand ?: 'pg_dump') . ' --host=%s --port=%s --username=%s --dbname=%s --schema=public --no-owner --no-privileges --schema-only %s', escapeshellarg($password), escapeshellarg($host), escapeshellarg($port), escapeshellarg($username), escapeshellarg($database), $buildOnlyTableParameters('-t'));
}
}

Expand Down
3 changes: 3 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ Sitegeist:
# # default is the main flowCommand-Setting
# flowCommand: ~
#
# # the custom remote dump command, defaults to mysqldump or pg_dump
# dumpCommand: ~
#
# # options to adjust the clone process
# clone:
# # Optionally skip the publish step
Expand Down

0 comments on commit e0c2a9c

Please sign in to comment.