1 | <?php |
||
7 | class DatabaseManager |
||
8 | { |
||
9 | /** |
||
10 | * MySQL and MySQLDump login arguments. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | private $credentials = '-u%s -p%s -h%s -P%s'; |
||
15 | /** |
||
16 | * Name of original database. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | private $source = ''; |
||
21 | /** |
||
22 | * Name of temporary database that will store data from original. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | private $temporary = ''; |
||
27 | /** |
||
28 | * Name of an object where this class is called. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | private $callee; |
||
33 | |||
34 | /** |
||
35 | * @param string $connection |
||
36 | * Database connection name (key in $databases array from settings.php). |
||
37 | * @param string $callee |
||
38 | * Must be the value of "self::class" of callee object. |
||
39 | */ |
||
40 | public function __construct($connection, $callee) |
||
74 | |||
75 | /** |
||
76 | * Restore original database. |
||
77 | */ |
||
78 | public function __destruct() |
||
85 | |||
86 | /** |
||
87 | * @param string $name |
||
88 | * Name of the database to check. |
||
89 | * |
||
90 | * @return bool |
||
91 | * Checking state. |
||
92 | */ |
||
93 | public function exist($name) |
||
97 | |||
98 | /** |
||
99 | * @param string $name |
||
100 | * Name of the database to drop. |
||
101 | */ |
||
102 | public function drop($name) |
||
108 | |||
109 | /** |
||
110 | * @param string $name |
||
111 | * Name of the database to create. |
||
112 | */ |
||
113 | public function create($name) |
||
119 | |||
120 | /** |
||
121 | * @param string $source |
||
122 | * Source DB name. |
||
123 | * @param string $destination |
||
124 | * Name of the new DB. |
||
125 | */ |
||
126 | public function copy($source, $destination) |
||
132 | |||
133 | /** |
||
134 | * Executes a shell command. |
||
135 | * |
||
136 | * @param string $command |
||
137 | * Command to execute. |
||
138 | * |
||
139 | * @return string |
||
140 | * Result of a shell command. |
||
141 | */ |
||
142 | private function exec($command) |
||
157 | } |
||
158 |