1 | <?php |
||
20 | class Pgdump extends Abstraction implements Executable |
||
21 | { |
||
22 | use OptionMasker; |
||
23 | |||
24 | /** |
||
25 | * Host to connect to |
||
26 | * --host=<hostname> |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $host; |
||
31 | |||
32 | /** |
||
33 | * Port to connect to |
||
34 | * --port=<portnumber> |
||
35 | * |
||
36 | * @var int |
||
37 | */ |
||
38 | private $port; |
||
39 | |||
40 | /** |
||
41 | * User to connect with |
||
42 | * --user=<username> |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $user; |
||
47 | |||
48 | /** |
||
49 | * Password to authenticate with |
||
50 | * --password=<password> |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | private $password; |
||
55 | |||
56 | /** |
||
57 | * Database to dump |
||
58 | * db-name |
||
59 | * |
||
60 | * @var string |
||
61 | */ |
||
62 | private $databaseToDump; |
||
63 | |||
64 | /** |
||
65 | * List of schmeas to dump |
||
66 | * --schema=<schema> |
||
67 | * |
||
68 | * @var array |
||
69 | */ |
||
70 | private $schemasToDump = []; |
||
71 | |||
72 | /** |
||
73 | * Exclude Schemas |
||
74 | * --exclude-schema=<schema> |
||
75 | * |
||
76 | * @var array |
||
77 | */ |
||
78 | private $schemasToExclude = []; |
||
79 | |||
80 | /** |
||
81 | * Tables to dump. |
||
82 | * --table=<table> |
||
83 | * |
||
84 | * @var array |
||
85 | */ |
||
86 | private $tablesToDump = []; |
||
87 | |||
88 | /** |
||
89 | * List of tables to exclude |
||
90 | * --exclude-table=<table> |
||
91 | * |
||
92 | * @var array |
||
93 | */ |
||
94 | private $tablesToExclude = []; |
||
95 | |||
96 | /** |
||
97 | * Don't dump the structure |
||
98 | * --data-only |
||
99 | * |
||
100 | * @var boolean |
||
101 | */ |
||
102 | private $dataOnly; |
||
103 | |||
104 | /** |
||
105 | * Dump only schema definitions. |
||
106 | * --schema-only |
||
107 | * |
||
108 | * @var boolean |
||
109 | */ |
||
110 | private $schemaOnly; |
||
111 | |||
112 | /** |
||
113 | * Do not dump data for any tables matching the table pattern. |
||
114 | * --exclude-table-data |
||
115 | * |
||
116 | * @var array |
||
117 | */ |
||
118 | private $excludeTableData = []; |
||
119 | |||
120 | /** |
||
121 | * Add drop statements to the dump. |
||
122 | * --clean |
||
123 | * |
||
124 | * @var boolean |
||
125 | */ |
||
126 | private $clean = false; |
||
127 | |||
128 | /** |
||
129 | * Encoding of the dump file |
||
130 | * --encoding |
||
131 | * |
||
132 | * @var string |
||
133 | */ |
||
134 | private $encoding; |
||
135 | |||
136 | /** |
||
137 | * postgreSQL dump format definition |
||
138 | * --format [plain|custom|directory|tar] |
||
139 | * |
||
140 | * @var string |
||
141 | */ |
||
142 | private $format; |
||
143 | |||
144 | /** |
||
145 | * Allow any user to restore the dump |
||
146 | * --no-owner |
||
147 | * |
||
148 | * @var bool |
||
149 | */ |
||
150 | private $noOwner = false; |
||
151 | |||
152 | /** |
||
153 | * Prevent dumping of access privileges. |
||
154 | * --no-acl |
||
155 | * |
||
156 | * @var boolean |
||
157 | */ |
||
158 | private $noPrivileges; |
||
159 | |||
160 | /** |
||
161 | * Do not output commands to select tablespaces. |
||
162 | * --no-tablespaces |
||
163 | * |
||
164 | * @var boolean |
||
165 | */ |
||
166 | private $noTablespaces; |
||
167 | |||
168 | /** |
||
169 | * File to dump to |
||
170 | * --file |
||
171 | * |
||
172 | * @var string |
||
173 | */ |
||
174 | private $file; |
||
175 | |||
176 | /** |
||
177 | * List of available output formats |
||
178 | * |
||
179 | * @var array |
||
180 | */ |
||
181 | private $availableFormats = [ |
||
182 | 'p' => true, |
||
183 | 'plain' => true, |
||
184 | 'c' => true, |
||
185 | 'custom' => true, |
||
186 | 'd' => true, |
||
187 | 'directory' => true, |
||
188 | 't' => true, |
||
189 | 'tar' => true, |
||
190 | ]; |
||
191 | |||
192 | /** |
||
193 | * Constructor. |
||
194 | * |
||
195 | * @param string $path |
||
196 | */ |
||
197 | public function __construct(string $path = '') |
||
202 | |||
203 | /** |
||
204 | * Set the postgreSQL credentials. |
||
205 | * |
||
206 | * @param string $user |
||
207 | * @param string $password |
||
208 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
209 | */ |
||
210 | public function credentials(string $user = '', string $password = '') : Pgdump |
||
216 | |||
217 | /** |
||
218 | * Set the postgreSQL hostname. |
||
219 | * |
||
220 | * @param string $host |
||
221 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
222 | */ |
||
223 | public function useHost(string $host) : Pgdump |
||
228 | |||
229 | /** |
||
230 | * Set the postgreSQL port. |
||
231 | * |
||
232 | * @param int $port |
||
233 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
234 | */ |
||
235 | public function usePort(int $port) : Pgdump |
||
240 | |||
241 | /** |
||
242 | * Set database to dump. |
||
243 | * |
||
244 | * @param string $database |
||
245 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
246 | */ |
||
247 | public function dumpDatabase(string $database) : Pgdump |
||
252 | |||
253 | /** |
||
254 | * Add drop statements to the dump file. |
||
255 | * Works only on format=plain-text. |
||
256 | * |
||
257 | * @param boolean $bool |
||
258 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
259 | */ |
||
260 | public function addDropStatements(bool $bool) : Pgdump |
||
265 | |||
266 | /** |
||
267 | * Add the --no-owner option so no ownership setting commands will be added. |
||
268 | * |
||
269 | * @param boolean $bool |
||
270 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
271 | */ |
||
272 | public function skipOwnerCommands(bool $bool) : Pgdump |
||
277 | |||
278 | /** |
||
279 | * Set schemas to dump. |
||
280 | * |
||
281 | * @param array $schemas |
||
282 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
283 | */ |
||
284 | public function dumpSchemas(array $schemas) : Pgdump |
||
289 | |||
290 | /** |
||
291 | * Set schemas to exclude. |
||
292 | * |
||
293 | * @param array $schemas |
||
294 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
295 | */ |
||
296 | public function excludeSchemas(array $schemas) : Pgdump |
||
301 | |||
302 | /** |
||
303 | * Set tables to dump. |
||
304 | * |
||
305 | * @param array $tables |
||
306 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
307 | */ |
||
308 | public function dumpTables(array $tables) : Pgdump |
||
313 | |||
314 | /** |
||
315 | * Set tables to ignore. |
||
316 | * |
||
317 | * @param array $tables |
||
318 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
319 | */ |
||
320 | public function excludeTables(array $tables) : Pgdump |
||
325 | |||
326 | /** |
||
327 | * Set tables where no data is dumped. |
||
328 | * |
||
329 | * @param array $tables |
||
330 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
331 | */ |
||
332 | public function excludeTableData(array $tables) : Pgdump |
||
337 | |||
338 | /** |
||
339 | * Dump only the schema information. |
||
340 | * |
||
341 | * @param boolean $bool |
||
342 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
343 | * @throws \phpbu\App\Exception |
||
344 | */ |
||
345 | public function dumpSchemaOnly(bool $bool) : Pgdump |
||
353 | |||
354 | /** |
||
355 | * Dump no schema information. |
||
356 | * |
||
357 | * @param boolean $bool |
||
358 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
359 | * @throws \phpbu\App\Exception |
||
360 | */ |
||
361 | public function dumpDataOnly(bool $bool) : Pgdump |
||
369 | |||
370 | /** |
||
371 | * Set the dump target path. |
||
372 | * |
||
373 | * @param string $path |
||
374 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
375 | */ |
||
376 | public function dumpTo(string $path) : Pgdump |
||
381 | |||
382 | /** |
||
383 | * Set the dump format. |
||
384 | * |
||
385 | * @param string $format |
||
386 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
387 | * @throws \phpbu\App\Exception |
||
388 | */ |
||
389 | public function dumpFormat(string $format) : Pgdump |
||
397 | |||
398 | /** |
||
399 | * Do not dump commands setting ownership. |
||
400 | * --no-owner |
||
401 | * |
||
402 | * @param bool $bool |
||
403 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
404 | */ |
||
405 | public function dumpNoOwner(bool $bool) : Pgdump |
||
410 | |||
411 | /** |
||
412 | * Do not output commands to select tablespaces. |
||
413 | * --no-tablespaces |
||
414 | * |
||
415 | * @param bool $bool |
||
416 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
417 | */ |
||
418 | public function dumpNoTablespaces(bool $bool) : Pgdump |
||
423 | |||
424 | /** |
||
425 | * Prevent dumping of access privileges. |
||
426 | * --no-acl |
||
427 | * |
||
428 | * @param boolean $bool |
||
429 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
430 | */ |
||
431 | public function dumpNoPrivileges(bool $bool) : Pgdump |
||
436 | /** |
||
437 | * Set the output file encoding. |
||
438 | * |
||
439 | * @param string $encoding |
||
440 | * @return \phpbu\App\Cli\Executable\Pgdump |
||
441 | */ |
||
442 | public function encode(string $encoding) : Pgdump |
||
447 | |||
448 | /** |
||
449 | * Pgdump CommandLine generator. |
||
450 | * |
||
451 | * @return \SebastianFeldmann\Cli\CommandLine |
||
452 | */ |
||
453 | protected function createCommandLine() : CommandLine |
||
482 | |||
483 | /** |
||
484 | * Handle command schema settings. |
||
485 | * |
||
486 | * @param \SebastianFeldmann\Cli\Command\Executable $cmd |
||
487 | */ |
||
488 | protected function handleSchemas(Cmd $cmd) |
||
498 | |||
499 | /** |
||
500 | * Handle command table settings. |
||
501 | * |
||
502 | * @param \SebastianFeldmann\Cli\Command\Executable $cmd |
||
503 | */ |
||
504 | protected function handleTables(Cmd $cmd) |
||
518 | } |
||
519 |