Skip to content

Commit e0c2a9c

Browse files
committed
Merge branch 'configurableDumpCommand'
# Conflicts: # composer.json
2 parents 90a395f + 1857956 commit e0c2a9c

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

Classes/Command/CloneCommandController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function presetCommand($presetName, $yes = false, $keepDb = false)
104104
$yes,
105105
$keepDb,
106106
$configuration['flowCommand'] ?? null,
107+
$configuration['dumpCommand'] ?? null,
107108
$configuration['sshOptions'] ?? ''
108109
);
109110
} else {
@@ -128,7 +129,8 @@ public function presetCommand($presetName, $yes = false, $keepDb = false)
128129
* @param null $postClone command or array of commands to be executed after cloning
129130
* @param boolean $yes confirm execution without further input
130131
* @param boolean $keepDb skip dropping of database during sync
131-
* @param null $remoteFlowCommand the flow command to execute on the remote system
132+
* @param string|null $remoteFlowCommand the flow command to execute on the remote system
133+
* @param string|null $remoteDumpCommand the dump command to execute on the remote system
132134
* @param string $sshOptions additional options for the ssh command
133135
* @throws StopCommandException
134136
* @throws StopActionException
@@ -144,6 +146,7 @@ protected function cloneRemoteHost(
144146
$yes = false,
145147
$keepDb = false,
146148
$remoteFlowCommand = null,
149+
$remoteDumpCommand = null,
147150
$sshOptions = ''
148151
)
149152
{
@@ -283,6 +286,7 @@ protected function cloneRemoteHost(
283286
$remotePersistenceConfiguration['user'],
284287
escapeshellcmd($remotePersistenceConfiguration['password']),
285288
$remotePersistenceConfiguration['dbname'],
289+
$remoteDumpCommand,
286290
$tableContentToSkip
287291
),
288292
$this->dbal->buildCmd(
@@ -311,6 +315,7 @@ protected function cloneRemoteHost(
311315
$remotePersistenceConfiguration['user'],
312316
escapeshellcmd($remotePersistenceConfiguration['password']),
313317
$remotePersistenceConfiguration['dbname'],
318+
$remoteDumpCommand,
314319
$tableContentToSkip
315320
),
316321
$this->dbal->buildCmd(

Classes/Command/StashCommandController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function createCommand($name)
7171
$this->renderHeadLine('Write Manifest');
7272
$presetName = $this->configurationService->getCurrentPreset();
7373
$presetConfiguration = $this->configurationService->getCurrentConfiguration();
74+
$remoteDumpCommand = $presetConfiguration['dumpCommand'] ?? null;
7475
$cloneTimestamp = $this->configurationService->getMostRecentCloneTimeStamp();
7576
$stashTimestamp = time();
7677

@@ -96,7 +97,8 @@ public function createCommand($name)
9697
(int)$this->databaseConfiguration['port'],
9798
$this->databaseConfiguration['user'],
9899
$this->databaseConfiguration['password'],
99-
$this->databaseConfiguration['dbname']
100+
$this->databaseConfiguration['dbname'],
101+
$remoteDumpCommand
100102
) . ' > ' . $databaseDestination
101103
);
102104

Classes/DBAL/SimpleDBAL.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,30 @@ public function buildCmd(string $driver, ?string $host, int $port, string $usern
3636
* @param string $username
3737
* @param string $password
3838
* @param string $database
39+
* @param string|null $dumpCommand
3940
* @param array $excludeTables
4041
* @return string
4142
*/
42-
public function buildDataDumpCmd(string $driver, ?string $host, int $port, string $username, string $password, string $database, array $excludeTables = []): string
43-
{
43+
public function buildDataDumpCmd(
44+
string $driver,
45+
?string $host,
46+
int $port,
47+
string $username,
48+
string $password,
49+
string $database,
50+
?string $dumpCommand = null,
51+
array $excludeTables = []
52+
): string {
4453
$buildExcludeTableParameters = static function (string $parameterName) use ($excludeTables, $database) {
4554
return implode(' ', array_map(static function (string $excludeTable) use ($parameterName, $database) {
4655
return sprintf('%s %s.%s', $parameterName, $database, $excludeTable);
4756
}, $excludeTables));
4857
};
4958

5059
if ($driver === 'pdo_mysql') {
51-
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));
60+
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));
5261
} else if ($driver === 'pdo_pgsql') {
53-
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));
62+
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));
5463
}
5564
}
5665

@@ -61,21 +70,30 @@ public function buildDataDumpCmd(string $driver, ?string $host, int $port, strin
6170
* @param string $username
6271
* @param string $password
6372
* @param string $database
73+
* @param ?string $dumpCommand
6474
* @param array $tables
6575
* @return string
6676
*/
67-
public function buildSchemaDumpCmd(string $driver, ?string $host, int $port, string $username, string $password, string $database, array $tables = []): string
68-
{
77+
public function buildSchemaDumpCmd(
78+
string $driver,
79+
?string $host,
80+
int $port,
81+
string $username,
82+
string $password,
83+
string $database,
84+
?string $dumpCommand = null,
85+
array $tables = []
86+
): string {
6987
$buildOnlyTableParameters = static function (string $parameterName = '') use ($tables) {
7088
return implode(' ', array_map(static function (string $table) use ($parameterName) {
7189
return trim($parameterName . ' ' . $table);
7290
}, $tables));
7391
};
7492

7593
if ($driver === 'pdo_mysql') {
76-
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());
94+
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());
7795
} else if ($driver === 'pdo_pgsql') {
78-
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'));
96+
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'));
7997
}
8098
}
8199

Configuration/Settings.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ Sitegeist:
3131
# # default is the main flowCommand-Setting
3232
# flowCommand: ~
3333
#
34+
# # the custom remote dump command, defaults to mysqldump or pg_dump
35+
# dumpCommand: ~
36+
#
3437
# # options to adjust the clone process
3538
# clone:
3639
# # Optionally skip the publish step

0 commit comments

Comments
 (0)