@@ -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
0 commit comments