1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CodexShaper\Dumper\Traits; |
4
|
|
|
|
5
|
|
|
trait PrepareOptionsTrait |
6
|
|
|
{ |
7
|
58 |
|
public function prepareHost() |
8
|
|
|
{ |
9
|
58 |
|
switch (strtolower($this->getDumperClassName())) { |
|
|
|
|
10
|
58 |
|
case 'pgsqldumper': |
11
|
30 |
|
return ($this->socket !== '') ? $this->socket : $this->host; |
12
|
28 |
|
case 'mongodumper'; |
13
|
28 |
|
return !empty($this->host) ? "--host {$this->host}" : ""; |
14
|
|
|
} |
15
|
|
|
} |
16
|
|
|
|
17
|
58 |
|
public function preparePort() |
18
|
|
|
{ |
19
|
58 |
|
switch (strtolower($this->getDumperClassName())) { |
20
|
58 |
|
case 'pgsqldumper': |
21
|
30 |
|
return !empty($this->port) ? '-p ' . $this->port : ''; |
22
|
28 |
|
case 'mongodumper': |
23
|
28 |
|
return !empty($this->port) ? "--port {$this->port}" : ""; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
28 |
|
public function prepareSocket() |
28
|
|
|
{ |
29
|
28 |
|
switch (strtolower($this->getDumperClassName())) { |
30
|
28 |
|
case 'mysqldumper': |
31
|
28 |
|
return ($this->socket !== '') ? "--socket={$this->socket}" : ''; |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
80 |
|
public function prepareDatabase() |
36
|
|
|
{ |
37
|
80 |
|
switch (strtolower($this->getDumperClassName())) { |
38
|
80 |
|
case 'mysqldumper': |
39
|
46 |
|
case 'pgsqldumper': |
40
|
64 |
|
return !empty($this->dbName) ? $this->dbName : ""; |
41
|
16 |
|
case 'mongodumper'; |
42
|
16 |
|
return !empty($this->dbName) ? "--db {$this->dbName}" : ""; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
58 |
|
public function prepareUserName() |
47
|
|
|
{ |
48
|
58 |
|
switch (strtolower($this->getDumperClassName())) { |
49
|
58 |
|
case 'pgsqldumper': |
50
|
30 |
|
return !empty($this->username) ? $this->username : ""; |
51
|
28 |
|
case 'mongodumper'; |
52
|
28 |
|
return !empty($this->username) ? "--username {$this->username}" : ""; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
52 |
|
public function prepareIncludeTables() |
57
|
|
|
{ |
58
|
52 |
|
switch (strtolower($this->getDumperClassName())) { |
59
|
52 |
|
case 'mysqldumper': |
60
|
28 |
|
$includeTables = (count($this->tables) > 0) ? implode(' ', $this->tables) : ''; |
61
|
28 |
|
return !empty($includeTables) ? "--tables {$includeTables}" : ''; |
62
|
24 |
|
case 'pgsqldumper': |
63
|
24 |
|
return (count($this->tables) > 0) ? '-t ' . implode(' -t ', $this->tables) : ""; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
52 |
|
public function prepareIgnoreTables() |
68
|
|
|
{ |
69
|
52 |
|
switch (strtolower($this->getDumperClassName())) { |
70
|
52 |
|
case 'mysqldumper': |
71
|
28 |
|
$ignoreTablesArgs = []; |
72
|
28 |
|
foreach ($this->ignoreTables as $tableName) { |
73
|
4 |
|
$ignoreTablesArgs[] = "--ignore-table={$this->dbName}.{$tableName}"; |
74
|
|
|
} |
75
|
28 |
|
return (count($ignoreTablesArgs) > 0) ? implode(' ', $ignoreTablesArgs) : ''; |
76
|
24 |
|
case 'pgsqldumper'; |
77
|
24 |
|
return (count($this->ignoreTables) > 0) ? '-T ' . implode(' -T ', $this->ignoreTables) : ''; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
52 |
|
public function prepareCreateTables() |
82
|
|
|
{ |
83
|
52 |
|
switch (strtolower($this->getDumperClassName())) { |
84
|
52 |
|
case 'mysqldumper': |
85
|
28 |
|
return !$this->createTables ? '--no-create-info' : ''; |
86
|
24 |
|
case 'pgsqldumper': |
87
|
24 |
|
return (!$this->createTables) ? '--data-only' : ''; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|