@@ -29,10 +29,10 @@ class DatabaseJanitor {
29
29
* DatabaseJanitor constructor.
30
30
*/
31
31
public function __construct ($ database , $ user , $ host , $ password , $ dumpOptions ) {
32
- $ this ->database = $ database ;
33
- $ this ->user = $ user ;
34
- $ this ->host = $ host ;
35
- $ this ->password = $ password ;
32
+ $ this ->database = $ database ;
33
+ $ this ->user = $ user ;
34
+ $ this ->host = $ host ;
35
+ $ this ->password = $ password ;
36
36
$ this ->dumpOptions = $ dumpOptions ;
37
37
try {
38
38
$ this ->connection = new \PDO ('mysql:host= ' . $ this ->host . ';dbname= ' . $ this ->database , $ this ->user , $ this ->password , [
@@ -57,22 +57,22 @@ public function dump($host = FALSE, $output = FALSE, $trim = FALSE) {
57
57
58
58
if ($ host ) {
59
59
$ this ->database = $ host ->database ;
60
- $ this ->user = $ host ->user ;
61
- $ this ->host = $ host ->host ;
60
+ $ this ->user = $ host ->user ;
61
+ $ this ->host = $ host ->host ;
62
62
$ this ->password = $ host ->password ;
63
63
}
64
64
65
65
$ dumpSettings = [
66
- 'add-locks ' => FALSE ,
66
+ 'add-locks ' => FALSE ,
67
67
'exclude-tables ' => $ this ->dumpOptions ['excluded_tables ' ] ?? [],
68
68
'no-data ' => $ this ->dumpOptions ['no-data ' ] ?? [],
69
69
];
70
70
try {
71
71
$ dump = new Mysqldump ('mysql:host= ' . $ this ->host . ';dbname= ' . $ this ->database , $ this ->user , $ this ->password , $ dumpSettings );
72
72
if ($ trim ) {
73
- $ dump ->setTransformTableNameHook (function ($ table_name , $ reset ) {
74
- return $ this ->rename_table ($ table_name , $ reset );
75
- });
73
+ $ dump ->setTransformTableNameHook (function ($ table_name , $ reset ) {
74
+ return $ this ->renameTable ($ table_name , $ reset );
75
+ });
76
76
}
77
77
$ dump ->setTransformColumnValueHook (function ($ table_name , $ col_name , $ col_value ) {
78
78
return $ this ->sanitize ($ table_name , $ col_name , $ col_value , $ this ->dumpOptions );
@@ -101,7 +101,7 @@ public function dump($host = FALSE, $output = FALSE, $trim = FALSE) {
101
101
* @return string
102
102
* New col value.
103
103
*/
104
- public function sanitize ($ table_name , $ col_name , $ col_value , $ options ) {
104
+ public function sanitize ($ table_name , $ col_name , $ col_value , array $ options ) {
105
105
if (isset ($ options ['sanitize_tables ' ])) {
106
106
foreach ($ options ['sanitize_tables ' ] as $ table => $ val ) {
107
107
if ($ table == $ table_name ) {
@@ -201,7 +201,18 @@ private function getPrimaryKey($table) {
201
201
return $ primary_key ;
202
202
}
203
203
204
- public function rename_table ($ table_name , $ reset ) {
204
+ /**
205
+ * Rename table function hook to manipulate during dump.
206
+ *
207
+ * @param string $table_name
208
+ * Current table name.
209
+ * @param bool $reset
210
+ * Whether to reset table name back to original (if altered was passed).
211
+ *
212
+ * @return string
213
+ * Returns the altered table name.
214
+ */
215
+ public function renameTable ($ table_name , $ reset ) {
205
216
if (in_array ($ table_name , $ this ->dumpOptions ['trim_tables ' ])) {
206
217
return 'janitor_ ' . $ table_name ;
207
218
}
@@ -210,4 +221,5 @@ public function rename_table($table_name, $reset) {
210
221
}
211
222
return $ table_name ;
212
223
}
224
+
213
225
}
0 commit comments