Skip to content

Commit 20d0202

Browse files
committed
Update Dumper
1 parent ae1aa8a commit 20d0202

File tree

6 files changed

+72
-38
lines changed

6 files changed

+72
-38
lines changed

src/Drivers/MongoDumper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ public function restore(string $restorePath = "")
4848
$this->run();
4949
}
5050

51+
public function getDumpCommand($destinationPath = '')
52+
{
53+
$destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath;
54+
$dumpCommand = $this->prepareDumpCommand($destinationPath);
55+
56+
return $this->removeExtraSpaces($dumpCommand);
57+
}
58+
59+
public function getRestoreCommand(string $filePath = '')
60+
{
61+
$filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath;
62+
$restoreCommand = $this->prepareRestoreCommand($filePath);
63+
64+
return $this->removeExtraSpaces($restoreCommand);
65+
}
66+
5167
protected function prepareDumpCommand(string $destinationPath): string
5268
{
5369
$archive = $this->isCompress ? "--archive --gzip" : "";

src/Drivers/MysqlDumper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ public function restore(string $restorePath = "")
6565
return $this;
6666
}
6767

68+
public function getDumpCommand(string $credentialFile = '', $destinationPath = '')
69+
{
70+
$destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath;
71+
$dumpCommand = $this->prepareDumpCommand($credentialFile, $destinationPath);
72+
73+
return $this->removeExtraSpaces($dumpCommand);
74+
}
75+
76+
public function getRestoreCommand(string $credentialFile = '', string $filePath = '')
77+
{
78+
$filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath;
79+
$restoreCommand = $this->prepareRestoreCommand($credentialFile, $filePath);
80+
81+
return $this->removeExtraSpaces($restoreCommand);
82+
}
83+
6884
protected function prepareDumpCommand(string $credentialFile, string $destinationPath): string
6985
{
7086
$dumpCommand = sprintf(

src/Drivers/PgsqlDumper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ public function restore(string $restorePath = "")
4343
$this->runCommand();
4444
}
4545

46+
public function getDumpCommand($destinationPath = '')
47+
{
48+
$destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath;
49+
$dumpCommand = $this->prepareDumpCommand($destinationPath);
50+
51+
return $this->removeExtraSpaces($dumpCommand);
52+
}
53+
54+
public function getRestoreCommand(string $filePath = '')
55+
{
56+
$filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath;
57+
$restoreCommand = $this->prepareRestoreCommand($filePath);
58+
59+
return $this->removeExtraSpaces($restoreCommand);
60+
}
61+
4662
protected function prepareDumpCommand(string $destinationPath): string
4763
{
4864
$dumpCommand = sprintf(

src/Drivers/SqliteDumper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ public function restore(string $restorePath = "")
2222
$this->run();
2323
}
2424

25+
public function getDumpCommand($destinationPath = '')
26+
{
27+
$destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath;
28+
$dumpCommand = $this->prepareDumpCommand($destinationPath);
29+
30+
return $this->removeExtraSpaces($dumpCommand);
31+
}
32+
33+
public function getRestoreCommand(string $filePath = '')
34+
{
35+
$filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath;
36+
$restoreCommand = $this->prepareRestoreCommand($filePath);
37+
38+
return $this->removeExtraSpaces($restoreCommand);
39+
}
40+
2541
protected function prepareDumpCommand(string $destinationPath): string
2642
{
2743
$dumpCommand = sprintf(

src/Dumper.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -62,44 +62,6 @@ protected function run()
6262
}
6363
}
6464

65-
public function getDumpCommand(string $credentialFile = '', $destinationPath = '')
66-
{
67-
$destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath;
68-
switch (strtolower($this->getDumperClassName())) {
69-
case 'mysqldumper':
70-
$dumpCommand = $this->prepareDumpCommand($credentialFile, $destinationPath);
71-
break;
72-
default:
73-
$dumpCommand = $this->prepareDumpCommand($destinationPath);
74-
break;
75-
}
76-
77-
return $this->removeExtraSpaces($dumpCommand);
78-
}
79-
80-
public function getRestoreCommand(string $credentialFile = '', string $filePath = '')
81-
{
82-
$filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath;
83-
switch (strtolower($this->getDumperClassName())) {
84-
case 'mysqldumper':
85-
$restoreCommand = $this->prepareRestoreCommand($credentialFile, $filePath);
86-
break;
87-
default:
88-
$restoreCommand = $this->prepareRestoreCommand($filePath);
89-
break;
90-
}
91-
92-
return $this->removeExtraSpaces($restoreCommand);
93-
}
94-
95-
public function getDumperClassName()
96-
{
97-
$classWithNamespace = static::class;
98-
$partials = explode("\\", $classWithNamespace);
99-
$className = end($partials);
100-
return $className;
101-
}
102-
10365
public function removeExtraSpaces(string $str)
10466
{
10567
return preg_replace('/\s+/', ' ', $str);

src/Traits/PrepareOptionsTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ public function prepareIgnoreTables()
7777
return (count($this->ignoreTables) > 0) ? '-T ' . implode(' -T ', $this->ignoreTables) : '';
7878
}
7979
}
80+
81+
public function getDumperClassName()
82+
{
83+
$classWithNamespace = static::class;
84+
$partials = explode("\\", $classWithNamespace);
85+
$className = end($partials);
86+
return $className;
87+
}
8088
}

0 commit comments

Comments
 (0)