Skip to content

Commit

Permalink
Update Dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
maab16 committed Jan 1, 2020
1 parent ae1aa8a commit 20d0202
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 38 deletions.
16 changes: 16 additions & 0 deletions src/Drivers/MongoDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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" : "";
Expand Down
16 changes: 16 additions & 0 deletions src/Drivers/MysqlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions src/Drivers/PgsqlDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions src/Drivers/SqliteDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
38 changes: 0 additions & 38 deletions src/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/Traits/PrepareOptionsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 20d0202

Please sign in to comment.