From 20d0202e76898dbbf280294fe02c95f9b11f3e2d Mon Sep 17 00:00:00 2001 From: Md Abu Ahsan Basir Date: Wed, 1 Jan 2020 22:09:15 +0600 Subject: [PATCH] Update Dumper --- src/Drivers/MongoDumper.php | 16 +++++++++++++ src/Drivers/MysqlDumper.php | 16 +++++++++++++ src/Drivers/PgsqlDumper.php | 16 +++++++++++++ src/Drivers/SqliteDumper.php | 16 +++++++++++++ src/Dumper.php | 38 ------------------------------ src/Traits/PrepareOptionsTrait.php | 8 +++++++ 6 files changed, 72 insertions(+), 38 deletions(-) diff --git a/src/Drivers/MongoDumper.php b/src/Drivers/MongoDumper.php index 36ba042..94158e4 100644 --- a/src/Drivers/MongoDumper.php +++ b/src/Drivers/MongoDumper.php @@ -48,6 +48,22 @@ public function restore(string $restorePath = "") $this->run(); } + public function getDumpCommand($destinationPath = '') + { + $destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath; + $dumpCommand = $this->prepareDumpCommand($destinationPath); + + return $this->removeExtraSpaces($dumpCommand); + } + + public function getRestoreCommand(string $filePath = '') + { + $filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath; + $restoreCommand = $this->prepareRestoreCommand($filePath); + + return $this->removeExtraSpaces($restoreCommand); + } + protected function prepareDumpCommand(string $destinationPath): string { $archive = $this->isCompress ? "--archive --gzip" : ""; diff --git a/src/Drivers/MysqlDumper.php b/src/Drivers/MysqlDumper.php index 5746cc1..2cc4235 100644 --- a/src/Drivers/MysqlDumper.php +++ b/src/Drivers/MysqlDumper.php @@ -65,6 +65,22 @@ public function restore(string $restorePath = "") return $this; } + public function getDumpCommand(string $credentialFile = '', $destinationPath = '') + { + $destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath; + $dumpCommand = $this->prepareDumpCommand($credentialFile, $destinationPath); + + return $this->removeExtraSpaces($dumpCommand); + } + + public function getRestoreCommand(string $credentialFile = '', string $filePath = '') + { + $filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath; + $restoreCommand = $this->prepareRestoreCommand($credentialFile, $filePath); + + return $this->removeExtraSpaces($restoreCommand); + } + protected function prepareDumpCommand(string $credentialFile, string $destinationPath): string { $dumpCommand = sprintf( diff --git a/src/Drivers/PgsqlDumper.php b/src/Drivers/PgsqlDumper.php index e0b9836..d2e3293 100644 --- a/src/Drivers/PgsqlDumper.php +++ b/src/Drivers/PgsqlDumper.php @@ -43,6 +43,22 @@ public function restore(string $restorePath = "") $this->runCommand(); } + public function getDumpCommand($destinationPath = '') + { + $destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath; + $dumpCommand = $this->prepareDumpCommand($destinationPath); + + return $this->removeExtraSpaces($dumpCommand); + } + + public function getRestoreCommand(string $filePath = '') + { + $filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath; + $restoreCommand = $this->prepareRestoreCommand($filePath); + + return $this->removeExtraSpaces($restoreCommand); + } + protected function prepareDumpCommand(string $destinationPath): string { $dumpCommand = sprintf( diff --git a/src/Drivers/SqliteDumper.php b/src/Drivers/SqliteDumper.php index cb37f01..9bdac77 100644 --- a/src/Drivers/SqliteDumper.php +++ b/src/Drivers/SqliteDumper.php @@ -22,6 +22,22 @@ public function restore(string $restorePath = "") $this->run(); } + public function getDumpCommand($destinationPath = '') + { + $destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath; + $dumpCommand = $this->prepareDumpCommand($destinationPath); + + return $this->removeExtraSpaces($dumpCommand); + } + + public function getRestoreCommand(string $filePath = '') + { + $filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath; + $restoreCommand = $this->prepareRestoreCommand($filePath); + + return $this->removeExtraSpaces($restoreCommand); + } + protected function prepareDumpCommand(string $destinationPath): string { $dumpCommand = sprintf( diff --git a/src/Dumper.php b/src/Dumper.php index 6fc19bc..e33e805 100644 --- a/src/Dumper.php +++ b/src/Dumper.php @@ -62,44 +62,6 @@ protected function run() } } - public function getDumpCommand(string $credentialFile = '', $destinationPath = '') - { - $destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath; - switch (strtolower($this->getDumperClassName())) { - case 'mysqldumper': - $dumpCommand = $this->prepareDumpCommand($credentialFile, $destinationPath); - break; - default: - $dumpCommand = $this->prepareDumpCommand($destinationPath); - break; - } - - return $this->removeExtraSpaces($dumpCommand); - } - - public function getRestoreCommand(string $credentialFile = '', string $filePath = '') - { - $filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath; - switch (strtolower($this->getDumperClassName())) { - case 'mysqldumper': - $restoreCommand = $this->prepareRestoreCommand($credentialFile, $filePath); - break; - default: - $restoreCommand = $this->prepareRestoreCommand($filePath); - break; - } - - return $this->removeExtraSpaces($restoreCommand); - } - - public function getDumperClassName() - { - $classWithNamespace = static::class; - $partials = explode("\\", $classWithNamespace); - $className = end($partials); - return $className; - } - public function removeExtraSpaces(string $str) { return preg_replace('/\s+/', ' ', $str); diff --git a/src/Traits/PrepareOptionsTrait.php b/src/Traits/PrepareOptionsTrait.php index 061e6c6..7bb05c6 100644 --- a/src/Traits/PrepareOptionsTrait.php +++ b/src/Traits/PrepareOptionsTrait.php @@ -77,4 +77,12 @@ public function prepareIgnoreTables() return (count($this->ignoreTables) > 0) ? '-T ' . implode(' -T ', $this->ignoreTables) : ''; } } + + public function getDumperClassName() + { + $classWithNamespace = static::class; + $partials = explode("\\", $classWithNamespace); + $className = end($partials); + return $className; + } }