1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Backup\BackupHandlers\Database\Databases; |
4
|
|
|
|
5
|
|
|
use Spatie\Backup\Console; |
6
|
|
|
|
7
|
|
|
class PgSQLDatabase implements DatabaseInterface |
8
|
|
|
{ |
9
|
|
|
protected $console; |
10
|
|
|
protected $database; |
11
|
|
|
protected $schema; |
12
|
|
|
protected $username; |
13
|
|
|
protected $password; |
14
|
|
|
protected $host; |
15
|
|
|
protected $port; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param Console $console |
19
|
|
|
* @param $database |
20
|
|
|
* @param string $schema |
21
|
|
|
* @param $username |
22
|
|
|
* @param $password |
23
|
|
|
* @param string $host |
24
|
|
|
* @param int $port |
25
|
|
|
* @param string $socket |
|
|
|
|
26
|
|
|
*/ |
27
|
|
View Code Duplication |
public function __construct(Console $console, $database, $schema, $username, $password, $host, $port) |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
$this->console = $console; |
30
|
|
|
$this->database = $database; |
31
|
|
|
$this->schema = $schema; |
32
|
|
|
$this->username = $username; |
33
|
|
|
$this->password = $password; |
34
|
|
|
$this->host = $host; |
35
|
|
|
$this->port = $port; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Create a database dump. |
40
|
|
|
* |
41
|
|
|
* @param $destinationFile |
42
|
|
|
* |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public function dump($destinationFile) |
46
|
|
|
{ |
47
|
|
|
$command = sprintf('export PGHOST && %spg_dump '.(!$this->useCopy() ? '--inserts' : '').' --schema=%s %s > %s', |
48
|
|
|
$this->getDumpCommandPath(), |
49
|
|
|
escapeshellarg($this->schema), |
50
|
|
|
escapeshellarg($this->database), |
51
|
|
|
escapeshellarg($destinationFile) |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$env = [ |
55
|
|
|
'PGHOST' => $this->host, |
56
|
|
|
'PGUSER' => $this->username, |
57
|
|
|
'PGPASSWORD' => $this->password, |
58
|
|
|
'PGPORT' => $this->port |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
return $this->console->run($command, config('laravel-backup.pgsql.timeoutInSeconds'), $env); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Return the file extension of a dump file (sql, ...). |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function getFileExtension() |
70
|
|
|
{ |
71
|
|
|
return 'sql'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get the path to the pgsql_dump. |
76
|
|
|
* |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
protected function getDumpCommandPath() |
80
|
|
|
{ |
81
|
|
|
return config('laravel-backup.pgsql.dump_command_path'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Determine if COPY should be used instead of INSERT. |
86
|
|
|
*/ |
87
|
|
|
protected function useCopy() |
88
|
|
|
{ |
89
|
|
|
return config('laravel-backup.pgsql.use_copy'); |
90
|
|
|
} |
91
|
|
|
} |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.