1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CodexShaper\Dumper\Drivers; |
4
|
|
|
|
5
|
|
|
use CodexShaper\Dumper\Dumper; |
6
|
|
|
|
7
|
|
|
class SqliteDumper extends Dumper |
8
|
|
|
{ |
9
|
|
|
public function dump(string $destinationPath = "") |
10
|
|
|
{ |
11
|
|
|
$destinationPath = !empty($destinationPath) ? '"' . $destinationPath . '"' : '"' . $this->destinationPath . '"'; |
12
|
|
|
$dumpCommand = $this->prepareDumpCommand($destinationPath); |
13
|
|
|
$this->command = $this->removeExtraSpaces($dumpCommand); |
14
|
|
|
$this->run(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function restore(string $restorePath = "") |
18
|
|
|
{ |
19
|
|
|
$restorePath = !empty($restorePath) ? '"' . $restorePath . '"' : '"' . $this->restorePath . '"'; |
20
|
|
|
$restoreCommand = $this->prepareRestoreCommand($restorePath); |
21
|
|
|
$this->command = $this->removeExtraSpaces($restoreCommand); |
22
|
|
|
$this->run(); |
23
|
|
|
} |
24
|
|
|
|
25
|
8 |
|
public function getDumpCommand($destinationPath = '') |
26
|
|
|
{ |
27
|
8 |
|
$destinationPath = !empty($destinationPath) ? $destinationPath : $this->destinationPath; |
28
|
8 |
|
$dumpCommand = $this->prepareDumpCommand($destinationPath); |
29
|
|
|
|
30
|
8 |
|
return $this->removeExtraSpaces($dumpCommand); |
31
|
|
|
} |
32
|
|
|
|
33
|
8 |
|
public function getRestoreCommand(string $filePath = '') |
34
|
|
|
{ |
35
|
8 |
|
$filePath = !empty($filePath) ? '"' . $filePath : $this->restorePath; |
36
|
8 |
|
$restoreCommand = $this->prepareRestoreCommand($filePath); |
37
|
|
|
|
38
|
8 |
|
return $this->removeExtraSpaces($restoreCommand); |
39
|
|
|
} |
40
|
|
|
|
41
|
8 |
|
protected function prepareDumpCommand(string $destinationPath): string |
42
|
|
|
{ |
43
|
8 |
|
$dumpCommand = sprintf( |
44
|
8 |
|
"%s %s .dump", |
45
|
8 |
|
$this->quoteCommand($this->commandBinaryPath . 'sqlite3'), |
46
|
8 |
|
$this->dbName |
47
|
|
|
); |
48
|
|
|
|
49
|
8 |
|
if ($this->isCompress) { |
50
|
2 |
|
$compressCommand = $this->quoteCommand("{$this->compressBinaryPath}{$this->compressCommand}"); |
51
|
2 |
|
return "{$dumpCommand} | $compressCommand > \"{$destinationPath}{$this->compressExtension}\""; |
52
|
|
|
} |
53
|
|
|
|
54
|
6 |
|
return "{$dumpCommand} > \"{$destinationPath}\""; |
55
|
|
|
} |
56
|
|
|
|
57
|
8 |
|
protected function prepareRestoreCommand(string $filePath): string |
58
|
|
|
{ |
59
|
8 |
|
$restoreCommand = sprintf("%s %s", |
60
|
8 |
|
$this->quoteCommand($this->commandBinaryPath . 'sqlite3'), |
61
|
8 |
|
$this->dbName |
62
|
|
|
); |
63
|
|
|
|
64
|
8 |
|
if ($this->isCompress) { |
65
|
2 |
|
$compressCommand = $this->quoteCommand("{$this->compressBinaryPath}{$this->compressCommand}"); |
66
|
2 |
|
return "$compressCommand < \"{$filePath}\" | {$restoreCommand}"; |
67
|
|
|
} |
68
|
|
|
|
69
|
6 |
|
return "{$restoreCommand} < \"{$filePath}\""; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|