@@ -469,6 +469,11 @@ |
||
469 | 469 | * handler $fd - file handler where to write the records |
470 | 470 | * @return |
471 | 471 | */ |
472 | + |
|
473 | + /** |
|
474 | + * @param integer $start |
|
475 | + * @param integer $limit |
|
476 | + */ |
|
472 | 477 | public function export_table($databaseName, $tableName, $start, $limit, $dumpfile) |
473 | 478 | { |
474 | 479 | $this->logger->debug(sprintf(("Exporting table %s.%s data"), $databaseName, $tableName)); |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
285 | 285 | } |
286 | 286 | $inc++; |
287 | - } |
|
287 | + } |
|
288 | 288 | |
289 | 289 | return $tablesList; |
290 | 290 | |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | $buffer = ""; |
508 | 508 | $this->countRecords++; |
509 | 509 | |
510 | - foreach ($arr as $key => $value) { |
|
510 | + foreach ($arr as $key => $value) { |
|
511 | 511 | $value = $this->_real_escape($value); |
512 | 512 | |
513 | 513 | if(method_exists($this, 'remove_placeholder_escape')){ |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | $line = ("\n#\n# Table structure for table `$tableName`\n#\n\n"); |
539 | 539 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
540 | 540 | |
541 | - if ($this->dbDropSyntax) |
|
542 | - { |
|
541 | + if ($this->dbDropSyntax) |
|
542 | + { |
|
543 | 543 | $line = ("\nDROP table IF EXISTS `$tableName`;\n"); |
544 | 544 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
545 | 545 | } |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | |
24 | -class Xcloner_Database extends wpdb{ |
|
24 | +class Xcloner_Database extends wpdb { |
|
25 | 25 | |
26 | 26 | |
27 | - public $debug = 0; |
|
28 | - public $recordsPerSession = 10000; |
|
29 | - public $dbCompatibility = ""; |
|
27 | + public $debug = 0; |
|
28 | + public $recordsPerSession = 10000; |
|
29 | + public $dbCompatibility = ""; |
|
30 | 30 | public $dbDropSyntax = 1; |
31 | 31 | public $countRecords = 0; |
32 | 32 | |
@@ -38,24 +38,24 @@ discard block |
||
38 | 38 | private $TEMP_DBPROCESS_FILE = ".database"; |
39 | 39 | private $TEMP_DUMP_FILE = "database-backup.sql"; |
40 | 40 | |
41 | - public function __construct(Xcloner $xcloner_container, $wp_user="", $wp_pass="", $wp_db="", $wp_host="") |
|
41 | + public function __construct(Xcloner $xcloner_container, $wp_user = "", $wp_pass = "", $wp_db = "", $wp_host = "") |
|
42 | 42 | { |
43 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_database"); |
|
44 | - $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
45 | - $this->fs = $xcloner_container->get_xcloner_filesystem(); |
|
43 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_database"); |
|
44 | + $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
45 | + $this->fs = $xcloner_container->get_xcloner_filesystem(); |
|
46 | 46 | |
47 | - if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) |
|
48 | - $this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
47 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) |
|
48 | + $this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
49 | 49 | |
50 | - if(!$this->recordsPerSession) |
|
50 | + if (!$this->recordsPerSession) |
|
51 | 51 | $this->recordsPerSession = 100; |
52 | 52 | |
53 | - if(!$wp_user && !$wp_pass && !$wp_host && !$wp_db ) |
|
53 | + if (!$wp_user && !$wp_pass && !$wp_host && !$wp_db) |
|
54 | 54 | { |
55 | 55 | $wp_host = $this->xcloner_settings->get_db_hostname(); |
56 | 56 | $wp_user = $this->xcloner_settings->get_db_username(); |
57 | 57 | $wp_pass = $this->xcloner_settings->get_db_password(); |
58 | - $wp_db = $this->xcloner_settings->get_db_database(); |
|
58 | + $wp_db = $this->xcloner_settings->get_db_database(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | parent::__construct($wp_user, $wp_pass, $wp_db, $wp_host); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function init($data, $start = 0) |
73 | 73 | { |
74 | - if($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)){ |
|
74 | + if ($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
75 | 75 | $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
76 | 76 | } |
77 | 77 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | "database_count"=>0, |
91 | 91 | ); |
92 | 92 | |
93 | - if(!$this->xcloner_settings->get_enable_mysql_backup()) |
|
93 | + if (!$this->xcloner_settings->get_enable_mysql_backup()) |
|
94 | 94 | { |
95 | 95 | $return['finished'] = 1; |
96 | 96 | return $return; |
@@ -100,44 +100,44 @@ discard block |
||
100 | 100 | |
101 | 101 | $this->init($params, $init); |
102 | 102 | |
103 | - if($init) |
|
103 | + if ($init) |
|
104 | 104 | { |
105 | 105 | $db_count = 0; |
106 | 106 | |
107 | - if(isset($params['#'])) |
|
107 | + if (isset($params['#'])) |
|
108 | 108 | { |
109 | - foreach($params['#'] as $database) |
|
109 | + foreach ($params['#'] as $database) |
|
110 | 110 | { |
111 | - if(!isset($params[$database]) or !is_array($params[$database])) |
|
111 | + if (!isset($params[$database]) or !is_array($params[$database])) |
|
112 | 112 | $params[$database] = array(); |
113 | 113 | } |
114 | 114 | $db_count = -1; |
115 | 115 | } |
116 | 116 | |
117 | - if(isset($params) and is_array($params)) |
|
118 | - foreach($params as $database=>$tables) |
|
117 | + if (isset($params) and is_array($params)) |
|
118 | + foreach ($params as $database=>$tables) |
|
119 | 119 | { |
120 | - if($database != "#") |
|
120 | + if ($database != "#") |
|
121 | 121 | { |
122 | 122 | $stats = $this->write_backup_process_list($database, $tables); |
123 | - $return['stats']['tables_count'] += $stats['tables_count']; |
|
124 | - $return['stats']['total_records'] += $stats['total_records']; |
|
123 | + $return['stats']['tables_count'] += $stats['tables_count']; |
|
124 | + $return['stats']['total_records'] += $stats['total_records']; |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - if(sizeof($params)) |
|
129 | - $return['stats']['database_count'] = sizeof($params)+$db_count; |
|
128 | + if (sizeof($params)) |
|
129 | + $return['stats']['database_count'] = sizeof($params) + $db_count; |
|
130 | 130 | else |
131 | 131 | $return['stats']['database_count'] = 0; |
132 | 132 | |
133 | 133 | return $return; |
134 | 134 | } |
135 | 135 | |
136 | - if(!isset($extra_params['startAtLine'])) |
|
136 | + if (!isset($extra_params['startAtLine'])) |
|
137 | 137 | $extra_params['startAtLine'] = 0; |
138 | - if(!isset($extra_params['startAtRecord'])) |
|
138 | + if (!isset($extra_params['startAtRecord'])) |
|
139 | 139 | $extra_params['startAtRecord'] = 0; |
140 | - if(!isset($extra_params['dumpfile'])) |
|
140 | + if (!isset($extra_params['dumpfile'])) |
|
141 | 141 | $extra_params['dumpfile'] = ""; |
142 | 142 | |
143 | 143 | $return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']); |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | public function log($message = "") |
149 | 149 | { |
150 | 150 | |
151 | - if($message){ |
|
152 | - $this->logger->info( $message, array("")); |
|
153 | - }else{ |
|
154 | - if($this->last_query) |
|
155 | - $this->logger->debug( $this->last_query, array("")); |
|
156 | - if($this->last_error) |
|
157 | - $this->logger->error( $this->last_error, array("")); |
|
151 | + if ($message) { |
|
152 | + $this->logger->info($message, array("")); |
|
153 | + } else { |
|
154 | + if ($this->last_query) |
|
155 | + $this->logger->debug($this->last_query, array("")); |
|
156 | + if ($this->last_error) |
|
157 | + $this->logger->error($this->last_error, array("")); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function error($message) |
171 | 171 | { |
172 | - $this->logger->error( $message, array("")); |
|
172 | + $this->logger->error($message, array("")); |
|
173 | 173 | |
174 | 174 | return; |
175 | 175 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | |
203 | 203 | $query = "show tables in `".$database."`"; |
204 | 204 | |
205 | - $res = $this->get_results($query); |
|
205 | + $res = $this->get_results($query); |
|
206 | 206 | $this->log(); |
207 | 207 | |
208 | 208 | return count($res); |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname); |
226 | 226 | $i++; |
227 | 227 | |
228 | - if(is_array($databases)) |
|
229 | - foreach( $databases as $db){ |
|
230 | - if($db->Database != $this->dbname) |
|
228 | + if (is_array($databases)) |
|
229 | + foreach ($databases as $db) { |
|
230 | + if ($db->Database != $this->dbname) |
|
231 | 231 | { |
232 | 232 | $databases_list[$i]['name'] = $db->Database; |
233 | 233 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database); |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $tablesList[0] = array( ); |
253 | 253 | $inc = 0; |
254 | 254 | |
255 | - if(!$database) |
|
255 | + if (!$database) |
|
256 | 256 | $database = $this->dbname; |
257 | 257 | |
258 | 258 | $this->logger->debug(sprintf(("Listing tables in %s database"), $database)); |
@@ -260,14 +260,14 @@ discard block |
||
260 | 260 | $tables = $this->get_results("SHOW TABLES in `".$database."`"); |
261 | 261 | $this->log(); |
262 | 262 | |
263 | - foreach ($tables as $table){ |
|
263 | + foreach ($tables as $table) { |
|
264 | 264 | |
265 | 265 | $table = array_values((array)$table)[0]; |
266 | 266 | |
267 | 267 | $tablesList[$inc]['name'] = $table; |
268 | 268 | $tablesList[$inc]['database'] = $database; |
269 | 269 | |
270 | - if($get_num_records) |
|
270 | + if ($get_num_records) |
|
271 | 271 | { |
272 | 272 | $records_num_result = $this->get_var("SELECT count(*) FROM `".$database."`.`".$table."`"); |
273 | 273 | $this->log(); |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | |
278 | 278 | $tablesList[$inc]['excluded'] = 0; |
279 | 279 | |
280 | - if(sizeof($included) and is_array($included)) |
|
281 | - if(!in_array($table, $included) ) |
|
280 | + if (sizeof($included) and is_array($included)) |
|
281 | + if (!in_array($table, $included)) |
|
282 | 282 | { |
283 | 283 | $tablesList[$inc]['excluded'] = 1; |
284 | 284 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | |
300 | 300 | $tables = $this->list_tables($dbname, $incl_tables, 1); |
301 | 301 | |
302 | - if($this->dbname != $dbname) |
|
302 | + if ($this->dbname != $dbname) |
|
303 | 303 | $dumpfile = $dbname."-backup.sql"; |
304 | 304 | else |
305 | 305 | $dumpfile = $this->TEMP_DUMP_FILE; |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
309 | 309 | |
310 | 310 | // write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records |
311 | - foreach($tables as $key=>$table) |
|
312 | - if($table!= "" and !$tables[$key]['excluded']){ |
|
311 | + foreach ($tables as $key=>$table) |
|
312 | + if ($table != "" and !$tables[$key]['excluded']) { |
|
313 | 313 | |
314 | 314 | $line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']); |
315 | 315 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | |
338 | 338 | $result = $this->get_var("SELECT count(*) FROM $table;"); |
339 | 339 | |
340 | - return intval($result) ;// not max limit on 32 bit systems 2147483647; on 64 bit 999999999999 |
|
340 | + return intval($result); // not max limit on 32 bit systems 2147483647; on 64 bit 999999999999 |
|
341 | 341 | |
342 | 342 | } |
343 | 343 | |
@@ -353,25 +353,25 @@ discard block |
||
353 | 353 | * int $dbDropSyntax - check if the DROP TABLE syntax should be added |
354 | 354 | * @return array $return |
355 | 355 | */ |
356 | - public function process_incremental($startAtLine= 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility= ""){ |
|
356 | + public function process_incremental($startAtLine = 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility = "") { |
|
357 | 357 | |
358 | 358 | $count = 0; |
359 | 359 | $return['finished'] = 0; |
360 | 360 | $lines = array(); |
361 | 361 | |
362 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
363 | - $lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
362 | + if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
363 | + $lines = array_filter(explode("\n", $this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
364 | 364 | |
365 | - foreach ($lines as $buffer){ |
|
365 | + foreach ($lines as $buffer) { |
|
366 | 366 | |
367 | - if($count == $startAtLine) |
|
367 | + if ($count == $startAtLine) |
|
368 | 368 | { |
369 | 369 | |
370 | - $tableInfo =explode("\t", $buffer); |
|
370 | + $tableInfo = explode("\t", $buffer); |
|
371 | 371 | |
372 | - if($tableInfo[0] == "###newdump###"){ |
|
372 | + if ($tableInfo[0] == "###newdump###") { |
|
373 | 373 | // we create a new mysql dump file |
374 | - if($dumpfile != ""){ |
|
374 | + if ($dumpfile != "") { |
|
375 | 375 | // we finished a previous one and write the footers |
376 | 376 | $return['dumpsize'] = $this->data_footers($dumpfile); |
377 | 377 | } |
@@ -385,13 +385,13 @@ discard block |
||
385 | 385 | $startAtLine++; |
386 | 386 | $return['new_dump'] = 1; |
387 | 387 | //break; |
388 | - }else{ |
|
388 | + } else { |
|
389 | 389 | //we export the table |
390 | - if($tableInfo[0] == "###enddump###") |
|
390 | + if ($tableInfo[0] == "###enddump###") |
|
391 | 391 | $return['endDump'] = 1; |
392 | 392 | |
393 | 393 | //table is excluded |
394 | - if($tableInfo[2]) |
|
394 | + if ($tableInfo[2]) |
|
395 | 395 | continue; |
396 | 396 | |
397 | 397 | $next = $startAtRecord + $this->recordsPerSession; |
@@ -403,28 +403,28 @@ discard block |
||
403 | 403 | |
404 | 404 | //return something to the browser |
405 | 405 | $return['databaseName'] = $databaseName; |
406 | - $return['tableName'] = $tableName; |
|
406 | + $return['tableName'] = $tableName; |
|
407 | 407 | $return['totalRecords'] = $tableInfo[1]; |
408 | 408 | |
409 | 409 | $processed_records = 0; |
410 | 410 | |
411 | - if(trim($tableName) !="" and !$tableInfo[2]) |
|
411 | + if (trim($tableName) != "" and !$tableInfo[2]) |
|
412 | 412 | $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
413 | 413 | |
414 | - $return['processedRecords'] = $startAtRecord+$processed_records; |
|
414 | + $return['processedRecords'] = $startAtRecord + $processed_records; |
|
415 | 415 | |
416 | - if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
416 | + if ($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
417 | 417 | { |
418 | - $startAtLine ++; |
|
418 | + $startAtLine++; |
|
419 | 419 | $startAtRecord = 0; |
420 | - }else{ |
|
420 | + } else { |
|
421 | 421 | $startAtRecord = $startAtRecord + $this->recordsPerSession; |
422 | 422 | } |
423 | 423 | |
424 | 424 | //$return['dbCompatibility'] = self::$dbCompatibility; |
425 | 425 | |
426 | - $return['startAtLine'] = $startAtLine; |
|
427 | - $return['startAtRecord'] = $startAtRecord; |
|
426 | + $return['startAtLine'] = $startAtLine; |
|
427 | + $return['startAtRecord'] = $startAtRecord; |
|
428 | 428 | $return['dumpfile'] = $dumpfile; |
429 | 429 | $return['dumpsize'] = $this->fs->get_tmp_filesystem_append()->getSize($dumpfile); |
430 | 430 | |
@@ -442,15 +442,15 @@ discard block |
||
442 | 442 | } |
443 | 443 | |
444 | 444 | //while is finished, lets go home... |
445 | - if($dumpfile != ""){ |
|
445 | + if ($dumpfile != "") { |
|
446 | 446 | // we finished a previous one and write the footers |
447 | 447 | $return['dumpsize'] = $this->data_footers($dumpfile); |
448 | 448 | $return['dumpfile'] = ($dumpfile); |
449 | 449 | } |
450 | 450 | $return['finished'] = 1; |
451 | - $return['startAtLine'] = $startAtLine; |
|
451 | + $return['startAtLine'] = $startAtLine; |
|
452 | 452 | |
453 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
453 | + if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
454 | 454 | $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
455 | 455 | |
456 | 456 | $this->logger->debug(sprintf(("Database backup finished!"))); |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | |
480 | 480 | $records = 0; |
481 | 481 | |
482 | - if($start == 0) |
|
482 | + if ($start == 0) |
|
483 | 483 | $this->dump_structure($databaseName, $tableName, $dumpfile); |
484 | 484 | |
485 | 485 | $start = intval($start); |
@@ -487,20 +487,20 @@ discard block |
||
487 | 487 | //exporting the table content now |
488 | 488 | |
489 | 489 | $query = "SELECT * from `$databaseName`.`$tableName` Limit $start, $limit ;"; |
490 | - if($this->use_mysqli) |
|
490 | + if ($this->use_mysqli) |
|
491 | 491 | { |
492 | 492 | $result = mysqli_query($this->dbh, $query); |
493 | 493 | $mysql_fetch_function = "mysqli_fetch_array"; |
494 | 494 | |
495 | - }else{ |
|
495 | + } else { |
|
496 | 496 | $result = mysql_query($query, $this->dbh); |
497 | 497 | $mysql_fetch_function = "mysqli_fetch_array"; |
498 | 498 | } |
499 | 499 | //$result = $this->get_results($query, ARRAY_N); |
500 | 500 | //print_r($result); exit; |
501 | 501 | |
502 | - if($result){ |
|
503 | - while($row = $mysql_fetch_function($result, MYSQLI_ASSOC)){ |
|
502 | + if ($result) { |
|
503 | + while ($row = $mysql_fetch_function($result, MYSQLI_ASSOC)) { |
|
504 | 504 | |
505 | 505 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, "INSERT INTO `$tableName` VALUES ("); |
506 | 506 | $arr = $row; |
@@ -510,13 +510,13 @@ discard block |
||
510 | 510 | foreach ($arr as $key => $value) { |
511 | 511 | $value = $this->_real_escape($value); |
512 | 512 | |
513 | - if(method_exists($this, 'remove_placeholder_escape')){ |
|
513 | + if (method_exists($this, 'remove_placeholder_escape')) { |
|
514 | 514 | $value = $this->remove_placeholder_escape($value); |
515 | 515 | } |
516 | 516 | |
517 | 517 | $buffer .= "'".$value."', "; |
518 | 518 | } |
519 | - $buffer = rtrim($buffer, ', ') . ");\n"; |
|
519 | + $buffer = rtrim($buffer, ', ').");\n"; |
|
520 | 520 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $buffer); |
521 | 521 | unset($buffer); |
522 | 522 | |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | |
532 | 532 | } |
533 | 533 | |
534 | - public function dump_structure($databaseName, $tableName ,$dumpfile) |
|
534 | + public function dump_structure($databaseName, $tableName, $dumpfile) |
|
535 | 535 | { |
536 | 536 | $this->log(sprintf(__("Dumping the structure for %s.%s table"), $databaseName, $tableName)); |
537 | 537 | |
@@ -546,14 +546,14 @@ discard block |
||
546 | 546 | |
547 | 547 | //$result = mysqli_query($this->dbh,"SHOW CREATE table `$databaseName`.`$tableName`;"); |
548 | 548 | $result = $this->get_row("SHOW CREATE table `$databaseName`.`$tableName`;", ARRAY_N); |
549 | - if($result){ |
|
549 | + if ($result) { |
|
550 | 550 | //$row = mysqli_fetch_row( $result); |
551 | 551 | $line = ($result[1].";\n"); |
552 | 552 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
553 | 553 | } |
554 | 554 | |
555 | - $line = ( "\n#\n# End Structure for table `$tableName`\n#\n\n"); |
|
556 | - $line .=("#\n# Dumping data for table `$tableName`\n#\n\n"); |
|
555 | + $line = ("\n#\n# End Structure for table `$tableName`\n#\n\n"); |
|
556 | + $line .= ("#\n# Dumping data for table `$tableName`\n#\n\n"); |
|
557 | 557 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
558 | 558 | |
559 | 559 | return; |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | |
577 | 577 | } |
578 | 578 | |
579 | - public function resetcountRecords(){ |
|
579 | + public function resetcountRecords() { |
|
580 | 580 | |
581 | 581 | $this->countRecords = 0; |
582 | 582 | |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | |
585 | 585 | } |
586 | 586 | |
587 | - public function getcountRecords(){ |
|
587 | + public function getcountRecords() { |
|
588 | 588 | |
589 | 589 | return $this->countRecords; |
590 | 590 | |
@@ -601,14 +601,14 @@ discard block |
||
601 | 601 | $return .= "# Powered by XCloner Site Backup\n"; |
602 | 602 | $return .= "# http://www.xcloner.com\n"; |
603 | 603 | $return .= "#\n"; |
604 | - $return .= "# Host: " . get_site_url() . "\n"; |
|
605 | - $return .= "# Generation Time: " . date("M j, Y \a\\t H:i") . "\n"; |
|
606 | - $return .= "# PHP Version: " . phpversion() . "\n"; |
|
607 | - $return .= "# Database Charset: ". $this->charset . "\n"; |
|
604 | + $return .= "# Host: ".get_site_url()."\n"; |
|
605 | + $return .= "# Generation Time: ".date("M j, Y \a\\t H:i")."\n"; |
|
606 | + $return .= "# PHP Version: ".phpversion()."\n"; |
|
607 | + $return .= "# Database Charset: ".$this->charset."\n"; |
|
608 | 608 | |
609 | 609 | $results = $this->get_results("SHOW VARIABLES LIKE \"%version%\";", ARRAY_N); |
610 | - if(isset($results)){ |
|
611 | - foreach($results as $result){ |
|
610 | + if (isset($results)) { |
|
611 | + foreach ($results as $result) { |
|
612 | 612 | |
613 | 613 | $return .= "# MYSQL ".$result[0].": ".$result[1]."\n"; |
614 | 614 | |
@@ -618,13 +618,13 @@ discard block |
||
618 | 618 | $results = $this->get_results("SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME |
619 | 619 | FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".$database."';"); |
620 | 620 | |
621 | - if(isset($results[0])){ |
|
621 | + if (isset($results[0])) { |
|
622 | 622 | |
623 | 623 | $return .= "# MYSQL DEFAULT_CHARACTER_SET_NAME: ".$results[0]->DEFAULT_CHARACTER_SET_NAME."\n"; |
624 | 624 | $return .= "# MYSQL SCHEMA_NAME: ".$results[0]->DEFAULT_COLLATION_NAME."\n"; |
625 | 625 | } |
626 | 626 | |
627 | - $return .= "#\n# Database : `" . $database . "`\n# --------------------------------------------------------\n\n"; |
|
627 | + $return .= "#\n# Database : `".$database."`\n# --------------------------------------------------------\n\n"; |
|
628 | 628 | |
629 | 629 | $this->log(sprintf(__("Writing %s database dump headers"), $database)); |
630 | 630 |
@@ -44,11 +44,13 @@ discard block |
||
44 | 44 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
45 | 45 | $this->fs = $xcloner_container->get_xcloner_filesystem(); |
46 | 46 | |
47 | - if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) |
|
48 | - $this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
47 | + if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) { |
|
48 | + $this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
49 | + } |
|
49 | 50 | |
50 | - if(!$this->recordsPerSession) |
|
51 | - $this->recordsPerSession = 100; |
|
51 | + if(!$this->recordsPerSession) { |
|
52 | + $this->recordsPerSession = 100; |
|
53 | + } |
|
52 | 54 | |
53 | 55 | if(!$wp_user && !$wp_pass && !$wp_host && !$wp_db ) |
54 | 56 | { |
@@ -108,37 +110,43 @@ discard block |
||
108 | 110 | { |
109 | 111 | foreach($params['#'] as $database) |
110 | 112 | { |
111 | - if(!isset($params[$database]) or !is_array($params[$database])) |
|
112 | - $params[$database] = array(); |
|
113 | + if(!isset($params[$database]) or !is_array($params[$database])) { |
|
114 | + $params[$database] = array(); |
|
115 | + } |
|
113 | 116 | } |
114 | 117 | $db_count = -1; |
115 | 118 | } |
116 | 119 | |
117 | - if(isset($params) and is_array($params)) |
|
118 | - foreach($params as $database=>$tables) |
|
120 | + if(isset($params) and is_array($params)) { |
|
121 | + foreach($params as $database=>$tables) |
|
119 | 122 | { |
120 | 123 | if($database != "#") |
121 | 124 | { |
122 | - $stats = $this->write_backup_process_list($database, $tables); |
|
125 | + $stats = $this->write_backup_process_list($database, $tables); |
|
126 | + } |
|
123 | 127 | $return['stats']['tables_count'] += $stats['tables_count']; |
124 | 128 | $return['stats']['total_records'] += $stats['total_records']; |
125 | 129 | } |
126 | 130 | } |
127 | 131 | |
128 | - if(sizeof($params)) |
|
129 | - $return['stats']['database_count'] = sizeof($params)+$db_count; |
|
130 | - else |
|
131 | - $return['stats']['database_count'] = 0; |
|
132 | + if(sizeof($params)) { |
|
133 | + $return['stats']['database_count'] = sizeof($params)+$db_count; |
|
134 | + } else { |
|
135 | + $return['stats']['database_count'] = 0; |
|
136 | + } |
|
132 | 137 | |
133 | 138 | return $return; |
134 | 139 | } |
135 | 140 | |
136 | - if(!isset($extra_params['startAtLine'])) |
|
137 | - $extra_params['startAtLine'] = 0; |
|
138 | - if(!isset($extra_params['startAtRecord'])) |
|
139 | - $extra_params['startAtRecord'] = 0; |
|
140 | - if(!isset($extra_params['dumpfile'])) |
|
141 | - $extra_params['dumpfile'] = ""; |
|
141 | + if(!isset($extra_params['startAtLine'])) { |
|
142 | + $extra_params['startAtLine'] = 0; |
|
143 | + } |
|
144 | + if(!isset($extra_params['startAtRecord'])) { |
|
145 | + $extra_params['startAtRecord'] = 0; |
|
146 | + } |
|
147 | + if(!isset($extra_params['dumpfile'])) { |
|
148 | + $extra_params['dumpfile'] = ""; |
|
149 | + } |
|
142 | 150 | |
143 | 151 | $return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']); |
144 | 152 | |
@@ -150,11 +158,13 @@ discard block |
||
150 | 158 | |
151 | 159 | if($message){ |
152 | 160 | $this->logger->info( $message, array("")); |
153 | - }else{ |
|
154 | - if($this->last_query) |
|
155 | - $this->logger->debug( $this->last_query, array("")); |
|
156 | - if($this->last_error) |
|
157 | - $this->logger->error( $this->last_error, array("")); |
|
161 | + } else{ |
|
162 | + if($this->last_query) { |
|
163 | + $this->logger->debug( $this->last_query, array("")); |
|
164 | + } |
|
165 | + if($this->last_error) { |
|
166 | + $this->logger->error( $this->last_error, array("")); |
|
167 | + } |
|
158 | 168 | } |
159 | 169 | |
160 | 170 | return; |
@@ -225,11 +235,12 @@ discard block |
||
225 | 235 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname); |
226 | 236 | $i++; |
227 | 237 | |
228 | - if(is_array($databases)) |
|
229 | - foreach( $databases as $db){ |
|
238 | + if(is_array($databases)) { |
|
239 | + foreach( $databases as $db){ |
|
230 | 240 | if($db->Database != $this->dbname) |
231 | 241 | { |
232 | 242 | $databases_list[$i]['name'] = $db->Database; |
243 | + } |
|
233 | 244 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database); |
234 | 245 | $i++; |
235 | 246 | } |
@@ -252,8 +263,9 @@ discard block |
||
252 | 263 | $tablesList[0] = array( ); |
253 | 264 | $inc = 0; |
254 | 265 | |
255 | - if(!$database) |
|
256 | - $database = $this->dbname; |
|
266 | + if(!$database) { |
|
267 | + $database = $this->dbname; |
|
268 | + } |
|
257 | 269 | |
258 | 270 | $this->logger->debug(sprintf(("Listing tables in %s database"), $database)); |
259 | 271 | |
@@ -277,10 +289,11 @@ discard block |
||
277 | 289 | |
278 | 290 | $tablesList[$inc]['excluded'] = 0; |
279 | 291 | |
280 | - if(sizeof($included) and is_array($included)) |
|
281 | - if(!in_array($table, $included) ) |
|
292 | + if(sizeof($included) and is_array($included)) { |
|
293 | + if(!in_array($table, $included) ) |
|
282 | 294 | { |
283 | 295 | $tablesList[$inc]['excluded'] = 1; |
296 | + } |
|
284 | 297 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
285 | 298 | } |
286 | 299 | $inc++; |
@@ -299,19 +312,21 @@ discard block |
||
299 | 312 | |
300 | 313 | $tables = $this->list_tables($dbname, $incl_tables, 1); |
301 | 314 | |
302 | - if($this->dbname != $dbname) |
|
303 | - $dumpfile = $dbname."-backup.sql"; |
|
304 | - else |
|
305 | - $dumpfile = $this->TEMP_DUMP_FILE; |
|
315 | + if($this->dbname != $dbname) { |
|
316 | + $dumpfile = $dbname."-backup.sql"; |
|
317 | + } else { |
|
318 | + $dumpfile = $this->TEMP_DUMP_FILE; |
|
319 | + } |
|
306 | 320 | |
307 | 321 | $line = sprintf("###newdump###\t%s\t%s\n", $dbname, $dumpfile); |
308 | 322 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
309 | 323 | |
310 | 324 | // write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records |
311 | - foreach($tables as $key=>$table) |
|
312 | - if($table!= "" and !$tables[$key]['excluded']){ |
|
325 | + foreach($tables as $key=>$table) { |
|
326 | + if($table!= "" and !$tables[$key]['excluded']){ |
|
313 | 327 | |
314 | 328 | $line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']); |
329 | + } |
|
315 | 330 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
316 | 331 | $return['tables_count']++; |
317 | 332 | $return['total_records'] += $tables[$key]['records']; |
@@ -359,8 +374,9 @@ discard block |
||
359 | 374 | $return['finished'] = 0; |
360 | 375 | $lines = array(); |
361 | 376 | |
362 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
363 | - $lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
377 | + if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
378 | + $lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
379 | + } |
|
364 | 380 | |
365 | 381 | foreach ($lines as $buffer){ |
366 | 382 | |
@@ -385,14 +401,16 @@ discard block |
||
385 | 401 | $startAtLine++; |
386 | 402 | $return['new_dump'] = 1; |
387 | 403 | //break; |
388 | - }else{ |
|
404 | + } else{ |
|
389 | 405 | //we export the table |
390 | - if($tableInfo[0] == "###enddump###") |
|
391 | - $return['endDump'] = 1; |
|
406 | + if($tableInfo[0] == "###enddump###") { |
|
407 | + $return['endDump'] = 1; |
|
408 | + } |
|
392 | 409 | |
393 | 410 | //table is excluded |
394 | - if($tableInfo[2]) |
|
395 | - continue; |
|
411 | + if($tableInfo[2]) { |
|
412 | + continue; |
|
413 | + } |
|
396 | 414 | |
397 | 415 | $next = $startAtRecord + $this->recordsPerSession; |
398 | 416 | |
@@ -408,16 +426,19 @@ discard block |
||
408 | 426 | |
409 | 427 | $processed_records = 0; |
410 | 428 | |
411 | - if(trim($tableName) !="" and !$tableInfo[2]) |
|
412 | - $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
|
429 | + if(trim($tableName) !="" and !$tableInfo[2]) { |
|
430 | + $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
|
431 | + } |
|
413 | 432 | |
414 | 433 | $return['processedRecords'] = $startAtRecord+$processed_records; |
415 | 434 | |
416 | - if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
435 | + if($next >= $tableInfo[1]) { |
|
436 | + //we finished loading the records for next sessions, will go to the new record |
|
417 | 437 | { |
418 | 438 | $startAtLine ++; |
439 | + } |
|
419 | 440 | $startAtRecord = 0; |
420 | - }else{ |
|
441 | + } else{ |
|
421 | 442 | $startAtRecord = $startAtRecord + $this->recordsPerSession; |
422 | 443 | } |
423 | 444 | |
@@ -450,8 +471,9 @@ discard block |
||
450 | 471 | $return['finished'] = 1; |
451 | 472 | $return['startAtLine'] = $startAtLine; |
452 | 473 | |
453 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
454 | - $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
|
474 | + if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
475 | + $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
|
476 | + } |
|
455 | 477 | |
456 | 478 | $this->logger->debug(sprintf(("Database backup finished!"))); |
457 | 479 | |
@@ -479,8 +501,9 @@ discard block |
||
479 | 501 | |
480 | 502 | $records = 0; |
481 | 503 | |
482 | - if($start == 0) |
|
483 | - $this->dump_structure($databaseName, $tableName, $dumpfile); |
|
504 | + if($start == 0) { |
|
505 | + $this->dump_structure($databaseName, $tableName, $dumpfile); |
|
506 | + } |
|
484 | 507 | |
485 | 508 | $start = intval($start); |
486 | 509 | $limit = intval($limit); |
@@ -492,7 +515,7 @@ discard block |
||
492 | 515 | $result = mysqli_query($this->dbh, $query); |
493 | 516 | $mysql_fetch_function = "mysqli_fetch_array"; |
494 | 517 | |
495 | - }else{ |
|
518 | + } else{ |
|
496 | 519 | $result = mysql_query($query, $this->dbh); |
497 | 520 | $mysql_fetch_function = "mysqli_fetch_array"; |
498 | 521 | } |
@@ -26,6 +26,6 @@ |
||
26 | 26 | */ |
27 | 27 | |
28 | 28 | // If uninstall not called from WordPress, then exit. |
29 | -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
|
29 | +if (!defined('WP_UNINSTALL_PLUGIN')) { |
|
30 | 30 | exit; |
31 | 31 | } |
@@ -65,13 +65,8 @@ |
||
65 | 65 | |
66 | 66 | use League\Flysystem\Config; |
67 | 67 | use League\Flysystem\Filesystem; |
68 | -use League\Flysystem\Util; |
|
69 | 68 | use League\Flysystem\Adapter\Local; |
70 | - |
|
71 | 69 | use splitbrain\PHPArchive\Tar; |
72 | -use splitbrain\PHPArchive\Archive; |
|
73 | -use splitbrain\PHPArchive\FileInfo; |
|
74 | - |
|
75 | 70 | use Monolog\Logger; |
76 | 71 | use Monolog\Handler\StreamHandler; |
77 | 72 |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | * Update Wordpress url in wp-config.php method |
652 | 652 | * @param $wp_path |
653 | 653 | * @param $url |
654 | - * @param $mysqli |
|
654 | + * @param mysqli $mysqli |
|
655 | 655 | * @return bool |
656 | 656 | * @throws Exception |
657 | 657 | */ |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | * Get backup hash method |
782 | 782 | * |
783 | 783 | * @param $backup_file |
784 | - * @return bool |
|
784 | + * @return false|string |
|
785 | 785 | */ |
786 | 786 | private function get_hash_from_backup($backup_file) |
787 | 787 | { |
@@ -1004,7 +1004,7 @@ discard block |
||
1004 | 1004 | /** |
1005 | 1005 | * Return bytes from human readable value |
1006 | 1006 | * |
1007 | - * @param $val |
|
1007 | + * @param string $val |
|
1008 | 1008 | * @return int |
1009 | 1009 | * |
1010 | 1010 | */ |
@@ -1088,7 +1088,7 @@ discard block |
||
1088 | 1088 | * Sort_by method |
1089 | 1089 | * |
1090 | 1090 | * @param $array |
1091 | - * @param $field |
|
1091 | + * @param string $field |
|
1092 | 1092 | * @param string $direction |
1093 | 1093 | * @return bool |
1094 | 1094 | */ |
@@ -1097,6 +1097,10 @@ discard block |
||
1097 | 1097 | $direction = strtolower($direction); |
1098 | 1098 | |
1099 | 1099 | usort($array, |
1100 | + |
|
1101 | + /** |
|
1102 | + * @param string $b |
|
1103 | + */ |
|
1100 | 1104 | function($a, $b) use($field, $direction){ |
1101 | 1105 | |
1102 | 1106 | $a = $a[$field]; |
@@ -1162,7 +1166,7 @@ discard block |
||
1162 | 1166 | * Serialize fix methods below for mysql query lines |
1163 | 1167 | * |
1164 | 1168 | * @param $query |
1165 | - * @return string|string[]|null |
|
1169 | + * @return string |
|
1166 | 1170 | */ |
1167 | 1171 | |
1168 | 1172 | function do_serialized_fix($query) |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | private $backup_storage_dir; |
107 | 107 | private $parent_api; |
108 | 108 | |
109 | - /** |
|
110 | - * Xcloner_Restore constructor. |
|
111 | - * @param string $parent_api |
|
112 | - * @throws Exception |
|
113 | - */ |
|
109 | + /** |
|
110 | + * Xcloner_Restore constructor. |
|
111 | + * @param string $parent_api |
|
112 | + * @throws Exception |
|
113 | + */ |
|
114 | 114 | public function __construct($parent_api = "") |
115 | 115 | { |
116 | 116 | register_shutdown_function(array($this, 'exception_handler')); |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | |
151 | 151 | } |
152 | 152 | |
153 | - /** |
|
154 | - * Exception handler method |
|
155 | - */ |
|
153 | + /** |
|
154 | + * Exception handler method |
|
155 | + */ |
|
156 | 156 | public function exception_handler() { |
157 | 157 | |
158 | 158 | $error = error_get_last(); |
@@ -164,20 +164,20 @@ discard block |
||
164 | 164 | |
165 | 165 | } |
166 | 166 | |
167 | - /** |
|
168 | - * @param $type |
|
169 | - * @return mixed|string |
|
170 | - */ |
|
167 | + /** |
|
168 | + * @param $type |
|
169 | + * @return mixed|string |
|
170 | + */ |
|
171 | 171 | private function friendly_error_type($type) { |
172 | - static $levels=null; |
|
173 | - if ($levels===null) { |
|
174 | - $levels=[]; |
|
175 | - foreach (get_defined_constants() as $key=>$value) { |
|
176 | - if (strpos($key,'E_')!==0) {continue;} |
|
172 | + static $levels=null; |
|
173 | + if ($levels===null) { |
|
174 | + $levels=[]; |
|
175 | + foreach (get_defined_constants() as $key=>$value) { |
|
176 | + if (strpos($key,'E_')!==0) {continue;} |
|
177 | 177 | $levels[$value]= $key; //substr($key,2); |
178 | - } |
|
179 | - } |
|
180 | - return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
|
178 | + } |
|
179 | + } |
|
180 | + return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | public function get_logger_filename() |
@@ -187,12 +187,12 @@ discard block |
||
187 | 187 | return $filename; |
188 | 188 | } |
189 | 189 | |
190 | - /** |
|
191 | - * Init method |
|
192 | - * |
|
193 | - * @return mixed|void |
|
194 | - * @throws Exception |
|
195 | - */ |
|
190 | + /** |
|
191 | + * Init method |
|
192 | + * |
|
193 | + * @return mixed|void |
|
194 | + * @throws Exception |
|
195 | + */ |
|
196 | 196 | public function init() |
197 | 197 | { |
198 | 198 | if(isset($_POST['xcloner_action']) and $_POST['xcloner_action']) |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | return $this->check_system(); |
217 | 217 | } |
218 | 218 | |
219 | - /** |
|
220 | - * Write file method |
|
221 | - * |
|
222 | - * @return bool|int |
|
223 | - * @throws Exception |
|
224 | - */ |
|
219 | + /** |
|
220 | + * Write file method |
|
221 | + * |
|
222 | + * @return bool|int |
|
223 | + * @throws Exception |
|
224 | + */ |
|
225 | 225 | public function write_file_action() |
226 | 226 | { |
227 | 227 | if(isset($_POST['file'])) |
@@ -248,10 +248,10 @@ discard block |
||
248 | 248 | throw new Exception("Unable to write data to file $target_file"); |
249 | 249 | |
250 | 250 | try { |
251 | - unlink($_FILES['blob']['tmp_name']); |
|
252 | - }catch(Exception $e){ |
|
251 | + unlink($_FILES['blob']['tmp_name']); |
|
252 | + }catch(Exception $e){ |
|
253 | 253 | |
254 | - } |
|
254 | + } |
|
255 | 255 | |
256 | 256 | }elseif(isset($_POST['blob'])){ |
257 | 257 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start'])); |
@@ -271,16 +271,16 @@ discard block |
||
271 | 271 | |
272 | 272 | } |
273 | 273 | |
274 | - /** |
|
275 | - * Connect to mysql server method |
|
276 | - * |
|
277 | - * @param $remote_mysql_host |
|
278 | - * @param $remote_mysql_user |
|
279 | - * @param $remote_mysql_pass |
|
280 | - * @param $remote_mysql_db |
|
281 | - * @return mysqli |
|
282 | - * @throws Exception |
|
283 | - */ |
|
274 | + /** |
|
275 | + * Connect to mysql server method |
|
276 | + * |
|
277 | + * @param $remote_mysql_host |
|
278 | + * @param $remote_mysql_user |
|
279 | + * @param $remote_mysql_pass |
|
280 | + * @param $remote_mysql_db |
|
281 | + * @return mysqli |
|
282 | + * @throws Exception |
|
283 | + */ |
|
284 | 284 | public function mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db ) |
285 | 285 | { |
286 | 286 | $this->logger->info(sprintf('Connecting to mysql database %s with %s@%s', $remote_mysql_db, $remote_mysql_user, $remote_mysql_host)); |
@@ -302,11 +302,11 @@ discard block |
||
302 | 302 | return $mysqli; |
303 | 303 | } |
304 | 304 | |
305 | - /** |
|
306 | - * Restore mysql backup file |
|
307 | - * |
|
308 | - * @throws Exception |
|
309 | - */ |
|
305 | + /** |
|
306 | + * Restore mysql backup file |
|
307 | + * |
|
308 | + * @throws Exception |
|
309 | + */ |
|
310 | 310 | public function restore_mysql_backup_action() |
311 | 311 | { |
312 | 312 | $mysqldump_file = filter_input(INPUT_POST, 'mysqldump_file', FILTER_SANITIZE_STRING); |
@@ -437,14 +437,14 @@ discard block |
||
437 | 437 | $this->send_response(200, $return); |
438 | 438 | } |
439 | 439 | |
440 | - /** |
|
441 | - * Url replace method inside database backup file |
|
442 | - * |
|
443 | - * @param $search |
|
444 | - * @param $replace |
|
445 | - * @param $query |
|
446 | - * @return mixed|string|string[]|null |
|
447 | - */ |
|
440 | + /** |
|
441 | + * Url replace method inside database backup file |
|
442 | + * |
|
443 | + * @param $search |
|
444 | + * @param $replace |
|
445 | + * @param $query |
|
446 | + * @return mixed|string|string[]|null |
|
447 | + */ |
|
448 | 448 | private function url_replace($search, $replace, $query) |
449 | 449 | { |
450 | 450 | $this->logger->info(sprintf("Doing url replace on query with length %s", strlen($query)), array("QUERY_REPLACE")); |
@@ -467,11 +467,11 @@ discard block |
||
467 | 467 | return $query; |
468 | 468 | } |
469 | 469 | |
470 | - /** |
|
471 | - * List backup files method |
|
472 | - * |
|
473 | - * @throws \League\Flysystem\FileNotFoundException |
|
474 | - */ |
|
470 | + /** |
|
471 | + * List backup files method |
|
472 | + * |
|
473 | + * @throws \League\Flysystem\FileNotFoundException |
|
474 | + */ |
|
475 | 475 | public function list_backup_files_action() |
476 | 476 | { |
477 | 477 | $backup_parts = array(); |
@@ -537,11 +537,11 @@ discard block |
||
537 | 537 | $this->send_response(200, $return); |
538 | 538 | } |
539 | 539 | |
540 | - /** |
|
541 | - * Finish backup restore method |
|
542 | - * |
|
543 | - * @throws \League\Flysystem\FileNotFoundException |
|
544 | - */ |
|
540 | + /** |
|
541 | + * Finish backup restore method |
|
542 | + * |
|
543 | + * @throws \League\Flysystem\FileNotFoundException |
|
544 | + */ |
|
545 | 545 | public function restore_finish_action() |
546 | 546 | { |
547 | 547 | $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
@@ -582,12 +582,12 @@ discard block |
||
582 | 582 | $this->send_response(200, $return); |
583 | 583 | } |
584 | 584 | |
585 | - /** |
|
586 | - * Delete backup temporary folder |
|
587 | - * |
|
588 | - * @param $remote_path |
|
589 | - * @return bool |
|
590 | - */ |
|
585 | + /** |
|
586 | + * Delete backup temporary folder |
|
587 | + * |
|
588 | + * @param $remote_path |
|
589 | + * @return bool |
|
590 | + */ |
|
591 | 591 | private function delete_backup_temporary_folder($remote_path) |
592 | 592 | { |
593 | 593 | $this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS'); |
@@ -615,11 +615,11 @@ discard block |
||
615 | 615 | |
616 | 616 | } |
617 | 617 | |
618 | - /** |
|
619 | - * Delete restore script method |
|
620 | - * |
|
621 | - * @throws \League\Flysystem\FileNotFoundException |
|
622 | - */ |
|
618 | + /** |
|
619 | + * Delete restore script method |
|
620 | + * |
|
621 | + * @throws \League\Flysystem\FileNotFoundException |
|
622 | + */ |
|
623 | 623 | private function delete_self() |
624 | 624 | { |
625 | 625 | if($this->filesystem->has("vendor.phar")) |
@@ -652,14 +652,14 @@ discard block |
||
652 | 652 | |
653 | 653 | } |
654 | 654 | |
655 | - /** |
|
656 | - * Update Wordpress url in wp-config.php method |
|
657 | - * @param $wp_path |
|
658 | - * @param $url |
|
659 | - * @param $mysqli |
|
660 | - * @return bool |
|
661 | - * @throws Exception |
|
662 | - */ |
|
655 | + /** |
|
656 | + * Update Wordpress url in wp-config.php method |
|
657 | + * @param $wp_path |
|
658 | + * @param $url |
|
659 | + * @param $mysqli |
|
660 | + * @return bool |
|
661 | + * @throws Exception |
|
662 | + */ |
|
663 | 663 | private function update_wp_url($wp_path, $url, $mysqli) |
664 | 664 | { |
665 | 665 | $wp_config = $wp_path.DS."wp-config.php"; |
@@ -687,17 +687,17 @@ discard block |
||
687 | 687 | return true; |
688 | 688 | } |
689 | 689 | |
690 | - /** |
|
691 | - * Update local wp-config.php file method |
|
692 | - * |
|
693 | - * @param $remote_path |
|
694 | - * @param $remote_mysql_host |
|
695 | - * @param $remote_mysql_user |
|
696 | - * @param $remote_mysql_pass |
|
697 | - * @param $remote_mysql_db |
|
698 | - * @return string |
|
699 | - * @throws Exception |
|
700 | - */ |
|
690 | + /** |
|
691 | + * Update local wp-config.php file method |
|
692 | + * |
|
693 | + * @param $remote_path |
|
694 | + * @param $remote_mysql_host |
|
695 | + * @param $remote_mysql_user |
|
696 | + * @param $remote_mysql_pass |
|
697 | + * @param $remote_mysql_db |
|
698 | + * @return string |
|
699 | + * @throws Exception |
|
700 | + */ |
|
701 | 701 | private function update_wp_config($remote_path, $remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db) |
702 | 702 | { |
703 | 703 | $wp_config = $remote_path.DS."wp-config.php"; |
@@ -729,10 +729,10 @@ discard block |
||
729 | 729 | |
730 | 730 | } |
731 | 731 | |
732 | - /** |
|
733 | - * List mysqldump database backup files |
|
734 | - * |
|
735 | - */ |
|
732 | + /** |
|
733 | + * List mysqldump database backup files |
|
734 | + * |
|
735 | + */ |
|
736 | 736 | public function list_mysqldump_backups_action() |
737 | 737 | { |
738 | 738 | $source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING); |
@@ -782,12 +782,12 @@ discard block |
||
782 | 782 | $this->send_response(200, $return); |
783 | 783 | } |
784 | 784 | |
785 | - /** |
|
786 | - * Get backup hash method |
|
787 | - * |
|
788 | - * @param $backup_file |
|
789 | - * @return bool |
|
790 | - */ |
|
785 | + /** |
|
786 | + * Get backup hash method |
|
787 | + * |
|
788 | + * @param $backup_file |
|
789 | + * @return bool |
|
790 | + */ |
|
791 | 791 | private function get_hash_from_backup($backup_file) |
792 | 792 | { |
793 | 793 | if(!$backup_file) |
@@ -801,11 +801,11 @@ discard block |
||
801 | 801 | return false; |
802 | 802 | } |
803 | 803 | |
804 | - /** |
|
805 | - * List backup archives found on local system |
|
806 | - * |
|
807 | - * @throws \League\Flysystem\FileNotFoundException |
|
808 | - */ |
|
804 | + /** |
|
805 | + * List backup archives found on local system |
|
806 | + * |
|
807 | + * @throws \League\Flysystem\FileNotFoundException |
|
808 | + */ |
|
809 | 809 | public function list_backup_archives_action() |
810 | 810 | { |
811 | 811 | $local_backup_file = filter_input(INPUT_POST, 'local_backup_file', FILTER_SANITIZE_STRING); |
@@ -864,12 +864,12 @@ discard block |
||
864 | 864 | |
865 | 865 | } |
866 | 866 | |
867 | - /** |
|
868 | - * Restore backup archive to local path |
|
869 | - * |
|
870 | - * @throws \League\Flysystem\FileNotFoundException |
|
871 | - * @throws \splitbrain\PHPArchive\ArchiveIOException |
|
872 | - */ |
|
867 | + /** |
|
868 | + * Restore backup archive to local path |
|
869 | + * |
|
870 | + * @throws \League\Flysystem\FileNotFoundException |
|
871 | + * @throws \splitbrain\PHPArchive\ArchiveIOException |
|
872 | + */ |
|
873 | 873 | public function restore_backup_to_path_action() |
874 | 874 | { |
875 | 875 | $source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING); |
@@ -944,9 +944,9 @@ discard block |
||
944 | 944 | $this->send_response(200, $return); |
945 | 945 | } |
946 | 946 | |
947 | - /** |
|
948 | - * Get current directory method |
|
949 | - */ |
|
947 | + /** |
|
948 | + * Get current directory method |
|
949 | + */ |
|
950 | 950 | public function get_current_directory_action() |
951 | 951 | { |
952 | 952 | global $wpdb; |
@@ -980,11 +980,11 @@ discard block |
||
980 | 980 | $this->send_response(200, $return); |
981 | 981 | } |
982 | 982 | |
983 | - /** |
|
984 | - * Check current filesystem |
|
985 | - * |
|
986 | - * @throws Exception |
|
987 | - */ |
|
983 | + /** |
|
984 | + * Check current filesystem |
|
985 | + * |
|
986 | + * @throws Exception |
|
987 | + */ |
|
988 | 988 | public function check_system() |
989 | 989 | { |
990 | 990 | //check if i can write |
@@ -1006,35 +1006,35 @@ discard block |
||
1006 | 1006 | $this->send_response(200, $return); |
1007 | 1007 | } |
1008 | 1008 | |
1009 | - /** |
|
1010 | - * Return bytes from human readable value |
|
1011 | - * |
|
1012 | - * @param $val |
|
1013 | - * @return int |
|
1014 | - * |
|
1015 | - */ |
|
1016 | - private function return_bytes($val) { |
|
1017 | - $numeric_val = (int)trim($val); |
|
1018 | - $last = strtolower($val[strlen($val)-1]); |
|
1019 | - switch($last) { |
|
1020 | - // The 'G' modifier is available since PHP 5.1.0 |
|
1021 | - case 'g': |
|
1022 | - $numeric_val *= 1024; |
|
1023 | - case 'm': |
|
1024 | - $numeric_val *= 1024; |
|
1025 | - case 'k': |
|
1026 | - $numeric_val *= 1024; |
|
1027 | - } |
|
1028 | - |
|
1029 | - return $numeric_val; |
|
1030 | - } |
|
1031 | - |
|
1032 | - /** |
|
1033 | - * Check if backup archive os multipart |
|
1034 | - * |
|
1035 | - * @param $backup_name |
|
1036 | - * @return bool |
|
1037 | - */ |
|
1009 | + /** |
|
1010 | + * Return bytes from human readable value |
|
1011 | + * |
|
1012 | + * @param $val |
|
1013 | + * @return int |
|
1014 | + * |
|
1015 | + */ |
|
1016 | + private function return_bytes($val) { |
|
1017 | + $numeric_val = (int)trim($val); |
|
1018 | + $last = strtolower($val[strlen($val)-1]); |
|
1019 | + switch($last) { |
|
1020 | + // The 'G' modifier is available since PHP 5.1.0 |
|
1021 | + case 'g': |
|
1022 | + $numeric_val *= 1024; |
|
1023 | + case 'm': |
|
1024 | + $numeric_val *= 1024; |
|
1025 | + case 'k': |
|
1026 | + $numeric_val *= 1024; |
|
1027 | + } |
|
1028 | + |
|
1029 | + return $numeric_val; |
|
1030 | + } |
|
1031 | + |
|
1032 | + /** |
|
1033 | + * Check if backup archive os multipart |
|
1034 | + * |
|
1035 | + * @param $backup_name |
|
1036 | + * @return bool |
|
1037 | + */ |
|
1038 | 1038 | public function is_multipart($backup_name) |
1039 | 1039 | { |
1040 | 1040 | if(stristr($backup_name, "-multipart")) |
@@ -1043,13 +1043,13 @@ discard block |
||
1043 | 1043 | return false; |
1044 | 1044 | } |
1045 | 1045 | |
1046 | - /** |
|
1047 | - * Get backup archive size |
|
1048 | - * |
|
1049 | - * @param $backup_name |
|
1050 | - * @return bool|false|int |
|
1051 | - * @throws \League\Flysystem\FileNotFoundException |
|
1052 | - */ |
|
1046 | + /** |
|
1047 | + * Get backup archive size |
|
1048 | + * |
|
1049 | + * @param $backup_name |
|
1050 | + * @return bool|false|int |
|
1051 | + * @throws \League\Flysystem\FileNotFoundException |
|
1052 | + */ |
|
1053 | 1053 | public function get_backup_size($backup_name) |
1054 | 1054 | { |
1055 | 1055 | $backup_size = $this->filesystem->getSize($backup_name); |
@@ -1063,12 +1063,12 @@ discard block |
||
1063 | 1063 | return $backup_size; |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - /** |
|
1067 | - * Get multipart backup files list |
|
1068 | - * @param $backup_name |
|
1069 | - * @return array |
|
1070 | - * @throws \League\Flysystem\FileNotFoundException |
|
1071 | - */ |
|
1066 | + /** |
|
1067 | + * Get multipart backup files list |
|
1068 | + * @param $backup_name |
|
1069 | + * @return array |
|
1070 | + * @throws \League\Flysystem\FileNotFoundException |
|
1071 | + */ |
|
1072 | 1072 | public function get_multipart_files($backup_name) |
1073 | 1073 | { |
1074 | 1074 | $files = array(); |
@@ -1089,58 +1089,58 @@ discard block |
||
1089 | 1089 | return $files; |
1090 | 1090 | } |
1091 | 1091 | |
1092 | - /** |
|
1093 | - * Sort_by method |
|
1094 | - * |
|
1095 | - * @param $array |
|
1096 | - * @param $field |
|
1097 | - * @param string $direction |
|
1098 | - * @return bool |
|
1099 | - */ |
|
1100 | - private function sort_by( &$array, $field, $direction = 'asc') |
|
1101 | - { |
|
1102 | - $direction = strtolower($direction); |
|
1103 | - |
|
1104 | - usort($array, |
|
1105 | - function($a, $b) use($field, $direction){ |
|
1106 | - |
|
1107 | - $a = $a[$field]; |
|
1108 | - $b = $b[$field]; |
|
1109 | - |
|
1110 | - if ($a == $b) |
|
1111 | - { |
|
1112 | - return 0; |
|
1113 | - } |
|
1114 | - |
|
1115 | - if($direction == 'desc') { |
|
1116 | - if($a > $b) { |
|
1117 | - return -1; |
|
1118 | - } |
|
1119 | - else{ |
|
1120 | - return 1; |
|
1121 | - } |
|
1122 | - }else { |
|
1123 | - if($a < $b) { |
|
1124 | - return -1; |
|
1125 | - } |
|
1126 | - else{ |
|
1127 | - return 1; |
|
1128 | - } |
|
1129 | - } |
|
1130 | - |
|
1131 | - //return ($a.($direction == 'desc' ? '>' : '<').$b) ? -1 : 1; |
|
1132 | - } |
|
1133 | - ); |
|
1134 | - |
|
1135 | - return true; |
|
1136 | - } |
|
1137 | - |
|
1138 | - /** |
|
1139 | - * Send response method |
|
1140 | - * |
|
1141 | - * @param int $status |
|
1142 | - * @param $response |
|
1143 | - */ |
|
1092 | + /** |
|
1093 | + * Sort_by method |
|
1094 | + * |
|
1095 | + * @param $array |
|
1096 | + * @param $field |
|
1097 | + * @param string $direction |
|
1098 | + * @return bool |
|
1099 | + */ |
|
1100 | + private function sort_by( &$array, $field, $direction = 'asc') |
|
1101 | + { |
|
1102 | + $direction = strtolower($direction); |
|
1103 | + |
|
1104 | + usort($array, |
|
1105 | + function($a, $b) use($field, $direction){ |
|
1106 | + |
|
1107 | + $a = $a[$field]; |
|
1108 | + $b = $b[$field]; |
|
1109 | + |
|
1110 | + if ($a == $b) |
|
1111 | + { |
|
1112 | + return 0; |
|
1113 | + } |
|
1114 | + |
|
1115 | + if($direction == 'desc') { |
|
1116 | + if($a > $b) { |
|
1117 | + return -1; |
|
1118 | + } |
|
1119 | + else{ |
|
1120 | + return 1; |
|
1121 | + } |
|
1122 | + }else { |
|
1123 | + if($a < $b) { |
|
1124 | + return -1; |
|
1125 | + } |
|
1126 | + else{ |
|
1127 | + return 1; |
|
1128 | + } |
|
1129 | + } |
|
1130 | + |
|
1131 | + //return ($a.($direction == 'desc' ? '>' : '<').$b) ? -1 : 1; |
|
1132 | + } |
|
1133 | + ); |
|
1134 | + |
|
1135 | + return true; |
|
1136 | + } |
|
1137 | + |
|
1138 | + /** |
|
1139 | + * Send response method |
|
1140 | + * |
|
1141 | + * @param int $status |
|
1142 | + * @param $response |
|
1143 | + */ |
|
1144 | 1144 | public static function send_response($status = 200, $response) |
1145 | 1145 | { |
1146 | 1146 | header("Access-Control-Allow-Origin: *"); |
@@ -1163,12 +1163,12 @@ discard block |
||
1163 | 1163 | exit; |
1164 | 1164 | } |
1165 | 1165 | |
1166 | - /** |
|
1167 | - * Serialize fix methods below for mysql query lines |
|
1168 | - * |
|
1169 | - * @param $query |
|
1170 | - * @return string|string[]|null |
|
1171 | - */ |
|
1166 | + /** |
|
1167 | + * Serialize fix methods below for mysql query lines |
|
1168 | + * |
|
1169 | + * @param $query |
|
1170 | + * @return string|string[]|null |
|
1171 | + */ |
|
1172 | 1172 | |
1173 | 1173 | function do_serialized_fix($query) |
1174 | 1174 | { |
@@ -1181,51 +1181,51 @@ discard block |
||
1181 | 1181 | $m[3] = ""; |
1182 | 1182 | |
1183 | 1183 | $data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";'; |
1184 | - //return $this->unescape_quotes($data); |
|
1184 | + //return $this->unescape_quotes($data); |
|
1185 | 1185 | |
1186 | - return $data; |
|
1187 | - }, $query); |
|
1186 | + return $data; |
|
1187 | + }, $query); |
|
1188 | 1188 | } |
1189 | 1189 | |
1190 | - /** |
|
1191 | - * Unescape quotes method |
|
1192 | - * |
|
1193 | - * @param $value |
|
1194 | - * @return mixed |
|
1195 | - */ |
|
1190 | + /** |
|
1191 | + * Unescape quotes method |
|
1192 | + * |
|
1193 | + * @param $value |
|
1194 | + * @return mixed |
|
1195 | + */ |
|
1196 | 1196 | private function unescape_quotes($value) { |
1197 | 1197 | return str_replace('\"', '"', $value); |
1198 | 1198 | } |
1199 | 1199 | |
1200 | - /** |
|
1201 | - * Unescape mysql method |
|
1202 | - * |
|
1203 | - * @param $value |
|
1204 | - * @return mixed |
|
1205 | - */ |
|
1200 | + /** |
|
1201 | + * Unescape mysql method |
|
1202 | + * |
|
1203 | + * @param $value |
|
1204 | + * @return mixed |
|
1205 | + */ |
|
1206 | 1206 | private function unescape_mysql($value) { |
1207 | 1207 | return str_replace(array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"'), |
1208 | 1208 | array("\\", "\0", "\n", "\r", "\x1a", "'", '"'), |
1209 | 1209 | $value); |
1210 | 1210 | } |
1211 | 1211 | |
1212 | - /** |
|
1213 | - * Check if string is in serialized format |
|
1214 | - * |
|
1215 | - * @param $s |
|
1216 | - * @return bool |
|
1217 | - */ |
|
1212 | + /** |
|
1213 | + * Check if string is in serialized format |
|
1214 | + * |
|
1215 | + * @param $s |
|
1216 | + * @return bool |
|
1217 | + */ |
|
1218 | 1218 | private function has_serialized($s) |
1219 | 1219 | { |
1220 | 1220 | if( |
1221 | - stristr($s, '{' ) !== false && |
|
1222 | - stristr($s, '}' ) !== false && |
|
1223 | - stristr($s, ';' ) !== false && |
|
1224 | - stristr($s, ':' ) !== false |
|
1225 | - ){ |
|
1226 | - return true; |
|
1221 | + stristr($s, '{' ) !== false && |
|
1222 | + stristr($s, '}' ) !== false && |
|
1223 | + stristr($s, ';' ) !== false && |
|
1224 | + stristr($s, ':' ) !== false |
|
1225 | + ){ |
|
1226 | + return true; |
|
1227 | 1227 | }else{ |
1228 | - return false; |
|
1228 | + return false; |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | } |
@@ -1,30 +1,30 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if(!defined('AUTH_KEY')) |
|
3 | +if (!defined('AUTH_KEY')) |
|
4 | 4 | { |
5 | 5 | define('AUTH_KEY', ''); |
6 | 6 | } |
7 | 7 | |
8 | -if(!defined("DS")) |
|
8 | +if (!defined("DS")) |
|
9 | 9 | { |
10 | 10 | define("DS", DIRECTORY_SEPARATOR); |
11 | 11 | } |
12 | 12 | |
13 | -if(!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1) |
|
13 | +if (!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1) |
|
14 | 14 | { |
15 | - if(!AUTH_KEY) |
|
15 | + if (!AUTH_KEY) |
|
16 | 16 | { |
17 | 17 | Xcloner_Restore::send_response("404", "Could not run restore script, AUTH_KEY not set!"); |
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
21 | - if(!isset($_REQUEST['hash'])) |
|
21 | + if (!isset($_REQUEST['hash'])) |
|
22 | 22 | { |
23 | 23 | Xcloner_Restore::send_response("404", "Could not run restore script, sent HASH is empty!"); |
24 | 24 | exit; |
25 | 25 | } |
26 | 26 | |
27 | - if($_REQUEST['hash'] != AUTH_KEY) |
|
27 | + if ($_REQUEST['hash'] != AUTH_KEY) |
|
28 | 28 | { |
29 | 29 | Xcloner_Restore::send_response("404", "Could not run restore script, AUTH_KEY doesn't match the sent HASH!"); |
30 | 30 | exit; |
@@ -32,28 +32,28 @@ discard block |
||
32 | 32 | } |
33 | 33 | |
34 | 34 | //check minimum PHP version |
35 | -if(version_compare(phpversion(), Xcloner_Restore::xcloner_minimum_version, '<')) |
|
35 | +if (version_compare(phpversion(), Xcloner_Restore::xcloner_minimum_version, '<')) |
|
36 | 36 | { |
37 | - Xcloner_Restore::send_response(500, sprintf(("XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s"),Xcloner_Restore::xcloner_minimum_version, phpversion()) ); |
|
37 | + Xcloner_Restore::send_response(500, sprintf(("XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s"), Xcloner_Restore::xcloner_minimum_version, phpversion())); |
|
38 | 38 | exit; |
39 | 39 | |
40 | 40 | } |
41 | 41 | |
42 | -$file = dirname( __DIR__ ) . DS.'vendor'.DS.'autoload.php'; |
|
42 | +$file = dirname(__DIR__).DS.'vendor'.DS.'autoload.php'; |
|
43 | 43 | |
44 | -if(file_exists($file)) |
|
44 | +if (file_exists($file)) |
|
45 | 45 | { |
46 | 46 | |
47 | 47 | require_once($file); |
48 | 48 | } |
49 | -elseif(file_exists("vendor.phar") and extension_loaded('phar')) |
|
49 | +elseif (file_exists("vendor.phar") and extension_loaded('phar')) |
|
50 | 50 | { |
51 | 51 | require_once(__DIR__.DS."vendor.phar"); |
52 | -}else{ |
|
52 | +} else { |
|
53 | 53 | |
54 | - $file = dirname( __FILE__ ) . DS.'vendor'.DS.'autoload.php'; |
|
54 | + $file = dirname(__FILE__).DS.'vendor'.DS.'autoload.php'; |
|
55 | 55 | |
56 | - if(!file_exists($file)) |
|
56 | + if (!file_exists($file)) |
|
57 | 57 | { |
58 | 58 | Xcloner_Restore::send_response("404", "File $file does not exists, please extract the vendor.tgz archive on the server or enable PHP Phar module!"); |
59 | 59 | exit; |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | |
79 | 79 | //do not modify below |
80 | 80 | $that = ""; |
81 | -if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
81 | +if (defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
82 | 82 | { |
83 | 83 | $that = $this; |
84 | 84 | } |
85 | 85 | $xcloner_restore = new Xcloner_Restore($that); |
86 | 86 | |
87 | -try{ |
|
87 | +try { |
|
88 | 88 | $return = $xcloner_restore->init(); |
89 | 89 | $xcloner_restore->send_response(200, $return); |
90 | -}catch(Exception $e){ |
|
90 | +}catch (Exception $e) { |
|
91 | 91 | $xcloner_restore->send_response(417, $e->getMessage()); |
92 | 92 | } |
93 | 93 | |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | |
97 | 97 | const xcloner_minimum_version = "5.4.0"; |
98 | 98 | |
99 | - private $backup_archive_extensions = array("zip", "tar", "tgz", "tar.gz", "gz", "csv"); |
|
100 | - private $process_files_limit = 150; |
|
101 | - private $process_files_limit_list = 350; |
|
102 | - private $process_mysql_records_limit = 250; |
|
99 | + private $backup_archive_extensions = array("zip", "tar", "tgz", "tar.gz", "gz", "csv"); |
|
100 | + private $process_files_limit = 150; |
|
101 | + private $process_files_limit_list = 350; |
|
102 | + private $process_mysql_records_limit = 250; |
|
103 | 103 | private $adapter; |
104 | 104 | private $filesystem; |
105 | 105 | private $logger; |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | { |
116 | 116 | register_shutdown_function(array($this, 'exception_handler')); |
117 | 117 | |
118 | - if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
118 | + if (defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
119 | 119 | { |
120 | 120 | $dir = $parent_api->get_xcloner_container()->get_xcloner_settings()->get_xcloner_store_path(); |
121 | 121 | } |
122 | 122 | |
123 | - if(!isset($dir) || !$dir){ |
|
123 | + if (!isset($dir) || !$dir) { |
|
124 | 124 | $dir = dirname(__FILE__); |
125 | 125 | } |
126 | 126 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | |
129 | 129 | $this->backup_storage_dir = $dir; |
130 | 130 | |
131 | - $this->adapter = new Local($dir ,LOCK_EX, 'SKIP_LINKS'); |
|
131 | + $this->adapter = new Local($dir, LOCK_EX, 'SKIP_LINKS'); |
|
132 | 132 | $this->filesystem = new Filesystem($this->adapter, new Config([ |
133 | 133 | 'disable_asserts' => true, |
134 | 134 | ])); |
@@ -137,15 +137,15 @@ discard block |
||
137 | 137 | |
138 | 138 | $logger_path = $this->get_logger_filename(); |
139 | 139 | |
140 | - if(!is_writeable($logger_path) and !touch($logger_path)) |
|
140 | + if (!is_writeable($logger_path) and !touch($logger_path)) |
|
141 | 141 | { |
142 | 142 | $logger_path = "php://stderr"; |
143 | 143 | } |
144 | 144 | |
145 | 145 | $this->logger->pushHandler(new StreamHandler($logger_path, Logger::DEBUG)); |
146 | 146 | |
147 | - if(isset($_POST['API_ID'])){ |
|
148 | - $this->logger->info("Processing ajax request ID ".substr(filter_input(INPUT_POST, 'API_ID', FILTER_SANITIZE_STRING), 0 , 15)); |
|
147 | + if (isset($_POST['API_ID'])) { |
|
148 | + $this->logger->info("Processing ajax request ID ".substr(filter_input(INPUT_POST, 'API_ID', FILTER_SANITIZE_STRING), 0, 15)); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | } |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | |
158 | 158 | $error = error_get_last(); |
159 | 159 | |
160 | - if($error['type'] and $this->logger) |
|
160 | + if ($error['type'] and $this->logger) |
|
161 | 161 | { |
162 | - $this->logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true)); |
|
162 | + $this->logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true)); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | } |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | * @return mixed|string |
170 | 170 | */ |
171 | 171 | private function friendly_error_type($type) { |
172 | - static $levels=null; |
|
173 | - if ($levels===null) { |
|
174 | - $levels=[]; |
|
172 | + static $levels = null; |
|
173 | + if ($levels === null) { |
|
174 | + $levels = []; |
|
175 | 175 | foreach (get_defined_constants() as $key=>$value) { |
176 | - if (strpos($key,'E_')!==0) {continue;} |
|
177 | - $levels[$value]= $key; //substr($key,2); |
|
176 | + if (strpos($key, 'E_') !== 0) {continue; } |
|
177 | + $levels[$value] = $key; //substr($key,2); |
|
178 | 178 | } |
179 | 179 | } |
180 | 180 | return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | public function get_logger_filename() |
184 | 184 | { |
185 | - $filename = $this->backup_storage_dir .DS. "xcloner_restore.log"; |
|
185 | + $filename = $this->backup_storage_dir.DS."xcloner_restore.log"; |
|
186 | 186 | |
187 | 187 | return $filename; |
188 | 188 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function init() |
197 | 197 | { |
198 | - if(isset($_POST['xcloner_action']) and $_POST['xcloner_action']) |
|
198 | + if (isset($_POST['xcloner_action']) and $_POST['xcloner_action']) |
|
199 | 199 | { |
200 | 200 | $method = filter_input(INPUT_POST, 'xcloner_action', FILTER_SANITIZE_STRING); |
201 | 201 | |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | |
204 | 204 | $method .= "_action"; |
205 | 205 | |
206 | - if(method_exists($this, $method)) |
|
206 | + if (method_exists($this, $method)) |
|
207 | 207 | { |
208 | 208 | $this->logger->debug(sprintf('Starting action %s', $method)); |
209 | 209 | return call_user_func(array($this, $method)); |
210 | 210 | |
211 | - }else{ |
|
212 | - throw new Exception($method ." does not exists"); |
|
211 | + } else { |
|
212 | + throw new Exception($method." does not exists"); |
|
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
@@ -224,43 +224,43 @@ discard block |
||
224 | 224 | */ |
225 | 225 | public function write_file_action() |
226 | 226 | { |
227 | - if(isset($_POST['file'])) |
|
227 | + if (isset($_POST['file'])) |
|
228 | 228 | { |
229 | 229 | $target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING); |
230 | 230 | |
231 | - if(!$_POST['start']) |
|
231 | + if (!$_POST['start']) |
|
232 | 232 | $fp = fopen($target_file, "wb+"); |
233 | 233 | else |
234 | 234 | $fp = fopen($target_file, "ab+"); |
235 | 235 | |
236 | - if(!$fp) |
|
236 | + if (!$fp) |
|
237 | 237 | throw new Exception("Unable to open $target_file file for writing"); |
238 | 238 | |
239 | 239 | fseek($fp, $_POST['start']); |
240 | 240 | |
241 | - if(isset($_FILES['blob'])) |
|
241 | + if (isset($_FILES['blob'])) |
|
242 | 242 | { |
243 | 243 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using FILES blob', filesize($_FILES['blob']['tmp_name']), $target_file, $_POST['start'])); |
244 | 244 | |
245 | 245 | $blob = file_get_contents($_FILES['blob']['tmp_name']); |
246 | 246 | |
247 | - if(!$bytes_written = fwrite($fp, $blob)) |
|
247 | + if (!$bytes_written = fwrite($fp, $blob)) |
|
248 | 248 | throw new Exception("Unable to write data to file $target_file"); |
249 | 249 | |
250 | 250 | try { |
251 | 251 | unlink($_FILES['blob']['tmp_name']); |
252 | - }catch(Exception $e){ |
|
252 | + }catch (Exception $e) { |
|
253 | 253 | |
254 | 254 | } |
255 | 255 | |
256 | - }elseif(isset($_POST['blob'])){ |
|
256 | + }elseif (isset($_POST['blob'])) { |
|
257 | 257 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start'])); |
258 | 258 | |
259 | 259 | $blob = $_POST['blob']; |
260 | 260 | |
261 | - if(!$bytes_written = fwrite($fp, $blob)) |
|
261 | + if (!$bytes_written = fwrite($fp, $blob)) |
|
262 | 262 | throw new Exception("Unable to write data to file $target_file"); |
263 | - }else{ |
|
263 | + } else { |
|
264 | 264 | throw new Exception("Upload failed, did not receive any binary data"); |
265 | 265 | } |
266 | 266 | |
@@ -281,20 +281,20 @@ discard block |
||
281 | 281 | * @return mysqli |
282 | 282 | * @throws Exception |
283 | 283 | */ |
284 | - public function mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db ) |
|
284 | + public function mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db) |
|
285 | 285 | { |
286 | 286 | $this->logger->info(sprintf('Connecting to mysql database %s with %s@%s', $remote_mysql_db, $remote_mysql_user, $remote_mysql_host)); |
287 | 287 | |
288 | 288 | $mysqli = new mysqli($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db); |
289 | 289 | |
290 | 290 | if ($mysqli->connect_error) { |
291 | - throw new Exception('Connect Error (' . $mysqli->connect_errno . ') ' |
|
291 | + throw new Exception('Connect Error ('.$mysqli->connect_errno.') ' |
|
292 | 292 | . $mysqli->connect_error); |
293 | 293 | } |
294 | 294 | |
295 | 295 | $mysqli->query("SET sql_mode='';"); |
296 | 296 | $mysqli->query("SET foreign_key_checks = 0;"); |
297 | - if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) |
|
297 | + if (isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) |
|
298 | 298 | $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
299 | 299 | else |
300 | 300 | $mysqli->query("SET NAMES utf8;"); |
@@ -309,15 +309,15 @@ discard block |
||
309 | 309 | */ |
310 | 310 | public function restore_mysql_backup_action() |
311 | 311 | { |
312 | - $mysqldump_file = filter_input(INPUT_POST, 'mysqldump_file', FILTER_SANITIZE_STRING); |
|
313 | - $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
|
312 | + $mysqldump_file = filter_input(INPUT_POST, 'mysqldump_file', FILTER_SANITIZE_STRING); |
|
313 | + $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
|
314 | 314 | $remote_mysql_user = filter_input(INPUT_POST, 'remote_mysql_user', FILTER_SANITIZE_STRING); |
315 | 315 | $remote_mysql_pass = filter_input(INPUT_POST, 'remote_mysql_pass', FILTER_SANITIZE_STRING); |
316 | - $remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING); |
|
316 | + $remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING); |
|
317 | 317 | $remote_mysql_host = filter_input(INPUT_POST, 'remote_mysql_host', FILTER_SANITIZE_STRING); |
318 | - $execute_query = trim(stripslashes($_POST['query'])); |
|
319 | - $error_line = filter_input(INPUT_POST, 'error_line', FILTER_SANITIZE_NUMBER_INT); |
|
320 | - $start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT); |
|
318 | + $execute_query = trim(stripslashes($_POST['query'])); |
|
319 | + $error_line = filter_input(INPUT_POST, 'error_line', FILTER_SANITIZE_NUMBER_INT); |
|
320 | + $start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT); |
|
321 | 321 | |
322 | 322 | $wp_home_url = filter_input(INPUT_POST, 'wp_home_url', FILTER_SANITIZE_STRING); |
323 | 323 | $remote_restore_url = filter_input(INPUT_POST, 'remote_restore_url', FILTER_SANITIZE_STRING); |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | |
328 | 328 | $mysql_backup_file = $remote_path.DS.$mysqldump_file; |
329 | 329 | |
330 | - if(!file_exists($mysql_backup_file)) |
|
331 | - throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file)); |
|
330 | + if (!file_exists($mysql_backup_file)) |
|
331 | + throw new Exception(sprintf("Mysql backup file %s does not exists", $mysql_backup_file)); |
|
332 | 332 | |
333 | 333 | |
334 | 334 | /*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | }*/ |
343 | 343 | |
344 | 344 | { |
345 | - $mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db ); |
|
345 | + $mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | $line_count = 0; |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | $return['backup_size'] = filesize($mysql_backup_file); |
353 | 353 | |
354 | 354 | $fp = fopen($mysql_backup_file, "r"); |
355 | - if($fp) |
|
355 | + if ($fp) |
|
356 | 356 | { |
357 | 357 | $this->logger->info(sprintf("Opening mysql dump file %s at position %s.", $mysql_backup_file, $start)); |
358 | 358 | fseek($fp, $start); |
@@ -360,49 +360,49 @@ discard block |
||
360 | 360 | // process the line read. |
361 | 361 | |
362 | 362 | //check if line is comment |
363 | - if(substr($line, 0, 1) == "#") |
|
363 | + if (substr($line, 0, 1) == "#") |
|
364 | 364 | continue; |
365 | 365 | |
366 | 366 | //check if line is empty |
367 | - if($line == "\n" or trim($line) == "") |
|
367 | + if ($line == "\n" or trim($line) == "") |
|
368 | 368 | continue; |
369 | 369 | |
370 | - if(substr($line, strlen($line)-2, strlen($line)) == ";\n") |
|
370 | + if (substr($line, strlen($line) - 2, strlen($line)) == ";\n") |
|
371 | 371 | $query .= $line; |
372 | - else{ |
|
372 | + else { |
|
373 | 373 | $query .= $line; |
374 | 374 | continue; |
375 | 375 | } |
376 | 376 | |
377 | - if($execute_query) |
|
377 | + if ($execute_query) |
|
378 | 378 | { |
379 | - $query = (($execute_query)); |
|
379 | + $query = (($execute_query)); |
|
380 | 380 | $execute_query = ""; |
381 | 381 | } |
382 | 382 | |
383 | 383 | //Doing serialized url replace here |
384 | 384 | |
385 | - if($wp_site_url and $wp_home_url and strlen($wp_home_url) < strlen($wp_site_url)) |
|
385 | + if ($wp_site_url and $wp_home_url and strlen($wp_home_url) < strlen($wp_site_url)) |
|
386 | 386 | { |
387 | - list($wp_home_url,$wp_site_url) = array($wp_site_url,$wp_home_url); |
|
388 | - list($remote_restore_url,$restore_site_url) = array($restore_site_url,$remote_restore_url); |
|
387 | + list($wp_home_url, $wp_site_url) = array($wp_site_url, $wp_home_url); |
|
388 | + list($remote_restore_url, $restore_site_url) = array($restore_site_url, $remote_restore_url); |
|
389 | 389 | |
390 | 390 | } |
391 | 391 | |
392 | - if($wp_home_url and $remote_restore_url and strpos($query, $wp_home_url) !== false) |
|
392 | + if ($wp_home_url and $remote_restore_url and strpos($query, $wp_home_url) !== false) |
|
393 | 393 | { |
394 | 394 | $query = $this->url_replace($wp_home_url, $remote_restore_url, $query); |
395 | 395 | } |
396 | 396 | |
397 | - if($wp_site_url and $restore_site_url and strpos($query, $wp_site_url) !== false) |
|
397 | + if ($wp_site_url and $restore_site_url and strpos($query, $wp_site_url) !== false) |
|
398 | 398 | { |
399 | 399 | $query = $this->url_replace($wp_site_url, $restore_site_url, $query); |
400 | 400 | } |
401 | 401 | |
402 | - if(!$mysqli->query($query) && !stristr($mysqli->error,"Duplicate entry")) |
|
402 | + if (!$mysqli->query($query) && !stristr($mysqli->error, "Duplicate entry")) |
|
403 | 403 | { |
404 | 404 | //$return['error_line'] = $line_count; |
405 | - $return['start'] = ftell($fp)-strlen($line); |
|
405 | + $return['start'] = ftell($fp) - strlen($line); |
|
406 | 406 | $return['query_error'] = true; |
407 | 407 | $return['query'] = $query; |
408 | 408 | $return['message'] = sprintf("Mysql Error: %s\n", $mysqli->error); |
@@ -423,12 +423,12 @@ discard block |
||
423 | 423 | |
424 | 424 | $return['start'] = ftell($fp); |
425 | 425 | |
426 | - $this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start']-$start))); |
|
426 | + $this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start'] - $start))); |
|
427 | 427 | |
428 | - if(!feof($fp)) |
|
428 | + if (!feof($fp)) |
|
429 | 429 | { |
430 | 430 | $return['finished'] = 0; |
431 | - }else{ |
|
431 | + } else { |
|
432 | 432 | $this->logger->info(sprintf("Mysql Import Done.")); |
433 | 433 | } |
434 | 434 | |
@@ -451,12 +451,12 @@ discard block |
||
451 | 451 | $query = str_replace($search, $replace, $query); |
452 | 452 | $original_query = $query; |
453 | 453 | |
454 | - if($this->has_serialized($query)) |
|
454 | + if ($this->has_serialized($query)) |
|
455 | 455 | { |
456 | 456 | $this->logger->info(sprintf("Query contains serialized data, doing serialized size fix"), array("QUERY_REPLACE")); |
457 | 457 | $query = $this->do_serialized_fix($query); |
458 | 458 | |
459 | - if(!$query) |
|
459 | + if (!$query) |
|
460 | 460 | { |
461 | 461 | $this->logger->info(sprintf("Serialization probably failed here..."), array("QUERY_REPLACE")); |
462 | 462 | $query = $original_query; |
@@ -477,37 +477,37 @@ discard block |
||
477 | 477 | $backup_parts = array(); |
478 | 478 | |
479 | 479 | $source_backup_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING); |
480 | - $start = (int)filter_input(INPUT_POST, 'start', FILTER_SANITIZE_STRING); |
|
481 | - $return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_STRING); |
|
480 | + $start = (int)filter_input(INPUT_POST, 'start', FILTER_SANITIZE_STRING); |
|
481 | + $return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_STRING); |
|
482 | 482 | |
483 | 483 | $backup_file = $source_backup_file; |
484 | 484 | |
485 | - if($this->is_multipart($backup_file)) |
|
485 | + if ($this->is_multipart($backup_file)) |
|
486 | 486 | { |
487 | 487 | $backup_parts = $this->get_multipart_files($backup_file); |
488 | 488 | $backup_file = $backup_parts[$return['part']]; |
489 | 489 | } |
490 | 490 | |
491 | - try{ |
|
491 | + try { |
|
492 | 492 | $tar = new Tar(); |
493 | 493 | $tar->open($this->backup_storage_dir.DS.$backup_file, $start); |
494 | 494 | |
495 | 495 | $data = $tar->contents($this->process_files_limit_list); |
496 | - }catch(Exception $e) |
|
496 | + }catch (Exception $e) |
|
497 | 497 | { |
498 | 498 | $return['error'] = true; |
499 | 499 | $return['message'] = $e->getMessage(); |
500 | 500 | $this->send_response(200, $return); |
501 | 501 | } |
502 | 502 | |
503 | - $return['files'] = array(); |
|
504 | - $return['finished'] = 1; |
|
505 | - $return['total_size'] = filesize($this->backup_storage_dir.DS.$backup_file); |
|
503 | + $return['files'] = array(); |
|
504 | + $return['finished'] = 1; |
|
505 | + $return['total_size'] = filesize($this->backup_storage_dir.DS.$backup_file); |
|
506 | 506 | $i = 0; |
507 | 507 | |
508 | - if(isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
508 | + if (isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
509 | 509 | { |
510 | - foreach($data['extracted_files'] as $file) |
|
510 | + foreach ($data['extracted_files'] as $file) |
|
511 | 511 | { |
512 | 512 | $return['files'][$i]['path'] = $file->getPath(); |
513 | 513 | $return['files'][$i]['size'] = $file->getSize(); |
@@ -517,18 +517,18 @@ discard block |
||
517 | 517 | } |
518 | 518 | } |
519 | 519 | |
520 | - if(isset($data['start'])) |
|
520 | + if (isset($data['start'])) |
|
521 | 521 | { |
522 | 522 | $return['start'] = $data['start']; |
523 | 523 | $return['finished'] = 0; |
524 | - }else{ |
|
525 | - if($this->is_multipart($source_backup_file)) |
|
524 | + } else { |
|
525 | + if ($this->is_multipart($source_backup_file)) |
|
526 | 526 | { |
527 | 527 | $return['start'] = 0; |
528 | 528 | |
529 | 529 | ++$return['part']; |
530 | 530 | |
531 | - if($return['part'] < sizeof($backup_parts)) |
|
531 | + if ($return['part'] < sizeof($backup_parts)) |
|
532 | 532 | $return['finished'] = 0; |
533 | 533 | |
534 | 534 | } |
@@ -551,28 +551,28 @@ discard block |
||
551 | 551 | |
552 | 552 | $remote_mysql_user = filter_input(INPUT_POST, 'remote_mysql_user', FILTER_SANITIZE_STRING); |
553 | 553 | $remote_mysql_pass = filter_input(INPUT_POST, 'remote_mysql_pass', FILTER_SANITIZE_STRING); |
554 | - $remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING); |
|
554 | + $remote_mysql_db = filter_input(INPUT_POST, 'remote_mysql_db', FILTER_SANITIZE_STRING); |
|
555 | 555 | $remote_mysql_host = filter_input(INPUT_POST, 'remote_mysql_host', FILTER_SANITIZE_STRING); |
556 | 556 | |
557 | - $update_remote_site_url = filter_input(INPUT_POST, 'update_remote_site_url', FILTER_SANITIZE_NUMBER_INT); |
|
558 | - $delete_restore_script = filter_input(INPUT_POST, 'delete_restore_script', FILTER_SANITIZE_NUMBER_INT); |
|
559 | - $delete_backup_temporary_folder = filter_input(INPUT_POST, 'delete_backup_temporary_folder', FILTER_SANITIZE_NUMBER_INT); |
|
557 | + $update_remote_site_url = filter_input(INPUT_POST, 'update_remote_site_url', FILTER_SANITIZE_NUMBER_INT); |
|
558 | + $delete_restore_script = filter_input(INPUT_POST, 'delete_restore_script', FILTER_SANITIZE_NUMBER_INT); |
|
559 | + $delete_backup_temporary_folder = filter_input(INPUT_POST, 'delete_backup_temporary_folder', FILTER_SANITIZE_NUMBER_INT); |
|
560 | 560 | |
561 | - if($update_remote_site_url) |
|
561 | + if ($update_remote_site_url) |
|
562 | 562 | { |
563 | - $mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db ); |
|
563 | + $mysqli = $this->mysql_connect($remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db); |
|
564 | 564 | $this->update_wp_config($remote_path, $remote_mysql_host, $remote_mysql_user, $remote_mysql_pass, $remote_mysql_db); |
565 | 565 | $this->update_wp_url($remote_path, $remote_restore_url, $mysqli); |
566 | 566 | } |
567 | 567 | |
568 | - if($delete_backup_temporary_folder) |
|
568 | + if ($delete_backup_temporary_folder) |
|
569 | 569 | { |
570 | 570 | $this->delete_backup_temporary_folder($remote_path); |
571 | 571 | } |
572 | 572 | |
573 | - if(!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1) |
|
573 | + if (!defined('XCLONER_PLUGIN_ACCESS') || XCLONER_PLUGIN_ACCESS != 1) |
|
574 | 574 | { |
575 | - if($delete_restore_script) |
|
575 | + if ($delete_restore_script) |
|
576 | 576 | { |
577 | 577 | $this->delete_self(); |
578 | 578 | } |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | */ |
591 | 591 | private function delete_backup_temporary_folder($remote_path) |
592 | 592 | { |
593 | - $this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS'); |
|
593 | + $this->target_adapter = new Local($remote_path, LOCK_EX, 'SKIP_LINKS'); |
|
594 | 594 | $this->target_filesystem = new Filesystem($this->target_adapter, new Config([ |
595 | 595 | 'disable_asserts' => true, |
596 | 596 | ])); |
@@ -598,13 +598,13 @@ discard block |
||
598 | 598 | $mysqldump_list = array(); |
599 | 599 | $list = $this->target_filesystem->listContents(); |
600 | 600 | |
601 | - foreach($list as $file) |
|
601 | + foreach ($list as $file) |
|
602 | 602 | { |
603 | 603 | $matches = array(); |
604 | 604 | |
605 | - if($file['type'] == "dir") |
|
605 | + if ($file['type'] == "dir") |
|
606 | 606 | { |
607 | - if(preg_match("/xcloner-(\w*)/", $file['basename'], $matches)){ |
|
607 | + if (preg_match("/xcloner-(\w*)/", $file['basename'], $matches)) { |
|
608 | 608 | $this->logger->info(sprintf('Deleting temporary folder %s', $file['path'])); |
609 | 609 | $this->target_filesystem->deleteDir($file['path']); |
610 | 610 | } |
@@ -622,29 +622,29 @@ discard block |
||
622 | 622 | */ |
623 | 623 | private function delete_self() |
624 | 624 | { |
625 | - if($this->filesystem->has("vendor.phar")) |
|
625 | + if ($this->filesystem->has("vendor.phar")) |
|
626 | 626 | { |
627 | 627 | $this->logger->info(sprintf('Deleting vendor.phar')); |
628 | 628 | $this->filesystem->delete("vendor.phar"); |
629 | 629 | } |
630 | - if($this->filesystem->has("vendor")) |
|
630 | + if ($this->filesystem->has("vendor")) |
|
631 | 631 | { |
632 | 632 | $this->logger->info(sprintf('Deleting vendor folder')); |
633 | 633 | $this->filesystem->deleteDir("vendor"); |
634 | 634 | } |
635 | - if($this->filesystem->has("xcloner_restore.php")) |
|
635 | + if ($this->filesystem->has("xcloner_restore.php")) |
|
636 | 636 | { |
637 | 637 | $this->logger->info(sprintf('Deleting xcloner_restore.php')); |
638 | 638 | $this->filesystem->delete("xcloner_restore.php"); |
639 | 639 | } |
640 | 640 | |
641 | - if($this->filesystem->has("xcloner_restore.log")) |
|
641 | + if ($this->filesystem->has("xcloner_restore.log")) |
|
642 | 642 | { |
643 | 643 | $this->logger->info(sprintf('Deleting xcloner_restore.log')); |
644 | 644 | $this->filesystem->delete("xcloner_restore.log"); |
645 | 645 | } |
646 | 646 | |
647 | - if($this->filesystem->has($this->get_logger_filename())) |
|
647 | + if ($this->filesystem->has($this->get_logger_filename())) |
|
648 | 648 | { |
649 | 649 | $this->logger->info(sprintf('Deleting logger file %s', $this->get_logger_filename())); |
650 | 650 | $this->filesystem->delete($this->get_logger_filename()); |
@@ -666,11 +666,11 @@ discard block |
||
666 | 666 | |
667 | 667 | $this->logger->info(sprintf('Updating site url to %s', $url)); |
668 | 668 | |
669 | - if(file_exists($wp_config)) |
|
669 | + if (file_exists($wp_config)) |
|
670 | 670 | { |
671 | 671 | $config = file_get_contents($wp_config); |
672 | 672 | preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches); |
673 | - if(isset($matches[1])) |
|
673 | + if (isset($matches[1])) |
|
674 | 674 | $table_prefix = $matches[1]; |
675 | 675 | else |
676 | 676 | throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
@@ -678,10 +678,10 @@ discard block |
||
678 | 678 | else |
679 | 679 | throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
680 | 680 | |
681 | - if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) |
|
681 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) |
|
682 | 682 | throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
683 | 683 | |
684 | - if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) |
|
684 | + if (!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) |
|
685 | 685 | throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
686 | 686 | |
687 | 687 | return true; |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | { |
703 | 703 | $wp_config = $remote_path.DS."wp-config.php"; |
704 | 704 | |
705 | - if(!file_exists($wp_config)) |
|
705 | + if (!file_exists($wp_config)) |
|
706 | 706 | { |
707 | 707 | throw new Exception("Could not find the wp-config.php in ".$remote_path); |
708 | 708 | } |
@@ -720,7 +720,7 @@ discard block |
||
720 | 720 | |
721 | 721 | $this->logger->info(sprintf('Updating wp-config.php file with the new mysql details')); |
722 | 722 | |
723 | - if(!file_put_contents($wp_config, $content)) |
|
723 | + if (!file_put_contents($wp_config, $content)) |
|
724 | 724 | throw new Exception("Could not write updated config data to ".$wp_config); |
725 | 725 | |
726 | 726 | chmod($wp_config, $file_perms); |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | |
741 | 741 | $hash = $this->get_hash_from_backup($source_backup_file); |
742 | 742 | |
743 | - $this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS'); |
|
743 | + $this->target_adapter = new Local($remote_path, LOCK_EX, 'SKIP_LINKS'); |
|
744 | 744 | $this->target_filesystem = new Filesystem($this->target_adapter, new Config([ |
745 | 745 | 'disable_asserts' => true, |
746 | 746 | ])); |
@@ -748,25 +748,25 @@ discard block |
||
748 | 748 | $mysqldump_list = array(); |
749 | 749 | $list = $this->target_filesystem->listContents(); |
750 | 750 | |
751 | - foreach($list as $file) |
|
751 | + foreach ($list as $file) |
|
752 | 752 | { |
753 | 753 | $matches = array(); |
754 | 754 | |
755 | - if($file['type'] == "dir") |
|
755 | + if ($file['type'] == "dir") |
|
756 | 756 | { |
757 | - if(preg_match("/xcloner-(\w*)/", $file['basename'], $matches)) |
|
757 | + if (preg_match("/xcloner-(\w*)/", $file['basename'], $matches)) |
|
758 | 758 | { |
759 | 759 | $files = $this->target_filesystem->listContents($file['basename']); |
760 | - foreach($files as $file) |
|
760 | + foreach ($files as $file) |
|
761 | 761 | { |
762 | - if($file['extension'] == "sql") |
|
762 | + if ($file['extension'] == "sql") |
|
763 | 763 | { |
764 | 764 | $this->logger->info(sprintf('Found %s mysql backup file', $file['path'])); |
765 | 765 | $mysqldump_list[$file['path']]['path'] = $file['path']; |
766 | 766 | $mysqldump_list[$file['path']]['size'] = $file['size']; |
767 | - $mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i",$file['timestamp']); |
|
767 | + $mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i", $file['timestamp']); |
|
768 | 768 | |
769 | - if($hash and $hash == $matches[1]) |
|
769 | + if ($hash and $hash == $matches[1]) |
|
770 | 770 | $mysqldump_list[$file['path']]['selected'] = "selected"; |
771 | 771 | else |
772 | 772 | $mysqldump_list[$file['path']]['selected'] = ""; |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | } |
777 | 777 | } |
778 | 778 | |
779 | - $this->sort_by($mysqldump_list, 'timestamp','desc'); |
|
779 | + $this->sort_by($mysqldump_list, 'timestamp', 'desc'); |
|
780 | 780 | $return['files'] = $mysqldump_list; |
781 | 781 | |
782 | 782 | $this->send_response(200, $return); |
@@ -790,12 +790,12 @@ discard block |
||
790 | 790 | */ |
791 | 791 | private function get_hash_from_backup($backup_file) |
792 | 792 | { |
793 | - if(!$backup_file) |
|
793 | + if (!$backup_file) |
|
794 | 794 | return false; |
795 | 795 | |
796 | - $result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file)-10, strlen($backup_file)), $matches) ; |
|
796 | + $result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file) - 10, strlen($backup_file)), $matches); |
|
797 | 797 | |
798 | - if($result and isset($matches[1])) |
|
798 | + if ($result and isset($matches[1])) |
|
799 | 799 | return ($matches[1]); |
800 | 800 | |
801 | 801 | return false; |
@@ -814,18 +814,18 @@ discard block |
||
814 | 814 | $backup_files = array(); |
815 | 815 | $parents = array(); |
816 | 816 | |
817 | - foreach($list as $file_info) |
|
817 | + foreach ($list as $file_info) |
|
818 | 818 | { |
819 | 819 | $data = array(); |
820 | 820 | |
821 | - if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
821 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
822 | 822 | { |
823 | 823 | $lines = explode(PHP_EOL, $this->filesystem->read($file_info['path'])); |
824 | - foreach($lines as $line) |
|
825 | - if($line) |
|
824 | + foreach ($lines as $line) |
|
825 | + if ($line) |
|
826 | 826 | { |
827 | 827 | $data = str_getcsv($line); |
828 | - if(is_array($data)){ |
|
828 | + if (is_array($data)) { |
|
829 | 829 | $parents[$data[0]] = $file_info['path']; |
830 | 830 | $file_info['childs'][] = $data; |
831 | 831 | $file_info['size'] += $data[2]; |
@@ -834,19 +834,19 @@ discard block |
||
834 | 834 | |
835 | 835 | } |
836 | 836 | |
837 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
837 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
838 | 838 | $backup_files[$file_info['path']] = $file_info; |
839 | 839 | } |
840 | 840 | |
841 | 841 | $new_list = array(); |
842 | 842 | |
843 | - foreach($backup_files as $key=>$file_info) |
|
843 | + foreach ($backup_files as $key=>$file_info) |
|
844 | 844 | { |
845 | - if(isset($parents[$file_info['path']])) |
|
845 | + if (isset($parents[$file_info['path']])) |
|
846 | 846 | $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
847 | - else{ |
|
847 | + else { |
|
848 | 848 | |
849 | - if($local_backup_file and ($file_info['basename'] == $local_backup_file)) |
|
849 | + if ($local_backup_file and ($file_info['basename'] == $local_backup_file)) |
|
850 | 850 | $file_info['selected'] = 'selected'; |
851 | 851 | |
852 | 852 | $this->logger->info(sprintf('Found %s backup file', $file_info['path'])); |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | |
857 | 857 | } |
858 | 858 | |
859 | - $this->sort_by($new_list, "timestamp","desc"); |
|
859 | + $this->sort_by($new_list, "timestamp", "desc"); |
|
860 | 860 | |
861 | 861 | $return['files'] = $new_list; |
862 | 862 | |
@@ -872,15 +872,15 @@ discard block |
||
872 | 872 | */ |
873 | 873 | public function restore_backup_to_path_action() |
874 | 874 | { |
875 | - $source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING); |
|
876 | - $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
|
875 | + $source_backup_file = filter_input(INPUT_POST, 'backup_file', FILTER_SANITIZE_STRING); |
|
876 | + $remote_path = filter_input(INPUT_POST, 'remote_path', FILTER_SANITIZE_STRING); |
|
877 | 877 | $include_filter_files = filter_input(INPUT_POST, 'filter_files', FILTER_SANITIZE_STRING); |
878 | 878 | $exclude_filter_files = ""; |
879 | - $start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT); |
|
880 | - $return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_NUMBER_INT); |
|
879 | + $start = filter_input(INPUT_POST, 'start', FILTER_SANITIZE_NUMBER_INT); |
|
880 | + $return['part'] = (int)filter_input(INPUT_POST, 'part', FILTER_SANITIZE_NUMBER_INT); |
|
881 | 881 | $return['processed'] = (int)filter_input(INPUT_POST, 'processed', FILTER_SANITIZE_NUMBER_INT); |
882 | 882 | |
883 | - $this->target_adapter = new Local($remote_path ,LOCK_EX, 'SKIP_LINKS'); |
|
883 | + $this->target_adapter = new Local($remote_path, LOCK_EX, 'SKIP_LINKS'); |
|
884 | 884 | $this->target_filesystem = new Filesystem($this->target_adapter, new Config([ |
885 | 885 | 'disable_asserts' => true, |
886 | 886 | ])); |
@@ -892,9 +892,9 @@ discard block |
||
892 | 892 | $return['total_size'] = $this->get_backup_size($backup_file); |
893 | 893 | |
894 | 894 | $backup_archive = new Tar(); |
895 | - if($this->is_multipart($backup_file)) |
|
895 | + if ($this->is_multipart($backup_file)) |
|
896 | 896 | { |
897 | - if(!$return['part']) |
|
897 | + if (!$return['part']) |
|
898 | 898 | $return['processed'] += $this->filesystem->getSize($backup_file); |
899 | 899 | |
900 | 900 | $backup_parts = $this->get_multipart_files($backup_file); |
@@ -902,41 +902,41 @@ discard block |
||
902 | 902 | } |
903 | 903 | |
904 | 904 | $this->logger->info(sprintf('Opening backup archive %s at position %s', $backup_file, $start)); |
905 | - $backup_archive->open($this->backup_storage_dir .DS. $backup_file, $start); |
|
905 | + $backup_archive->open($this->backup_storage_dir.DS.$backup_file, $start); |
|
906 | 906 | |
907 | - $data = $backup_archive->extract($remote_path, '',$exclude_filter_files,$include_filter_files, $this->process_files_limit); |
|
907 | + $data = $backup_archive->extract($remote_path, '', $exclude_filter_files, $include_filter_files, $this->process_files_limit); |
|
908 | 908 | |
909 | - if(isset($data['extracted_files'])) |
|
909 | + if (isset($data['extracted_files'])) |
|
910 | 910 | { |
911 | - foreach($data['extracted_files'] as $spl_fileinfo) |
|
911 | + foreach ($data['extracted_files'] as $spl_fileinfo) |
|
912 | 912 | { |
913 | 913 | $this->logger->info(sprintf('Extracted %s file', $spl_fileinfo->getPath())); |
914 | 914 | $return['extracted_files'][] = $spl_fileinfo->getPath()." (".$spl_fileinfo->getSize()." bytes)"; |
915 | 915 | } |
916 | 916 | } |
917 | 917 | |
918 | - if(isset($data['start'])) |
|
918 | + if (isset($data['start'])) |
|
919 | 919 | //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
920 | 920 | { |
921 | 921 | $return['finished'] = 0; |
922 | 922 | $return['start'] = $data['start']; |
923 | - }else{ |
|
923 | + } else { |
|
924 | 924 | |
925 | 925 | $return['processed'] += $start; |
926 | 926 | |
927 | - if($this->is_multipart($source_backup_file)) |
|
927 | + if ($this->is_multipart($source_backup_file)) |
|
928 | 928 | { |
929 | 929 | $return['start'] = 0; |
930 | 930 | |
931 | 931 | ++$return['part']; |
932 | 932 | |
933 | - if($return['part'] < sizeof($backup_parts)) |
|
933 | + if ($return['part'] < sizeof($backup_parts)) |
|
934 | 934 | $return['finished'] = 0; |
935 | 935 | |
936 | 936 | } |
937 | 937 | } |
938 | 938 | |
939 | - if($return['finished']) |
|
939 | + if ($return['finished']) |
|
940 | 940 | $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
941 | 941 | |
942 | 942 | $return['backup_file'] = $backup_file; |
@@ -953,24 +953,24 @@ discard block |
||
953 | 953 | |
954 | 954 | $restore_script_url = filter_input(INPUT_POST, 'restore_script_url', FILTER_SANITIZE_STRING); |
955 | 955 | |
956 | - $pathinfo = pathinfo( __FILE__); |
|
956 | + $pathinfo = pathinfo(__FILE__); |
|
957 | 957 | |
958 | 958 | $suffix = ""; |
959 | 959 | $return['remote_mysql_host'] = "localhost"; |
960 | 960 | $return['remote_mysql_user'] = ""; |
961 | 961 | $return['remote_mysql_pass'] = ""; |
962 | - $return['remote_mysql_db'] = ""; |
|
962 | + $return['remote_mysql_db'] = ""; |
|
963 | 963 | |
964 | - if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
964 | + if (defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
|
965 | 965 | { |
966 | 966 | $return['dir'] = realpath(get_home_path().DS.$suffix); |
967 | - $return['restore_script_url'] = get_site_url(); |
|
967 | + $return['restore_script_url'] = get_site_url(); |
|
968 | 968 | $return['remote_mysql_host'] = $wpdb->dbhost; |
969 | 969 | $return['remote_mysql_user'] = $wpdb->dbuser; |
970 | 970 | $return['remote_mysql_pass'] = $wpdb->dbpassword; |
971 | - $return['remote_mysql_db'] = $wpdb->dbname; |
|
971 | + $return['remote_mysql_db'] = $wpdb->dbname; |
|
972 | 972 | } |
973 | - else{ |
|
973 | + else { |
|
974 | 974 | $return['dir'] = ($pathinfo['dirname']).DS.$suffix; |
975 | 975 | $return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix; |
976 | 976 | } |
@@ -989,17 +989,17 @@ discard block |
||
989 | 989 | { |
990 | 990 | //check if i can write |
991 | 991 | $tmp_file = md5(time()); |
992 | - if(!file_put_contents($tmp_file, "++")) |
|
992 | + if (!file_put_contents($tmp_file, "++")) |
|
993 | 993 | throw new Exception("Could not write to new host"); |
994 | 994 | |
995 | - if(!unlink($tmp_file)) |
|
995 | + if (!unlink($tmp_file)) |
|
996 | 996 | throw new Exception("Could not delete temporary file from new host"); |
997 | 997 | |
998 | 998 | $max_upload = $this->return_bytes((ini_get('upload_max_filesize'))); |
999 | 999 | $max_post = $this->return_bytes((ini_get('post_max_size'))); |
1000 | 1000 | |
1001 | 1001 | $return['max_upload_size'] = min($max_upload, $max_post); // bytes |
1002 | - $return['status'] = true; |
|
1002 | + $return['status'] = true; |
|
1003 | 1003 | |
1004 | 1004 | $this->logger->info(sprintf('Current filesystem max upload size is %s bytes', $return['max_upload_size'])); |
1005 | 1005 | |
@@ -1015,8 +1015,8 @@ discard block |
||
1015 | 1015 | */ |
1016 | 1016 | private function return_bytes($val) { |
1017 | 1017 | $numeric_val = (int)trim($val); |
1018 | - $last = strtolower($val[strlen($val)-1]); |
|
1019 | - switch($last) { |
|
1018 | + $last = strtolower($val[strlen($val) - 1]); |
|
1019 | + switch ($last) { |
|
1020 | 1020 | // The 'G' modifier is available since PHP 5.1.0 |
1021 | 1021 | case 'g': |
1022 | 1022 | $numeric_val *= 1024; |
@@ -1037,7 +1037,7 @@ discard block |
||
1037 | 1037 | */ |
1038 | 1038 | public function is_multipart($backup_name) |
1039 | 1039 | { |
1040 | - if(stristr($backup_name, "-multipart")) |
|
1040 | + if (stristr($backup_name, "-multipart")) |
|
1041 | 1041 | return true; |
1042 | 1042 | |
1043 | 1043 | return false; |
@@ -1053,10 +1053,10 @@ discard block |
||
1053 | 1053 | public function get_backup_size($backup_name) |
1054 | 1054 | { |
1055 | 1055 | $backup_size = $this->filesystem->getSize($backup_name); |
1056 | - if($this->is_multipart($backup_name)) |
|
1056 | + if ($this->is_multipart($backup_name)) |
|
1057 | 1057 | { |
1058 | 1058 | $backup_parts = $this->get_multipart_files($backup_name); |
1059 | - foreach($backup_parts as $part_file) |
|
1059 | + foreach ($backup_parts as $part_file) |
|
1060 | 1060 | $backup_size += $this->filesystem->getSize($part_file); |
1061 | 1061 | } |
1062 | 1062 | |
@@ -1073,12 +1073,12 @@ discard block |
||
1073 | 1073 | { |
1074 | 1074 | $files = array(); |
1075 | 1075 | |
1076 | - if($this->is_multipart($backup_name)) |
|
1076 | + if ($this->is_multipart($backup_name)) |
|
1077 | 1077 | { |
1078 | 1078 | $lines = explode(PHP_EOL, $this->filesystem->read($backup_name)); |
1079 | - foreach($lines as $line) |
|
1079 | + foreach ($lines as $line) |
|
1080 | 1080 | { |
1081 | - if($line) |
|
1081 | + if ($line) |
|
1082 | 1082 | { |
1083 | 1083 | $data = str_getcsv($line); |
1084 | 1084 | $files[] = $data[0]; |
@@ -1097,7 +1097,7 @@ discard block |
||
1097 | 1097 | * @param string $direction |
1098 | 1098 | * @return bool |
1099 | 1099 | */ |
1100 | - private function sort_by( &$array, $field, $direction = 'asc') |
|
1100 | + private function sort_by(&$array, $field, $direction = 'asc') |
|
1101 | 1101 | { |
1102 | 1102 | $direction = strtolower($direction); |
1103 | 1103 | |
@@ -1112,18 +1112,18 @@ discard block |
||
1112 | 1112 | return 0; |
1113 | 1113 | } |
1114 | 1114 | |
1115 | - if($direction == 'desc') { |
|
1116 | - if($a > $b) { |
|
1115 | + if ($direction == 'desc') { |
|
1116 | + if ($a > $b) { |
|
1117 | 1117 | return -1; |
1118 | 1118 | } |
1119 | - else{ |
|
1119 | + else { |
|
1120 | 1120 | return 1; |
1121 | 1121 | } |
1122 | - }else { |
|
1123 | - if($a < $b) { |
|
1122 | + } else { |
|
1123 | + if ($a < $b) { |
|
1124 | 1124 | return -1; |
1125 | 1125 | } |
1126 | - else{ |
|
1126 | + else { |
|
1127 | 1127 | return 1; |
1128 | 1128 | } |
1129 | 1129 | } |
@@ -1149,11 +1149,11 @@ discard block |
||
1149 | 1149 | $return['status'] = $status; |
1150 | 1150 | $return['statusText'] = $response; |
1151 | 1151 | |
1152 | - if(isset($response['error']) && $response['error']) |
|
1152 | + if (isset($response['error']) && $response['error']) |
|
1153 | 1153 | { |
1154 | 1154 | $return['statusText'] = $response['message']; |
1155 | 1155 | $return['error'] = true; |
1156 | - }elseif($status != 200 and $status != 418) |
|
1156 | + }elseif ($status != 200 and $status != 418) |
|
1157 | 1157 | { |
1158 | 1158 | $return['error'] = true; |
1159 | 1159 | $return['message'] = $response; |
@@ -1172,12 +1172,12 @@ discard block |
||
1172 | 1172 | |
1173 | 1173 | function do_serialized_fix($query) |
1174 | 1174 | { |
1175 | - $query = str_replace(array("\\n","\\r","\\'"), array("","","\""), ($query)); |
|
1175 | + $query = str_replace(array("\\n", "\\r", "\\'"), array("", "", "\""), ($query)); |
|
1176 | 1176 | |
1177 | - return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function ($m) { |
|
1177 | + return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function($m) { |
|
1178 | 1178 | $data = ""; |
1179 | 1179 | |
1180 | - if(!isset($m[3])) |
|
1180 | + if (!isset($m[3])) |
|
1181 | 1181 | $m[3] = ""; |
1182 | 1182 | |
1183 | 1183 | $data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";'; |
@@ -1204,8 +1204,8 @@ discard block |
||
1204 | 1204 | * @return mixed |
1205 | 1205 | */ |
1206 | 1206 | private function unescape_mysql($value) { |
1207 | - return str_replace(array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"'), |
|
1208 | - array("\\", "\0", "\n", "\r", "\x1a", "'", '"'), |
|
1207 | + return str_replace(array("\\\\", "\\0", "\\n", "\\r", "\Z", "\'", '\"'), |
|
1208 | + array("\\", "\0", "\n", "\r", "\x1a", "'", '"'), |
|
1209 | 1209 | $value); |
1210 | 1210 | } |
1211 | 1211 | |
@@ -1217,14 +1217,14 @@ discard block |
||
1217 | 1217 | */ |
1218 | 1218 | private function has_serialized($s) |
1219 | 1219 | { |
1220 | - if( |
|
1221 | - stristr($s, '{' ) !== false && |
|
1222 | - stristr($s, '}' ) !== false && |
|
1223 | - stristr($s, ';' ) !== false && |
|
1224 | - stristr($s, ':' ) !== false |
|
1225 | - ){ |
|
1220 | + if ( |
|
1221 | + stristr($s, '{') !== false && |
|
1222 | + stristr($s, '}') !== false && |
|
1223 | + stristr($s, ';') !== false && |
|
1224 | + stristr($s, ':') !== false |
|
1225 | + ) { |
|
1226 | 1226 | return true; |
1227 | - }else{ |
|
1227 | + } else { |
|
1228 | 1228 | return false; |
1229 | 1229 | } |
1230 | 1230 |
@@ -45,11 +45,10 @@ discard block |
||
45 | 45 | { |
46 | 46 | |
47 | 47 | require_once($file); |
48 | -} |
|
49 | -elseif(file_exists("vendor.phar") and extension_loaded('phar')) |
|
48 | +} elseif(file_exists("vendor.phar") and extension_loaded('phar')) |
|
50 | 49 | { |
51 | 50 | require_once(__DIR__.DS."vendor.phar"); |
52 | -}else{ |
|
51 | +} else{ |
|
53 | 52 | |
54 | 53 | $file = dirname( __FILE__ ) . DS.'vendor'.DS.'autoload.php'; |
55 | 54 | |
@@ -87,7 +86,7 @@ discard block |
||
87 | 86 | try{ |
88 | 87 | $return = $xcloner_restore->init(); |
89 | 88 | $xcloner_restore->send_response(200, $return); |
90 | -}catch(Exception $e){ |
|
89 | +} catch(Exception $e){ |
|
91 | 90 | $xcloner_restore->send_response(417, $e->getMessage()); |
92 | 91 | } |
93 | 92 | |
@@ -208,7 +207,7 @@ discard block |
||
208 | 207 | $this->logger->debug(sprintf('Starting action %s', $method)); |
209 | 208 | return call_user_func(array($this, $method)); |
210 | 209 | |
211 | - }else{ |
|
210 | + } else{ |
|
212 | 211 | throw new Exception($method ." does not exists"); |
213 | 212 | } |
214 | 213 | } |
@@ -228,13 +227,15 @@ discard block |
||
228 | 227 | { |
229 | 228 | $target_file = filter_input(INPUT_POST, 'file', FILTER_SANITIZE_STRING); |
230 | 229 | |
231 | - if(!$_POST['start']) |
|
232 | - $fp = fopen($target_file, "wb+"); |
|
233 | - else |
|
234 | - $fp = fopen($target_file, "ab+"); |
|
230 | + if(!$_POST['start']) { |
|
231 | + $fp = fopen($target_file, "wb+"); |
|
232 | + } else { |
|
233 | + $fp = fopen($target_file, "ab+"); |
|
234 | + } |
|
235 | 235 | |
236 | - if(!$fp) |
|
237 | - throw new Exception("Unable to open $target_file file for writing"); |
|
236 | + if(!$fp) { |
|
237 | + throw new Exception("Unable to open $target_file file for writing"); |
|
238 | + } |
|
238 | 239 | |
239 | 240 | fseek($fp, $_POST['start']); |
240 | 241 | |
@@ -244,23 +245,25 @@ discard block |
||
244 | 245 | |
245 | 246 | $blob = file_get_contents($_FILES['blob']['tmp_name']); |
246 | 247 | |
247 | - if(!$bytes_written = fwrite($fp, $blob)) |
|
248 | - throw new Exception("Unable to write data to file $target_file"); |
|
248 | + if(!$bytes_written = fwrite($fp, $blob)) { |
|
249 | + throw new Exception("Unable to write data to file $target_file"); |
|
250 | + } |
|
249 | 251 | |
250 | 252 | try { |
251 | 253 | unlink($_FILES['blob']['tmp_name']); |
252 | - }catch(Exception $e){ |
|
254 | + } catch(Exception $e){ |
|
253 | 255 | |
254 | 256 | } |
255 | 257 | |
256 | - }elseif(isset($_POST['blob'])){ |
|
258 | + } elseif(isset($_POST['blob'])){ |
|
257 | 259 | $this->logger->debug(sprintf('Writing %s bytes to file %s starting position %s using POST blob', strlen($_POST['blob']), $target_file, $_POST['start'])); |
258 | 260 | |
259 | 261 | $blob = $_POST['blob']; |
260 | 262 | |
261 | - if(!$bytes_written = fwrite($fp, $blob)) |
|
262 | - throw new Exception("Unable to write data to file $target_file"); |
|
263 | - }else{ |
|
263 | + if(!$bytes_written = fwrite($fp, $blob)) { |
|
264 | + throw new Exception("Unable to write data to file $target_file"); |
|
265 | + } |
|
266 | + } else{ |
|
264 | 267 | throw new Exception("Upload failed, did not receive any binary data"); |
265 | 268 | } |
266 | 269 | |
@@ -294,10 +297,11 @@ discard block |
||
294 | 297 | |
295 | 298 | $mysqli->query("SET sql_mode='';"); |
296 | 299 | $mysqli->query("SET foreign_key_checks = 0;"); |
297 | - if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) |
|
298 | - $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
|
299 | - else |
|
300 | - $mysqli->query("SET NAMES utf8;"); |
|
300 | + if(isset($_REQUEST['charset_of_file']) and $_REQUEST['charset_of_file']) { |
|
301 | + $mysqli->query("SET NAMES ".$_REQUEST['charset_of_file'].""); |
|
302 | + } else { |
|
303 | + $mysqli->query("SET NAMES utf8;"); |
|
304 | + } |
|
301 | 305 | |
302 | 306 | return $mysqli; |
303 | 307 | } |
@@ -327,8 +331,9 @@ discard block |
||
327 | 331 | |
328 | 332 | $mysql_backup_file = $remote_path.DS.$mysqldump_file; |
329 | 333 | |
330 | - if(!file_exists($mysql_backup_file)) |
|
331 | - throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file)); |
|
334 | + if(!file_exists($mysql_backup_file)) { |
|
335 | + throw new Exception(sprintf("Mysql backup file %s does not exists",$mysql_backup_file)); |
|
336 | + } |
|
332 | 337 | |
333 | 338 | |
334 | 339 | /*if(defined('XCLONER_PLUGIN_ACCESS') && XCLONER_PLUGIN_ACCESS) |
@@ -360,16 +365,18 @@ discard block |
||
360 | 365 | // process the line read. |
361 | 366 | |
362 | 367 | //check if line is comment |
363 | - if(substr($line, 0, 1) == "#") |
|
364 | - continue; |
|
368 | + if(substr($line, 0, 1) == "#") { |
|
369 | + continue; |
|
370 | + } |
|
365 | 371 | |
366 | 372 | //check if line is empty |
367 | - if($line == "\n" or trim($line) == "") |
|
368 | - continue; |
|
373 | + if($line == "\n" or trim($line) == "") { |
|
374 | + continue; |
|
375 | + } |
|
369 | 376 | |
370 | - if(substr($line, strlen($line)-2, strlen($line)) == ";\n") |
|
371 | - $query .= $line; |
|
372 | - else{ |
|
377 | + if(substr($line, strlen($line)-2, strlen($line)) == ";\n") { |
|
378 | + $query .= $line; |
|
379 | + } else{ |
|
373 | 380 | $query .= $line; |
374 | 381 | continue; |
375 | 382 | } |
@@ -428,7 +435,7 @@ discard block |
||
428 | 435 | if(!feof($fp)) |
429 | 436 | { |
430 | 437 | $return['finished'] = 0; |
431 | - }else{ |
|
438 | + } else{ |
|
432 | 439 | $this->logger->info(sprintf("Mysql Import Done.")); |
433 | 440 | } |
434 | 441 | |
@@ -493,7 +500,7 @@ discard block |
||
493 | 500 | $tar->open($this->backup_storage_dir.DS.$backup_file, $start); |
494 | 501 | |
495 | 502 | $data = $tar->contents($this->process_files_limit_list); |
496 | - }catch(Exception $e) |
|
503 | + } catch(Exception $e) |
|
497 | 504 | { |
498 | 505 | $return['error'] = true; |
499 | 506 | $return['message'] = $e->getMessage(); |
@@ -521,15 +528,16 @@ discard block |
||
521 | 528 | { |
522 | 529 | $return['start'] = $data['start']; |
523 | 530 | $return['finished'] = 0; |
524 | - }else{ |
|
531 | + } else{ |
|
525 | 532 | if($this->is_multipart($source_backup_file)) |
526 | 533 | { |
527 | 534 | $return['start'] = 0; |
528 | 535 | |
529 | 536 | ++$return['part']; |
530 | 537 | |
531 | - if($return['part'] < sizeof($backup_parts)) |
|
532 | - $return['finished'] = 0; |
|
538 | + if($return['part'] < sizeof($backup_parts)) { |
|
539 | + $return['finished'] = 0; |
|
540 | + } |
|
533 | 541 | |
534 | 542 | } |
535 | 543 | } |
@@ -670,19 +678,22 @@ discard block |
||
670 | 678 | { |
671 | 679 | $config = file_get_contents($wp_config); |
672 | 680 | preg_match("/.*table_prefix.*=.*'(.*)'/i", $config, $matches); |
673 | - if(isset($matches[1])) |
|
674 | - $table_prefix = $matches[1]; |
|
675 | - else |
|
676 | - throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
681 | + if(isset($matches[1])) { |
|
682 | + $table_prefix = $matches[1]; |
|
683 | + } else { |
|
684 | + throw new Exception("Could not load wordpress table prefix from wp-config.php file."); |
|
685 | + } |
|
686 | + } else { |
|
687 | + throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
677 | 688 | } |
678 | - else |
|
679 | - throw new Exception("Could not update the SITEURL and HOME, wp-config.php file not found"); |
|
680 | 689 | |
681 | - if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) |
|
682 | - throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
690 | + if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='home'")) { |
|
691 | + throw new Exception(sprintf("Could not update the HOME option, error: %s\n", $mysqli->error)); |
|
692 | + } |
|
683 | 693 | |
684 | - if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) |
|
685 | - throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
694 | + if(!$mysqli->query("update ".$table_prefix."options set option_value='".($url)."' where option_name='siteurl'")) { |
|
695 | + throw new Exception(sprintf("Could not update the SITEURL option, error: %s\n", $mysqli->error)); |
|
696 | + } |
|
686 | 697 | |
687 | 698 | return true; |
688 | 699 | } |
@@ -720,8 +731,9 @@ discard block |
||
720 | 731 | |
721 | 732 | $this->logger->info(sprintf('Updating wp-config.php file with the new mysql details')); |
722 | 733 | |
723 | - if(!file_put_contents($wp_config, $content)) |
|
724 | - throw new Exception("Could not write updated config data to ".$wp_config); |
|
734 | + if(!file_put_contents($wp_config, $content)) { |
|
735 | + throw new Exception("Could not write updated config data to ".$wp_config); |
|
736 | + } |
|
725 | 737 | |
726 | 738 | chmod($wp_config, $file_perms); |
727 | 739 | |
@@ -766,10 +778,11 @@ discard block |
||
766 | 778 | $mysqldump_list[$file['path']]['size'] = $file['size']; |
767 | 779 | $mysqldump_list[$file['path']]['timestamp'] = date("d M,Y H:i",$file['timestamp']); |
768 | 780 | |
769 | - if($hash and $hash == $matches[1]) |
|
770 | - $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
771 | - else |
|
772 | - $mysqldump_list[$file['path']]['selected'] = ""; |
|
781 | + if($hash and $hash == $matches[1]) { |
|
782 | + $mysqldump_list[$file['path']]['selected'] = "selected"; |
|
783 | + } else { |
|
784 | + $mysqldump_list[$file['path']]['selected'] = ""; |
|
785 | + } |
|
773 | 786 | } |
774 | 787 | } |
775 | 788 | } |
@@ -790,13 +803,15 @@ discard block |
||
790 | 803 | */ |
791 | 804 | private function get_hash_from_backup($backup_file) |
792 | 805 | { |
793 | - if(!$backup_file) |
|
794 | - return false; |
|
806 | + if(!$backup_file) { |
|
807 | + return false; |
|
808 | + } |
|
795 | 809 | |
796 | 810 | $result = preg_match("/-(\w*)./", substr($backup_file, strlen($backup_file)-10, strlen($backup_file)), $matches) ; |
797 | 811 | |
798 | - if($result and isset($matches[1])) |
|
799 | - return ($matches[1]); |
|
812 | + if($result and isset($matches[1])) { |
|
813 | + return ($matches[1]); |
|
814 | + } |
|
800 | 815 | |
801 | 816 | return false; |
802 | 817 | } |
@@ -821,10 +836,11 @@ discard block |
||
821 | 836 | if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
822 | 837 | { |
823 | 838 | $lines = explode(PHP_EOL, $this->filesystem->read($file_info['path'])); |
824 | - foreach($lines as $line) |
|
825 | - if($line) |
|
839 | + foreach($lines as $line) { |
|
840 | + if($line) |
|
826 | 841 | { |
827 | 842 | $data = str_getcsv($line); |
843 | + } |
|
828 | 844 | if(is_array($data)){ |
829 | 845 | $parents[$data[0]] = $file_info['path']; |
830 | 846 | $file_info['childs'][] = $data; |
@@ -834,20 +850,22 @@ discard block |
||
834 | 850 | |
835 | 851 | } |
836 | 852 | |
837 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
838 | - $backup_files[$file_info['path']] = $file_info; |
|
853 | + if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
854 | + $backup_files[$file_info['path']] = $file_info; |
|
855 | + } |
|
839 | 856 | } |
840 | 857 | |
841 | 858 | $new_list = array(); |
842 | 859 | |
843 | 860 | foreach($backup_files as $key=>$file_info) |
844 | 861 | { |
845 | - if(isset($parents[$file_info['path']])) |
|
846 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
847 | - else{ |
|
862 | + if(isset($parents[$file_info['path']])) { |
|
863 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
864 | + } else{ |
|
848 | 865 | |
849 | - if($local_backup_file and ($file_info['basename'] == $local_backup_file)) |
|
850 | - $file_info['selected'] = 'selected'; |
|
866 | + if($local_backup_file and ($file_info['basename'] == $local_backup_file)) { |
|
867 | + $file_info['selected'] = 'selected'; |
|
868 | + } |
|
851 | 869 | |
852 | 870 | $this->logger->info(sprintf('Found %s backup file', $file_info['path'])); |
853 | 871 | |
@@ -894,8 +912,9 @@ discard block |
||
894 | 912 | $backup_archive = new Tar(); |
895 | 913 | if($this->is_multipart($backup_file)) |
896 | 914 | { |
897 | - if(!$return['part']) |
|
898 | - $return['processed'] += $this->filesystem->getSize($backup_file); |
|
915 | + if(!$return['part']) { |
|
916 | + $return['processed'] += $this->filesystem->getSize($backup_file); |
|
917 | + } |
|
899 | 918 | |
900 | 919 | $backup_parts = $this->get_multipart_files($backup_file); |
901 | 920 | $backup_file = $backup_parts[$return['part']]; |
@@ -915,12 +934,13 @@ discard block |
||
915 | 934 | } |
916 | 935 | } |
917 | 936 | |
918 | - if(isset($data['start'])) |
|
919 | - //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
937 | + if(isset($data['start'])) { |
|
938 | + //if(isset($data['start']) and $data['start'] <= $this->filesystem->getSize($backup_file)) |
|
920 | 939 | { |
921 | 940 | $return['finished'] = 0; |
941 | + } |
|
922 | 942 | $return['start'] = $data['start']; |
923 | - }else{ |
|
943 | + } else{ |
|
924 | 944 | |
925 | 945 | $return['processed'] += $start; |
926 | 946 | |
@@ -930,14 +950,16 @@ discard block |
||
930 | 950 | |
931 | 951 | ++$return['part']; |
932 | 952 | |
933 | - if($return['part'] < sizeof($backup_parts)) |
|
934 | - $return['finished'] = 0; |
|
953 | + if($return['part'] < sizeof($backup_parts)) { |
|
954 | + $return['finished'] = 0; |
|
955 | + } |
|
935 | 956 | |
936 | 957 | } |
937 | 958 | } |
938 | 959 | |
939 | - if($return['finished']) |
|
940 | - $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
960 | + if($return['finished']) { |
|
961 | + $this->logger->info(sprintf('Done extracting %s', $source_backup_file)); |
|
962 | + } |
|
941 | 963 | |
942 | 964 | $return['backup_file'] = $backup_file; |
943 | 965 | |
@@ -969,8 +991,7 @@ discard block |
||
969 | 991 | $return['remote_mysql_user'] = $wpdb->dbuser; |
970 | 992 | $return['remote_mysql_pass'] = $wpdb->dbpassword; |
971 | 993 | $return['remote_mysql_db'] = $wpdb->dbname; |
972 | - } |
|
973 | - else{ |
|
994 | + } else{ |
|
974 | 995 | $return['dir'] = ($pathinfo['dirname']).DS.$suffix; |
975 | 996 | $return['restore_script_url'] = str_replace($pathinfo['basename'], "", $restore_script_url).$suffix; |
976 | 997 | } |
@@ -989,11 +1010,13 @@ discard block |
||
989 | 1010 | { |
990 | 1011 | //check if i can write |
991 | 1012 | $tmp_file = md5(time()); |
992 | - if(!file_put_contents($tmp_file, "++")) |
|
993 | - throw new Exception("Could not write to new host"); |
|
1013 | + if(!file_put_contents($tmp_file, "++")) { |
|
1014 | + throw new Exception("Could not write to new host"); |
|
1015 | + } |
|
994 | 1016 | |
995 | - if(!unlink($tmp_file)) |
|
996 | - throw new Exception("Could not delete temporary file from new host"); |
|
1017 | + if(!unlink($tmp_file)) { |
|
1018 | + throw new Exception("Could not delete temporary file from new host"); |
|
1019 | + } |
|
997 | 1020 | |
998 | 1021 | $max_upload = $this->return_bytes((ini_get('upload_max_filesize'))); |
999 | 1022 | $max_post = $this->return_bytes((ini_get('post_max_size'))); |
@@ -1037,8 +1060,9 @@ discard block |
||
1037 | 1060 | */ |
1038 | 1061 | public function is_multipart($backup_name) |
1039 | 1062 | { |
1040 | - if(stristr($backup_name, "-multipart")) |
|
1041 | - return true; |
|
1063 | + if(stristr($backup_name, "-multipart")) { |
|
1064 | + return true; |
|
1065 | + } |
|
1042 | 1066 | |
1043 | 1067 | return false; |
1044 | 1068 | } |
@@ -1056,8 +1080,9 @@ discard block |
||
1056 | 1080 | if($this->is_multipart($backup_name)) |
1057 | 1081 | { |
1058 | 1082 | $backup_parts = $this->get_multipart_files($backup_name); |
1059 | - foreach($backup_parts as $part_file) |
|
1060 | - $backup_size += $this->filesystem->getSize($part_file); |
|
1083 | + foreach($backup_parts as $part_file) { |
|
1084 | + $backup_size += $this->filesystem->getSize($part_file); |
|
1085 | + } |
|
1061 | 1086 | } |
1062 | 1087 | |
1063 | 1088 | return $backup_size; |
@@ -1115,15 +1140,13 @@ discard block |
||
1115 | 1140 | if($direction == 'desc') { |
1116 | 1141 | if($a > $b) { |
1117 | 1142 | return -1; |
1118 | - } |
|
1119 | - else{ |
|
1143 | + } else{ |
|
1120 | 1144 | return 1; |
1121 | 1145 | } |
1122 | - }else { |
|
1146 | + } else { |
|
1123 | 1147 | if($a < $b) { |
1124 | 1148 | return -1; |
1125 | - } |
|
1126 | - else{ |
|
1149 | + } else{ |
|
1127 | 1150 | return 1; |
1128 | 1151 | } |
1129 | 1152 | } |
@@ -1153,7 +1176,7 @@ discard block |
||
1153 | 1176 | { |
1154 | 1177 | $return['statusText'] = $response['message']; |
1155 | 1178 | $return['error'] = true; |
1156 | - }elseif($status != 200 and $status != 418) |
|
1179 | + } elseif($status != 200 and $status != 418) |
|
1157 | 1180 | { |
1158 | 1181 | $return['error'] = true; |
1159 | 1182 | $return['message'] = $response; |
@@ -1177,8 +1200,9 @@ discard block |
||
1177 | 1200 | return preg_replace_callback('!s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");!', function ($m) { |
1178 | 1201 | $data = ""; |
1179 | 1202 | |
1180 | - if(!isset($m[3])) |
|
1181 | - $m[3] = ""; |
|
1203 | + if(!isset($m[3])) { |
|
1204 | + $m[3] = ""; |
|
1205 | + } |
|
1182 | 1206 | |
1183 | 1207 | $data = 's:'.strlen(($m[3])).':\"'.($m[3]).'\";'; |
1184 | 1208 | //return $this->unescape_quotes($data); |
@@ -1224,7 +1248,7 @@ discard block |
||
1224 | 1248 | stristr($s, ':' ) !== false |
1225 | 1249 | ){ |
1226 | 1250 | return true; |
1227 | - }else{ |
|
1251 | + } else{ |
|
1228 | 1252 | return false; |
1229 | 1253 | } |
1230 | 1254 |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | |
351 | 351 | if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){ |
352 | 352 | $this->xcloner_settings->generate_new_hash(); |
353 | - }else{ |
|
353 | + } else{ |
|
354 | 354 | $this->xcloner_settings->set_hash($_POST['hash']); |
355 | 355 | } |
356 | 356 | } |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | |
453 | 453 | try{ |
454 | 454 | $this->xcloner_scheduler->xcloner_scheduler_callback(0, $schedule); |
455 | - }catch(Exception $e){ |
|
455 | + } catch(Exception $e){ |
|
456 | 456 | $this->get_xcloner_logger()->error($e->getMessage()); |
457 | 457 | } |
458 | 458 |
@@ -301,10 +301,10 @@ discard block |
||
301 | 301 | */ |
302 | 302 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php'; |
303 | 303 | |
304 | - /** |
|
305 | - * The class responsible for the XCloner Encryption methods. |
|
306 | - */ |
|
307 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-encryption.php'; |
|
304 | + /** |
|
305 | + * The class responsible for the XCloner Encryption methods. |
|
306 | + */ |
|
307 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-encryption.php'; |
|
308 | 308 | |
309 | 309 | /** |
310 | 310 | * The class responsible for defining all actions that occur in the public-facing |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
333 | 333 | |
334 | 334 | //wp_localize_script( 'ajax-script', 'my_ajax_object', |
335 | - // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
|
335 | + // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
|
336 | 336 | |
337 | 337 | } |
338 | 338 | |
@@ -368,8 +368,8 @@ discard block |
||
368 | 368 | |
369 | 369 | private function define_plugin_settings(){ |
370 | 370 | /** |
371 | - * register wporg_settings_init to the admin_init action hook |
|
372 | - */ |
|
371 | + * register wporg_settings_init to the admin_init action hook |
|
372 | + */ |
|
373 | 373 | |
374 | 374 | $this->xcloner_settings = new XCloner_Settings($this); |
375 | 375 | |
@@ -524,15 +524,15 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | function friendly_error_type($type) { |
527 | - static $levels=null; |
|
528 | - if ($levels===null) { |
|
529 | - $levels=[]; |
|
530 | - foreach (get_defined_constants() as $key=>$value) { |
|
531 | - if (strpos($key,'E_')!==0) {continue;} |
|
527 | + static $levels=null; |
|
528 | + if ($levels===null) { |
|
529 | + $levels=[]; |
|
530 | + foreach (get_defined_constants() as $key=>$value) { |
|
531 | + if (strpos($key,'E_')!==0) {continue;} |
|
532 | 532 | $levels[$value]= $key; //substr($key,2); |
533 | - } |
|
534 | - } |
|
535 | - return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
|
533 | + } |
|
534 | + } |
|
535 | + return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | private function define_ajax_hooks() |
@@ -578,24 +578,24 @@ discard block |
||
578 | 578 | add_action( 'wp_ajax_get_manage_backups_list', array($xcloner_api,'get_manage_backups_list') ); |
579 | 579 | add_action( 'admin_notices', array($this, 'xcloner_error_admin_notices' )); |
580 | 580 | |
581 | - } |
|
581 | + } |
|
582 | 582 | |
583 | - //Do a pre-update backup of targeted files |
|
584 | - if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
|
585 | - { |
|
583 | + //Do a pre-update backup of targeted files |
|
584 | + if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
|
585 | + { |
|
586 | 586 | add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3); |
587 | 587 | } |
588 | 588 | } |
589 | 589 | |
590 | 590 | function add_plugin_action_links($links, $file) { |
591 | - if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) |
|
591 | + if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) |
|
592 | 592 | { |
593 | 593 | $links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>'; |
594 | 594 | $links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>'; |
595 | 595 | } |
596 | 596 | |
597 | - return $links; |
|
598 | - } |
|
597 | + return $links; |
|
598 | + } |
|
599 | 599 | |
600 | 600 | public function xcloner_error_admin_notices() { |
601 | 601 | settings_errors( 'xcloner_error_message' ); |
@@ -679,9 +679,9 @@ discard block |
||
679 | 679 | function xcloner_display() |
680 | 680 | { |
681 | 681 | // check user capabilities |
682 | - if (!current_user_can('manage_options')) { |
|
683 | - return; |
|
684 | - } |
|
682 | + if (!current_user_can('manage_options')) { |
|
683 | + return; |
|
684 | + } |
|
685 | 685 | |
686 | 686 | $page = sanitize_key($_GET['page']); |
687 | 687 |
@@ -168,15 +168,15 @@ discard block |
||
168 | 168 | return $this->xcloner_encryption; |
169 | 169 | } |
170 | 170 | |
171 | - public function check_dependencies(){ |
|
171 | + public function check_dependencies() { |
|
172 | 172 | |
173 | 173 | $backup_storage_path = realpath(__DIR__.DS."..".DS."..".DS."..").DS."backups".DS; |
174 | 174 | |
175 | 175 | define("XCLONER_STORAGE_PATH", realpath($backup_storage_path)); |
176 | 176 | |
177 | - if(!is_dir($backup_storage_path)) |
|
177 | + if (!is_dir($backup_storage_path)) |
|
178 | 178 | { |
179 | - if(!@mkdir($backup_storage_path)) |
|
179 | + if (!@mkdir($backup_storage_path)) |
|
180 | 180 | { |
181 | 181 | $status = "error"; |
182 | 182 | $message = sprintf(__("Unable to create the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | return; |
185 | 185 | } |
186 | 186 | } |
187 | - if(!is_writable($backup_storage_path)) |
|
187 | + if (!is_writable($backup_storage_path)) |
|
188 | 188 | { |
189 | 189 | $status = "error"; |
190 | 190 | $message = sprintf(__("Unable to write to the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
@@ -198,15 +198,15 @@ discard block |
||
198 | 198 | public function trigger_message($message, $status = "error", $message_param1 = "", $message_param2 = "", $message_param3 = "") |
199 | 199 | { |
200 | 200 | $message = sprintf(__($message), $message_param1, $message_param2, $message_param3); |
201 | - add_action( 'xcloner_admin_notices', array($this,"trigger_message_notice"), 10, 2); |
|
202 | - do_action( 'xcloner_admin_notices', $message, $status); |
|
201 | + add_action('xcloner_admin_notices', array($this, "trigger_message_notice"), 10, 2); |
|
202 | + do_action('xcloner_admin_notices', $message, $status); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | public function trigger_message_notice($message, $status = "success") |
206 | 206 | { |
207 | 207 | ?> |
208 | 208 | <div class="notice notice-<?php echo $status?> is-dismissible"> |
209 | - <p><?php _e( $message, 'xcloner-backup-and-restore' ); ?></p> |
|
209 | + <p><?php _e($message, 'xcloner-backup-and-restore'); ?></p> |
|
210 | 210 | </div> |
211 | 211 | <?php |
212 | 212 | } |
@@ -233,84 +233,84 @@ discard block |
||
233 | 233 | * The class responsible for orchestrating the actions and filters of the |
234 | 234 | * core plugin. |
235 | 235 | */ |
236 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-loader.php'; |
|
236 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-loader.php'; |
|
237 | 237 | |
238 | 238 | /** |
239 | 239 | * The class responsible for defining internationalization functionality |
240 | 240 | * of the plugin. |
241 | 241 | */ |
242 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-i18n.php'; |
|
242 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-i18n.php'; |
|
243 | 243 | |
244 | 244 | /** |
245 | 245 | * The class responsible for defining all actions that occur in the admin area. |
246 | 246 | */ |
247 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-xcloner-admin.php'; |
|
247 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-xcloner-admin.php'; |
|
248 | 248 | |
249 | 249 | /** |
250 | 250 | * The class responsible for debugging XCloner. |
251 | 251 | */ |
252 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-logger.php'; |
|
252 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-logger.php'; |
|
253 | 253 | |
254 | 254 | /** |
255 | 255 | * The class responsible for defining the admin settings area. |
256 | 256 | */ |
257 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-settings.php'; |
|
257 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-settings.php'; |
|
258 | 258 | |
259 | 259 | /** |
260 | 260 | * The class responsible for defining the Remote Storage settings area. |
261 | 261 | */ |
262 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-remote-storage.php'; |
|
262 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-remote-storage.php'; |
|
263 | 263 | |
264 | 264 | /** |
265 | 265 | * The class responsible for implementing the database backup methods. |
266 | 266 | */ |
267 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-database.php'; |
|
267 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-database.php'; |
|
268 | 268 | |
269 | 269 | /** |
270 | 270 | * The class responsible for sanitization of users input. |
271 | 271 | */ |
272 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-sanitization.php'; |
|
272 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-sanitization.php'; |
|
273 | 273 | |
274 | 274 | /** |
275 | 275 | * The class responsible for XCloner system requirements validation. |
276 | 276 | */ |
277 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-requirements.php'; |
|
277 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-requirements.php'; |
|
278 | 278 | |
279 | 279 | /** |
280 | 280 | * The class responsible for XCloner backup archive creation. |
281 | 281 | */ |
282 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-archive.php'; |
|
282 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-archive.php'; |
|
283 | 283 | |
284 | 284 | /** |
285 | 285 | * The class responsible for XCloner API requests. |
286 | 286 | */ |
287 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-api.php'; |
|
287 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-api.php'; |
|
288 | 288 | |
289 | 289 | /** |
290 | 290 | * The class responsible for the XCloner File System methods. |
291 | 291 | */ |
292 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-system.php'; |
|
292 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-system.php'; |
|
293 | 293 | |
294 | 294 | /** |
295 | 295 | * The class responsible for the XCloner File Transfer methods. |
296 | 296 | */ |
297 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-transfer.php'; |
|
297 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-transfer.php'; |
|
298 | 298 | |
299 | 299 | /** |
300 | 300 | * The class responsible for the XCloner Scheduler methods. |
301 | 301 | */ |
302 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php'; |
|
302 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-scheduler.php'; |
|
303 | 303 | |
304 | 304 | /** |
305 | 305 | * The class responsible for the XCloner Encryption methods. |
306 | 306 | */ |
307 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-encryption.php'; |
|
307 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-encryption.php'; |
|
308 | 308 | |
309 | 309 | /** |
310 | 310 | * The class responsible for defining all actions that occur in the public-facing |
311 | 311 | * side of the site. |
312 | 312 | */ |
313 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-xcloner-public.php'; |
|
313 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-xcloner-public.php'; |
|
314 | 314 | |
315 | 315 | $this->loader = new Xcloner_Loader($this); |
316 | 316 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | |
330 | 330 | $plugin_i18n = new Xcloner_i18n(); |
331 | 331 | |
332 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
332 | + $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
|
333 | 333 | |
334 | 334 | //wp_localize_script( 'ajax-script', 'my_ajax_object', |
335 | 335 | // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
@@ -345,13 +345,13 @@ discard block |
||
345 | 345 | */ |
346 | 346 | private function define_admin_hooks() { |
347 | 347 | |
348 | - $plugin_admin = new Xcloner_Admin( $this ); |
|
348 | + $plugin_admin = new Xcloner_Admin($this); |
|
349 | 349 | $this->plugin_admin = $plugin_admin; |
350 | 350 | |
351 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
352 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
351 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
|
352 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
|
353 | 353 | |
354 | - add_action( 'backup_archive_finished', array($this, 'do_action_after_backup_finished'), 10, 2); |
|
354 | + add_action('backup_archive_finished', array($this, 'do_action_after_backup_finished'), 10, 2); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -360,31 +360,31 @@ discard block |
||
360 | 360 | * @access private |
361 | 361 | * |
362 | 362 | */ |
363 | - private function define_admin_menu(){ |
|
363 | + private function define_admin_menu() { |
|
364 | 364 | |
365 | 365 | add_action('admin_menu', array($this->loader, 'xcloner_backup_add_admin_menu')); |
366 | 366 | |
367 | 367 | } |
368 | 368 | |
369 | - private function define_plugin_settings(){ |
|
369 | + private function define_plugin_settings() { |
|
370 | 370 | /** |
371 | 371 | * register wporg_settings_init to the admin_init action hook |
372 | 372 | */ |
373 | 373 | |
374 | 374 | $this->xcloner_settings = new XCloner_Settings($this); |
375 | 375 | |
376 | - if(defined('DOING_CRON') || isset($_POST['hash'])){ |
|
376 | + if (defined('DOING_CRON') || isset($_POST['hash'])) { |
|
377 | 377 | |
378 | - if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){ |
|
378 | + if (defined('DOING_CRON') || $_POST['hash'] == "generate_hash") { |
|
379 | 379 | $this->xcloner_settings->generate_new_hash(); |
380 | - }else{ |
|
380 | + } else { |
|
381 | 381 | $this->xcloner_settings->set_hash($_POST['hash']); |
382 | 382 | } |
383 | 383 | } |
384 | 384 | |
385 | - if(defined('DOING_CRON') || !isset($_POST['hash'])) |
|
385 | + if (defined('DOING_CRON') || !isset($_POST['hash'])) |
|
386 | 386 | { |
387 | - add_action( 'shutdown', function(){ |
|
387 | + add_action('shutdown', function() { |
|
388 | 388 | $this->xcloner_filesystem = new Xcloner_File_System($this); |
389 | 389 | $this->xcloner_filesystem->remove_tmp_filesystem(); |
390 | 390 | }); |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | */ |
408 | 408 | public function pre_auto_update($type, $item, $context) |
409 | 409 | { |
410 | - if(!$type) |
|
410 | + if (!$type) |
|
411 | 411 | { |
412 | 412 | return false; |
413 | 413 | } |
@@ -416,10 +416,10 @@ discard block |
||
416 | 416 | |
417 | 417 | $content_dir = str_replace(ABSPATH, "", WP_CONTENT_DIR); |
418 | 418 | $plugins_dir = str_replace(ABSPATH, "", WP_PLUGIN_DIR); |
419 | - $langs_dir = $content_dir . DS . "languages"; |
|
420 | - $themes_dir = $content_dir . DS . "themes"; |
|
419 | + $langs_dir = $content_dir.DS."languages"; |
|
420 | + $themes_dir = $content_dir.DS."themes"; |
|
421 | 421 | |
422 | - switch ( $type ) { |
|
422 | + switch ($type) { |
|
423 | 423 | case 'core': |
424 | 424 | $exclude_files = array( |
425 | 425 | "^(?!(wp-admin|wp-includes|(?!.*\/.*.php)))(.*)$", |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | |
430 | 430 | $dir_array = explode(DS, $plugins_dir); |
431 | 431 | |
432 | - foreach($dir_array as $dir) |
|
432 | + foreach ($dir_array as $dir) |
|
433 | 433 | { |
434 | 434 | $data .= "\/".$dir; |
435 | 435 | $regex .= $data."$|"; |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | |
446 | 446 | $dir_array = explode(DS, $themes_dir); |
447 | 447 | |
448 | - foreach($dir_array as $dir) |
|
448 | + foreach ($dir_array as $dir) |
|
449 | 449 | { |
450 | 450 | $data .= "\/".$dir; |
451 | 451 | $regex .= $data."$|"; |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | |
462 | 462 | $dir_array = explode(DS, $langs_dir); |
463 | 463 | |
464 | - foreach($dir_array as $dir) |
|
464 | + foreach ($dir_array as $dir) |
|
465 | 465 | { |
466 | 466 | $data .= "\/".$dir; |
467 | 467 | $regex .= $data."$|"; |
@@ -487,9 +487,9 @@ discard block |
||
487 | 487 | $schedule['backup_params']->email_notification = get_option('admin_email'); |
488 | 488 | $schedule['backup_params']->backup_name = "backup_pre_auto_update_".$type."_[domain]-[time]-sql"; |
489 | 489 | |
490 | - try{ |
|
490 | + try { |
|
491 | 491 | $this->xcloner_scheduler->xcloner_scheduler_callback(0, $schedule); |
492 | - }catch(Exception $e){ |
|
492 | + }catch (Exception $e) { |
|
493 | 493 | $this->get_xcloner_logger()->error($e->getMessage()); |
494 | 494 | } |
495 | 495 | |
@@ -504,10 +504,10 @@ discard block |
||
504 | 504 | */ |
505 | 505 | private function define_public_hooks() { |
506 | 506 | |
507 | - $plugin_public = new Xcloner_Public( $this ); |
|
507 | + $plugin_public = new Xcloner_Public($this); |
|
508 | 508 | |
509 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
510 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
509 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); |
|
510 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); |
|
511 | 511 | |
512 | 512 | } |
513 | 513 | |
@@ -516,20 +516,20 @@ discard block |
||
516 | 516 | $logger = new XCloner_Logger($this, "php_system"); |
517 | 517 | $error = error_get_last(); |
518 | 518 | |
519 | - if($error['type'] and $logger) |
|
519 | + if ($error['type'] and $logger) |
|
520 | 520 | { |
521 | - $logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true)); |
|
521 | + $logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true)); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | } |
525 | 525 | |
526 | 526 | function friendly_error_type($type) { |
527 | - static $levels=null; |
|
528 | - if ($levels===null) { |
|
529 | - $levels=[]; |
|
527 | + static $levels = null; |
|
528 | + if ($levels === null) { |
|
529 | + $levels = []; |
|
530 | 530 | foreach (get_defined_constants() as $key=>$value) { |
531 | - if (strpos($key,'E_')!==0) {continue;} |
|
532 | - $levels[$value]= $key; //substr($key,2); |
|
531 | + if (strpos($key, 'E_') !== 0) {continue; } |
|
532 | + $levels[$value] = $key; //substr($key,2); |
|
533 | 533 | } |
534 | 534 | } |
535 | 535 | return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
@@ -539,56 +539,56 @@ discard block |
||
539 | 539 | { |
540 | 540 | //adding the pre-update hook |
541 | 541 | |
542 | - if(is_admin() || defined('DOING_CRON')) |
|
542 | + if (is_admin() || defined('DOING_CRON')) |
|
543 | 543 | { |
544 | - $this->xcloner_logger = new XCloner_Logger($this, "xcloner_api"); |
|
545 | - $this->xcloner_filesystem = new Xcloner_File_System($this); |
|
544 | + $this->xcloner_logger = new XCloner_Logger($this, "xcloner_api"); |
|
545 | + $this->xcloner_filesystem = new Xcloner_File_System($this); |
|
546 | 546 | |
547 | 547 | //$this->xcloner_filesystem->set_diff_timestamp_start (strtotime("-15 days")); |
548 | 548 | |
549 | - $this->archive_system = new Xcloner_Archive($this); |
|
550 | - $this->xcloner_database = new Xcloner_Database($this); |
|
551 | - $this->xcloner_scheduler = new Xcloner_Scheduler($this); |
|
552 | - $this->xcloner_remote_storage = new Xcloner_Remote_Storage($this); |
|
549 | + $this->archive_system = new Xcloner_Archive($this); |
|
550 | + $this->xcloner_database = new Xcloner_Database($this); |
|
551 | + $this->xcloner_scheduler = new Xcloner_Scheduler($this); |
|
552 | + $this->xcloner_remote_storage = new Xcloner_Remote_Storage($this); |
|
553 | 553 | $this->xcloner_file_transfer = new Xcloner_File_Transfer($this); |
554 | 554 | $this->xcloner_encryption = new Xcloner_Encryption($this); |
555 | 555 | |
556 | - $xcloner_api = new Xcloner_Api($this); |
|
557 | - |
|
558 | - add_action( 'wp_ajax_get_database_tables_action', array($xcloner_api,'get_database_tables_action') ); |
|
559 | - add_action( 'wp_ajax_get_file_system_action', array($xcloner_api,'get_file_system_action') ); |
|
560 | - add_action( 'wp_ajax_scan_filesystem', array($xcloner_api,'scan_filesystem') ); |
|
561 | - add_action( 'wp_ajax_backup_database', array($xcloner_api,'backup_database') ); |
|
562 | - add_action( 'wp_ajax_backup_files' , array($xcloner_api,'backup_files') ); |
|
563 | - add_action( 'wp_ajax_save_schedule' , array($xcloner_api,'save_schedule') ); |
|
564 | - add_action( 'wp_ajax_get_schedule_by_id', array($xcloner_api,'get_schedule_by_id') ); |
|
565 | - add_action( 'wp_ajax_get_scheduler_list', array($xcloner_api,'get_scheduler_list') ); |
|
566 | - add_action( 'wp_ajax_delete_schedule_by_id' , array($xcloner_api,'delete_schedule_by_id') ); |
|
567 | - add_action( 'wp_ajax_delete_backup_by_name' , array($xcloner_api,'delete_backup_by_name') ); |
|
568 | - add_action( 'wp_ajax_download_backup_by_name', array($xcloner_api,'download_backup_by_name') ); |
|
569 | - add_action( 'wp_ajax_remote_storage_save_status', array($xcloner_api,'remote_storage_save_status') ); |
|
570 | - add_action( 'wp_ajax_upload_backup_to_remote', array($xcloner_api,'upload_backup_to_remote') ); |
|
571 | - add_action( 'wp_ajax_list_backup_files' , array($xcloner_api,'list_backup_files') ); |
|
572 | - add_action( 'wp_ajax_restore_upload_backup' , array($xcloner_api,'restore_upload_backup') ); |
|
573 | - add_action( 'wp_ajax_download_restore_script', array($xcloner_api,'download_restore_script') ); |
|
574 | - add_action( 'wp_ajax_copy_backup_remote_to_local', array($xcloner_api,'copy_backup_remote_to_local') ); |
|
575 | - add_action( 'wp_ajax_restore_backup', array($xcloner_api,'restore_backup') ); |
|
576 | - add_action( 'wp_ajax_backup_encryption', array($xcloner_api,'backup_encryption') ); |
|
577 | - add_action( 'wp_ajax_backup_decryption', array($xcloner_api,'backup_decryption') ); |
|
578 | - add_action( 'wp_ajax_get_manage_backups_list', array($xcloner_api,'get_manage_backups_list') ); |
|
579 | - add_action( 'admin_notices', array($this, 'xcloner_error_admin_notices' )); |
|
556 | + $xcloner_api = new Xcloner_Api($this); |
|
557 | + |
|
558 | + add_action('wp_ajax_get_database_tables_action', array($xcloner_api, 'get_database_tables_action')); |
|
559 | + add_action('wp_ajax_get_file_system_action', array($xcloner_api, 'get_file_system_action')); |
|
560 | + add_action('wp_ajax_scan_filesystem', array($xcloner_api, 'scan_filesystem')); |
|
561 | + add_action('wp_ajax_backup_database', array($xcloner_api, 'backup_database')); |
|
562 | + add_action('wp_ajax_backup_files', array($xcloner_api, 'backup_files')); |
|
563 | + add_action('wp_ajax_save_schedule', array($xcloner_api, 'save_schedule')); |
|
564 | + add_action('wp_ajax_get_schedule_by_id', array($xcloner_api, 'get_schedule_by_id')); |
|
565 | + add_action('wp_ajax_get_scheduler_list', array($xcloner_api, 'get_scheduler_list')); |
|
566 | + add_action('wp_ajax_delete_schedule_by_id', array($xcloner_api, 'delete_schedule_by_id')); |
|
567 | + add_action('wp_ajax_delete_backup_by_name', array($xcloner_api, 'delete_backup_by_name')); |
|
568 | + add_action('wp_ajax_download_backup_by_name', array($xcloner_api, 'download_backup_by_name')); |
|
569 | + add_action('wp_ajax_remote_storage_save_status', array($xcloner_api, 'remote_storage_save_status')); |
|
570 | + add_action('wp_ajax_upload_backup_to_remote', array($xcloner_api, 'upload_backup_to_remote')); |
|
571 | + add_action('wp_ajax_list_backup_files', array($xcloner_api, 'list_backup_files')); |
|
572 | + add_action('wp_ajax_restore_upload_backup', array($xcloner_api, 'restore_upload_backup')); |
|
573 | + add_action('wp_ajax_download_restore_script', array($xcloner_api, 'download_restore_script')); |
|
574 | + add_action('wp_ajax_copy_backup_remote_to_local', array($xcloner_api, 'copy_backup_remote_to_local')); |
|
575 | + add_action('wp_ajax_restore_backup', array($xcloner_api, 'restore_backup')); |
|
576 | + add_action('wp_ajax_backup_encryption', array($xcloner_api, 'backup_encryption')); |
|
577 | + add_action('wp_ajax_backup_decryption', array($xcloner_api, 'backup_decryption')); |
|
578 | + add_action('wp_ajax_get_manage_backups_list', array($xcloner_api, 'get_manage_backups_list')); |
|
579 | + add_action('admin_notices', array($this, 'xcloner_error_admin_notices')); |
|
580 | 580 | |
581 | 581 | } |
582 | 582 | |
583 | 583 | //Do a pre-update backup of targeted files |
584 | - if($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
|
584 | + if ($this->get_xcloner_settings()->get_xcloner_option('xcloner_enable_pre_update_backup')) |
|
585 | 585 | { |
586 | 586 | add_action("pre_auto_update", array($this, "pre_auto_update"), 1, 3); |
587 | 587 | } |
588 | 588 | } |
589 | 589 | |
590 | 590 | function add_plugin_action_links($links, $file) { |
591 | - if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) |
|
591 | + if ($file == plugin_basename(dirname(dirname(__FILE__)).'/xcloner.php')) |
|
592 | 592 | { |
593 | 593 | $links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>'; |
594 | 594 | $links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>'; |
@@ -598,13 +598,13 @@ discard block |
||
598 | 598 | } |
599 | 599 | |
600 | 600 | public function xcloner_error_admin_notices() { |
601 | - settings_errors( 'xcloner_error_message' ); |
|
601 | + settings_errors('xcloner_error_message'); |
|
602 | 602 | } |
603 | 603 | |
604 | 604 | public function define_cron_hooks() |
605 | 605 | { |
606 | 606 | //registering new schedule intervals |
607 | - add_filter( 'cron_schedules', array($this, 'add_new_intervals')); |
|
607 | + add_filter('cron_schedules', array($this, 'add_new_intervals')); |
|
608 | 608 | |
609 | 609 | |
610 | 610 | $xcloner_scheduler = $this->get_xcloner_scheduler(); |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | |
686 | 686 | $page = sanitize_key($_GET['page']); |
687 | 687 | |
688 | - if($page) |
|
688 | + if ($page) |
|
689 | 689 | { |
690 | 690 | $this->display($page); |
691 | 691 | } |
@@ -47,8 +47,6 @@ |
||
47 | 47 | * |
48 | 48 | * @since 1.0.0 |
49 | 49 | * |
50 | - * @param string $plugin_name The name of this plugin. |
|
51 | - * @param string $version The version of this plugin. |
|
52 | 50 | */ |
53 | 51 | public function __construct( Xcloner $xcloner_container ) { |
54 | 52 |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param string $plugin_name The name of this plugin. |
51 | 51 | * @param string $version The version of this plugin. |
52 | 52 | */ |
53 | - public function __construct( Xcloner $xcloner_container ) { |
|
53 | + public function __construct(Xcloner $xcloner_container) { |
|
54 | 54 | |
55 | 55 | $this->plugin_name = $xcloner_container->get_plugin_name(); |
56 | 56 | $this->version = $xcloner_container->get_version(); |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @since 1.0.0 |
68 | 68 | */ |
69 | - public function enqueue_styles( $hook ) { |
|
69 | + public function enqueue_styles($hook) { |
|
70 | 70 | |
71 | - if ( ! stristr( $hook, "page_" . $this->plugin_name ) || ( isset( $_GET['option'] ) and $_GET['option'] == "com_cloner" ) ) { |
|
71 | + if (!stristr($hook, "page_".$this->plugin_name) || (isset($_GET['option']) and $_GET['option'] == "com_cloner")) { |
|
72 | 72 | return; |
73 | 73 | } |
74 | 74 | |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * class. |
85 | 85 | */ |
86 | 86 | |
87 | - wp_enqueue_style( $this->plugin_name . "_materialize", plugin_dir_url( __FILE__ ) . 'css/materialize.min.css', array(), $this->version, 'all' ); |
|
88 | - wp_enqueue_style( $this->plugin_name . "_materialize.clockpicker", plugin_dir_url( __FILE__ ) . 'css/materialize.clockpicker.css', array(), $this->version, 'all' ); |
|
89 | - wp_enqueue_style( $this->plugin_name . "_materialize.icons", '//fonts.googleapis.com/icon?family=Material+Icons', array(), $this->version, 'all' ); |
|
90 | - wp_enqueue_style( $this->plugin_name . "_jquery.datatables", plugin_dir_url( __FILE__ ) . 'css/jquery.dataTables.min.css', array(), $this->version, 'all' ); |
|
91 | - wp_enqueue_style( $this->plugin_name . "_jquery.datatables.responsive", plugin_dir_url( __FILE__ ) . 'css/responsive.dataTables.css', array(), $this->version, 'all' ); |
|
92 | - wp_enqueue_style( $this->plugin_name . "_jstree", dirname( plugin_dir_url( __FILE__ ) ) . '/vendor/vakata/jstree/dist/themes/default/style.min.css', array(), '3.3', 'all' ); |
|
93 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/xcloner-admin.css', array(), $this->version, 'all' ); |
|
87 | + wp_enqueue_style($this->plugin_name."_materialize", plugin_dir_url(__FILE__).'css/materialize.min.css', array(), $this->version, 'all'); |
|
88 | + wp_enqueue_style($this->plugin_name."_materialize.clockpicker", plugin_dir_url(__FILE__).'css/materialize.clockpicker.css', array(), $this->version, 'all'); |
|
89 | + wp_enqueue_style($this->plugin_name."_materialize.icons", '//fonts.googleapis.com/icon?family=Material+Icons', array(), $this->version, 'all'); |
|
90 | + wp_enqueue_style($this->plugin_name."_jquery.datatables", plugin_dir_url(__FILE__).'css/jquery.dataTables.min.css', array(), $this->version, 'all'); |
|
91 | + wp_enqueue_style($this->plugin_name."_jquery.datatables.responsive", plugin_dir_url(__FILE__).'css/responsive.dataTables.css', array(), $this->version, 'all'); |
|
92 | + wp_enqueue_style($this->plugin_name."_jstree", dirname(plugin_dir_url(__FILE__)).'/vendor/vakata/jstree/dist/themes/default/style.min.css', array(), '3.3', 'all'); |
|
93 | + wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/xcloner-admin.css', array(), $this->version, 'all'); |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @since 1.0.0 |
101 | 101 | */ |
102 | - public function enqueue_scripts( $hook ) { |
|
102 | + public function enqueue_scripts($hook) { |
|
103 | 103 | |
104 | - if ( ! stristr( $hook, "page_" . $this->plugin_name ) ) { |
|
104 | + if (!stristr($hook, "page_".$this->plugin_name)) { |
|
105 | 105 | return; |
106 | 106 | } |
107 | 107 | |
@@ -118,25 +118,25 @@ discard block |
||
118 | 118 | */ |
119 | 119 | |
120 | 120 | add_thickbox(); |
121 | - wp_enqueue_script( 'plugin-install' ); |
|
122 | - wp_enqueue_script( 'updates' ); |
|
123 | - wp_enqueue_script( $this->plugin_name . "_materialize", plugin_dir_url( __FILE__ ) . 'js/materialize.min.js', array( 'jquery' ), $this->version, false ); |
|
124 | - wp_enqueue_script( $this->plugin_name . "_materialize.clockpicker", plugin_dir_url( __FILE__ ) . 'js/materialize.clockpicker.js', array( 'jquery' ), $this->version, false ); |
|
125 | - wp_enqueue_script( $this->plugin_name . "_jquery.datatables", plugin_dir_url( __FILE__ ) . 'js/jquery.dataTables.min.js', array( 'jquery' ), $this->version, false ); |
|
126 | - wp_enqueue_script( $this->plugin_name . "_jquery.datatables.respnsive", plugin_dir_url( __FILE__ ) . 'js/dataTables.responsive.js', array( 'jquery' ), $this->version, false ); |
|
127 | - wp_enqueue_script( $this->plugin_name . "_vakata", dirname( plugin_dir_url( __FILE__ ) ) . '/vendor/vakata/jstree/dist/jstree.min.js', array( 'jquery' ), '3.3', false ); |
|
128 | - wp_enqueue_script( $this->plugin_name . "_xcloner-backup-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-backup-class.js', array( 'jquery' ), $this->version, false ); |
|
129 | - wp_enqueue_script( $this->plugin_name . "_xcloner-scheduler-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-scheduler-class.js', array( 'jquery' ), $this->version, false ); |
|
130 | - wp_enqueue_script( $this->plugin_name . "_xcloner-restore-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-restore-class.js', array( 'jquery' ), $this->version, false ); |
|
131 | - wp_enqueue_script( $this->plugin_name . "_xcloner-manage-backups-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-manage-backups-class.js', array( 'jquery' ), $this->version, false ); |
|
132 | - wp_enqueue_script( $this->plugin_name . "_xcloner-remote-storage-class", plugin_dir_url( __FILE__ ) . 'js/xcloner-remote-storage-class.js', array( 'jquery' ), $this->version, false ); |
|
133 | - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/xcloner-admin.js', array( 'jquery' ), $this->version, false ); |
|
121 | + wp_enqueue_script('plugin-install'); |
|
122 | + wp_enqueue_script('updates'); |
|
123 | + wp_enqueue_script($this->plugin_name."_materialize", plugin_dir_url(__FILE__).'js/materialize.min.js', array('jquery'), $this->version, false); |
|
124 | + wp_enqueue_script($this->plugin_name."_materialize.clockpicker", plugin_dir_url(__FILE__).'js/materialize.clockpicker.js', array('jquery'), $this->version, false); |
|
125 | + wp_enqueue_script($this->plugin_name."_jquery.datatables", plugin_dir_url(__FILE__).'js/jquery.dataTables.min.js', array('jquery'), $this->version, false); |
|
126 | + wp_enqueue_script($this->plugin_name."_jquery.datatables.respnsive", plugin_dir_url(__FILE__).'js/dataTables.responsive.js', array('jquery'), $this->version, false); |
|
127 | + wp_enqueue_script($this->plugin_name."_vakata", dirname(plugin_dir_url(__FILE__)).'/vendor/vakata/jstree/dist/jstree.min.js', array('jquery'), '3.3', false); |
|
128 | + wp_enqueue_script($this->plugin_name."_xcloner-backup-class", plugin_dir_url(__FILE__).'js/xcloner-backup-class.js', array('jquery'), $this->version, false); |
|
129 | + wp_enqueue_script($this->plugin_name."_xcloner-scheduler-class", plugin_dir_url(__FILE__).'js/xcloner-scheduler-class.js', array('jquery'), $this->version, false); |
|
130 | + wp_enqueue_script($this->plugin_name."_xcloner-restore-class", plugin_dir_url(__FILE__).'js/xcloner-restore-class.js', array('jquery'), $this->version, false); |
|
131 | + wp_enqueue_script($this->plugin_name."_xcloner-manage-backups-class", plugin_dir_url(__FILE__).'js/xcloner-manage-backups-class.js', array('jquery'), $this->version, false); |
|
132 | + wp_enqueue_script($this->plugin_name."_xcloner-remote-storage-class", plugin_dir_url(__FILE__).'js/xcloner-remote-storage-class.js', array('jquery'), $this->version, false); |
|
133 | + wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/xcloner-admin.js', array('jquery'), $this->version, false); |
|
134 | 134 | |
135 | 135 | |
136 | 136 | } |
137 | 137 | |
138 | 138 | public function xcloner_init_page() { |
139 | - require_once( "partials/xcloner_init_page.php" ); |
|
139 | + require_once("partials/xcloner_init_page.php"); |
|
140 | 140 | |
141 | 141 | } |
142 | 142 | |
@@ -145,70 +145,70 @@ discard block |
||
145 | 145 | $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
146 | 146 | |
147 | 147 | |
148 | - if ( isset( $_POST['action'] ) ) { |
|
149 | - $_POST['action'] = $xcloner_sanitization->sanitize_input_as_string( $_POST['action'] ); |
|
150 | - $remote_storage->save( $_POST['action'] ); |
|
148 | + if (isset($_POST['action'])) { |
|
149 | + $_POST['action'] = $xcloner_sanitization->sanitize_input_as_string($_POST['action']); |
|
150 | + $remote_storage->save($_POST['action']); |
|
151 | 151 | } |
152 | 152 | |
153 | - if ( isset( $_POST['authentification_code'] ) && $_POST['authentification_code'] != "" ) { |
|
154 | - $_POST['authentification_code'] = $xcloner_sanitization->sanitize_input_as_string( $_POST['authentification_code'] ); |
|
153 | + if (isset($_POST['authentification_code']) && $_POST['authentification_code'] != "") { |
|
154 | + $_POST['authentification_code'] = $xcloner_sanitization->sanitize_input_as_string($_POST['authentification_code']); |
|
155 | 155 | |
156 | - $remote_storage->set_access_token( $_POST['authentification_code'] ); |
|
156 | + $remote_storage->set_access_token($_POST['authentification_code']); |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( isset( $_POST['connection_check'] ) && $_POST['connection_check'] ) { |
|
160 | - $remote_storage->check( $_POST['action'] ); |
|
159 | + if (isset($_POST['connection_check']) && $_POST['connection_check']) { |
|
160 | + $remote_storage->check($_POST['action']); |
|
161 | 161 | } |
162 | 162 | |
163 | - require_once( "partials/xcloner_remote_storage_page.php" ); |
|
163 | + require_once("partials/xcloner_remote_storage_page.php"); |
|
164 | 164 | |
165 | 165 | } |
166 | 166 | |
167 | 167 | public function xcloner_scheduled_backups_page() { |
168 | 168 | $requirements = $this->xcloner_container->get_xcloner_requirements(); |
169 | 169 | |
170 | - if ( ! $requirements->check_backup_ready_status() ) { |
|
171 | - require_once( "partials/xcloner_init_page.php" ); |
|
170 | + if (!$requirements->check_backup_ready_status()) { |
|
171 | + require_once("partials/xcloner_init_page.php"); |
|
172 | 172 | |
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | |
176 | - require_once( "partials/xcloner_scheduled_backups_page.php" ); |
|
176 | + require_once("partials/xcloner_scheduled_backups_page.php"); |
|
177 | 177 | |
178 | 178 | } |
179 | 179 | |
180 | 180 | public function xcloner_manage_backups_page() { |
181 | - require_once( "partials/xcloner_manage_backups_page.php" ); |
|
181 | + require_once("partials/xcloner_manage_backups_page.php"); |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | |
185 | 185 | public function xcloner_debugger_page() { |
186 | - require_once( "partials/xcloner_console_page.php" ); |
|
186 | + require_once("partials/xcloner_console_page.php"); |
|
187 | 187 | |
188 | 188 | } |
189 | 189 | |
190 | 190 | public function xcloner_restore_page() { |
191 | - require_once( "partials/xcloner_restore_page.php" ); |
|
191 | + require_once("partials/xcloner_restore_page.php"); |
|
192 | 192 | |
193 | 193 | } |
194 | 194 | |
195 | 195 | public function xcloner_generate_backups_page() { |
196 | 196 | $requirements = $this->xcloner_container->get_xcloner_requirements(); |
197 | 197 | |
198 | - if ( ! $requirements->check_backup_ready_status() ) { |
|
199 | - require_once( "partials/xcloner_init_page.php" ); |
|
198 | + if (!$requirements->check_backup_ready_status()) { |
|
199 | + require_once("partials/xcloner_init_page.php"); |
|
200 | 200 | |
201 | 201 | return false; |
202 | 202 | } |
203 | 203 | |
204 | - require_once( "partials/xcloner_generate_backups_page.php" ); |
|
204 | + require_once("partials/xcloner_generate_backups_page.php"); |
|
205 | 205 | |
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
209 | 209 | public function xcloner_settings_page() { |
210 | 210 | // check user capabilities |
211 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
211 | + if (!current_user_can('manage_options')) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | 214 | |
@@ -216,40 +216,40 @@ discard block |
||
216 | 216 | |
217 | 217 | // check if the user have submitted the settings |
218 | 218 | // wordpress will add the "settings-updated" $_GET parameter to the url |
219 | - if ( isset( $_GET['settings-updated'] ) ) { |
|
219 | + if (isset($_GET['settings-updated'])) { |
|
220 | 220 | // add settings saved message with the class of "updated" |
221 | - add_settings_error( 'wporg_messages', 'wporg_message', __( 'Settings Saved', 'wporg' ), 'updated' ); |
|
221 | + add_settings_error('wporg_messages', 'wporg_message', __('Settings Saved', 'wporg'), 'updated'); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | // show error/update messages |
225 | - settings_errors( 'wporg_messages' ); |
|
225 | + settings_errors('wporg_messages'); |
|
226 | 226 | ?> |
227 | 227 | |
228 | 228 | <?php |
229 | 229 | $xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization(); |
230 | 230 | |
231 | - if ( isset( $_GET['tab'] ) ) { |
|
232 | - $active_tab = $xcloner_sanitization->sanitize_input_as_string( $_GET['tab'] ); |
|
231 | + if (isset($_GET['tab'])) { |
|
232 | + $active_tab = $xcloner_sanitization->sanitize_input_as_string($_GET['tab']); |
|
233 | 233 | } // end if |
234 | 234 | else { |
235 | 235 | $active_tab = "general_options"; |
236 | 236 | } |
237 | 237 | |
238 | 238 | ?> |
239 | - <h1><?= esc_html( get_admin_page_title() ); ?></h1> |
|
239 | + <h1><?= esc_html(get_admin_page_title()); ?></h1> |
|
240 | 240 | |
241 | 241 | <ul class="nav-tab-wrapper row"> |
242 | 242 | <li><a href="?page=xcloner_settings_page&tab=general_options" |
243 | - class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'general_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'General Options', 'xcloner-backup-and-restore' ) ?></a> |
|
243 | + class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'general_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('General Options', 'xcloner-backup-and-restore') ?></a> |
|
244 | 244 | </li> |
245 | 245 | <li><a href="?page=xcloner_settings_page&tab=mysql_options" |
246 | - class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'mysql_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'Mysql Options', 'xcloner-backup-and-restore' ) ?></a> |
|
246 | + class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'mysql_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('Mysql Options', 'xcloner-backup-and-restore') ?></a> |
|
247 | 247 | </li> |
248 | 248 | <li><a href="?page=xcloner_settings_page&tab=system_options" |
249 | - class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'system_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'System Options', 'xcloner-backup-and-restore' ) ?></a> |
|
249 | + class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'system_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('System Options', 'xcloner-backup-and-restore') ?></a> |
|
250 | 250 | </li> |
251 | 251 | <li><a href="?page=xcloner_settings_page&tab=cleanup_options" |
252 | - class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'cleanup_options' ? 'nav-tab-active' : ''; ?>"><?php echo __( 'Cleanup Options', 'xcloner-backup-and-restore' ) ?></a> |
|
252 | + class="nav-tab col s12 m3 l2 <?php echo $active_tab == 'cleanup_options' ? 'nav-tab-active' : ''; ?>"><?php echo __('Cleanup Options', 'xcloner-backup-and-restore') ?></a> |
|
253 | 253 | </li> |
254 | 254 | </ul> |
255 | 255 | |
@@ -258,27 +258,27 @@ discard block |
||
258 | 258 | <form action="options.php" method="post"> |
259 | 259 | <?php |
260 | 260 | |
261 | - if ( $active_tab == 'general_options' ) { |
|
261 | + if ($active_tab == 'general_options') { |
|
262 | 262 | |
263 | - settings_fields( 'xcloner_general_settings_group' ); |
|
264 | - do_settings_sections( 'xcloner_settings_page' ); |
|
263 | + settings_fields('xcloner_general_settings_group'); |
|
264 | + do_settings_sections('xcloner_settings_page'); |
|
265 | 265 | |
266 | - } elseif ( $active_tab == 'mysql_options' ) { |
|
266 | + } elseif ($active_tab == 'mysql_options') { |
|
267 | 267 | |
268 | - settings_fields( 'xcloner_mysql_settings_group' ); |
|
269 | - do_settings_sections( 'xcloner_mysql_settings_page' ); |
|
270 | - } elseif ( $active_tab == 'system_options' ) { |
|
268 | + settings_fields('xcloner_mysql_settings_group'); |
|
269 | + do_settings_sections('xcloner_mysql_settings_page'); |
|
270 | + } elseif ($active_tab == 'system_options') { |
|
271 | 271 | |
272 | - settings_fields( 'xcloner_system_settings_group' ); |
|
273 | - do_settings_sections( 'xcloner_system_settings_page' ); |
|
274 | - } elseif ( $active_tab == 'cleanup_options' ) { |
|
272 | + settings_fields('xcloner_system_settings_group'); |
|
273 | + do_settings_sections('xcloner_system_settings_page'); |
|
274 | + } elseif ($active_tab == 'cleanup_options') { |
|
275 | 275 | |
276 | - settings_fields( 'xcloner_cleanup_settings_group' ); |
|
277 | - do_settings_sections( 'xcloner_cleanup_settings_page' ); |
|
276 | + settings_fields('xcloner_cleanup_settings_group'); |
|
277 | + do_settings_sections('xcloner_cleanup_settings_page'); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | // output save settings button |
281 | - submit_button( 'Save Settings' ); |
|
281 | + submit_button('Save Settings'); |
|
282 | 282 | ?> |
283 | 283 | </form> |
284 | 284 |
@@ -28,13 +28,8 @@ |
||
28 | 28 | |
29 | 29 | use League\Flysystem\Config; |
30 | 30 | use League\Flysystem\Filesystem; |
31 | -use League\Flysystem\Util; |
|
32 | 31 | use League\Flysystem\Adapter\Local; |
33 | - |
|
34 | 32 | use splitbrain\PHPArchive\Tar; |
35 | -use splitbrain\PHPArchive\Zip; |
|
36 | -use splitbrain\PHPArchive\Archive; |
|
37 | -use splitbrain\PHPArchive\FileInfo; |
|
38 | 33 | |
39 | 34 | |
40 | 35 | /** |
@@ -43,903 +43,903 @@ discard block |
||
43 | 43 | class Xcloner_Api |
44 | 44 | { |
45 | 45 | |
46 | - private $xcloner_database; |
|
47 | - private $xcloner_settings; |
|
48 | - private $xcloner_file_system; |
|
49 | - private $xcloner_requirements; |
|
50 | - private $xcloner_sanitization; |
|
51 | - private $xcloner_encryption; |
|
52 | - private $xcloner_remote_storage; |
|
53 | - private $archive_system; |
|
54 | - private $form_params; |
|
55 | - private $logger; |
|
56 | - private $xcloner_container; |
|
57 | - |
|
58 | - /** |
|
59 | - * XCloner_Api construct class |
|
60 | - * |
|
61 | - * @param Xcloner $xcloner_container [description] |
|
62 | - */ |
|
63 | - public function __construct(Xcloner $xcloner_container) |
|
64 | - { |
|
65 | - global $wpdb; |
|
66 | - |
|
67 | - if (WP_DEBUG) { |
|
68 | - error_reporting(0); |
|
69 | - } |
|
70 | - |
|
71 | - if (ob_get_length()) { |
|
72 | - ob_end_clean(); |
|
73 | - } |
|
74 | - ob_start(); |
|
75 | - |
|
76 | - $wpdb->show_errors = false; |
|
77 | - |
|
78 | - $this->xcloner_container = $xcloner_container; |
|
79 | - |
|
80 | - $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
81 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api"); |
|
82 | - $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
|
83 | - $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
|
84 | - $this->xcloner_requirements = $xcloner_container->get_xcloner_requirements(); |
|
85 | - $this->archive_system = $xcloner_container->get_archive_system(); |
|
86 | - $this->xcloner_database = $xcloner_container->get_xcloner_database(); |
|
87 | - $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler(); |
|
88 | - $this->xcloner_encryption = $xcloner_container->get_xcloner_encryption(); |
|
89 | - $this->xcloner_remote_storage = $xcloner_container->get_xcloner_remote_storage(); |
|
90 | - |
|
91 | - if (isset($_POST['API_ID'])) { |
|
92 | - $this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), |
|
93 | - 0, 15)); |
|
94 | - } |
|
95 | - |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Get XCloner Container |
|
100 | - * @return XCloner return the XCloner container |
|
101 | - */ |
|
102 | - public function get_xcloner_container() |
|
103 | - { |
|
104 | - return $this->xcloner_container; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Check if user has access to this class |
|
109 | - * @return die() returns die() if user is not allowed |
|
110 | - * @link http://www.wordpress.org |
|
111 | - */ |
|
112 | - private function check_access() |
|
113 | - { |
|
114 | - if (function_exists('current_user_can') && !current_user_can('manage_options')) { |
|
115 | - die("Not allowed access here!"); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Initialize the database connection |
|
121 | - */ |
|
122 | - public function init_db() |
|
123 | - { |
|
124 | - return; |
|
125 | - |
|
126 | - |
|
127 | - $data['dbHostname'] = $this->xcloner_settings->get_db_hostname(); |
|
128 | - $data['dbUsername'] = $this->xcloner_settings->get_db_username(); |
|
129 | - $data['dbPassword'] = $this->xcloner_settings->get_db_password(); |
|
130 | - $data['dbDatabase'] = $this->xcloner_settings->get_db_database(); |
|
131 | - |
|
132 | - |
|
133 | - $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
134 | - $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database"; |
|
135 | - $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql"; |
|
136 | - |
|
137 | - try { |
|
138 | - $this->xcloner_database->init($data); |
|
139 | - |
|
140 | - } catch (Exception $e) { |
|
141 | - |
|
142 | - $this->send_response($e->getMessage()); |
|
143 | - $this->logger->error($e->getMessage()); |
|
144 | - |
|
145 | - } |
|
146 | - |
|
147 | - return $this->xcloner_database; |
|
148 | - |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /* |
|
46 | + private $xcloner_database; |
|
47 | + private $xcloner_settings; |
|
48 | + private $xcloner_file_system; |
|
49 | + private $xcloner_requirements; |
|
50 | + private $xcloner_sanitization; |
|
51 | + private $xcloner_encryption; |
|
52 | + private $xcloner_remote_storage; |
|
53 | + private $archive_system; |
|
54 | + private $form_params; |
|
55 | + private $logger; |
|
56 | + private $xcloner_container; |
|
57 | + |
|
58 | + /** |
|
59 | + * XCloner_Api construct class |
|
60 | + * |
|
61 | + * @param Xcloner $xcloner_container [description] |
|
62 | + */ |
|
63 | + public function __construct(Xcloner $xcloner_container) |
|
64 | + { |
|
65 | + global $wpdb; |
|
66 | + |
|
67 | + if (WP_DEBUG) { |
|
68 | + error_reporting(0); |
|
69 | + } |
|
70 | + |
|
71 | + if (ob_get_length()) { |
|
72 | + ob_end_clean(); |
|
73 | + } |
|
74 | + ob_start(); |
|
75 | + |
|
76 | + $wpdb->show_errors = false; |
|
77 | + |
|
78 | + $this->xcloner_container = $xcloner_container; |
|
79 | + |
|
80 | + $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
81 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api"); |
|
82 | + $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
|
83 | + $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
|
84 | + $this->xcloner_requirements = $xcloner_container->get_xcloner_requirements(); |
|
85 | + $this->archive_system = $xcloner_container->get_archive_system(); |
|
86 | + $this->xcloner_database = $xcloner_container->get_xcloner_database(); |
|
87 | + $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler(); |
|
88 | + $this->xcloner_encryption = $xcloner_container->get_xcloner_encryption(); |
|
89 | + $this->xcloner_remote_storage = $xcloner_container->get_xcloner_remote_storage(); |
|
90 | + |
|
91 | + if (isset($_POST['API_ID'])) { |
|
92 | + $this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), |
|
93 | + 0, 15)); |
|
94 | + } |
|
95 | + |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Get XCloner Container |
|
100 | + * @return XCloner return the XCloner container |
|
101 | + */ |
|
102 | + public function get_xcloner_container() |
|
103 | + { |
|
104 | + return $this->xcloner_container; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Check if user has access to this class |
|
109 | + * @return die() returns die() if user is not allowed |
|
110 | + * @link http://www.wordpress.org |
|
111 | + */ |
|
112 | + private function check_access() |
|
113 | + { |
|
114 | + if (function_exists('current_user_can') && !current_user_can('manage_options')) { |
|
115 | + die("Not allowed access here!"); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Initialize the database connection |
|
121 | + */ |
|
122 | + public function init_db() |
|
123 | + { |
|
124 | + return; |
|
125 | + |
|
126 | + |
|
127 | + $data['dbHostname'] = $this->xcloner_settings->get_db_hostname(); |
|
128 | + $data['dbUsername'] = $this->xcloner_settings->get_db_username(); |
|
129 | + $data['dbPassword'] = $this->xcloner_settings->get_db_password(); |
|
130 | + $data['dbDatabase'] = $this->xcloner_settings->get_db_database(); |
|
131 | + |
|
132 | + |
|
133 | + $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
134 | + $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database"; |
|
135 | + $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql"; |
|
136 | + |
|
137 | + try { |
|
138 | + $this->xcloner_database->init($data); |
|
139 | + |
|
140 | + } catch (Exception $e) { |
|
141 | + |
|
142 | + $this->send_response($e->getMessage()); |
|
143 | + $this->logger->error($e->getMessage()); |
|
144 | + |
|
145 | + } |
|
146 | + |
|
147 | + return $this->xcloner_database; |
|
148 | + |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /* |
|
153 | 153 | * Save Schedule API |
154 | 154 | */ |
155 | - public function save_schedule() |
|
156 | - { |
|
157 | - global $wpdb; |
|
158 | - |
|
159 | - $this->check_access(); |
|
160 | - |
|
161 | - $scheduler = $this->xcloner_scheduler; |
|
162 | - $params = array(); |
|
163 | - $schedule = array(); |
|
164 | - $response = array(); |
|
165 | - |
|
166 | - if (isset($_POST['data'])) { |
|
167 | - $params = json_decode(stripslashes($_POST['data'])); |
|
168 | - } |
|
169 | - |
|
170 | - $this->process_params($params); |
|
171 | - |
|
172 | - if (isset($_POST['id'])) { |
|
173 | - |
|
174 | - $this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']); |
|
175 | - $this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']); |
|
176 | - if ($_POST['diff_start_date']) { |
|
177 | - $this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date'])); |
|
178 | - } else { |
|
179 | - $this->form_params['backup_params']['diff_start_date'] = ""; |
|
180 | - } |
|
181 | - $this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']); |
|
182 | - $this->form_params['backup_params']['backup_encrypt'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['backup_encrypt']); |
|
183 | - $this->form_params['backup_params']['start_at'] = strtotime($_POST['schedule_start_date']); |
|
184 | - $this->form_params['backup_params']['schedule_frequency'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_frequency']); |
|
185 | - $this->form_params['backup_params']['schedule_storage'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_storage']); |
|
186 | - $this->form_params['database'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['table_params']))); |
|
187 | - $this->form_params['excluded_files'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['excluded_files']))); |
|
188 | - |
|
189 | - //$this->form_params['backup_params']['backup_type'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_type']); |
|
190 | - |
|
191 | - $tables = explode(PHP_EOL, $this->form_params['database']); |
|
192 | - $return = array(); |
|
193 | - |
|
194 | - foreach ($tables as $table) { |
|
195 | - $table = str_replace("\r", "", $table); |
|
196 | - $data = explode(".", $table); |
|
197 | - if (isset($data[1])) { |
|
198 | - $return[$data[0]][] = $data[1]; |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - $this->form_params['database'] = ($return); |
|
203 | - |
|
204 | - $excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']); |
|
205 | - $return = array(); |
|
206 | - |
|
207 | - foreach ($excluded_files as $file) { |
|
208 | - $file = str_replace("\r", "", $file); |
|
209 | - if ($file) { |
|
210 | - $return[] = $file; |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - $this->form_params['excluded_files'] = ($return); |
|
215 | - |
|
216 | - $schedule['start_at'] = $this->form_params['backup_params']['start_at']; |
|
217 | - |
|
218 | - if (!isset($_POST['status'])) { |
|
219 | - $schedule['status'] = 0; |
|
220 | - } else { |
|
221 | - $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
|
222 | - } |
|
223 | - } else { |
|
224 | - |
|
225 | - $schedule['status'] = 1; |
|
226 | - $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
|
227 | - " " . $this->form_params['backup_params']['schedule_start_time']); |
|
228 | - |
|
229 | - if ($schedule['start_at'] <= time()) { |
|
230 | - $schedule['start_at'] = ""; |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - if (!$schedule['start_at']) { |
|
235 | - $schedule['start_at'] = date('Y-m-d H:i:s', time()); |
|
236 | - } else { |
|
237 | - $schedule['start_at'] = date('Y-m-d H:i:s', |
|
238 | - $schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
239 | - } |
|
240 | - |
|
241 | - $schedule['name'] = $this->form_params['backup_params']['schedule_name']; |
|
242 | - $schedule['recurrence'] = $this->form_params['backup_params']['schedule_frequency']; |
|
243 | - if (!isset($this->form_params['backup_params']['schedule_storage'])) { |
|
244 | - $this->form_params['backup_params']['schedule_storage'] = ""; |
|
245 | - } |
|
246 | - $schedule['remote_storage'] = $this->form_params['backup_params']['schedule_storage']; |
|
247 | - //$schedule['backup_type'] = $this->form_params['backup_params']['backup_type']; |
|
248 | - $schedule['params'] = json_encode($this->form_params); |
|
249 | - |
|
250 | - if (!isset($_POST['id'])) { |
|
251 | - $wpdb->insert( |
|
252 | - $wpdb->prefix . 'xcloner_scheduler', |
|
253 | - $schedule, |
|
254 | - array( |
|
255 | - '%s', |
|
256 | - '%s' |
|
257 | - ) |
|
258 | - ); |
|
259 | - } else { |
|
260 | - $wpdb->update( |
|
261 | - $wpdb->prefix . 'xcloner_scheduler', |
|
262 | - $schedule, |
|
263 | - array('id' => $_POST['id']), |
|
264 | - array( |
|
265 | - '%s', |
|
266 | - '%s' |
|
267 | - ) |
|
268 | - ); |
|
269 | - } |
|
270 | - if (isset($_POST['id'])) { |
|
271 | - $scheduler->update_cron_hook($_POST['id']); |
|
272 | - } |
|
273 | - |
|
274 | - if ($wpdb->last_error) { |
|
275 | - $response['error'] = 1; |
|
276 | - $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/ |
|
277 | - ; |
|
278 | - |
|
279 | - } |
|
280 | - |
|
281 | - $scheduler->update_wp_cron_hooks(); |
|
282 | - $response['finished'] = 1; |
|
283 | - |
|
284 | - $this->send_response($response); |
|
285 | - } |
|
286 | - |
|
287 | - /* |
|
155 | + public function save_schedule() |
|
156 | + { |
|
157 | + global $wpdb; |
|
158 | + |
|
159 | + $this->check_access(); |
|
160 | + |
|
161 | + $scheduler = $this->xcloner_scheduler; |
|
162 | + $params = array(); |
|
163 | + $schedule = array(); |
|
164 | + $response = array(); |
|
165 | + |
|
166 | + if (isset($_POST['data'])) { |
|
167 | + $params = json_decode(stripslashes($_POST['data'])); |
|
168 | + } |
|
169 | + |
|
170 | + $this->process_params($params); |
|
171 | + |
|
172 | + if (isset($_POST['id'])) { |
|
173 | + |
|
174 | + $this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']); |
|
175 | + $this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']); |
|
176 | + if ($_POST['diff_start_date']) { |
|
177 | + $this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date'])); |
|
178 | + } else { |
|
179 | + $this->form_params['backup_params']['diff_start_date'] = ""; |
|
180 | + } |
|
181 | + $this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']); |
|
182 | + $this->form_params['backup_params']['backup_encrypt'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['backup_encrypt']); |
|
183 | + $this->form_params['backup_params']['start_at'] = strtotime($_POST['schedule_start_date']); |
|
184 | + $this->form_params['backup_params']['schedule_frequency'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_frequency']); |
|
185 | + $this->form_params['backup_params']['schedule_storage'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_storage']); |
|
186 | + $this->form_params['database'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['table_params']))); |
|
187 | + $this->form_params['excluded_files'] = (stripslashes($this->xcloner_sanitization->sanitize_input_as_raw($_POST['excluded_files']))); |
|
188 | + |
|
189 | + //$this->form_params['backup_params']['backup_type'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_type']); |
|
190 | + |
|
191 | + $tables = explode(PHP_EOL, $this->form_params['database']); |
|
192 | + $return = array(); |
|
193 | + |
|
194 | + foreach ($tables as $table) { |
|
195 | + $table = str_replace("\r", "", $table); |
|
196 | + $data = explode(".", $table); |
|
197 | + if (isset($data[1])) { |
|
198 | + $return[$data[0]][] = $data[1]; |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + $this->form_params['database'] = ($return); |
|
203 | + |
|
204 | + $excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']); |
|
205 | + $return = array(); |
|
206 | + |
|
207 | + foreach ($excluded_files as $file) { |
|
208 | + $file = str_replace("\r", "", $file); |
|
209 | + if ($file) { |
|
210 | + $return[] = $file; |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + $this->form_params['excluded_files'] = ($return); |
|
215 | + |
|
216 | + $schedule['start_at'] = $this->form_params['backup_params']['start_at']; |
|
217 | + |
|
218 | + if (!isset($_POST['status'])) { |
|
219 | + $schedule['status'] = 0; |
|
220 | + } else { |
|
221 | + $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
|
222 | + } |
|
223 | + } else { |
|
224 | + |
|
225 | + $schedule['status'] = 1; |
|
226 | + $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
|
227 | + " " . $this->form_params['backup_params']['schedule_start_time']); |
|
228 | + |
|
229 | + if ($schedule['start_at'] <= time()) { |
|
230 | + $schedule['start_at'] = ""; |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + if (!$schedule['start_at']) { |
|
235 | + $schedule['start_at'] = date('Y-m-d H:i:s', time()); |
|
236 | + } else { |
|
237 | + $schedule['start_at'] = date('Y-m-d H:i:s', |
|
238 | + $schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
239 | + } |
|
240 | + |
|
241 | + $schedule['name'] = $this->form_params['backup_params']['schedule_name']; |
|
242 | + $schedule['recurrence'] = $this->form_params['backup_params']['schedule_frequency']; |
|
243 | + if (!isset($this->form_params['backup_params']['schedule_storage'])) { |
|
244 | + $this->form_params['backup_params']['schedule_storage'] = ""; |
|
245 | + } |
|
246 | + $schedule['remote_storage'] = $this->form_params['backup_params']['schedule_storage']; |
|
247 | + //$schedule['backup_type'] = $this->form_params['backup_params']['backup_type']; |
|
248 | + $schedule['params'] = json_encode($this->form_params); |
|
249 | + |
|
250 | + if (!isset($_POST['id'])) { |
|
251 | + $wpdb->insert( |
|
252 | + $wpdb->prefix . 'xcloner_scheduler', |
|
253 | + $schedule, |
|
254 | + array( |
|
255 | + '%s', |
|
256 | + '%s' |
|
257 | + ) |
|
258 | + ); |
|
259 | + } else { |
|
260 | + $wpdb->update( |
|
261 | + $wpdb->prefix . 'xcloner_scheduler', |
|
262 | + $schedule, |
|
263 | + array('id' => $_POST['id']), |
|
264 | + array( |
|
265 | + '%s', |
|
266 | + '%s' |
|
267 | + ) |
|
268 | + ); |
|
269 | + } |
|
270 | + if (isset($_POST['id'])) { |
|
271 | + $scheduler->update_cron_hook($_POST['id']); |
|
272 | + } |
|
273 | + |
|
274 | + if ($wpdb->last_error) { |
|
275 | + $response['error'] = 1; |
|
276 | + $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/ |
|
277 | + ; |
|
278 | + |
|
279 | + } |
|
280 | + |
|
281 | + $scheduler->update_wp_cron_hooks(); |
|
282 | + $response['finished'] = 1; |
|
283 | + |
|
284 | + $this->send_response($response); |
|
285 | + } |
|
286 | + |
|
287 | + /* |
|
288 | 288 | * |
289 | 289 | * Backup Files API |
290 | 290 | * |
291 | 291 | */ |
292 | - public function backup_files() |
|
293 | - { |
|
294 | - $this->check_access(); |
|
295 | - |
|
296 | - $params = json_decode(stripslashes($_POST['data'])); |
|
297 | - |
|
298 | - $init = (int)$_POST['init']; |
|
299 | - |
|
300 | - if ($params === null) { |
|
301 | - die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
302 | - } |
|
303 | - |
|
304 | - $this->process_params($params); |
|
305 | - |
|
306 | - $return['finished'] = 1; |
|
307 | - |
|
308 | - //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
|
309 | - try { |
|
310 | - $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], |
|
311 | - $this->form_params['extra'], $init); |
|
312 | - } catch (Exception $e) { |
|
313 | - $return = array(); |
|
314 | - $return['error'] = true; |
|
315 | - $return['status'] = 500; |
|
316 | - $return['error_message'] = $e->getMessage(); |
|
317 | - |
|
318 | - return $this->send_response($return, $hash = 1); |
|
319 | - } |
|
320 | - |
|
321 | - if ($return['finished']) { |
|
322 | - $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
|
323 | - if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { |
|
324 | - $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - $data = $return; |
|
329 | - |
|
330 | - //check if backup is finished |
|
331 | - if ($return['finished']) { |
|
332 | - if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) { |
|
333 | - try { |
|
334 | - $from = ""; |
|
335 | - $subject = ""; |
|
336 | - $additional['lines_total'] = $return['extra']['lines_total']; |
|
337 | - $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], |
|
338 | - $this->form_params, "", $additional); |
|
339 | - } catch (Exception $e) { |
|
340 | - $this->logger->error($e->getMessage()); |
|
341 | - } |
|
342 | - } |
|
343 | - $this->xcloner_file_system->remove_tmp_filesystem(); |
|
344 | - } |
|
345 | - |
|
346 | - return $this->send_response($data, $hash = 1); |
|
347 | - } |
|
348 | - |
|
349 | - /* |
|
292 | + public function backup_files() |
|
293 | + { |
|
294 | + $this->check_access(); |
|
295 | + |
|
296 | + $params = json_decode(stripslashes($_POST['data'])); |
|
297 | + |
|
298 | + $init = (int)$_POST['init']; |
|
299 | + |
|
300 | + if ($params === null) { |
|
301 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
302 | + } |
|
303 | + |
|
304 | + $this->process_params($params); |
|
305 | + |
|
306 | + $return['finished'] = 1; |
|
307 | + |
|
308 | + //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
|
309 | + try { |
|
310 | + $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], |
|
311 | + $this->form_params['extra'], $init); |
|
312 | + } catch (Exception $e) { |
|
313 | + $return = array(); |
|
314 | + $return['error'] = true; |
|
315 | + $return['status'] = 500; |
|
316 | + $return['error_message'] = $e->getMessage(); |
|
317 | + |
|
318 | + return $this->send_response($return, $hash = 1); |
|
319 | + } |
|
320 | + |
|
321 | + if ($return['finished']) { |
|
322 | + $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
|
323 | + if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { |
|
324 | + $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + $data = $return; |
|
329 | + |
|
330 | + //check if backup is finished |
|
331 | + if ($return['finished']) { |
|
332 | + if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) { |
|
333 | + try { |
|
334 | + $from = ""; |
|
335 | + $subject = ""; |
|
336 | + $additional['lines_total'] = $return['extra']['lines_total']; |
|
337 | + $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], |
|
338 | + $this->form_params, "", $additional); |
|
339 | + } catch (Exception $e) { |
|
340 | + $this->logger->error($e->getMessage()); |
|
341 | + } |
|
342 | + } |
|
343 | + $this->xcloner_file_system->remove_tmp_filesystem(); |
|
344 | + } |
|
345 | + |
|
346 | + return $this->send_response($data, $hash = 1); |
|
347 | + } |
|
348 | + |
|
349 | + /* |
|
350 | 350 | * |
351 | 351 | * Backup Database API |
352 | 352 | * |
353 | 353 | */ |
354 | - public function backup_database() |
|
355 | - { |
|
356 | - $this->check_access(); |
|
354 | + public function backup_database() |
|
355 | + { |
|
356 | + $this->check_access(); |
|
357 | 357 | |
358 | - $params = json_decode(stripslashes($_POST['data'])); |
|
358 | + $params = json_decode(stripslashes($_POST['data'])); |
|
359 | 359 | |
360 | - $init = (int)$_POST['init']; |
|
360 | + $init = (int)$_POST['init']; |
|
361 | 361 | |
362 | - if ($params === null) { |
|
363 | - die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
364 | - } |
|
362 | + if ($params === null) { |
|
363 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
364 | + } |
|
365 | 365 | |
366 | - $this->process_params($params); |
|
366 | + $this->process_params($params); |
|
367 | 367 | |
368 | - //$xcloner_database = $this->init_db(); |
|
369 | - $return = $this->xcloner_database->start_database_recursion($this->form_params['database'], |
|
370 | - $this->form_params['extra'], $init); |
|
368 | + //$xcloner_database = $this->init_db(); |
|
369 | + $return = $this->xcloner_database->start_database_recursion($this->form_params['database'], |
|
370 | + $this->form_params['extra'], $init); |
|
371 | 371 | |
372 | - if (isset($return['error']) and $return['error']) { |
|
373 | - $data['finished'] = 1; |
|
374 | - } else { |
|
375 | - $data['finished'] = $return['finished']; |
|
376 | - } |
|
372 | + if (isset($return['error']) and $return['error']) { |
|
373 | + $data['finished'] = 1; |
|
374 | + } else { |
|
375 | + $data['finished'] = $return['finished']; |
|
376 | + } |
|
377 | 377 | |
378 | - $data['extra'] = $return; |
|
378 | + $data['extra'] = $return; |
|
379 | 379 | |
380 | - return $this->send_response($data, $hash = 1); |
|
381 | - } |
|
380 | + return $this->send_response($data, $hash = 1); |
|
381 | + } |
|
382 | 382 | |
383 | - /* |
|
383 | + /* |
|
384 | 384 | * |
385 | 385 | * Scan Filesystem API |
386 | 386 | * |
387 | 387 | */ |
388 | - public function scan_filesystem() |
|
389 | - { |
|
390 | - $this->check_access(); |
|
388 | + public function scan_filesystem() |
|
389 | + { |
|
390 | + $this->check_access(); |
|
391 | 391 | |
392 | - $params = json_decode(stripslashes($_POST['data'])); |
|
393 | - $init = (int)$_POST['init']; |
|
392 | + $params = json_decode(stripslashes($_POST['data'])); |
|
393 | + $init = (int)$_POST['init']; |
|
394 | 394 | |
395 | - if ($params === null) { |
|
396 | - die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
397 | - } |
|
395 | + if ($params === null) { |
|
396 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
397 | + } |
|
398 | 398 | |
399 | - $hash = $this->process_params($params); |
|
399 | + $hash = $this->process_params($params); |
|
400 | 400 | |
401 | - $this->xcloner_file_system->set_excluded_files($this->form_params['excluded_files']); |
|
401 | + $this->xcloner_file_system->set_excluded_files($this->form_params['excluded_files']); |
|
402 | 402 | |
403 | - $return = $this->xcloner_file_system->start_file_recursion($init); |
|
403 | + $return = $this->xcloner_file_system->start_file_recursion($init); |
|
404 | 404 | |
405 | - $data["finished"] = !$return; |
|
406 | - $data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num(); |
|
407 | - $data["last_logged_file"] = $this->xcloner_file_system->last_logged_file(); |
|
408 | - $data["total_files_size"] = sprintf("%.2f", |
|
409 | - $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024)); |
|
405 | + $data["finished"] = !$return; |
|
406 | + $data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num(); |
|
407 | + $data["last_logged_file"] = $this->xcloner_file_system->last_logged_file(); |
|
408 | + $data["total_files_size"] = sprintf("%.2f", |
|
409 | + $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024)); |
|
410 | 410 | |
411 | - return $this->send_response($data, $hash = 1); |
|
412 | - } |
|
411 | + return $this->send_response($data, $hash = 1); |
|
412 | + } |
|
413 | 413 | |
414 | - /* |
|
414 | + /* |
|
415 | 415 | * |
416 | 416 | * Process params sent by the user |
417 | 417 | * |
418 | 418 | */ |
419 | - private function process_params($params) |
|
420 | - { |
|
421 | - if (isset($params->hash)) { |
|
422 | - $this->xcloner_settings->set_hash($params->hash); |
|
423 | - } |
|
424 | - |
|
425 | - $this->form_params['extra'] = array(); |
|
426 | - $this->form_params['backup_params'] = array(); |
|
427 | - |
|
428 | - $this->form_params['database'] = array(); |
|
429 | - |
|
430 | - if (isset($params->backup_params)) { |
|
431 | - foreach ($params->backup_params as $param) { |
|
432 | - $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value); |
|
433 | - $this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array( |
|
434 | - 'POST', |
|
435 | - 'fields filter' |
|
436 | - )); |
|
437 | - } |
|
438 | - } |
|
439 | - |
|
440 | - $this->form_params['database'] = array(); |
|
441 | - |
|
442 | - if (isset($params->table_params)) { |
|
443 | - foreach ($params->table_params as $param) { |
|
444 | - $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id); |
|
445 | - $this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array( |
|
446 | - 'POST', |
|
447 | - 'database filter' |
|
448 | - )); |
|
449 | - } |
|
450 | - } |
|
451 | - |
|
452 | - $this->form_params['excluded_files'] = array(); |
|
453 | - if (isset($params->files_params)) { |
|
454 | - foreach ($params->files_params as $param) { |
|
455 | - $this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
|
456 | - } |
|
457 | - |
|
458 | - $unique_exclude_files = array(); |
|
459 | - |
|
460 | - foreach ($params->files_params as $key => $param) { |
|
461 | - if (!in_array($param->parent, $this->form_params['excluded_files'])) { |
|
462 | - //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
|
463 | - $unique_exclude_files[] = $param->id; |
|
464 | - $this->logger->debug("Adding file filter " . $param->id . "\n", array( |
|
465 | - 'POST', |
|
466 | - 'exclude files filter' |
|
467 | - )); |
|
468 | - } |
|
469 | - } |
|
470 | - $this->form_params['excluded_files'] = (array)$unique_exclude_files; |
|
471 | - |
|
472 | - } |
|
473 | - |
|
474 | - //$this->form_params['excluded_files'] = array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default); |
|
475 | - |
|
476 | - if (isset($params->extra)) { |
|
477 | - foreach ($params->extra as $key => $value) { |
|
478 | - $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
|
479 | - } |
|
480 | - } |
|
481 | - |
|
482 | - if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) { |
|
483 | - $this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']); |
|
484 | - $this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']); |
|
485 | - } |
|
486 | - |
|
487 | - return $this->xcloner_settings->get_hash(); |
|
488 | - } |
|
489 | - |
|
490 | - /* |
|
419 | + private function process_params($params) |
|
420 | + { |
|
421 | + if (isset($params->hash)) { |
|
422 | + $this->xcloner_settings->set_hash($params->hash); |
|
423 | + } |
|
424 | + |
|
425 | + $this->form_params['extra'] = array(); |
|
426 | + $this->form_params['backup_params'] = array(); |
|
427 | + |
|
428 | + $this->form_params['database'] = array(); |
|
429 | + |
|
430 | + if (isset($params->backup_params)) { |
|
431 | + foreach ($params->backup_params as $param) { |
|
432 | + $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value); |
|
433 | + $this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array( |
|
434 | + 'POST', |
|
435 | + 'fields filter' |
|
436 | + )); |
|
437 | + } |
|
438 | + } |
|
439 | + |
|
440 | + $this->form_params['database'] = array(); |
|
441 | + |
|
442 | + if (isset($params->table_params)) { |
|
443 | + foreach ($params->table_params as $param) { |
|
444 | + $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id); |
|
445 | + $this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array( |
|
446 | + 'POST', |
|
447 | + 'database filter' |
|
448 | + )); |
|
449 | + } |
|
450 | + } |
|
451 | + |
|
452 | + $this->form_params['excluded_files'] = array(); |
|
453 | + if (isset($params->files_params)) { |
|
454 | + foreach ($params->files_params as $param) { |
|
455 | + $this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
|
456 | + } |
|
457 | + |
|
458 | + $unique_exclude_files = array(); |
|
459 | + |
|
460 | + foreach ($params->files_params as $key => $param) { |
|
461 | + if (!in_array($param->parent, $this->form_params['excluded_files'])) { |
|
462 | + //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
|
463 | + $unique_exclude_files[] = $param->id; |
|
464 | + $this->logger->debug("Adding file filter " . $param->id . "\n", array( |
|
465 | + 'POST', |
|
466 | + 'exclude files filter' |
|
467 | + )); |
|
468 | + } |
|
469 | + } |
|
470 | + $this->form_params['excluded_files'] = (array)$unique_exclude_files; |
|
471 | + |
|
472 | + } |
|
473 | + |
|
474 | + //$this->form_params['excluded_files'] = array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default); |
|
475 | + |
|
476 | + if (isset($params->extra)) { |
|
477 | + foreach ($params->extra as $key => $value) { |
|
478 | + $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
|
479 | + } |
|
480 | + } |
|
481 | + |
|
482 | + if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) { |
|
483 | + $this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']); |
|
484 | + $this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']); |
|
485 | + } |
|
486 | + |
|
487 | + return $this->xcloner_settings->get_hash(); |
|
488 | + } |
|
489 | + |
|
490 | + /* |
|
491 | 491 | * |
492 | 492 | * Get file list for tree view API |
493 | 493 | * |
494 | 494 | */ |
495 | - public function get_file_system_action() |
|
496 | - { |
|
497 | - $this->check_access(); |
|
498 | - |
|
499 | - $folder = $this->xcloner_sanitization->sanitize_input_as_relative_path($_POST['id']); |
|
500 | - |
|
501 | - $data = array(); |
|
502 | - |
|
503 | - if ($folder == "#") { |
|
504 | - |
|
505 | - $folder = "/"; |
|
506 | - $data[] = array( |
|
507 | - 'id' => $folder, |
|
508 | - 'parent' => '#', |
|
509 | - 'text' => $this->xcloner_settings->get_xcloner_start_path(), |
|
510 | - //'children' => true, |
|
511 | - 'state' => array('selected' => false, 'opened' => true), |
|
512 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png" |
|
513 | - ); |
|
514 | - } |
|
515 | - |
|
516 | - try { |
|
517 | - $files = $this->xcloner_file_system->list_directory($folder); |
|
518 | - } catch (Exception $e) { |
|
519 | - |
|
520 | - print $e->getMessage(); |
|
521 | - $this->logger->error($e->getMessage()); |
|
522 | - |
|
523 | - return; |
|
524 | - } |
|
525 | - |
|
526 | - $type = array(); |
|
527 | - foreach ($files as $key => $row) { |
|
528 | - $type[$key] = $row['type']; |
|
529 | - } |
|
530 | - array_multisort($type, SORT_ASC, $files); |
|
531 | - |
|
532 | - foreach ($files as $file) { |
|
533 | - $children = false; |
|
534 | - $text = $file['basename']; |
|
535 | - |
|
536 | - if ($file['type'] == "dir") { |
|
537 | - $children = true; |
|
538 | - } else { |
|
539 | - $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")"; |
|
540 | - } |
|
541 | - |
|
542 | - if ($this->xcloner_file_system->is_excluded($file)) { |
|
543 | - $selected = true; |
|
544 | - } else { |
|
545 | - $selected = false; |
|
546 | - } |
|
547 | - |
|
548 | - $data[] = array( |
|
549 | - 'id' => $file['path'], |
|
550 | - 'parent' => $folder, |
|
551 | - 'text' => $text, |
|
552 | - //'title' => "test", |
|
553 | - 'children' => $children, |
|
554 | - 'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected), |
|
555 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'], |
|
556 | - 0, 1)) . ".png" |
|
557 | - ); |
|
558 | - } |
|
559 | - |
|
560 | - |
|
561 | - return $this->send_response($data, 0); |
|
562 | - } |
|
563 | - |
|
564 | - /* |
|
495 | + public function get_file_system_action() |
|
496 | + { |
|
497 | + $this->check_access(); |
|
498 | + |
|
499 | + $folder = $this->xcloner_sanitization->sanitize_input_as_relative_path($_POST['id']); |
|
500 | + |
|
501 | + $data = array(); |
|
502 | + |
|
503 | + if ($folder == "#") { |
|
504 | + |
|
505 | + $folder = "/"; |
|
506 | + $data[] = array( |
|
507 | + 'id' => $folder, |
|
508 | + 'parent' => '#', |
|
509 | + 'text' => $this->xcloner_settings->get_xcloner_start_path(), |
|
510 | + //'children' => true, |
|
511 | + 'state' => array('selected' => false, 'opened' => true), |
|
512 | + 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png" |
|
513 | + ); |
|
514 | + } |
|
515 | + |
|
516 | + try { |
|
517 | + $files = $this->xcloner_file_system->list_directory($folder); |
|
518 | + } catch (Exception $e) { |
|
519 | + |
|
520 | + print $e->getMessage(); |
|
521 | + $this->logger->error($e->getMessage()); |
|
522 | + |
|
523 | + return; |
|
524 | + } |
|
525 | + |
|
526 | + $type = array(); |
|
527 | + foreach ($files as $key => $row) { |
|
528 | + $type[$key] = $row['type']; |
|
529 | + } |
|
530 | + array_multisort($type, SORT_ASC, $files); |
|
531 | + |
|
532 | + foreach ($files as $file) { |
|
533 | + $children = false; |
|
534 | + $text = $file['basename']; |
|
535 | + |
|
536 | + if ($file['type'] == "dir") { |
|
537 | + $children = true; |
|
538 | + } else { |
|
539 | + $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")"; |
|
540 | + } |
|
541 | + |
|
542 | + if ($this->xcloner_file_system->is_excluded($file)) { |
|
543 | + $selected = true; |
|
544 | + } else { |
|
545 | + $selected = false; |
|
546 | + } |
|
547 | + |
|
548 | + $data[] = array( |
|
549 | + 'id' => $file['path'], |
|
550 | + 'parent' => $folder, |
|
551 | + 'text' => $text, |
|
552 | + //'title' => "test", |
|
553 | + 'children' => $children, |
|
554 | + 'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected), |
|
555 | + 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'], |
|
556 | + 0, 1)) . ".png" |
|
557 | + ); |
|
558 | + } |
|
559 | + |
|
560 | + |
|
561 | + return $this->send_response($data, 0); |
|
562 | + } |
|
563 | + |
|
564 | + /* |
|
565 | 565 | * |
566 | 566 | * Get databases/tables list for frontend tree display API |
567 | 567 | * |
568 | 568 | */ |
569 | - public function get_database_tables_action() |
|
570 | - { |
|
571 | - $this->check_access(); |
|
572 | - |
|
573 | - $database = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['id']); |
|
574 | - |
|
575 | - $data = array(); |
|
576 | - |
|
577 | - $xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables'); |
|
578 | - |
|
579 | - if ($database == "#") { |
|
580 | - try { |
|
581 | - $return = $this->xcloner_database->get_all_databases(); |
|
582 | - } catch (Exception $e) { |
|
583 | - $this->logger->error($e->getMessage()); |
|
584 | - } |
|
585 | - |
|
586 | - foreach ($return as $database) { |
|
587 | - if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) { |
|
588 | - continue; |
|
589 | - } |
|
590 | - |
|
591 | - $state = array(); |
|
592 | - |
|
593 | - if ($database['name'] == $this->xcloner_settings->get_db_database()) { |
|
594 | - $state['selected'] = true; |
|
595 | - if ($database['num_tables'] < 25) { |
|
596 | - $state['opened'] = false; |
|
597 | - } |
|
598 | - } |
|
599 | - |
|
600 | - $data[] = array( |
|
601 | - 'id' => $database['name'], |
|
602 | - 'parent' => '#', |
|
603 | - 'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")", |
|
604 | - 'children' => true, |
|
605 | - 'state' => $state, |
|
606 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png" |
|
607 | - ); |
|
608 | - } |
|
609 | - |
|
610 | - } else { |
|
611 | - |
|
612 | - try { |
|
613 | - $return = $this->xcloner_database->list_tables($database, "", 1); |
|
614 | - } catch (Exception $e) { |
|
615 | - $this->logger->error($e->getMessage()); |
|
616 | - } |
|
617 | - |
|
618 | - foreach ($return as $table) { |
|
619 | - $state = array(); |
|
620 | - |
|
621 | - if ($xcloner_backup_only_wp_tables and !stristr($table['name'], |
|
622 | - $this->xcloner_settings->get_table_prefix())) { |
|
623 | - continue; |
|
624 | - } |
|
625 | - |
|
626 | - if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) { |
|
627 | - $state = array('selected' => true); |
|
628 | - } |
|
629 | - |
|
630 | - $data[] = array( |
|
631 | - 'id' => $database . "." . $table['name'], |
|
632 | - 'parent' => $database, |
|
633 | - 'text' => $table['name'] . " (" . (int)$table['records'] . ")", |
|
634 | - 'children' => false, |
|
635 | - 'state' => $state, |
|
636 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png" |
|
637 | - ); |
|
638 | - } |
|
639 | - } |
|
640 | - |
|
641 | - return $this->send_response($data, 0); |
|
642 | - } |
|
643 | - |
|
644 | - /* |
|
569 | + public function get_database_tables_action() |
|
570 | + { |
|
571 | + $this->check_access(); |
|
572 | + |
|
573 | + $database = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['id']); |
|
574 | + |
|
575 | + $data = array(); |
|
576 | + |
|
577 | + $xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables'); |
|
578 | + |
|
579 | + if ($database == "#") { |
|
580 | + try { |
|
581 | + $return = $this->xcloner_database->get_all_databases(); |
|
582 | + } catch (Exception $e) { |
|
583 | + $this->logger->error($e->getMessage()); |
|
584 | + } |
|
585 | + |
|
586 | + foreach ($return as $database) { |
|
587 | + if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) { |
|
588 | + continue; |
|
589 | + } |
|
590 | + |
|
591 | + $state = array(); |
|
592 | + |
|
593 | + if ($database['name'] == $this->xcloner_settings->get_db_database()) { |
|
594 | + $state['selected'] = true; |
|
595 | + if ($database['num_tables'] < 25) { |
|
596 | + $state['opened'] = false; |
|
597 | + } |
|
598 | + } |
|
599 | + |
|
600 | + $data[] = array( |
|
601 | + 'id' => $database['name'], |
|
602 | + 'parent' => '#', |
|
603 | + 'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")", |
|
604 | + 'children' => true, |
|
605 | + 'state' => $state, |
|
606 | + 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png" |
|
607 | + ); |
|
608 | + } |
|
609 | + |
|
610 | + } else { |
|
611 | + |
|
612 | + try { |
|
613 | + $return = $this->xcloner_database->list_tables($database, "", 1); |
|
614 | + } catch (Exception $e) { |
|
615 | + $this->logger->error($e->getMessage()); |
|
616 | + } |
|
617 | + |
|
618 | + foreach ($return as $table) { |
|
619 | + $state = array(); |
|
620 | + |
|
621 | + if ($xcloner_backup_only_wp_tables and !stristr($table['name'], |
|
622 | + $this->xcloner_settings->get_table_prefix())) { |
|
623 | + continue; |
|
624 | + } |
|
625 | + |
|
626 | + if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) { |
|
627 | + $state = array('selected' => true); |
|
628 | + } |
|
629 | + |
|
630 | + $data[] = array( |
|
631 | + 'id' => $database . "." . $table['name'], |
|
632 | + 'parent' => $database, |
|
633 | + 'text' => $table['name'] . " (" . (int)$table['records'] . ")", |
|
634 | + 'children' => false, |
|
635 | + 'state' => $state, |
|
636 | + 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png" |
|
637 | + ); |
|
638 | + } |
|
639 | + } |
|
640 | + |
|
641 | + return $this->send_response($data, 0); |
|
642 | + } |
|
643 | + |
|
644 | + /* |
|
645 | 645 | * |
646 | 646 | * Get schedule by id API |
647 | 647 | * |
648 | 648 | */ |
649 | - public function get_schedule_by_id() |
|
650 | - { |
|
651 | - $this->check_access(); |
|
649 | + public function get_schedule_by_id() |
|
650 | + { |
|
651 | + $this->check_access(); |
|
652 | 652 | |
653 | - $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
|
654 | - $scheduler = $this->xcloner_scheduler; |
|
655 | - $data = $scheduler->get_schedule_by_id($schedule_id); |
|
653 | + $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
|
654 | + $scheduler = $this->xcloner_scheduler; |
|
655 | + $data = $scheduler->get_schedule_by_id($schedule_id); |
|
656 | 656 | |
657 | - $data['start_at'] = date("Y-m-d H:i", |
|
658 | - strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
659 | - if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") { |
|
660 | - $data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date)); |
|
661 | - } |
|
657 | + $data['start_at'] = date("Y-m-d H:i", |
|
658 | + strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
659 | + if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") { |
|
660 | + $data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date)); |
|
661 | + } |
|
662 | 662 | |
663 | - return $this->send_response($data); |
|
664 | - } |
|
663 | + return $this->send_response($data); |
|
664 | + } |
|
665 | 665 | |
666 | - /* |
|
666 | + /* |
|
667 | 667 | * |
668 | 668 | * Get Schedule list API |
669 | 669 | * |
670 | 670 | */ |
671 | - public function get_scheduler_list() |
|
672 | - { |
|
673 | - $this->check_access(); |
|
671 | + public function get_scheduler_list() |
|
672 | + { |
|
673 | + $this->check_access(); |
|
674 | 674 | |
675 | - $scheduler = $this->xcloner_scheduler; |
|
676 | - $data = $scheduler->get_scheduler_list(); |
|
677 | - $return['data'] = array(); |
|
675 | + $scheduler = $this->xcloner_scheduler; |
|
676 | + $data = $scheduler->get_scheduler_list(); |
|
677 | + $return['data'] = array(); |
|
678 | 678 | |
679 | - foreach ($data as $res) { |
|
680 | - $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
|
679 | + foreach ($data as $res) { |
|
680 | + $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
|
681 | 681 | <a href=\"#" . $res->id . "\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
682 | - if ($res->status) { |
|
683 | - $status = '<i class="material-icons active status">timer</i>'; |
|
684 | - } else { |
|
685 | - $status = '<i class="material-icons status inactive">timer_off</i>'; |
|
686 | - } |
|
687 | - |
|
688 | - $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id)); |
|
689 | - |
|
690 | - $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time); |
|
691 | - |
|
692 | - $remote_storage = $res->remote_storage; |
|
693 | - |
|
694 | - if (!$next_run_time >= time()) { |
|
695 | - $next_run = " "; |
|
696 | - } |
|
697 | - |
|
698 | - if (trim($next_run)) { |
|
699 | - $date_text = date(get_option('date_format') . " " . get_option('time_format'), |
|
700 | - $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
701 | - |
|
702 | - if ($next_run_time >= time()) { |
|
703 | - $next_run = "in " . human_time_diff($next_run_time, time()); |
|
704 | - } else { |
|
705 | - $next_run = __("executed", 'xcloner-backup-and-restore'); |
|
706 | - } |
|
707 | - |
|
708 | - $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>"; |
|
709 | - //$next_run .=" ($date_text)"; |
|
710 | - } |
|
711 | - |
|
712 | - $backup_text = ""; |
|
713 | - $backup_size = ""; |
|
714 | - $backup_time = ""; |
|
715 | - |
|
716 | - if ($res->last_backup) { |
|
717 | - if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) { |
|
718 | - $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup); |
|
719 | - $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup)); |
|
720 | - $backup_time = date(get_option('date_format') . " " . get_option('time_format'), |
|
721 | - $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
722 | - } |
|
723 | - |
|
724 | - $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>"; |
|
725 | - } |
|
726 | - |
|
727 | - $schedules = wp_get_schedules(); |
|
728 | - |
|
729 | - if (isset($schedules[$res->recurrence])) { |
|
730 | - $res->recurrence = $schedules[$res->recurrence]['display']; |
|
731 | - } |
|
732 | - |
|
733 | - $return['data'][] = array( |
|
734 | - $res->id, |
|
735 | - $res->name, |
|
736 | - $res->recurrence,/*$res->start_at,*/ |
|
737 | - $next_run, |
|
738 | - $remote_storage, |
|
739 | - $backup_text, |
|
740 | - $status, |
|
741 | - $action |
|
742 | - ); |
|
743 | - } |
|
744 | - |
|
745 | - return $this->send_response($return, 0); |
|
746 | - } |
|
747 | - |
|
748 | - /* |
|
682 | + if ($res->status) { |
|
683 | + $status = '<i class="material-icons active status">timer</i>'; |
|
684 | + } else { |
|
685 | + $status = '<i class="material-icons status inactive">timer_off</i>'; |
|
686 | + } |
|
687 | + |
|
688 | + $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id)); |
|
689 | + |
|
690 | + $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time); |
|
691 | + |
|
692 | + $remote_storage = $res->remote_storage; |
|
693 | + |
|
694 | + if (!$next_run_time >= time()) { |
|
695 | + $next_run = " "; |
|
696 | + } |
|
697 | + |
|
698 | + if (trim($next_run)) { |
|
699 | + $date_text = date(get_option('date_format') . " " . get_option('time_format'), |
|
700 | + $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
701 | + |
|
702 | + if ($next_run_time >= time()) { |
|
703 | + $next_run = "in " . human_time_diff($next_run_time, time()); |
|
704 | + } else { |
|
705 | + $next_run = __("executed", 'xcloner-backup-and-restore'); |
|
706 | + } |
|
707 | + |
|
708 | + $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>"; |
|
709 | + //$next_run .=" ($date_text)"; |
|
710 | + } |
|
711 | + |
|
712 | + $backup_text = ""; |
|
713 | + $backup_size = ""; |
|
714 | + $backup_time = ""; |
|
715 | + |
|
716 | + if ($res->last_backup) { |
|
717 | + if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) { |
|
718 | + $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup); |
|
719 | + $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup)); |
|
720 | + $backup_time = date(get_option('date_format') . " " . get_option('time_format'), |
|
721 | + $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
722 | + } |
|
723 | + |
|
724 | + $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>"; |
|
725 | + } |
|
726 | + |
|
727 | + $schedules = wp_get_schedules(); |
|
728 | + |
|
729 | + if (isset($schedules[$res->recurrence])) { |
|
730 | + $res->recurrence = $schedules[$res->recurrence]['display']; |
|
731 | + } |
|
732 | + |
|
733 | + $return['data'][] = array( |
|
734 | + $res->id, |
|
735 | + $res->name, |
|
736 | + $res->recurrence,/*$res->start_at,*/ |
|
737 | + $next_run, |
|
738 | + $remote_storage, |
|
739 | + $backup_text, |
|
740 | + $status, |
|
741 | + $action |
|
742 | + ); |
|
743 | + } |
|
744 | + |
|
745 | + return $this->send_response($return, 0); |
|
746 | + } |
|
747 | + |
|
748 | + /* |
|
749 | 749 | * |
750 | 750 | * Delete Schedule by ID API |
751 | 751 | * |
752 | 752 | */ |
753 | - public function delete_schedule_by_id() |
|
754 | - { |
|
755 | - $this->check_access(); |
|
753 | + public function delete_schedule_by_id() |
|
754 | + { |
|
755 | + $this->check_access(); |
|
756 | 756 | |
757 | - $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
|
758 | - $scheduler = $this->xcloner_scheduler; |
|
759 | - $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id); |
|
757 | + $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
|
758 | + $scheduler = $this->xcloner_scheduler; |
|
759 | + $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id); |
|
760 | 760 | |
761 | - return $this->send_response($data); |
|
762 | - } |
|
761 | + return $this->send_response($data); |
|
762 | + } |
|
763 | 763 | |
764 | - /* |
|
764 | + /* |
|
765 | 765 | * |
766 | 766 | * Delete backup by name from the storage path |
767 | 767 | * |
768 | 768 | */ |
769 | - public function delete_backup_by_name() |
|
770 | - { |
|
771 | - $this->check_access(); |
|
769 | + public function delete_backup_by_name() |
|
770 | + { |
|
771 | + $this->check_access(); |
|
772 | + |
|
773 | + $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']); |
|
774 | + $storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_selection']); |
|
775 | + |
|
776 | + $data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name, $storage_selection); |
|
777 | + |
|
778 | + return $this->send_response($data); |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * API Incremental Backup Encryption Method |
|
783 | + */ |
|
784 | + public function backup_encryption() |
|
785 | + { |
|
786 | + $this->check_access(); |
|
787 | + |
|
788 | + $backup_parts = array(); |
|
789 | + $return = array(); |
|
772 | 790 | |
773 | - $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_POST['name']); |
|
774 | - $storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_selection']); |
|
775 | 791 | |
776 | - $data['finished'] = $this->xcloner_file_system->delete_backup_by_name($backup_name, $storage_selection); |
|
792 | + if (isset($_POST['data'])) { |
|
793 | + $params = json_decode(stripslashes($_POST['data'])); |
|
794 | + |
|
795 | + $this->process_params($params); |
|
796 | + $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($this->form_params['extra']['backup_parent']); |
|
797 | + |
|
798 | + if(isset($this->form_params['extra']['start'])) { |
|
799 | + $start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']); |
|
800 | + }else{ |
|
801 | + $start = 0; |
|
802 | + } |
|
803 | + |
|
804 | + if(isset($this->form_params['extra']['iv'])) { |
|
805 | + $iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']); |
|
806 | + }else{ |
|
807 | + $iv = ""; |
|
808 | + } |
|
809 | + |
|
810 | + if(isset($this->form_params['extra']['part'])) { |
|
811 | + $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']); |
|
812 | + }else{ |
|
813 | + $return['part'] = 0; |
|
814 | + } |
|
777 | 815 | |
778 | - return $this->send_response($data); |
|
779 | - } |
|
816 | + }else{ |
|
817 | + $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
818 | + $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
|
819 | + $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
|
820 | + $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
821 | + } |
|
780 | 822 | |
781 | - /** |
|
782 | - * API Incremental Backup Encryption Method |
|
783 | - */ |
|
784 | - public function backup_encryption() |
|
785 | - { |
|
786 | - $this->check_access(); |
|
787 | - |
|
788 | - $backup_parts = array(); |
|
789 | - $return = array(); |
|
790 | - |
|
791 | - |
|
792 | - if (isset($_POST['data'])) { |
|
793 | - $params = json_decode(stripslashes($_POST['data'])); |
|
794 | - |
|
795 | - $this->process_params($params); |
|
796 | - $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($this->form_params['extra']['backup_parent']); |
|
797 | - |
|
798 | - if(isset($this->form_params['extra']['start'])) { |
|
799 | - $start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']); |
|
800 | - }else{ |
|
801 | - $start = 0; |
|
802 | - } |
|
803 | - |
|
804 | - if(isset($this->form_params['extra']['iv'])) { |
|
805 | - $iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']); |
|
806 | - }else{ |
|
807 | - $iv = ""; |
|
808 | - } |
|
809 | - |
|
810 | - if(isset($this->form_params['extra']['part'])) { |
|
811 | - $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']); |
|
812 | - }else{ |
|
813 | - $return['part'] = 0; |
|
814 | - } |
|
815 | - |
|
816 | - }else{ |
|
817 | - $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
818 | - $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
|
819 | - $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
|
820 | - $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
821 | - } |
|
822 | - |
|
823 | - $backup_file = $source_backup_file; |
|
824 | - |
|
825 | - if ($this->xcloner_file_system->is_multipart($backup_file)) { |
|
826 | - $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file); |
|
827 | - $backup_file = $backup_parts[$return['part']]; |
|
828 | - } |
|
829 | - |
|
830 | - $return['processing_file'] = $backup_file; |
|
831 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
832 | - |
|
833 | - try { |
|
834 | - $this->logger->info(json_encode($_POST)); |
|
835 | - $this->logger->info($iv); |
|
836 | - $return = array_merge($return, |
|
837 | - $this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv))); |
|
838 | - }catch(\Exception $e){ |
|
839 | - $return['error'] = true; |
|
840 | - $return['message'] = $e->getMessage(); |
|
841 | - $return['error_message'] = $e->getMessage(); |
|
842 | - } |
|
843 | - |
|
844 | - //echo strlen($return['iv']);exit; |
|
845 | - |
|
846 | - if($return['finished']) { |
|
847 | - if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
|
848 | - $return['start'] = 0; |
|
849 | - |
|
850 | - ++$return['part']; |
|
851 | - |
|
852 | - if ($return['part'] < sizeof($backup_parts)) { |
|
853 | - $return['finished'] = 0; |
|
854 | - } |
|
855 | - |
|
856 | - } |
|
857 | - } |
|
858 | - |
|
859 | - if (isset($_POST['data'])) { |
|
860 | - $return['extra'] = array_merge($this->form_params['extra'], $return); |
|
861 | - } |
|
862 | - |
|
863 | - $this->send_response($return, 0); |
|
864 | - } |
|
865 | - |
|
866 | - /** |
|
867 | - * API Incremental Backup Decryption Method |
|
868 | - */ |
|
869 | - public function backup_decryption() |
|
870 | - { |
|
871 | - $this->check_access(); |
|
823 | + $backup_file = $source_backup_file; |
|
824 | + |
|
825 | + if ($this->xcloner_file_system->is_multipart($backup_file)) { |
|
826 | + $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file); |
|
827 | + $backup_file = $backup_parts[$return['part']]; |
|
828 | + } |
|
829 | + |
|
830 | + $return['processing_file'] = $backup_file; |
|
831 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
832 | + |
|
833 | + try { |
|
834 | + $this->logger->info(json_encode($_POST)); |
|
835 | + $this->logger->info($iv); |
|
836 | + $return = array_merge($return, |
|
837 | + $this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv))); |
|
838 | + }catch(\Exception $e){ |
|
839 | + $return['error'] = true; |
|
840 | + $return['message'] = $e->getMessage(); |
|
841 | + $return['error_message'] = $e->getMessage(); |
|
842 | + } |
|
872 | 843 | |
873 | - $backup_parts = array(); |
|
874 | - $return = array(); |
|
844 | + //echo strlen($return['iv']);exit; |
|
875 | 845 | |
876 | - $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
877 | - $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
|
878 | - $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
|
879 | - $decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']);; |
|
880 | - $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
846 | + if($return['finished']) { |
|
847 | + if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
|
848 | + $return['start'] = 0; |
|
881 | 849 | |
882 | - $backup_file = $source_backup_file; |
|
850 | + ++$return['part']; |
|
883 | 851 | |
884 | - if ($this->xcloner_file_system->is_multipart($backup_file)) { |
|
885 | - $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file); |
|
886 | - $backup_file = $backup_parts[$return['part']]; |
|
887 | - } |
|
852 | + if ($return['part'] < sizeof($backup_parts)) { |
|
853 | + $return['finished'] = 0; |
|
854 | + } |
|
888 | 855 | |
889 | - $return['processing_file'] = $backup_file; |
|
890 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
856 | + } |
|
857 | + } |
|
891 | 858 | |
892 | - try { |
|
893 | - $return = array_merge($return, |
|
894 | - $this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv))); |
|
895 | - }catch(\Exception $e){ |
|
896 | - $return['error'] = true; |
|
897 | - $return['message'] = $e->getMessage(); |
|
898 | - } |
|
859 | + if (isset($_POST['data'])) { |
|
860 | + $return['extra'] = array_merge($this->form_params['extra'], $return); |
|
861 | + } |
|
899 | 862 | |
900 | - if($return['finished']) { |
|
901 | - if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
|
902 | - $return['start'] = 0; |
|
863 | + $this->send_response($return, 0); |
|
864 | + } |
|
903 | 865 | |
904 | - ++$return['part']; |
|
866 | + /** |
|
867 | + * API Incremental Backup Decryption Method |
|
868 | + */ |
|
869 | + public function backup_decryption() |
|
870 | + { |
|
871 | + $this->check_access(); |
|
905 | 872 | |
906 | - if ($return['part'] < sizeof($backup_parts)) { |
|
907 | - $return['finished'] = 0; |
|
908 | - } |
|
873 | + $backup_parts = array(); |
|
874 | + $return = array(); |
|
909 | 875 | |
910 | - } |
|
911 | - } |
|
876 | + $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
877 | + $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
|
878 | + $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
|
879 | + $decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']);; |
|
880 | + $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
881 | + |
|
882 | + $backup_file = $source_backup_file; |
|
912 | 883 | |
913 | - $this->send_response($return, 0); |
|
914 | - } |
|
884 | + if ($this->xcloner_file_system->is_multipart($backup_file)) { |
|
885 | + $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file); |
|
886 | + $backup_file = $backup_parts[$return['part']]; |
|
887 | + } |
|
915 | 888 | |
916 | - public function get_manage_backups_list() { |
|
889 | + $return['processing_file'] = $backup_file; |
|
890 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
917 | 891 | |
918 | - $storage_selection = ""; |
|
892 | + try { |
|
893 | + $return = array_merge($return, |
|
894 | + $this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv))); |
|
895 | + }catch(\Exception $e){ |
|
896 | + $return['error'] = true; |
|
897 | + $return['message'] = $e->getMessage(); |
|
898 | + } |
|
899 | + |
|
900 | + if($return['finished']) { |
|
901 | + if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
|
902 | + $return['start'] = 0; |
|
919 | 903 | |
920 | - if (isset($_GET['storage_selection']) and $_GET['storage_selection']) { |
|
921 | - $storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']); |
|
922 | - } |
|
923 | - $available_storages = $this->xcloner_remote_storage->get_available_storages(); |
|
904 | + ++$return['part']; |
|
905 | + |
|
906 | + if ($return['part'] < sizeof($backup_parts)) { |
|
907 | + $return['finished'] = 0; |
|
908 | + } |
|
924 | 909 | |
925 | - $backup_list = $this->xcloner_file_system->get_backup_archives_list($storage_selection); |
|
926 | - $return = array(); |
|
910 | + } |
|
911 | + } |
|
927 | 912 | |
928 | - $i = -1; |
|
929 | - foreach ($backup_list as $file_info):?> |
|
913 | + $this->send_response($return, 0); |
|
914 | + } |
|
915 | + |
|
916 | + public function get_manage_backups_list() { |
|
917 | + |
|
918 | + $storage_selection = ""; |
|
919 | + |
|
920 | + if (isset($_GET['storage_selection']) and $_GET['storage_selection']) { |
|
921 | + $storage_selection = $this->xcloner_sanitization->sanitize_input_as_string($_GET['storage_selection']); |
|
922 | + } |
|
923 | + $available_storages = $this->xcloner_remote_storage->get_available_storages(); |
|
924 | + |
|
925 | + $backup_list = $this->xcloner_file_system->get_backup_archives_list($storage_selection); |
|
926 | + $return = array(); |
|
927 | + |
|
928 | + $i = -1; |
|
929 | + foreach ($backup_list as $file_info):?> |
|
930 | 930 | <?php |
931 | - if ($storage_selection == "gdrive") { |
|
932 | - $file_info['path'] = $file_info['filename'] . "." . $file_info['extension']; |
|
933 | - } |
|
934 | - $file_exists_on_local_storage = true; |
|
935 | - |
|
936 | - if ($storage_selection) { |
|
937 | - if (!$this->xcloner_file_system->get_storage_filesystem()->has($file_info['path'])) { |
|
938 | - $file_exists_on_local_storage = false; |
|
939 | - } |
|
940 | - } |
|
941 | - |
|
942 | - ?> |
|
931 | + if ($storage_selection == "gdrive") { |
|
932 | + $file_info['path'] = $file_info['filename'] . "." . $file_info['extension']; |
|
933 | + } |
|
934 | + $file_exists_on_local_storage = true; |
|
935 | + |
|
936 | + if ($storage_selection) { |
|
937 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($file_info['path'])) { |
|
938 | + $file_exists_on_local_storage = false; |
|
939 | + } |
|
940 | + } |
|
941 | + |
|
942 | + ?> |
|
943 | 943 | <?php if (!isset($file_info['parent'])): ?> |
944 | 944 | |
945 | 945 | <?php ob_start(); ?> |
@@ -949,21 +949,21 @@ discard block |
||
949 | 949 | <label for="checkbox_<?php echo $i ?>"> </label> |
950 | 950 | </p> |
951 | 951 | <?php |
952 | - $return['data'][$i][] = ob_get_contents(); |
|
953 | - ob_end_clean(); |
|
954 | - ?> |
|
952 | + $return['data'][$i][] = ob_get_contents(); |
|
953 | + ob_end_clean(); |
|
954 | + ?> |
|
955 | 955 | |
956 | 956 | <?php ob_start(); ?> |
957 | 957 | <span class=""><?php echo $file_info['path'] ?></span> |
958 | 958 | <?php if (!$file_exists_on_local_storage): ?> |
959 | 959 | <a href="#" |
960 | 960 | title="<?php echo __("File does not exists on local storage", |
961 | - "xcloner-backup-and-restore") ?>"><i |
|
961 | + "xcloner-backup-and-restore") ?>"><i |
|
962 | 962 | class="material-icons backup_warning">warning</i></a> |
963 | 963 | <?php endif ?> |
964 | 964 | <?php |
965 | - if (isset($file_info['childs']) and is_array($file_info['childs'])): |
|
966 | - ?> |
|
965 | + if (isset($file_info['childs']) and is_array($file_info['childs'])): |
|
966 | + ?> |
|
967 | 967 | <a href="#" title="expand" class="expand-multipart add"><i |
968 | 968 | class="material-icons">add</i></a> |
969 | 969 | <a href="#" title="collapse" class="expand-multipart remove"><i class="material-icons">remove</i></a> |
@@ -972,17 +972,17 @@ discard block |
||
972 | 972 | <li> |
973 | 973 | <?php echo $child[0] ?> (<?php echo size_format($child[2]) ?>) |
974 | 974 | <?php |
975 | - $child_exists_on_local_storage = true; |
|
976 | - if ($storage_selection) { |
|
977 | - if (!$this->xcloner_file_system->get_storage_filesystem()->has($child[0])) { |
|
978 | - $child_exists_on_local_storage = false; |
|
979 | - } |
|
980 | - } |
|
981 | - ?> |
|
975 | + $child_exists_on_local_storage = true; |
|
976 | + if ($storage_selection) { |
|
977 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($child[0])) { |
|
978 | + $child_exists_on_local_storage = false; |
|
979 | + } |
|
980 | + } |
|
981 | + ?> |
|
982 | 982 | <?php if (!$child_exists_on_local_storage): ?> |
983 | 983 | <a href="#" |
984 | 984 | title="<?php echo __("File does not exists on local storage", |
985 | - "xcloner-backup-and-restore") ?>"><i |
|
985 | + "xcloner-backup-and-restore") ?>"><i |
|
986 | 986 | class="material-icons backup_warning">warning</i></a> |
987 | 987 | <?php endif ?> |
988 | 988 | <?php if (!$storage_selection) : ?> |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | <?php else: ?> |
998 | 998 | <a href="#<?php echo $child[0] ?>" class="list-backup-content" |
999 | 999 | title="<?php echo __('List Backup Content', |
1000 | - 'xcloner-backup-and-restore') ?>"><i |
|
1000 | + 'xcloner-backup-and-restore') ?>"><i |
|
1001 | 1001 | class="material-icons">folder_open</i></a> |
1002 | 1002 | |
1003 | 1003 | <a href="#<?php echo $child[0] ?>" class="backup-encryption" |
@@ -1009,7 +1009,7 @@ discard block |
||
1009 | 1009 | <?php elseif ($storage_selection != "gdrive" && !$this->xcloner_file_system->get_storage_filesystem()->has($child[0])): ?> |
1010 | 1010 | <a href="#<?php echo $child[0] ?>" class="copy-remote-to-local" |
1011 | 1011 | title="<?php echo __('Push Backup To Local Storage', |
1012 | - 'xcloner-backup-and-restore') ?>"><i |
|
1012 | + 'xcloner-backup-and-restore') ?>"><i |
|
1013 | 1013 | class="material-icons">file_upload</i></a> |
1014 | 1014 | <?php endif ?> |
1015 | 1015 | </li> |
@@ -1017,24 +1017,24 @@ discard block |
||
1017 | 1017 | </ul> |
1018 | 1018 | <?php endif; ?> |
1019 | 1019 | <?php |
1020 | - $return['data'][$i][] = ob_get_contents(); |
|
1021 | - ob_end_clean(); |
|
1022 | - ?> |
|
1020 | + $return['data'][$i][] = ob_get_contents(); |
|
1021 | + ob_end_clean(); |
|
1022 | + ?> |
|
1023 | 1023 | <?php ob_start(); ?> |
1024 | 1024 | <?php if (isset($file_info['timestamp'])) |
1025 | - echo date("Y-m-d H:i", $file_info['timestamp']) |
|
1026 | - ?> |
|
1025 | + echo date("Y-m-d H:i", $file_info['timestamp']) |
|
1026 | + ?> |
|
1027 | 1027 | <?php |
1028 | - $return['data'][$i][] = ob_get_contents(); |
|
1029 | - ob_end_clean(); |
|
1030 | - ?> |
|
1028 | + $return['data'][$i][] = ob_get_contents(); |
|
1029 | + ob_end_clean(); |
|
1030 | + ?> |
|
1031 | 1031 | |
1032 | 1032 | <?php ob_start(); ?> |
1033 | 1033 | <?php echo size_format($file_info['size']) ?> |
1034 | 1034 | <?php |
1035 | - $return['data'][$i][] = ob_get_contents(); |
|
1036 | - ob_end_clean(); |
|
1037 | - ?> |
|
1035 | + $return['data'][$i][] = ob_get_contents(); |
|
1036 | + ob_end_clean(); |
|
1037 | + ?> |
|
1038 | 1038 | |
1039 | 1039 | <?php ob_start(); ?> |
1040 | 1040 | <?php if (!$storage_selection): ?> |
@@ -1045,14 +1045,14 @@ discard block |
||
1045 | 1045 | <?php if (sizeof($available_storages)): ?> |
1046 | 1046 | <a href="#<?php echo $file_info['basename'] ?>" class="cloud-upload" |
1047 | 1047 | title="<?php echo __('Send Backup To Remote Storage', |
1048 | - 'xcloner-backup-and-restore') ?>"><i |
|
1048 | + 'xcloner-backup-and-restore') ?>"><i |
|
1049 | 1049 | class="material-icons">cloud_upload</i></a> |
1050 | 1050 | <?php endif ?> |
1051 | 1051 | <?php |
1052 | - $basename = $file_info['basename']; |
|
1053 | - if(isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1054 | - $basename = $file_info['childs'][0][0]; |
|
1055 | - ?> |
|
1052 | + $basename = $file_info['basename']; |
|
1053 | + if(isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1054 | + $basename = $file_info['childs'][0][0]; |
|
1055 | + ?> |
|
1056 | 1056 | <?php if($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
1057 | 1057 | <a href="#<?php echo $file_info['basename'] ?>" class="backup-decryption" |
1058 | 1058 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
@@ -1081,193 +1081,193 @@ discard block |
||
1081 | 1081 | <?php endif ?> |
1082 | 1082 | |
1083 | 1083 | <?php |
1084 | - $return['data'][$i][] = ob_get_contents(); |
|
1085 | - ob_end_clean(); ?> |
|
1084 | + $return['data'][$i][] = ob_get_contents(); |
|
1085 | + ob_end_clean(); ?> |
|
1086 | 1086 | |
1087 | 1087 | <?php endif ?> |
1088 | 1088 | <?php endforeach ?> |
1089 | 1089 | <?php |
1090 | - $this->send_response($return, 0); |
|
1091 | - } |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * API method to list internal backup files |
|
1095 | - */ |
|
1096 | - public function list_backup_files() |
|
1097 | - { |
|
1098 | - $this->check_access(); |
|
1099 | - |
|
1100 | - $backup_parts = array(); |
|
1101 | - |
|
1102 | - $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
1103 | - $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
|
1104 | - $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
1105 | - |
|
1106 | - $backup_file = $source_backup_file; |
|
1107 | - |
|
1108 | - if ($this->xcloner_file_system->is_multipart($backup_file)) { |
|
1109 | - $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file); |
|
1110 | - $backup_file = $backup_parts[$return['part']]; |
|
1111 | - } |
|
1112 | - |
|
1113 | - if($this->xcloner_encryption->is_encrypted_file($backup_file)) { |
|
1114 | - $return['error'] = true; |
|
1115 | - $return['message'] = __("Backup archive is encrypted, please decrypt it first before you can list it's content.", "xcloner-backup-and-restore"); |
|
1116 | - $this->send_response($return, 0); |
|
1117 | - } |
|
1118 | - |
|
1119 | - try { |
|
1120 | - $tar = new Tar(); |
|
1121 | - $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start); |
|
1122 | - |
|
1123 | - $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
|
1124 | - } catch (Exception $e) { |
|
1125 | - $return['error'] = true; |
|
1126 | - $return['message'] = $e->getMessage(); |
|
1127 | - $this->send_response($return, 0); |
|
1128 | - } |
|
1129 | - |
|
1130 | - $return['files'] = array(); |
|
1131 | - $return['finished'] = 1; |
|
1132 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
1133 | - $i = 0; |
|
1134 | - |
|
1135 | - if (isset($data['extracted_files']) and is_array($data['extracted_files'])) { |
|
1136 | - foreach ($data['extracted_files'] as $file) { |
|
1137 | - $return['files'][$i]['path'] = $file->getPath(); |
|
1138 | - $return['files'][$i]['size'] = $file->getSize(); |
|
1139 | - $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'), |
|
1140 | - $file->getMtime()); |
|
1141 | - |
|
1142 | - $i++; |
|
1143 | - } |
|
1144 | - } |
|
1145 | - |
|
1146 | - if (isset($data['start'])) { |
|
1147 | - $return['start'] = $data['start']; |
|
1148 | - $return['finished'] = 0; |
|
1149 | - } else { |
|
1150 | - if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
|
1151 | - $return['start'] = 0; |
|
1152 | - |
|
1153 | - ++$return['part']; |
|
1154 | - |
|
1155 | - if ($return['part'] < sizeof($backup_parts)) { |
|
1156 | - $return['finished'] = 0; |
|
1157 | - } |
|
1158 | - |
|
1159 | - } |
|
1160 | - } |
|
1161 | - |
|
1162 | - $this->send_response($return, 0); |
|
1163 | - } |
|
1164 | - |
|
1165 | - /* |
|
1090 | + $this->send_response($return, 0); |
|
1091 | + } |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * API method to list internal backup files |
|
1095 | + */ |
|
1096 | + public function list_backup_files() |
|
1097 | + { |
|
1098 | + $this->check_access(); |
|
1099 | + |
|
1100 | + $backup_parts = array(); |
|
1101 | + |
|
1102 | + $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
1103 | + $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
|
1104 | + $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
1105 | + |
|
1106 | + $backup_file = $source_backup_file; |
|
1107 | + |
|
1108 | + if ($this->xcloner_file_system->is_multipart($backup_file)) { |
|
1109 | + $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file); |
|
1110 | + $backup_file = $backup_parts[$return['part']]; |
|
1111 | + } |
|
1112 | + |
|
1113 | + if($this->xcloner_encryption->is_encrypted_file($backup_file)) { |
|
1114 | + $return['error'] = true; |
|
1115 | + $return['message'] = __("Backup archive is encrypted, please decrypt it first before you can list it's content.", "xcloner-backup-and-restore"); |
|
1116 | + $this->send_response($return, 0); |
|
1117 | + } |
|
1118 | + |
|
1119 | + try { |
|
1120 | + $tar = new Tar(); |
|
1121 | + $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start); |
|
1122 | + |
|
1123 | + $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
|
1124 | + } catch (Exception $e) { |
|
1125 | + $return['error'] = true; |
|
1126 | + $return['message'] = $e->getMessage(); |
|
1127 | + $this->send_response($return, 0); |
|
1128 | + } |
|
1129 | + |
|
1130 | + $return['files'] = array(); |
|
1131 | + $return['finished'] = 1; |
|
1132 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
1133 | + $i = 0; |
|
1134 | + |
|
1135 | + if (isset($data['extracted_files']) and is_array($data['extracted_files'])) { |
|
1136 | + foreach ($data['extracted_files'] as $file) { |
|
1137 | + $return['files'][$i]['path'] = $file->getPath(); |
|
1138 | + $return['files'][$i]['size'] = $file->getSize(); |
|
1139 | + $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'), |
|
1140 | + $file->getMtime()); |
|
1141 | + |
|
1142 | + $i++; |
|
1143 | + } |
|
1144 | + } |
|
1145 | + |
|
1146 | + if (isset($data['start'])) { |
|
1147 | + $return['start'] = $data['start']; |
|
1148 | + $return['finished'] = 0; |
|
1149 | + } else { |
|
1150 | + if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
|
1151 | + $return['start'] = 0; |
|
1152 | + |
|
1153 | + ++$return['part']; |
|
1154 | + |
|
1155 | + if ($return['part'] < sizeof($backup_parts)) { |
|
1156 | + $return['finished'] = 0; |
|
1157 | + } |
|
1158 | + |
|
1159 | + } |
|
1160 | + } |
|
1161 | + |
|
1162 | + $this->send_response($return, 0); |
|
1163 | + } |
|
1164 | + |
|
1165 | + /* |
|
1166 | 1166 | * Copy remote backup to local storage |
1167 | 1167 | */ |
1168 | - public function copy_backup_remote_to_local() |
|
1169 | - { |
|
1168 | + public function copy_backup_remote_to_local() |
|
1169 | + { |
|
1170 | 1170 | |
1171 | - $this->check_access(); |
|
1171 | + $this->check_access(); |
|
1172 | 1172 | |
1173 | - $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
1174 | - $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']); |
|
1173 | + $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
1174 | + $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']); |
|
1175 | 1175 | |
1176 | - $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
1176 | + $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
1177 | 1177 | |
1178 | - $return = array(); |
|
1178 | + $return = array(); |
|
1179 | 1179 | |
1180 | - try { |
|
1181 | - if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) { |
|
1182 | - $return = call_user_func_array(array( |
|
1183 | - $xcloner_remote_storage, |
|
1184 | - "copy_backup_remote_to_local" |
|
1185 | - ), array($backup_file, $storage_type)); |
|
1186 | - } |
|
1187 | - } catch (Exception $e) { |
|
1180 | + try { |
|
1181 | + if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) { |
|
1182 | + $return = call_user_func_array(array( |
|
1183 | + $xcloner_remote_storage, |
|
1184 | + "copy_backup_remote_to_local" |
|
1185 | + ), array($backup_file, $storage_type)); |
|
1186 | + } |
|
1187 | + } catch (Exception $e) { |
|
1188 | 1188 | |
1189 | - $return['error'] = 1; |
|
1190 | - $return['message'] = $e->getMessage(); |
|
1191 | - } |
|
1189 | + $return['error'] = 1; |
|
1190 | + $return['message'] = $e->getMessage(); |
|
1191 | + } |
|
1192 | 1192 | |
1193 | - if (!$return) { |
|
1194 | - $return['error'] = 1; |
|
1195 | - $return['message'] = "Upload failed, please check the error log for more information!"; |
|
1196 | - } |
|
1193 | + if (!$return) { |
|
1194 | + $return['error'] = 1; |
|
1195 | + $return['message'] = "Upload failed, please check the error log for more information!"; |
|
1196 | + } |
|
1197 | 1197 | |
1198 | 1198 | |
1199 | - $this->send_response($return, 0); |
|
1199 | + $this->send_response($return, 0); |
|
1200 | 1200 | |
1201 | - } |
|
1201 | + } |
|
1202 | 1202 | |
1203 | - /* |
|
1203 | + /* |
|
1204 | 1204 | * |
1205 | 1205 | * Upload backup to remote API |
1206 | 1206 | * |
1207 | 1207 | */ |
1208 | - public function upload_backup_to_remote() |
|
1209 | - { |
|
1210 | - $this->check_access(); |
|
1208 | + public function upload_backup_to_remote() |
|
1209 | + { |
|
1210 | + $this->check_access(); |
|
1211 | 1211 | |
1212 | - $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
1213 | - $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']); |
|
1212 | + $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
1213 | + $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']); |
|
1214 | 1214 | |
1215 | - $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
1215 | + $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
1216 | 1216 | |
1217 | - $return = array(); |
|
1217 | + $return = array(); |
|
1218 | 1218 | |
1219 | - try { |
|
1220 | - if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) { |
|
1221 | - $return = call_user_func_array(array( |
|
1222 | - $xcloner_remote_storage, |
|
1223 | - "upload_backup_to_storage" |
|
1224 | - ), array($backup_file, $storage_type)); |
|
1225 | - } |
|
1226 | - } catch (Exception $e) { |
|
1219 | + try { |
|
1220 | + if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) { |
|
1221 | + $return = call_user_func_array(array( |
|
1222 | + $xcloner_remote_storage, |
|
1223 | + "upload_backup_to_storage" |
|
1224 | + ), array($backup_file, $storage_type)); |
|
1225 | + } |
|
1226 | + } catch (Exception $e) { |
|
1227 | 1227 | |
1228 | - $return['error'] = 1; |
|
1229 | - $return['message'] = $e->getMessage(); |
|
1230 | - } |
|
1228 | + $return['error'] = 1; |
|
1229 | + $return['message'] = $e->getMessage(); |
|
1230 | + } |
|
1231 | 1231 | |
1232 | - if (!$return) { |
|
1233 | - $return['error'] = 1; |
|
1234 | - $return['message'] = "Upload failed, please check the error log for more information!"; |
|
1235 | - } |
|
1232 | + if (!$return) { |
|
1233 | + $return['error'] = 1; |
|
1234 | + $return['message'] = "Upload failed, please check the error log for more information!"; |
|
1235 | + } |
|
1236 | 1236 | |
1237 | 1237 | |
1238 | - $this->send_response($return, 0); |
|
1238 | + $this->send_response($return, 0); |
|
1239 | 1239 | |
1240 | - } |
|
1240 | + } |
|
1241 | 1241 | |
1242 | - /* |
|
1242 | + /* |
|
1243 | 1243 | * |
1244 | 1244 | * Remote Storage Status Save |
1245 | 1245 | * |
1246 | 1246 | */ |
1247 | - public function remote_storage_save_status() |
|
1248 | - { |
|
1249 | - $this->check_access(); |
|
1247 | + public function remote_storage_save_status() |
|
1248 | + { |
|
1249 | + $this->check_access(); |
|
1250 | 1250 | |
1251 | - $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
1251 | + $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
1252 | 1252 | |
1253 | - $return['finished'] = $xcloner_remote_storage->change_storage_status($_POST['id'], $_POST['value']); |
|
1253 | + $return['finished'] = $xcloner_remote_storage->change_storage_status($_POST['id'], $_POST['value']); |
|
1254 | 1254 | |
1255 | - $this->send_response($return, 0); |
|
1256 | - } |
|
1255 | + $this->send_response($return, 0); |
|
1256 | + } |
|
1257 | 1257 | |
1258 | 1258 | |
1259 | - public function download_restore_script() |
|
1260 | - { |
|
1261 | - $this->check_access(); |
|
1259 | + public function download_restore_script() |
|
1260 | + { |
|
1261 | + $this->check_access(); |
|
1262 | 1262 | |
1263 | - @ob_end_clean(); |
|
1263 | + @ob_end_clean(); |
|
1264 | 1264 | |
1265 | - $adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS'); |
|
1266 | - $xcloner_plugin_filesystem = new Filesystem($adapter, new Config([ |
|
1267 | - 'disable_asserts' => true, |
|
1268 | - ])); |
|
1265 | + $adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS'); |
|
1266 | + $xcloner_plugin_filesystem = new Filesystem($adapter, new Config([ |
|
1267 | + 'disable_asserts' => true, |
|
1268 | + ])); |
|
1269 | 1269 | |
1270 | - /* Generate PHAR FILE |
|
1270 | + /* Generate PHAR FILE |
|
1271 | 1271 | $file = 'restore/vendor.built'; |
1272 | 1272 | |
1273 | 1273 | if(file_exists($file)) |
@@ -1283,178 +1283,178 @@ discard block |
||
1283 | 1283 | $phar2->setStub($phar2->createDefaultStub('vendor/autoload.php', 'vendor/autoload.php')); |
1284 | 1284 | * */ |
1285 | 1285 | |
1286 | - $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz"; |
|
1286 | + $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz"; |
|
1287 | 1287 | |
1288 | - $tar = new Tar(); |
|
1289 | - $tar->create($tmp_file); |
|
1288 | + $tar = new Tar(); |
|
1289 | + $tar->create($tmp_file); |
|
1290 | 1290 | |
1291 | - $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar"); |
|
1292 | - //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz"); |
|
1291 | + $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar"); |
|
1292 | + //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz"); |
|
1293 | 1293 | |
1294 | - $files = $xcloner_plugin_filesystem->listContents("vendor/", true); |
|
1295 | - foreach ($files as $file) { |
|
1296 | - $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']); |
|
1297 | - } |
|
1294 | + $files = $xcloner_plugin_filesystem->listContents("vendor/", true); |
|
1295 | + foreach ($files as $file) { |
|
1296 | + $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']); |
|
1297 | + } |
|
1298 | 1298 | |
1299 | - $content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php"); |
|
1300 | - $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content); |
|
1299 | + $content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php"); |
|
1300 | + $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content); |
|
1301 | 1301 | |
1302 | - $tar->addData("xcloner_restore.php", $content); |
|
1302 | + $tar->addData("xcloner_restore.php", $content); |
|
1303 | 1303 | |
1304 | - $tar->close(); |
|
1304 | + $tar->close(); |
|
1305 | 1305 | |
1306 | - if (file_exists($tmp_file)) { |
|
1307 | - header('Content-Description: File Transfer'); |
|
1308 | - header('Content-Type: application/octet-stream'); |
|
1309 | - header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"'); |
|
1310 | - header('Expires: 0'); |
|
1311 | - header('Cache-Control: must-revalidate'); |
|
1312 | - header('Pragma: public'); |
|
1313 | - header('Content-Length: ' . filesize($tmp_file)); |
|
1314 | - readfile($tmp_file); |
|
1306 | + if (file_exists($tmp_file)) { |
|
1307 | + header('Content-Description: File Transfer'); |
|
1308 | + header('Content-Type: application/octet-stream'); |
|
1309 | + header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"'); |
|
1310 | + header('Expires: 0'); |
|
1311 | + header('Cache-Control: must-revalidate'); |
|
1312 | + header('Pragma: public'); |
|
1313 | + header('Content-Length: ' . filesize($tmp_file)); |
|
1314 | + readfile($tmp_file); |
|
1315 | 1315 | |
1316 | - } |
|
1316 | + } |
|
1317 | 1317 | |
1318 | - @unlink($tmp_file); |
|
1319 | - exit; |
|
1320 | - } |
|
1318 | + @unlink($tmp_file); |
|
1319 | + exit; |
|
1320 | + } |
|
1321 | 1321 | |
1322 | - /* |
|
1322 | + /* |
|
1323 | 1323 | * |
1324 | 1324 | * Download backup by Name from the Storage Path |
1325 | 1325 | * |
1326 | 1326 | */ |
1327 | - public function download_backup_by_name() |
|
1328 | - { |
|
1329 | - $this->check_access(); |
|
1327 | + public function download_backup_by_name() |
|
1328 | + { |
|
1329 | + $this->check_access(); |
|
1330 | 1330 | |
1331 | - @ob_end_clean(); |
|
1331 | + @ob_end_clean(); |
|
1332 | 1332 | |
1333 | - $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']); |
|
1333 | + $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']); |
|
1334 | 1334 | |
1335 | 1335 | |
1336 | - $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name); |
|
1337 | - $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name); |
|
1336 | + $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name); |
|
1337 | + $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name); |
|
1338 | 1338 | |
1339 | 1339 | |
1340 | - header('Pragma: public'); |
|
1341 | - header('Expires: 0'); |
|
1342 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
1343 | - header('Cache-Control: private', false); |
|
1344 | - header('Content-Transfer-Encoding: binary'); |
|
1345 | - header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";'); |
|
1346 | - header('Content-Type: application/octet-stream'); |
|
1347 | - header('Content-Length: ' . $metadata['size']); |
|
1340 | + header('Pragma: public'); |
|
1341 | + header('Expires: 0'); |
|
1342 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
1343 | + header('Cache-Control: private', false); |
|
1344 | + header('Content-Transfer-Encoding: binary'); |
|
1345 | + header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";'); |
|
1346 | + header('Content-Type: application/octet-stream'); |
|
1347 | + header('Content-Length: ' . $metadata['size']); |
|
1348 | 1348 | |
1349 | - @ob_end_clean(); |
|
1349 | + @ob_end_clean(); |
|
1350 | 1350 | |
1351 | - $chunkSize = 1024 * 1024; |
|
1352 | - while (!feof($read_stream)) { |
|
1353 | - $buffer = fread($read_stream, $chunkSize); |
|
1354 | - echo $buffer; |
|
1355 | - } |
|
1356 | - fclose($read_stream); |
|
1357 | - exit; |
|
1351 | + $chunkSize = 1024 * 1024; |
|
1352 | + while (!feof($read_stream)) { |
|
1353 | + $buffer = fread($read_stream, $chunkSize); |
|
1354 | + echo $buffer; |
|
1355 | + } |
|
1356 | + fclose($read_stream); |
|
1357 | + exit; |
|
1358 | 1358 | |
1359 | - } |
|
1359 | + } |
|
1360 | 1360 | |
1361 | - /* |
|
1361 | + /* |
|
1362 | 1362 | * Restore upload backup |
1363 | 1363 | */ |
1364 | - public function restore_upload_backup() |
|
1365 | - { |
|
1366 | - $this->check_access(); |
|
1364 | + public function restore_upload_backup() |
|
1365 | + { |
|
1366 | + $this->check_access(); |
|
1367 | 1367 | |
1368 | - $return['part'] = 0; |
|
1369 | - $return['total_parts'] = 0; |
|
1370 | - $return['uploaded_size'] = 0; |
|
1371 | - $is_multipart = 0; |
|
1368 | + $return['part'] = 0; |
|
1369 | + $return['total_parts'] = 0; |
|
1370 | + $return['uploaded_size'] = 0; |
|
1371 | + $is_multipart = 0; |
|
1372 | 1372 | |
1373 | - $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
1374 | - $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']); |
|
1373 | + $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
|
1374 | + $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']); |
|
1375 | 1375 | |
1376 | - if (isset($_POST['part'])) { |
|
1377 | - $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
1378 | - } |
|
1376 | + if (isset($_POST['part'])) { |
|
1377 | + $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
1378 | + } |
|
1379 | 1379 | |
1380 | - if (isset($_POST['uploaded_size'])) { |
|
1381 | - $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
|
1382 | - } |
|
1380 | + if (isset($_POST['uploaded_size'])) { |
|
1381 | + $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
|
1382 | + } |
|
1383 | 1383 | |
1384 | - $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']); |
|
1385 | - $target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']); |
|
1384 | + $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']); |
|
1385 | + $target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']); |
|
1386 | 1386 | |
1387 | - $return['total_size'] = $this->xcloner_file_system->get_backup_size($file); |
|
1387 | + $return['total_size'] = $this->xcloner_file_system->get_backup_size($file); |
|
1388 | 1388 | |
1389 | - if ($this->xcloner_file_system->is_multipart($file)) { |
|
1390 | - $backup_parts = $this->xcloner_file_system->get_multipart_files($file); |
|
1389 | + if ($this->xcloner_file_system->is_multipart($file)) { |
|
1390 | + $backup_parts = $this->xcloner_file_system->get_multipart_files($file); |
|
1391 | 1391 | |
1392 | - $return['total_parts'] = sizeof($backup_parts) + 1; |
|
1392 | + $return['total_parts'] = sizeof($backup_parts) + 1; |
|
1393 | 1393 | |
1394 | - if ($return['part'] and isset($backup_parts[$return['part'] - 1])) { |
|
1395 | - $file = $backup_parts[$return['part'] - 1]; |
|
1396 | - } |
|
1394 | + if ($return['part'] and isset($backup_parts[$return['part'] - 1])) { |
|
1395 | + $file = $backup_parts[$return['part'] - 1]; |
|
1396 | + } |
|
1397 | 1397 | |
1398 | - $is_multipart = 1; |
|
1399 | - } |
|
1398 | + $is_multipart = 1; |
|
1399 | + } |
|
1400 | 1400 | |
1401 | - try { |
|
1401 | + try { |
|
1402 | 1402 | |
1403 | - $xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer(); |
|
1404 | - $xcloner_file_transfer->set_target($target_url); |
|
1405 | - $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
|
1403 | + $xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer(); |
|
1404 | + $xcloner_file_transfer->set_target($target_url); |
|
1405 | + $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
|
1406 | 1406 | |
1407 | - } catch (Exception $e) { |
|
1407 | + } catch (Exception $e) { |
|
1408 | 1408 | |
1409 | - $return = array(); |
|
1410 | - $return['error'] = true; |
|
1411 | - $return['status'] = 500; |
|
1412 | - $return['message'] = "CURL communication error with the restore host. " . $e->getMessage(); |
|
1413 | - $this->send_response($return, 0); |
|
1409 | + $return = array(); |
|
1410 | + $return['error'] = true; |
|
1411 | + $return['status'] = 500; |
|
1412 | + $return['message'] = "CURL communication error with the restore host. " . $e->getMessage(); |
|
1413 | + $this->send_response($return, 0); |
|
1414 | 1414 | |
1415 | - } |
|
1415 | + } |
|
1416 | 1416 | |
1417 | - $return['status'] = 200; |
|
1417 | + $return['status'] = 200; |
|
1418 | 1418 | |
1419 | - //we have finished the upload |
|
1420 | - if (!$return['start'] and $is_multipart) { |
|
1421 | - $return['part']++; |
|
1422 | - $return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file); |
|
1423 | - } |
|
1419 | + //we have finished the upload |
|
1420 | + if (!$return['start'] and $is_multipart) { |
|
1421 | + $return['part']++; |
|
1422 | + $return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file); |
|
1423 | + } |
|
1424 | 1424 | |
1425 | - $this->send_response($return, 0); |
|
1426 | - } |
|
1425 | + $this->send_response($return, 0); |
|
1426 | + } |
|
1427 | 1427 | |
1428 | - /* |
|
1428 | + /* |
|
1429 | 1429 | * Restore backup |
1430 | 1430 | */ |
1431 | - public function restore_backup() |
|
1432 | - { |
|
1433 | - $this->check_access(); |
|
1431 | + public function restore_backup() |
|
1432 | + { |
|
1433 | + $this->check_access(); |
|
1434 | 1434 | |
1435 | - define("XCLONER_PLUGIN_ACCESS", 1); |
|
1436 | - include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php"); |
|
1435 | + define("XCLONER_PLUGIN_ACCESS", 1); |
|
1436 | + include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php"); |
|
1437 | 1437 | |
1438 | - return; |
|
1439 | - } |
|
1438 | + return; |
|
1439 | + } |
|
1440 | 1440 | |
1441 | - /* |
|
1441 | + /* |
|
1442 | 1442 | * |
1443 | 1443 | * Send the json response back |
1444 | 1444 | * |
1445 | 1445 | */ |
1446 | - private function send_response($data, $attach_hash = 1) |
|
1447 | - { |
|
1446 | + private function send_response($data, $attach_hash = 1) |
|
1447 | + { |
|
1448 | 1448 | |
1449 | - if ($attach_hash and null !== $this->xcloner_settings->get_hash()) { |
|
1450 | - $data['hash'] = $this->xcloner_settings->get_hash(); |
|
1451 | - } |
|
1449 | + if ($attach_hash and null !== $this->xcloner_settings->get_hash()) { |
|
1450 | + $data['hash'] = $this->xcloner_settings->get_hash(); |
|
1451 | + } |
|
1452 | 1452 | |
1453 | - if (ob_get_length()) { |
|
1454 | - ob_clean(); |
|
1455 | - } |
|
1456 | - wp_send_json($data); |
|
1453 | + if (ob_get_length()) { |
|
1454 | + ob_clean(); |
|
1455 | + } |
|
1456 | + wp_send_json($data); |
|
1457 | 1457 | |
1458 | - die(); |
|
1459 | - } |
|
1458 | + die(); |
|
1459 | + } |
|
1460 | 1460 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | $this->xcloner_remote_storage = $xcloner_container->get_xcloner_remote_storage(); |
90 | 90 | |
91 | 91 | if (isset($_POST['API_ID'])) { |
92 | - $this->logger->info("Processing ajax request ID " . substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), |
|
92 | + $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), |
|
93 | 93 | 0, 15)); |
94 | 94 | } |
95 | 95 | |
@@ -131,13 +131,13 @@ discard block |
||
131 | 131 | |
132 | 132 | |
133 | 133 | $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
134 | - $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . ".database"; |
|
135 | - $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "database-sql.sql"; |
|
134 | + $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database"; |
|
135 | + $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql"; |
|
136 | 136 | |
137 | 137 | try { |
138 | 138 | $this->xcloner_database->init($data); |
139 | 139 | |
140 | - } catch (Exception $e) { |
|
140 | + }catch (Exception $e) { |
|
141 | 141 | |
142 | 142 | $this->send_response($e->getMessage()); |
143 | 143 | $this->logger->error($e->getMessage()); |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | } else { |
224 | 224 | |
225 | 225 | $schedule['status'] = 1; |
226 | - $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
|
227 | - " " . $this->form_params['backup_params']['schedule_start_time']); |
|
226 | + $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date']. |
|
227 | + " ".$this->form_params['backup_params']['schedule_start_time']); |
|
228 | 228 | |
229 | 229 | if ($schedule['start_at'] <= time()) { |
230 | 230 | $schedule['start_at'] = ""; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | |
250 | 250 | if (!isset($_POST['id'])) { |
251 | 251 | $wpdb->insert( |
252 | - $wpdb->prefix . 'xcloner_scheduler', |
|
252 | + $wpdb->prefix.'xcloner_scheduler', |
|
253 | 253 | $schedule, |
254 | 254 | array( |
255 | 255 | '%s', |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | ); |
259 | 259 | } else { |
260 | 260 | $wpdb->update( |
261 | - $wpdb->prefix . 'xcloner_scheduler', |
|
261 | + $wpdb->prefix.'xcloner_scheduler', |
|
262 | 262 | $schedule, |
263 | 263 | array('id' => $_POST['id']), |
264 | 264 | array( |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | try { |
310 | 310 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], |
311 | 311 | $this->form_params['extra'], $init); |
312 | - } catch (Exception $e) { |
|
312 | + }catch (Exception $e) { |
|
313 | 313 | $return = array(); |
314 | 314 | $return['error'] = true; |
315 | 315 | $return['status'] = 500; |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | $additional['lines_total'] = $return['extra']['lines_total']; |
337 | 337 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], |
338 | 338 | $this->form_params, "", $additional); |
339 | - } catch (Exception $e) { |
|
339 | + }catch (Exception $e) { |
|
340 | 340 | $this->logger->error($e->getMessage()); |
341 | 341 | } |
342 | 342 | } |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | if (isset($params->backup_params)) { |
431 | 431 | foreach ($params->backup_params as $param) { |
432 | 432 | $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value); |
433 | - $this->logger->debug("Adding form parameter " . $param->name . "." . $param->value . "\n", array( |
|
433 | + $this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array( |
|
434 | 434 | 'POST', |
435 | 435 | 'fields filter' |
436 | 436 | )); |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | if (isset($params->table_params)) { |
443 | 443 | foreach ($params->table_params as $param) { |
444 | 444 | $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id); |
445 | - $this->logger->debug("Adding database filter " . $param->parent . "." . $param->id . "\n", array( |
|
445 | + $this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array( |
|
446 | 446 | 'POST', |
447 | 447 | 'database filter' |
448 | 448 | )); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | if (!in_array($param->parent, $this->form_params['excluded_files'])) { |
462 | 462 | //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
463 | 463 | $unique_exclude_files[] = $param->id; |
464 | - $this->logger->debug("Adding file filter " . $param->id . "\n", array( |
|
464 | + $this->logger->debug("Adding file filter ".$param->id."\n", array( |
|
465 | 465 | 'POST', |
466 | 466 | 'exclude files filter' |
467 | 467 | )); |
@@ -509,13 +509,13 @@ discard block |
||
509 | 509 | 'text' => $this->xcloner_settings->get_xcloner_start_path(), |
510 | 510 | //'children' => true, |
511 | 511 | 'state' => array('selected' => false, 'opened' => true), |
512 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-root.png" |
|
512 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-root.png" |
|
513 | 513 | ); |
514 | 514 | } |
515 | 515 | |
516 | 516 | try { |
517 | 517 | $files = $this->xcloner_file_system->list_directory($folder); |
518 | - } catch (Exception $e) { |
|
518 | + }catch (Exception $e) { |
|
519 | 519 | |
520 | 520 | print $e->getMessage(); |
521 | 521 | $this->logger->error($e->getMessage()); |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | if ($file['type'] == "dir") { |
537 | 537 | $children = true; |
538 | 538 | } else { |
539 | - $text .= " (" . $this->xcloner_requirements->file_format_size($file['size']) . ")"; |
|
539 | + $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")"; |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | if ($this->xcloner_file_system->is_excluded($file)) { |
@@ -552,8 +552,8 @@ discard block |
||
552 | 552 | //'title' => "test", |
553 | 553 | 'children' => $children, |
554 | 554 | 'state' => array('selected' => $selected, 'opened' => false, "checkbox_disabled" => $selected), |
555 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/file-icon-" . strtolower(substr($file['type'], |
|
556 | - 0, 1)) . ".png" |
|
555 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/file-icon-".strtolower(substr($file['type'], |
|
556 | + 0, 1)).".png" |
|
557 | 557 | ); |
558 | 558 | } |
559 | 559 | |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | if ($database == "#") { |
580 | 580 | try { |
581 | 581 | $return = $this->xcloner_database->get_all_databases(); |
582 | - } catch (Exception $e) { |
|
582 | + }catch (Exception $e) { |
|
583 | 583 | $this->logger->error($e->getMessage()); |
584 | 584 | } |
585 | 585 | |
@@ -600,10 +600,10 @@ discard block |
||
600 | 600 | $data[] = array( |
601 | 601 | 'id' => $database['name'], |
602 | 602 | 'parent' => '#', |
603 | - 'text' => $database['name'] . " (" . (int)$database['num_tables'] . ")", |
|
603 | + 'text' => $database['name']." (".(int)$database['num_tables'].")", |
|
604 | 604 | 'children' => true, |
605 | 605 | 'state' => $state, |
606 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/database-icon.png" |
|
606 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/database-icon.png" |
|
607 | 607 | ); |
608 | 608 | } |
609 | 609 | |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | |
612 | 612 | try { |
613 | 613 | $return = $this->xcloner_database->list_tables($database, "", 1); |
614 | - } catch (Exception $e) { |
|
614 | + }catch (Exception $e) { |
|
615 | 615 | $this->logger->error($e->getMessage()); |
616 | 616 | } |
617 | 617 | |
@@ -628,12 +628,12 @@ discard block |
||
628 | 628 | } |
629 | 629 | |
630 | 630 | $data[] = array( |
631 | - 'id' => $database . "." . $table['name'], |
|
631 | + 'id' => $database.".".$table['name'], |
|
632 | 632 | 'parent' => $database, |
633 | - 'text' => $table['name'] . " (" . (int)$table['records'] . ")", |
|
633 | + 'text' => $table['name']." (".(int)$table['records'].")", |
|
634 | 634 | 'children' => false, |
635 | 635 | 'state' => $state, |
636 | - 'icon' => plugin_dir_url(dirname(__FILE__)) . "/admin/assets/table-icon.png" |
|
636 | + 'icon' => plugin_dir_url(dirname(__FILE__))."/admin/assets/table-icon.png" |
|
637 | 637 | ); |
638 | 638 | } |
639 | 639 | } |
@@ -677,17 +677,17 @@ discard block |
||
677 | 677 | $return['data'] = array(); |
678 | 678 | |
679 | 679 | foreach ($data as $res) { |
680 | - $action = "<a href=\"#" . $res->id . "\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
|
681 | - <a href=\"#" . $res->id . "\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
|
680 | + $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
|
681 | + <a href=\"#" . $res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
|
682 | 682 | if ($res->status) { |
683 | 683 | $status = '<i class="material-icons active status">timer</i>'; |
684 | 684 | } else { |
685 | 685 | $status = '<i class="material-icons status inactive">timer_off</i>'; |
686 | 686 | } |
687 | 687 | |
688 | - $next_run_time = wp_next_scheduled('xcloner_scheduler_' . $res->id, array($res->id)); |
|
688 | + $next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)); |
|
689 | 689 | |
690 | - $next_run = date(get_option('date_format') . " " . get_option('time_format'), $next_run_time); |
|
690 | + $next_run = date(get_option('date_format')." ".get_option('time_format'), $next_run_time); |
|
691 | 691 | |
692 | 692 | $remote_storage = $res->remote_storage; |
693 | 693 | |
@@ -696,16 +696,16 @@ discard block |
||
696 | 696 | } |
697 | 697 | |
698 | 698 | if (trim($next_run)) { |
699 | - $date_text = date(get_option('date_format') . " " . get_option('time_format'), |
|
699 | + $date_text = date(get_option('date_format')." ".get_option('time_format'), |
|
700 | 700 | $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
701 | 701 | |
702 | 702 | if ($next_run_time >= time()) { |
703 | - $next_run = "in " . human_time_diff($next_run_time, time()); |
|
703 | + $next_run = "in ".human_time_diff($next_run_time, time()); |
|
704 | 704 | } else { |
705 | 705 | $next_run = __("executed", 'xcloner-backup-and-restore'); |
706 | 706 | } |
707 | 707 | |
708 | - $next_run = "<a href='#' title='" . $date_text . "'>" . $next_run . "</a>"; |
|
708 | + $next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>"; |
|
709 | 709 | //$next_run .=" ($date_text)"; |
710 | 710 | } |
711 | 711 | |
@@ -717,11 +717,11 @@ discard block |
||
717 | 717 | if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) { |
718 | 718 | $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup); |
719 | 719 | $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup)); |
720 | - $backup_time = date(get_option('date_format') . " " . get_option('time_format'), |
|
720 | + $backup_time = date(get_option('date_format')." ".get_option('time_format'), |
|
721 | 721 | $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
722 | 722 | } |
723 | 723 | |
724 | - $backup_text = "<span title='" . $backup_time . "' class='shorten_string'>" . $res->last_backup . " (" . $backup_size . ")</span>"; |
|
724 | + $backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>"; |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | $schedules = wp_get_schedules(); |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | $return['data'][] = array( |
734 | 734 | $res->id, |
735 | 735 | $res->name, |
736 | - $res->recurrence,/*$res->start_at,*/ |
|
736 | + $res->recurrence, /*$res->start_at,*/ |
|
737 | 737 | $next_run, |
738 | 738 | $remote_storage, |
739 | 739 | $backup_text, |
@@ -795,25 +795,25 @@ discard block |
||
795 | 795 | $this->process_params($params); |
796 | 796 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($this->form_params['extra']['backup_parent']); |
797 | 797 | |
798 | - if(isset($this->form_params['extra']['start'])) { |
|
798 | + if (isset($this->form_params['extra']['start'])) { |
|
799 | 799 | $start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']); |
800 | - }else{ |
|
800 | + } else { |
|
801 | 801 | $start = 0; |
802 | 802 | } |
803 | 803 | |
804 | - if(isset($this->form_params['extra']['iv'])) { |
|
804 | + if (isset($this->form_params['extra']['iv'])) { |
|
805 | 805 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']); |
806 | - }else{ |
|
806 | + } else { |
|
807 | 807 | $iv = ""; |
808 | 808 | } |
809 | 809 | |
810 | - if(isset($this->form_params['extra']['part'])) { |
|
810 | + if (isset($this->form_params['extra']['part'])) { |
|
811 | 811 | $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']); |
812 | - }else{ |
|
812 | + } else { |
|
813 | 813 | $return['part'] = 0; |
814 | 814 | } |
815 | 815 | |
816 | - }else{ |
|
816 | + } else { |
|
817 | 817 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
818 | 818 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
819 | 819 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
@@ -828,14 +828,14 @@ discard block |
||
828 | 828 | } |
829 | 829 | |
830 | 830 | $return['processing_file'] = $backup_file; |
831 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
831 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
832 | 832 | |
833 | 833 | try { |
834 | 834 | $this->logger->info(json_encode($_POST)); |
835 | 835 | $this->logger->info($iv); |
836 | 836 | $return = array_merge($return, |
837 | 837 | $this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv))); |
838 | - }catch(\Exception $e){ |
|
838 | + }catch (\Exception $e) { |
|
839 | 839 | $return['error'] = true; |
840 | 840 | $return['message'] = $e->getMessage(); |
841 | 841 | $return['error_message'] = $e->getMessage(); |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | |
844 | 844 | //echo strlen($return['iv']);exit; |
845 | 845 | |
846 | - if($return['finished']) { |
|
846 | + if ($return['finished']) { |
|
847 | 847 | if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
848 | 848 | $return['start'] = 0; |
849 | 849 | |
@@ -857,7 +857,7 @@ discard block |
||
857 | 857 | } |
858 | 858 | |
859 | 859 | if (isset($_POST['data'])) { |
860 | - $return['extra'] = array_merge($this->form_params['extra'], $return); |
|
860 | + $return['extra'] = array_merge($this->form_params['extra'], $return); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | $this->send_response($return, 0); |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
877 | 877 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
878 | 878 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
879 | - $decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']);; |
|
879 | + $decryption_key = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['decryption_key']); ; |
|
880 | 880 | $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
881 | 881 | |
882 | 882 | $backup_file = $source_backup_file; |
@@ -887,17 +887,17 @@ discard block |
||
887 | 887 | } |
888 | 888 | |
889 | 889 | $return['processing_file'] = $backup_file; |
890 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
890 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
891 | 891 | |
892 | 892 | try { |
893 | 893 | $return = array_merge($return, |
894 | 894 | $this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv))); |
895 | - }catch(\Exception $e){ |
|
895 | + }catch (\Exception $e) { |
|
896 | 896 | $return['error'] = true; |
897 | 897 | $return['message'] = $e->getMessage(); |
898 | 898 | } |
899 | 899 | |
900 | - if($return['finished']) { |
|
900 | + if ($return['finished']) { |
|
901 | 901 | if ($this->xcloner_file_system->is_multipart($source_backup_file)) { |
902 | 902 | $return['start'] = 0; |
903 | 903 | |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | foreach ($backup_list as $file_info):?> |
930 | 930 | <?php |
931 | 931 | if ($storage_selection == "gdrive") { |
932 | - $file_info['path'] = $file_info['filename'] . "." . $file_info['extension']; |
|
932 | + $file_info['path'] = $file_info['filename'].".".$file_info['extension']; |
|
933 | 933 | } |
934 | 934 | $file_exists_on_local_storage = true; |
935 | 935 | |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | <a href="#<?php echo $child[0]; ?>" class="download" |
990 | 990 | title="Download Backup"><i class="material-icons">file_download</i></a> |
991 | 991 | |
992 | - <?php if($this->xcloner_encryption->is_encrypted_file($child[0])) :?> |
|
992 | + <?php if ($this->xcloner_encryption->is_encrypted_file($child[0])) :?> |
|
993 | 993 | <a href="#<?php echo $child[0] ?>" class="backup-decryption" |
994 | 994 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
995 | 995 | <i class="material-icons">enhanced_encryption</i> |
@@ -1050,10 +1050,10 @@ discard block |
||
1050 | 1050 | <?php endif ?> |
1051 | 1051 | <?php |
1052 | 1052 | $basename = $file_info['basename']; |
1053 | - if(isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1053 | + if (isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1054 | 1054 | $basename = $file_info['childs'][0][0]; |
1055 | 1055 | ?> |
1056 | - <?php if($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
|
1056 | + <?php if ($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
|
1057 | 1057 | <a href="#<?php echo $file_info['basename'] ?>" class="backup-decryption" |
1058 | 1058 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
1059 | 1059 | <i class="material-icons">enhanced_encryption</i> |
@@ -1110,7 +1110,7 @@ discard block |
||
1110 | 1110 | $backup_file = $backup_parts[$return['part']]; |
1111 | 1111 | } |
1112 | 1112 | |
1113 | - if($this->xcloner_encryption->is_encrypted_file($backup_file)) { |
|
1113 | + if ($this->xcloner_encryption->is_encrypted_file($backup_file)) { |
|
1114 | 1114 | $return['error'] = true; |
1115 | 1115 | $return['message'] = __("Backup archive is encrypted, please decrypt it first before you can list it's content.", "xcloner-backup-and-restore"); |
1116 | 1116 | $this->send_response($return, 0); |
@@ -1118,10 +1118,10 @@ discard block |
||
1118 | 1118 | |
1119 | 1119 | try { |
1120 | 1120 | $tar = new Tar(); |
1121 | - $tar->open($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file, $start); |
|
1121 | + $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); |
|
1122 | 1122 | |
1123 | 1123 | $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
1124 | - } catch (Exception $e) { |
|
1124 | + }catch (Exception $e) { |
|
1125 | 1125 | $return['error'] = true; |
1126 | 1126 | $return['message'] = $e->getMessage(); |
1127 | 1127 | $this->send_response($return, 0); |
@@ -1129,14 +1129,14 @@ discard block |
||
1129 | 1129 | |
1130 | 1130 | $return['files'] = array(); |
1131 | 1131 | $return['finished'] = 1; |
1132 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path() . DS . $backup_file); |
|
1132 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
1133 | 1133 | $i = 0; |
1134 | 1134 | |
1135 | 1135 | if (isset($data['extracted_files']) and is_array($data['extracted_files'])) { |
1136 | 1136 | foreach ($data['extracted_files'] as $file) { |
1137 | 1137 | $return['files'][$i]['path'] = $file->getPath(); |
1138 | 1138 | $return['files'][$i]['size'] = $file->getSize(); |
1139 | - $return['files'][$i]['mtime'] = date(get_option('date_format') . " " . get_option('time_format'), |
|
1139 | + $return['files'][$i]['mtime'] = date(get_option('date_format')." ".get_option('time_format'), |
|
1140 | 1140 | $file->getMtime()); |
1141 | 1141 | |
1142 | 1142 | $i++; |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | "copy_backup_remote_to_local" |
1185 | 1185 | ), array($backup_file, $storage_type)); |
1186 | 1186 | } |
1187 | - } catch (Exception $e) { |
|
1187 | + }catch (Exception $e) { |
|
1188 | 1188 | |
1189 | 1189 | $return['error'] = 1; |
1190 | 1190 | $return['message'] = $e->getMessage(); |
@@ -1223,7 +1223,7 @@ discard block |
||
1223 | 1223 | "upload_backup_to_storage" |
1224 | 1224 | ), array($backup_file, $storage_type)); |
1225 | 1225 | } |
1226 | - } catch (Exception $e) { |
|
1226 | + }catch (Exception $e) { |
|
1227 | 1227 | |
1228 | 1228 | $return['error'] = 1; |
1229 | 1229 | $return['message'] = $e->getMessage(); |
@@ -1283,21 +1283,21 @@ discard block |
||
1283 | 1283 | $phar2->setStub($phar2->createDefaultStub('vendor/autoload.php', 'vendor/autoload.php')); |
1284 | 1284 | * */ |
1285 | 1285 | |
1286 | - $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . "xcloner-restore.tgz"; |
|
1286 | + $tmp_file = $this->xcloner_settings->get_xcloner_tmp_path().DS."xcloner-restore.tgz"; |
|
1287 | 1287 | |
1288 | 1288 | $tar = new Tar(); |
1289 | 1289 | $tar->create($tmp_file); |
1290 | 1290 | |
1291 | - $tar->addFile(dirname(__DIR__) . "/restore/vendor.build.txt", "vendor.phar"); |
|
1291 | + $tar->addFile(dirname(__DIR__)."/restore/vendor.build.txt", "vendor.phar"); |
|
1292 | 1292 | //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz"); |
1293 | 1293 | |
1294 | 1294 | $files = $xcloner_plugin_filesystem->listContents("vendor/", true); |
1295 | 1295 | foreach ($files as $file) { |
1296 | - $tar->addFile(dirname(__DIR__) . DS . $file['path'], $file['path']); |
|
1296 | + $tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']); |
|
1297 | 1297 | } |
1298 | 1298 | |
1299 | - $content = file_get_contents(dirname(__DIR__) . "/restore/xcloner_restore.php"); |
|
1300 | - $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '" . md5(AUTH_KEY) . "');", $content); |
|
1299 | + $content = file_get_contents(dirname(__DIR__)."/restore/xcloner_restore.php"); |
|
1300 | + $content = str_replace("define('AUTH_KEY', '');", "define('AUTH_KEY', '".md5(AUTH_KEY)."');", $content); |
|
1301 | 1301 | |
1302 | 1302 | $tar->addData("xcloner_restore.php", $content); |
1303 | 1303 | |
@@ -1306,11 +1306,11 @@ discard block |
||
1306 | 1306 | if (file_exists($tmp_file)) { |
1307 | 1307 | header('Content-Description: File Transfer'); |
1308 | 1308 | header('Content-Type: application/octet-stream'); |
1309 | - header('Content-Disposition: attachment; filename="' . basename($tmp_file) . '"'); |
|
1309 | + header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"'); |
|
1310 | 1310 | header('Expires: 0'); |
1311 | 1311 | header('Cache-Control: must-revalidate'); |
1312 | 1312 | header('Pragma: public'); |
1313 | - header('Content-Length: ' . filesize($tmp_file)); |
|
1313 | + header('Content-Length: '.filesize($tmp_file)); |
|
1314 | 1314 | readfile($tmp_file); |
1315 | 1315 | |
1316 | 1316 | } |
@@ -1342,9 +1342,9 @@ discard block |
||
1342 | 1342 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
1343 | 1343 | header('Cache-Control: private', false); |
1344 | 1344 | header('Content-Transfer-Encoding: binary'); |
1345 | - header('Content-Disposition: attachment; filename="' . $metadata['path'] . '";'); |
|
1345 | + header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
|
1346 | 1346 | header('Content-Type: application/octet-stream'); |
1347 | - header('Content-Length: ' . $metadata['size']); |
|
1347 | + header('Content-Length: '.$metadata['size']); |
|
1348 | 1348 | |
1349 | 1349 | @ob_end_clean(); |
1350 | 1350 | |
@@ -1404,12 +1404,12 @@ discard block |
||
1404 | 1404 | $xcloner_file_transfer->set_target($target_url); |
1405 | 1405 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
1406 | 1406 | |
1407 | - } catch (Exception $e) { |
|
1407 | + }catch (Exception $e) { |
|
1408 | 1408 | |
1409 | 1409 | $return = array(); |
1410 | 1410 | $return['error'] = true; |
1411 | 1411 | $return['status'] = 500; |
1412 | - $return['message'] = "CURL communication error with the restore host. " . $e->getMessage(); |
|
1412 | + $return['message'] = "CURL communication error with the restore host. ".$e->getMessage(); |
|
1413 | 1413 | $this->send_response($return, 0); |
1414 | 1414 | |
1415 | 1415 | } |
@@ -1433,7 +1433,7 @@ discard block |
||
1433 | 1433 | $this->check_access(); |
1434 | 1434 | |
1435 | 1435 | define("XCLONER_PLUGIN_ACCESS", 1); |
1436 | - include_once(dirname(__DIR__) . DS . "restore" . DS . "xcloner_restore.php"); |
|
1436 | + include_once(dirname(__DIR__).DS."restore".DS."xcloner_restore.php"); |
|
1437 | 1437 | |
1438 | 1438 | return; |
1439 | 1439 | } |
@@ -797,23 +797,23 @@ discard block |
||
797 | 797 | |
798 | 798 | if(isset($this->form_params['extra']['start'])) { |
799 | 799 | $start = $this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['start']); |
800 | - }else{ |
|
800 | + } else{ |
|
801 | 801 | $start = 0; |
802 | 802 | } |
803 | 803 | |
804 | 804 | if(isset($this->form_params['extra']['iv'])) { |
805 | 805 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($this->form_params['extra']['iv']); |
806 | - }else{ |
|
806 | + } else{ |
|
807 | 807 | $iv = ""; |
808 | 808 | } |
809 | 809 | |
810 | 810 | if(isset($this->form_params['extra']['part'])) { |
811 | 811 | $return['part'] = (int)$this->xcloner_sanitization->sanitize_input_as_int($this->form_params['extra']['part']); |
812 | - }else{ |
|
812 | + } else{ |
|
813 | 813 | $return['part'] = 0; |
814 | 814 | } |
815 | 815 | |
816 | - }else{ |
|
816 | + } else{ |
|
817 | 817 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
818 | 818 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
819 | 819 | $iv = $this->xcloner_sanitization->sanitize_input_as_raw($_POST['iv']); |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | $this->logger->info($iv); |
836 | 836 | $return = array_merge($return, |
837 | 837 | $this->xcloner_encryption->encrypt_file($backup_file, "", "", $start, base64_decode($iv))); |
838 | - }catch(\Exception $e){ |
|
838 | + } catch(\Exception $e){ |
|
839 | 839 | $return['error'] = true; |
840 | 840 | $return['message'] = $e->getMessage(); |
841 | 841 | $return['error_message'] = $e->getMessage(); |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | try { |
893 | 893 | $return = array_merge($return, |
894 | 894 | $this->xcloner_encryption->decrypt_file($backup_file, "", $decryption_key, $start, base64_decode($iv))); |
895 | - }catch(\Exception $e){ |
|
895 | + } catch(\Exception $e){ |
|
896 | 896 | $return['error'] = true; |
897 | 897 | $return['message'] = $e->getMessage(); |
898 | 898 | } |
@@ -994,7 +994,8 @@ discard block |
||
994 | 994 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
995 | 995 | <i class="material-icons">enhanced_encryption</i> |
996 | 996 | </a> |
997 | - <?php else: ?> |
|
997 | + <?php else { |
|
998 | + : ?> |
|
998 | 999 | <a href="#<?php echo $child[0] ?>" class="list-backup-content" |
999 | 1000 | title="<?php echo __('List Backup Content', |
1000 | 1001 | 'xcloner-backup-and-restore') ?>"><i |
@@ -1013,7 +1014,9 @@ discard block |
||
1013 | 1014 | class="material-icons">file_upload</i></a> |
1014 | 1015 | <?php endif ?> |
1015 | 1016 | </li> |
1016 | - <?php endforeach; ?> |
|
1017 | + <?php endforeach; |
|
1018 | +} |
|
1019 | +?> |
|
1017 | 1020 | </ul> |
1018 | 1021 | <?php endif; ?> |
1019 | 1022 | <?php |
@@ -1021,11 +1024,12 @@ discard block |
||
1021 | 1024 | ob_end_clean(); |
1022 | 1025 | ?> |
1023 | 1026 | <?php ob_start(); ?> |
1024 | - <?php if (isset($file_info['timestamp'])) |
|
1027 | + <?php if (isset($file_info['timestamp'])) { |
|
1025 | 1028 | echo date("Y-m-d H:i", $file_info['timestamp']) |
1026 | 1029 | ?> |
1027 | 1030 | <?php |
1028 | 1031 | $return['data'][$i][] = ob_get_contents(); |
1032 | +} |
|
1029 | 1033 | ob_end_clean(); |
1030 | 1034 | ?> |
1031 | 1035 | |
@@ -1050,15 +1054,17 @@ discard block |
||
1050 | 1054 | <?php endif ?> |
1051 | 1055 | <?php |
1052 | 1056 | $basename = $file_info['basename']; |
1053 | - if(isset($file_info['childs']) and sizeof($file_info['childs'])) |
|
1054 | - $basename = $file_info['childs'][0][0]; |
|
1057 | + if(isset($file_info['childs']) and sizeof($file_info['childs'])) { |
|
1058 | + $basename = $file_info['childs'][0][0]; |
|
1059 | + } |
|
1055 | 1060 | ?> |
1056 | 1061 | <?php if($this->xcloner_encryption->is_encrypted_file($basename)) :?> |
1057 | 1062 | <a href="#<?php echo $file_info['basename'] ?>" class="backup-decryption" |
1058 | 1063 | title="<?php echo __('Backup Decryption', 'xcloner-backup-and-restore') ?>"> |
1059 | 1064 | <i class="material-icons">enhanced_encryption</i> |
1060 | 1065 | </a> |
1061 | - <?php else: ?> |
|
1066 | + <?php else { |
|
1067 | + : ?> |
|
1062 | 1068 | <a href="#<?php echo $file_info['basename'] ?>" class="list-backup-content" |
1063 | 1069 | title="<?php echo __('List Backup Content', 'xcloner-backup-and-restore') ?>"><i |
1064 | 1070 | class="material-icons">folder_open</i></a> |
@@ -1068,7 +1074,9 @@ discard block |
||
1068 | 1074 | <i class="material-icons">no_encryption</i> |
1069 | 1075 | </a> |
1070 | 1076 | <?php endif?> |
1071 | - <?php endif; ?> |
|
1077 | + <?php endif; |
|
1078 | +} |
|
1079 | +?> |
|
1072 | 1080 | |
1073 | 1081 | <a href="#<?php echo $file_info['basename'] ?>" class="delete" |
1074 | 1082 | title="<?php echo __('Delete Backup', 'xcloner-backup-and-restore') ?>"> |
@@ -28,7 +28,6 @@ |
||
28 | 28 | |
29 | 29 | use League\Flysystem\Config; |
30 | 30 | use League\Flysystem\Filesystem; |
31 | -use League\Flysystem\Util; |
|
32 | 31 | use League\Flysystem\Adapter\Local; |
33 | 32 | |
34 | 33 | /** |
@@ -102,8 +102,8 @@ discard block |
||
102 | 102 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
103 | 103 | 'disable_asserts' => true, |
104 | 104 | ])); |
105 | - } catch (Exception $e) { |
|
106 | - $this->logger->error("Filesystem Initialization Error: " . $e->getMessage()); |
|
105 | + }catch (Exception $e) { |
|
106 | + $this->logger->error("Filesystem Initialization Error: ".$e->getMessage()); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | { |
162 | 162 | if ($remote_storage_selection != "") { |
163 | 163 | $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
164 | - $method = "get_" . $remote_storage_selection . "_filesystem"; |
|
164 | + $method = "get_".$remote_storage_selection."_filesystem"; |
|
165 | 165 | |
166 | 166 | if (!method_exists($remote_storage, $method)) { |
167 | 167 | return false; |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | $this->build_files_list($file); |
432 | 432 | $counter++; |
433 | 433 | } else { |
434 | - $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n"); |
|
434 | + $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
|
435 | 435 | } |
436 | 436 | } |
437 | 437 | } else { |
@@ -472,15 +472,15 @@ discard block |
||
472 | 472 | { |
473 | 473 | $return = array(); |
474 | 474 | |
475 | - $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler(); |
|
475 | + $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
|
476 | 476 | if (file_exists($files_list_file)) { |
477 | 477 | $return[] = $files_list_file; |
478 | 478 | } |
479 | 479 | |
480 | 480 | if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
481 | - $log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1); |
|
481 | + $log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
482 | 482 | if (!file_exists($log_file)) { |
483 | - $log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename(); |
|
483 | + $log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename(); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | if (file_exists($log_file)) { |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | |
615 | 615 | $files = $this->start_filesystem->listContents($folder); |
616 | 616 | foreach ($files as $file) { |
617 | - if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) { |
|
617 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) { |
|
618 | 618 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), |
619 | 619 | $file['path']), array( |
620 | 620 | "FILESYSTEM SCAN", |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | } |
643 | 643 | } |
644 | 644 | |
645 | - } catch (Exception $e) { |
|
645 | + }catch (Exception $e) { |
|
646 | 646 | |
647 | 647 | $this->logger->error($e->getMessage()); |
648 | 648 | |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | |
653 | 653 | public function estimate_read_write_time() |
654 | 654 | { |
655 | - $tmp_file = ".xcloner" . substr(md5(time()), 0, 5); |
|
655 | + $tmp_file = ".xcloner".substr(md5(time()), 0, 5); |
|
656 | 656 | |
657 | 657 | $start_time = microtime(true); |
658 | 658 | |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | |
670 | 670 | $this->tmp_filesystem->delete($tmp_file); |
671 | 671 | |
672 | - } catch (Exception $e) { |
|
672 | + }catch (Exception $e) { |
|
673 | 673 | |
674 | 674 | $this->logger->error($e->getMessage()); |
675 | 675 | |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | $_backup_files_list = array(); |
687 | 687 | |
688 | 688 | //rule date limit |
689 | - $current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days"); |
|
689 | + $current_timestamp = strtotime("-".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days')." days"); |
|
690 | 690 | |
691 | 691 | $files = $this->storage_filesystem->listContents(); |
692 | 692 | |
@@ -711,18 +711,18 @@ discard block |
||
711 | 711 | { |
712 | 712 | $this->storage_filesystem->delete($file['path']); |
713 | 713 | $_storage_size -= $file['size']; |
714 | - $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
|
714 | + $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
|
715 | 715 | "STORAGE SIZE LIMIT", |
716 | - $_storage_size . " >= " . $set_storage_limit |
|
716 | + $_storage_size." >= ".$set_storage_limit |
|
717 | 717 | )); |
718 | 718 | } |
719 | 719 | |
720 | 720 | //processing rule days limit |
721 | 721 | if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) { |
722 | 722 | $this->storage_filesystem->delete($file['path']); |
723 | - $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
|
723 | + $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
|
724 | 724 | "RETENTION LIMIT TIMESTAMP", |
725 | - $file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') |
|
725 | + $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') |
|
726 | 726 | )); |
727 | 727 | } |
728 | 728 | |
@@ -730,9 +730,9 @@ discard block |
||
730 | 730 | if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) { |
731 | 731 | $this->storage_filesystem->delete($file['path']); |
732 | 732 | $_backups_counter--; |
733 | - $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
|
733 | + $this->logger->info("Deleting backup ".$file['path']." matching rule", array( |
|
734 | 734 | "BACKUP QUANTITY LIMIT", |
735 | - $_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') |
|
735 | + $_backups_counter." >= ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') |
|
736 | 736 | )); |
737 | 737 | } |
738 | 738 | |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | } |
830 | 830 | |
831 | 831 | if ($timestamp <= $this->get_diff_timestamp_start()) { |
832 | - return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start; |
|
832 | + return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start; |
|
833 | 833 | } |
834 | 834 | } |
835 | 835 | |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | |
843 | 843 | if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) { |
844 | 844 | if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
845 | - return "> " . $xcloner_exclude_files_larger_than_mb . "MB"; |
|
845 | + return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
846 | 846 | } |
847 | 847 | } |
848 | 848 | |
@@ -855,10 +855,10 @@ discard block |
||
855 | 855 | if ($excluded_file_pattern == "/") { |
856 | 856 | $needle = "$"; |
857 | 857 | } else { |
858 | - $needle = "$" . $excluded_file_pattern; |
|
858 | + $needle = "$".$excluded_file_pattern; |
|
859 | 859 | } |
860 | 860 | |
861 | - if (strstr("$" . $file['path'], $needle)) { |
|
861 | + if (strstr("$".$file['path'], $needle)) { |
|
862 | 862 | return $excluded_file_pattern; |
863 | 863 | } |
864 | 864 | } |
@@ -937,11 +937,11 @@ discard block |
||
937 | 937 | if ($file['path'] == "/") { |
938 | 938 | $needle = "/"; |
939 | 939 | } else { |
940 | - $needle = "/" . $file['path']; |
|
940 | + $needle = "/".$file['path']; |
|
941 | 941 | } |
942 | 942 | //echo $needle."---".$excluded_file_pattern."---\n"; |
943 | 943 | |
944 | - if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) { |
|
944 | + if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { |
|
945 | 945 | return $excluded_file_pattern; |
946 | 946 | } |
947 | 947 | } |
@@ -963,14 +963,14 @@ discard block |
||
963 | 963 | |
964 | 964 | $csv_filename = str_replace('"', '""', $file['path']); |
965 | 965 | |
966 | - $line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL; |
|
966 | + $line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
|
967 | 967 | |
968 | 968 | $this->last_logged_file = $file['path']; |
969 | 969 | |
970 | 970 | if ($file['type'] == "dir") { |
971 | 971 | try { |
972 | - $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n"); |
|
973 | - } catch (Exception $e) { |
|
972 | + $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
|
973 | + }catch (Exception $e) { |
|
974 | 974 | $this->logger->error($e->getMessage()); |
975 | 975 | } |
976 | 976 | } |
@@ -990,13 +990,13 @@ discard block |
||
990 | 990 | try { |
991 | 991 | if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) { |
992 | 992 | //adding fix for UTF-8 CSV preview |
993 | - $start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL; |
|
993 | + $start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL; |
|
994 | 994 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line); |
995 | 995 | } |
996 | 996 | |
997 | 997 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
998 | 998 | |
999 | - } catch (Exception $e) { |
|
999 | + }catch (Exception $e) { |
|
1000 | 1000 | |
1001 | 1001 | $this->logger->error($e->getMessage()); |
1002 | 1002 | } |
@@ -707,9 +707,11 @@ |
||
707 | 707 | foreach ($_backup_files_list as $file) { |
708 | 708 | //processing rule folder capacity |
709 | 709 | if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
710 | - $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
710 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) { |
|
711 | + //bytes |
|
711 | 712 | { |
712 | 713 | $this->storage_filesystem->delete($file['path']); |
714 | + } |
|
713 | 715 | $_storage_size -= $file['size']; |
714 | 716 | $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
715 | 717 | "STORAGE SIZE LIMIT", |
@@ -207,6 +207,9 @@ discard block |
||
207 | 207 | return $this->start_filesystem->normalizeFileInfo($info); |
208 | 208 | } |
209 | 209 | |
210 | + /** |
|
211 | + * @param string $file |
|
212 | + */ |
|
210 | 213 | public function get_storage_path_file_info($file) |
211 | 214 | { |
212 | 215 | return $this->getMetadataFull('storage_adapter', $file); |
@@ -741,6 +744,9 @@ discard block |
||
741 | 744 | |
742 | 745 | } |
743 | 746 | |
747 | + /** |
|
748 | + * @param string $tmp_file |
|
749 | + */ |
|
744 | 750 | public function estimate_reading_time($tmp_file) |
745 | 751 | { |
746 | 752 | $this->logger->debug(sprintf(("Estimating file system reading time"))); |
@@ -781,6 +787,9 @@ discard block |
||
781 | 787 | return $name; |
782 | 788 | } |
783 | 789 | |
790 | + /** |
|
791 | + * @param string $field |
|
792 | + */ |
|
784 | 793 | public function sort_by(&$array, $field, $direction = 'asc') |
785 | 794 | { |
786 | 795 | if (strtolower($direction) == "desc" || $direction == SORT_DESC) { |
@@ -37,848 +37,848 @@ discard block |
||
37 | 37 | class Xcloner_File_System |
38 | 38 | { |
39 | 39 | |
40 | - private $excluded_files = ""; |
|
41 | - private $additional_regex_patterns = array(); |
|
42 | - private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
43 | - private $included_files_handler = "backup_files.csv"; |
|
44 | - private $temp_dir_handler = ".dir"; |
|
45 | - public $filesystem; |
|
46 | - public $tmp_filesystem; |
|
47 | - public $storage_filesystem; |
|
48 | - private $xcloner_container; |
|
49 | - private $diff_timestamp_start = ""; |
|
50 | - |
|
51 | - private $logger; |
|
52 | - private $start_adapter; |
|
53 | - private $tmp_adapter; |
|
54 | - private $storage_adapter; |
|
55 | - private $xcloner_settings; |
|
56 | - private $start_filesystem; |
|
57 | - private $tmp_filesystem_append; |
|
58 | - private $storage_filesystem_append; |
|
59 | - |
|
60 | - private $files_counter; |
|
61 | - private $files_size; |
|
62 | - private $last_logged_file; |
|
63 | - private $folders_to_process_per_session = 25; |
|
64 | - private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted"); |
|
65 | - private $backup_name_tags = array('[time]', '[hostname]', '[domain]'); |
|
66 | - |
|
67 | - /** |
|
68 | - * Xcloner_File_System constructor. |
|
69 | - * @param Xcloner $xcloner_container |
|
70 | - * @param string $hash |
|
71 | - */ |
|
72 | - public function __construct(Xcloner $xcloner_container, $hash = "") |
|
73 | - { |
|
74 | - $this->xcloner_container = $xcloner_container; |
|
75 | - |
|
76 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system"); |
|
77 | - $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
78 | - |
|
79 | - try { |
|
80 | - |
|
81 | - $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
82 | - $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
|
83 | - 'disable_asserts' => true, |
|
84 | - ])); |
|
85 | - |
|
86 | - $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
87 | - $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
|
88 | - 'disable_asserts' => true, |
|
89 | - ])); |
|
90 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
91 | - $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
|
92 | - 'disable_asserts' => true, |
|
93 | - ])); |
|
94 | - |
|
95 | - $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
96 | - $this->storage_filesystem = new Filesystem($adapter, new Config([ |
|
97 | - 'disable_asserts' => true, |
|
98 | - ])); |
|
99 | - |
|
100 | - $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, |
|
101 | - 'SKIP_LINKS'); |
|
102 | - $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
|
103 | - 'disable_asserts' => true, |
|
104 | - ])); |
|
105 | - } catch (Exception $e) { |
|
106 | - $this->logger->error("Filesystem Initialization Error: " . $e->getMessage()); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - if ($value = get_option('xcloner_directories_to_scan_per_request')) { |
|
111 | - $this->folders_to_process_per_session = $value; |
|
112 | - } |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Set differential timestamp date |
|
118 | - * @param string $timestamp |
|
119 | - */ |
|
120 | - public function set_diff_timestamp_start($timestamp = "") |
|
121 | - { |
|
122 | - if ($timestamp) { |
|
123 | - $this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array( |
|
124 | - "FILESYSTEM", |
|
125 | - "DIFF" |
|
126 | - )); |
|
127 | - $this->diff_timestamp_start = $timestamp; |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Gets the differential timestamp date |
|
133 | - * @return string |
|
134 | - */ |
|
135 | - public function get_diff_timestamp_start() |
|
136 | - { |
|
137 | - return $this->diff_timestamp_start; |
|
138 | - } |
|
139 | - |
|
140 | - private function get_xcloner_container() |
|
141 | - { |
|
142 | - return $this->xcloner_container; |
|
143 | - } |
|
144 | - |
|
145 | - public function set_hash($hash) |
|
146 | - { |
|
147 | - $this->xcloner_settings->set_hash($hash); |
|
148 | - } |
|
149 | - |
|
150 | - public function get_hash($hash) |
|
151 | - { |
|
152 | - $this->xcloner_settings->get_hash(); |
|
153 | - } |
|
154 | - |
|
155 | - public function get_tmp_filesystem() |
|
156 | - { |
|
157 | - return $this->tmp_filesystem; |
|
158 | - } |
|
159 | - |
|
160 | - public function get_storage_filesystem($remote_storage_selection = "") |
|
161 | - { |
|
162 | - if ($remote_storage_selection != "") { |
|
163 | - $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
164 | - $method = "get_" . $remote_storage_selection . "_filesystem"; |
|
165 | - |
|
166 | - if (!method_exists($remote_storage, $method)) { |
|
167 | - return false; |
|
168 | - } |
|
169 | - |
|
170 | - list($adapter, $filesystem) = $remote_storage->$method(); |
|
171 | - |
|
172 | - return $filesystem; |
|
173 | - } |
|
174 | - |
|
175 | - return $this->storage_filesystem; |
|
176 | - } |
|
177 | - |
|
178 | - public function get_tmp_filesystem_adapter() |
|
179 | - { |
|
180 | - return $this->tmp_adapter; |
|
181 | - } |
|
182 | - |
|
183 | - public function get_tmp_filesystem_append() |
|
184 | - { |
|
185 | - return $this->tmp_filesystem_append; |
|
186 | - } |
|
187 | - |
|
188 | - public function get_start_adapter() |
|
189 | - { |
|
190 | - return $this->start_adapter; |
|
191 | - } |
|
192 | - |
|
193 | - public function get_start_filesystem() |
|
194 | - { |
|
195 | - return $this->start_filesystem; |
|
196 | - } |
|
197 | - |
|
198 | - public function get_logger() |
|
199 | - { |
|
200 | - return $this->logger; |
|
201 | - } |
|
202 | - |
|
203 | - public function get_start_path_file_info($file) |
|
204 | - { |
|
205 | - $info = $this->getMetadataFull('start_adapter', $file); |
|
206 | - |
|
207 | - return $this->start_filesystem->normalizeFileInfo($info); |
|
208 | - } |
|
209 | - |
|
210 | - public function get_storage_path_file_info($file) |
|
211 | - { |
|
212 | - return $this->getMetadataFull('storage_adapter', $file); |
|
213 | - } |
|
214 | - |
|
215 | - public function get_included_files_handler($metadata = 0) |
|
216 | - { |
|
217 | - $path = $this->included_files_handler; |
|
218 | - if (!$metadata) { |
|
219 | - return $path; |
|
220 | - } |
|
221 | - |
|
222 | - $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
|
223 | - |
|
224 | - return $spl_info; |
|
225 | - |
|
226 | - } |
|
227 | - |
|
228 | - public function get_temp_dir_handler() |
|
229 | - { |
|
230 | - return $this->temp_dir_handler; |
|
231 | - } |
|
232 | - |
|
233 | - public function get_latest_backup() |
|
234 | - { |
|
235 | - $files = $this->get_backup_archives_list(); |
|
236 | - |
|
237 | - if (is_array($files)) { |
|
238 | - $this->sort_by($files, "timestamp", "desc"); |
|
239 | - } |
|
240 | - |
|
241 | - $new_list = array(); |
|
242 | - |
|
243 | - foreach ($files as $key => $file) { |
|
244 | - if (!isset($file['parent'])) { |
|
245 | - $new_list[] = ($files[$key]); |
|
246 | - } |
|
247 | - } |
|
248 | - |
|
249 | - if (isset($new_list[0])) { |
|
250 | - return $new_list[0]; |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - public function get_latest_backups() |
|
255 | - { |
|
256 | - $files = $this->get_backup_archives_list(); |
|
257 | - |
|
258 | - if (is_array($files)) { |
|
259 | - $this->sort_by($files, "timestamp", "desc"); |
|
260 | - } |
|
261 | - |
|
262 | - $new_list = array(); |
|
263 | - |
|
264 | - foreach ($files as $key => $file) { |
|
265 | - if (!isset($file['parent'])) { |
|
266 | - $new_list[] = ($files[$key]); |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - return $new_list; |
|
271 | - } |
|
272 | - |
|
273 | - public function get_storage_usage() |
|
274 | - { |
|
275 | - $files = $this->get_backup_archives_list(); |
|
276 | - $total = 0; |
|
277 | - |
|
278 | - if (is_array($files)) { |
|
279 | - foreach ($files as $file) { |
|
280 | - $total += $file['size']; |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - return $total; |
|
285 | - } |
|
286 | - |
|
287 | - public function is_part($backup_name) |
|
288 | - { |
|
289 | - if (stristr($backup_name, "-part")) { |
|
290 | - return true; |
|
291 | - } |
|
292 | - |
|
293 | - return false; |
|
294 | - } |
|
295 | - |
|
296 | - public function is_multipart($backup_name) |
|
297 | - { |
|
298 | - if (stristr($backup_name, "-multipart")) { |
|
299 | - return true; |
|
300 | - } |
|
301 | - |
|
302 | - return false; |
|
303 | - } |
|
304 | - |
|
305 | - public function get_backup_size($backup_name) |
|
306 | - { |
|
307 | - $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
|
308 | - if ($this->is_multipart($backup_name)) { |
|
309 | - $backup_parts = $this->get_multipart_files($backup_name); |
|
310 | - foreach ($backup_parts as $part_file) { |
|
311 | - $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
312 | - } |
|
313 | - } |
|
314 | - |
|
315 | - return $backup_size; |
|
316 | - } |
|
317 | - |
|
318 | - public function get_multipart_files($backup_name, $storage_selection = "") |
|
319 | - { |
|
320 | - $files = array(); |
|
321 | - |
|
322 | - if ($this->is_multipart($backup_name)) { |
|
323 | - $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
|
324 | - foreach ($lines as $line) { |
|
325 | - if ($line) { |
|
326 | - $data = str_getcsv($line); |
|
327 | - $files[] = $data[0]; |
|
328 | - } |
|
329 | - } |
|
330 | - } |
|
331 | - |
|
332 | - return $files; |
|
333 | - } |
|
334 | - |
|
335 | - public function delete_backup_by_name($backup_name, $storage_selection = "") |
|
336 | - { |
|
337 | - if ($this->is_multipart($backup_name)) { |
|
338 | - $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
|
339 | - foreach ($lines as $line) { |
|
340 | - if ($line) { |
|
341 | - $data = str_getcsv($line); |
|
342 | - $this->get_storage_filesystem($storage_selection)->delete($data[0]); |
|
343 | - } |
|
344 | - } |
|
345 | - } |
|
346 | - |
|
347 | - if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) { |
|
348 | - $return = true; |
|
349 | - } else { |
|
350 | - $return = false; |
|
351 | - } |
|
352 | - |
|
353 | - return $return; |
|
354 | - } |
|
355 | - |
|
356 | - public function getMetadataFull($adapter = "storage_adapter", $path) |
|
357 | - { |
|
358 | - $location = $this->$adapter->applyPathPrefix($path); |
|
359 | - $spl_info = new SplFileInfo($location); |
|
360 | - |
|
361 | - return ($spl_info); |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - public function get_backup_archives_list($storage_selection = "") |
|
366 | - { |
|
367 | - $list = array(); |
|
368 | - |
|
369 | - |
|
370 | - if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) { |
|
371 | - $list = $this->get_storage_filesystem($storage_selection)->listContents(); |
|
372 | - } |
|
373 | - |
|
374 | - $backup_files = array(); |
|
375 | - $parents = array(); |
|
376 | - |
|
377 | - foreach ($list as $file_info) { |
|
378 | - if (isset($file_info['extension']) and $file_info['extension'] == "csv") { |
|
379 | - $data = array(); |
|
380 | - |
|
381 | - $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path'])); |
|
382 | - foreach ($lines as $line) { |
|
383 | - if ($line) { |
|
384 | - $data = str_getcsv($line); |
|
385 | - if (is_array($data)) { |
|
386 | - $parents[$data[0]] = $file_info['basename']; |
|
387 | - $file_info['childs'][] = $data; |
|
388 | - $file_info['size'] += $data[2]; |
|
389 | - } |
|
390 | - } |
|
391 | - } |
|
392 | - |
|
393 | - } |
|
394 | - |
|
395 | - if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], |
|
396 | - $this->backup_archive_extensions)) { |
|
397 | - $backup_files[$file_info['path']] = $file_info; |
|
398 | - } |
|
399 | - } |
|
400 | - |
|
401 | - foreach ($backup_files as $key => $file_info) { |
|
402 | - if (!isset($backup_files[$key]['timestamp'])) { |
|
403 | - //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']); |
|
404 | - } |
|
405 | - |
|
406 | - if (isset($parents[$file_info['basename']])) { |
|
407 | - $backup_files[$key]['parent'] = $parents[$file_info['basename']]; |
|
408 | - } |
|
409 | - } |
|
410 | - |
|
411 | - return $backup_files; |
|
412 | - } |
|
413 | - |
|
414 | - public function start_file_recursion($init = 0) |
|
415 | - { |
|
416 | - if ($init) { |
|
417 | - $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), |
|
418 | - $this->xcloner_settings->get_xcloner_start_path())); |
|
419 | - $this->do_system_init(); |
|
420 | - } |
|
421 | - |
|
422 | - if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
423 | - //.dir exists, we presume we have files to iterate |
|
424 | - $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
|
425 | - $files = array_filter(explode("\n", $content)); |
|
426 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
427 | - |
|
428 | - $counter = 0; |
|
429 | - foreach ($files as $file) { |
|
430 | - if ($counter < $this->folders_to_process_per_session) { |
|
431 | - $this->build_files_list($file); |
|
432 | - $counter++; |
|
433 | - } else { |
|
434 | - $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n"); |
|
435 | - } |
|
436 | - } |
|
437 | - } else { |
|
438 | - $this->build_files_list(); |
|
439 | - } |
|
440 | - |
|
441 | - if ($this->scan_finished()) { |
|
442 | - $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
|
443 | - $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
444 | - $this->files_counter++; |
|
445 | - |
|
446 | - //adding included dump file to the included files list |
|
447 | - if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) { |
|
448 | - $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
|
449 | - $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
450 | - $this->files_counter++; |
|
451 | - } |
|
452 | - |
|
453 | - //adding a default index.html to the temp xcloner folder |
|
454 | - if (!$this->get_tmp_filesystem()->has("index.html")) { |
|
455 | - $this->get_tmp_filesystem()->write("index.html", ""); |
|
456 | - } |
|
457 | - |
|
458 | - //adding the default log file |
|
459 | - if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) { |
|
460 | - $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
|
461 | - $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
462 | - $this->files_counter++; |
|
463 | - } |
|
464 | - |
|
465 | - return false; |
|
466 | - } |
|
467 | - |
|
468 | - return true; |
|
469 | - } |
|
470 | - |
|
471 | - public function get_backup_attachments() |
|
472 | - { |
|
473 | - $return = array(); |
|
474 | - |
|
475 | - $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler(); |
|
476 | - if (file_exists($files_list_file)) { |
|
477 | - $return[] = $files_list_file; |
|
478 | - } |
|
479 | - |
|
480 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
481 | - $log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1); |
|
482 | - if (!file_exists($log_file)) { |
|
483 | - $log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename(); |
|
484 | - } |
|
485 | - |
|
486 | - if (file_exists($log_file)) { |
|
487 | - $return[] = $log_file; |
|
488 | - } |
|
489 | - } |
|
490 | - |
|
491 | - return $return; |
|
492 | - } |
|
493 | - |
|
494 | - public function remove_tmp_filesystem() |
|
495 | - { |
|
496 | - //delete the temporary folder |
|
497 | - $this->logger->debug(sprintf("Deleting the temporary storage folder %s", |
|
498 | - $this->xcloner_settings->get_xcloner_tmp_path())); |
|
499 | - |
|
500 | - $contents = $this->get_tmp_filesystem()->listContents(); |
|
501 | - |
|
502 | - if (is_array($contents)) { |
|
503 | - foreach ($contents as $file_info) { |
|
504 | - $this->get_tmp_filesystem()->delete($file_info['path']); |
|
505 | - } |
|
506 | - } |
|
507 | - |
|
508 | - @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
|
509 | - |
|
510 | - return; |
|
511 | - } |
|
512 | - |
|
513 | - public function cleanup_tmp_directories() |
|
514 | - { |
|
515 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
516 | - $tmp_filesystem = new Filesystem($adapter, new Config([ |
|
517 | - 'disable_asserts' => true, |
|
518 | - ])); |
|
519 | - |
|
520 | - $contents = $tmp_filesystem->listContents(); |
|
521 | - |
|
522 | - foreach ($contents as $file) { |
|
523 | - |
|
524 | - if (preg_match("/.xcloner-(.*)/", $file['path'])) { |
|
525 | - if ($file['timestamp'] < strtotime("-1days")) { |
|
526 | - $tmp_filesystem->deleteDir($file['path']); |
|
527 | - $this->logger->debug(sprintf("Delete temporary directory %s", $file['path'])); |
|
528 | - } |
|
529 | - } |
|
530 | - } |
|
531 | - |
|
532 | - return true; |
|
533 | - } |
|
534 | - |
|
535 | - private function do_system_init() |
|
536 | - { |
|
537 | - $this->files_counter = 0; |
|
538 | - |
|
539 | - if (!$this->storage_filesystem->has("index.html")) { |
|
540 | - $this->storage_filesystem->write("index.html", ""); |
|
541 | - } |
|
542 | - |
|
543 | - if (!$this->tmp_filesystem->has("index.html")) { |
|
544 | - $this->tmp_filesystem->write("index.html", ""); |
|
545 | - } |
|
546 | - |
|
547 | - if ($this->tmp_filesystem->has($this->get_included_files_handler())) { |
|
548 | - $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
549 | - } |
|
550 | - |
|
551 | - if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
552 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
553 | - } |
|
554 | - } |
|
555 | - |
|
556 | - public function get_scanned_files_num() |
|
557 | - { |
|
558 | - return $this->files_counter; |
|
559 | - } |
|
560 | - |
|
561 | - public function get_scanned_files_total_size() |
|
562 | - { |
|
563 | - return $this->files_size; |
|
564 | - } |
|
565 | - |
|
566 | - public function last_logged_file() |
|
567 | - { |
|
568 | - return $this->last_logged_file; |
|
569 | - } |
|
570 | - |
|
571 | - public static function is_regex($regex) |
|
572 | - { |
|
573 | - return preg_match("/^\^(.*)\$$/i", $regex); |
|
574 | - } |
|
40 | + private $excluded_files = ""; |
|
41 | + private $additional_regex_patterns = array(); |
|
42 | + private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
43 | + private $included_files_handler = "backup_files.csv"; |
|
44 | + private $temp_dir_handler = ".dir"; |
|
45 | + public $filesystem; |
|
46 | + public $tmp_filesystem; |
|
47 | + public $storage_filesystem; |
|
48 | + private $xcloner_container; |
|
49 | + private $diff_timestamp_start = ""; |
|
50 | + |
|
51 | + private $logger; |
|
52 | + private $start_adapter; |
|
53 | + private $tmp_adapter; |
|
54 | + private $storage_adapter; |
|
55 | + private $xcloner_settings; |
|
56 | + private $start_filesystem; |
|
57 | + private $tmp_filesystem_append; |
|
58 | + private $storage_filesystem_append; |
|
59 | + |
|
60 | + private $files_counter; |
|
61 | + private $files_size; |
|
62 | + private $last_logged_file; |
|
63 | + private $folders_to_process_per_session = 25; |
|
64 | + private $backup_archive_extensions = array("tar", "tgz", "tar.gz", "gz", "csv", "encrypted", "decrypted"); |
|
65 | + private $backup_name_tags = array('[time]', '[hostname]', '[domain]'); |
|
66 | + |
|
67 | + /** |
|
68 | + * Xcloner_File_System constructor. |
|
69 | + * @param Xcloner $xcloner_container |
|
70 | + * @param string $hash |
|
71 | + */ |
|
72 | + public function __construct(Xcloner $xcloner_container, $hash = "") |
|
73 | + { |
|
74 | + $this->xcloner_container = $xcloner_container; |
|
75 | + |
|
76 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system"); |
|
77 | + $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
78 | + |
|
79 | + try { |
|
80 | + |
|
81 | + $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
82 | + $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
|
83 | + 'disable_asserts' => true, |
|
84 | + ])); |
|
85 | + |
|
86 | + $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
87 | + $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
|
88 | + 'disable_asserts' => true, |
|
89 | + ])); |
|
90 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
91 | + $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
|
92 | + 'disable_asserts' => true, |
|
93 | + ])); |
|
94 | + |
|
95 | + $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
96 | + $this->storage_filesystem = new Filesystem($adapter, new Config([ |
|
97 | + 'disable_asserts' => true, |
|
98 | + ])); |
|
99 | + |
|
100 | + $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, |
|
101 | + 'SKIP_LINKS'); |
|
102 | + $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
|
103 | + 'disable_asserts' => true, |
|
104 | + ])); |
|
105 | + } catch (Exception $e) { |
|
106 | + $this->logger->error("Filesystem Initialization Error: " . $e->getMessage()); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + if ($value = get_option('xcloner_directories_to_scan_per_request')) { |
|
111 | + $this->folders_to_process_per_session = $value; |
|
112 | + } |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Set differential timestamp date |
|
118 | + * @param string $timestamp |
|
119 | + */ |
|
120 | + public function set_diff_timestamp_start($timestamp = "") |
|
121 | + { |
|
122 | + if ($timestamp) { |
|
123 | + $this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array( |
|
124 | + "FILESYSTEM", |
|
125 | + "DIFF" |
|
126 | + )); |
|
127 | + $this->diff_timestamp_start = $timestamp; |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Gets the differential timestamp date |
|
133 | + * @return string |
|
134 | + */ |
|
135 | + public function get_diff_timestamp_start() |
|
136 | + { |
|
137 | + return $this->diff_timestamp_start; |
|
138 | + } |
|
139 | + |
|
140 | + private function get_xcloner_container() |
|
141 | + { |
|
142 | + return $this->xcloner_container; |
|
143 | + } |
|
144 | + |
|
145 | + public function set_hash($hash) |
|
146 | + { |
|
147 | + $this->xcloner_settings->set_hash($hash); |
|
148 | + } |
|
149 | + |
|
150 | + public function get_hash($hash) |
|
151 | + { |
|
152 | + $this->xcloner_settings->get_hash(); |
|
153 | + } |
|
154 | + |
|
155 | + public function get_tmp_filesystem() |
|
156 | + { |
|
157 | + return $this->tmp_filesystem; |
|
158 | + } |
|
159 | + |
|
160 | + public function get_storage_filesystem($remote_storage_selection = "") |
|
161 | + { |
|
162 | + if ($remote_storage_selection != "") { |
|
163 | + $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
164 | + $method = "get_" . $remote_storage_selection . "_filesystem"; |
|
165 | + |
|
166 | + if (!method_exists($remote_storage, $method)) { |
|
167 | + return false; |
|
168 | + } |
|
169 | + |
|
170 | + list($adapter, $filesystem) = $remote_storage->$method(); |
|
171 | + |
|
172 | + return $filesystem; |
|
173 | + } |
|
174 | + |
|
175 | + return $this->storage_filesystem; |
|
176 | + } |
|
177 | + |
|
178 | + public function get_tmp_filesystem_adapter() |
|
179 | + { |
|
180 | + return $this->tmp_adapter; |
|
181 | + } |
|
182 | + |
|
183 | + public function get_tmp_filesystem_append() |
|
184 | + { |
|
185 | + return $this->tmp_filesystem_append; |
|
186 | + } |
|
187 | + |
|
188 | + public function get_start_adapter() |
|
189 | + { |
|
190 | + return $this->start_adapter; |
|
191 | + } |
|
192 | + |
|
193 | + public function get_start_filesystem() |
|
194 | + { |
|
195 | + return $this->start_filesystem; |
|
196 | + } |
|
197 | + |
|
198 | + public function get_logger() |
|
199 | + { |
|
200 | + return $this->logger; |
|
201 | + } |
|
202 | + |
|
203 | + public function get_start_path_file_info($file) |
|
204 | + { |
|
205 | + $info = $this->getMetadataFull('start_adapter', $file); |
|
206 | + |
|
207 | + return $this->start_filesystem->normalizeFileInfo($info); |
|
208 | + } |
|
209 | + |
|
210 | + public function get_storage_path_file_info($file) |
|
211 | + { |
|
212 | + return $this->getMetadataFull('storage_adapter', $file); |
|
213 | + } |
|
214 | + |
|
215 | + public function get_included_files_handler($metadata = 0) |
|
216 | + { |
|
217 | + $path = $this->included_files_handler; |
|
218 | + if (!$metadata) { |
|
219 | + return $path; |
|
220 | + } |
|
221 | + |
|
222 | + $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
|
223 | + |
|
224 | + return $spl_info; |
|
225 | + |
|
226 | + } |
|
227 | + |
|
228 | + public function get_temp_dir_handler() |
|
229 | + { |
|
230 | + return $this->temp_dir_handler; |
|
231 | + } |
|
232 | + |
|
233 | + public function get_latest_backup() |
|
234 | + { |
|
235 | + $files = $this->get_backup_archives_list(); |
|
236 | + |
|
237 | + if (is_array($files)) { |
|
238 | + $this->sort_by($files, "timestamp", "desc"); |
|
239 | + } |
|
240 | + |
|
241 | + $new_list = array(); |
|
242 | + |
|
243 | + foreach ($files as $key => $file) { |
|
244 | + if (!isset($file['parent'])) { |
|
245 | + $new_list[] = ($files[$key]); |
|
246 | + } |
|
247 | + } |
|
248 | + |
|
249 | + if (isset($new_list[0])) { |
|
250 | + return $new_list[0]; |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + public function get_latest_backups() |
|
255 | + { |
|
256 | + $files = $this->get_backup_archives_list(); |
|
257 | + |
|
258 | + if (is_array($files)) { |
|
259 | + $this->sort_by($files, "timestamp", "desc"); |
|
260 | + } |
|
261 | + |
|
262 | + $new_list = array(); |
|
263 | + |
|
264 | + foreach ($files as $key => $file) { |
|
265 | + if (!isset($file['parent'])) { |
|
266 | + $new_list[] = ($files[$key]); |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + return $new_list; |
|
271 | + } |
|
272 | + |
|
273 | + public function get_storage_usage() |
|
274 | + { |
|
275 | + $files = $this->get_backup_archives_list(); |
|
276 | + $total = 0; |
|
277 | + |
|
278 | + if (is_array($files)) { |
|
279 | + foreach ($files as $file) { |
|
280 | + $total += $file['size']; |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + return $total; |
|
285 | + } |
|
286 | + |
|
287 | + public function is_part($backup_name) |
|
288 | + { |
|
289 | + if (stristr($backup_name, "-part")) { |
|
290 | + return true; |
|
291 | + } |
|
292 | + |
|
293 | + return false; |
|
294 | + } |
|
295 | + |
|
296 | + public function is_multipart($backup_name) |
|
297 | + { |
|
298 | + if (stristr($backup_name, "-multipart")) { |
|
299 | + return true; |
|
300 | + } |
|
301 | + |
|
302 | + return false; |
|
303 | + } |
|
304 | + |
|
305 | + public function get_backup_size($backup_name) |
|
306 | + { |
|
307 | + $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
|
308 | + if ($this->is_multipart($backup_name)) { |
|
309 | + $backup_parts = $this->get_multipart_files($backup_name); |
|
310 | + foreach ($backup_parts as $part_file) { |
|
311 | + $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
312 | + } |
|
313 | + } |
|
314 | + |
|
315 | + return $backup_size; |
|
316 | + } |
|
317 | + |
|
318 | + public function get_multipart_files($backup_name, $storage_selection = "") |
|
319 | + { |
|
320 | + $files = array(); |
|
321 | + |
|
322 | + if ($this->is_multipart($backup_name)) { |
|
323 | + $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
|
324 | + foreach ($lines as $line) { |
|
325 | + if ($line) { |
|
326 | + $data = str_getcsv($line); |
|
327 | + $files[] = $data[0]; |
|
328 | + } |
|
329 | + } |
|
330 | + } |
|
331 | + |
|
332 | + return $files; |
|
333 | + } |
|
334 | + |
|
335 | + public function delete_backup_by_name($backup_name, $storage_selection = "") |
|
336 | + { |
|
337 | + if ($this->is_multipart($backup_name)) { |
|
338 | + $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
|
339 | + foreach ($lines as $line) { |
|
340 | + if ($line) { |
|
341 | + $data = str_getcsv($line); |
|
342 | + $this->get_storage_filesystem($storage_selection)->delete($data[0]); |
|
343 | + } |
|
344 | + } |
|
345 | + } |
|
346 | + |
|
347 | + if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) { |
|
348 | + $return = true; |
|
349 | + } else { |
|
350 | + $return = false; |
|
351 | + } |
|
352 | + |
|
353 | + return $return; |
|
354 | + } |
|
355 | + |
|
356 | + public function getMetadataFull($adapter = "storage_adapter", $path) |
|
357 | + { |
|
358 | + $location = $this->$adapter->applyPathPrefix($path); |
|
359 | + $spl_info = new SplFileInfo($location); |
|
360 | + |
|
361 | + return ($spl_info); |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + public function get_backup_archives_list($storage_selection = "") |
|
366 | + { |
|
367 | + $list = array(); |
|
368 | + |
|
369 | + |
|
370 | + if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) { |
|
371 | + $list = $this->get_storage_filesystem($storage_selection)->listContents(); |
|
372 | + } |
|
373 | + |
|
374 | + $backup_files = array(); |
|
375 | + $parents = array(); |
|
376 | + |
|
377 | + foreach ($list as $file_info) { |
|
378 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") { |
|
379 | + $data = array(); |
|
380 | + |
|
381 | + $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path'])); |
|
382 | + foreach ($lines as $line) { |
|
383 | + if ($line) { |
|
384 | + $data = str_getcsv($line); |
|
385 | + if (is_array($data)) { |
|
386 | + $parents[$data[0]] = $file_info['basename']; |
|
387 | + $file_info['childs'][] = $data; |
|
388 | + $file_info['size'] += $data[2]; |
|
389 | + } |
|
390 | + } |
|
391 | + } |
|
392 | + |
|
393 | + } |
|
394 | + |
|
395 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], |
|
396 | + $this->backup_archive_extensions)) { |
|
397 | + $backup_files[$file_info['path']] = $file_info; |
|
398 | + } |
|
399 | + } |
|
400 | + |
|
401 | + foreach ($backup_files as $key => $file_info) { |
|
402 | + if (!isset($backup_files[$key]['timestamp'])) { |
|
403 | + //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']); |
|
404 | + } |
|
405 | + |
|
406 | + if (isset($parents[$file_info['basename']])) { |
|
407 | + $backup_files[$key]['parent'] = $parents[$file_info['basename']]; |
|
408 | + } |
|
409 | + } |
|
410 | + |
|
411 | + return $backup_files; |
|
412 | + } |
|
413 | + |
|
414 | + public function start_file_recursion($init = 0) |
|
415 | + { |
|
416 | + if ($init) { |
|
417 | + $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), |
|
418 | + $this->xcloner_settings->get_xcloner_start_path())); |
|
419 | + $this->do_system_init(); |
|
420 | + } |
|
421 | + |
|
422 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
423 | + //.dir exists, we presume we have files to iterate |
|
424 | + $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
|
425 | + $files = array_filter(explode("\n", $content)); |
|
426 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
427 | + |
|
428 | + $counter = 0; |
|
429 | + foreach ($files as $file) { |
|
430 | + if ($counter < $this->folders_to_process_per_session) { |
|
431 | + $this->build_files_list($file); |
|
432 | + $counter++; |
|
433 | + } else { |
|
434 | + $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file . "\n"); |
|
435 | + } |
|
436 | + } |
|
437 | + } else { |
|
438 | + $this->build_files_list(); |
|
439 | + } |
|
440 | + |
|
441 | + if ($this->scan_finished()) { |
|
442 | + $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
|
443 | + $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
444 | + $this->files_counter++; |
|
445 | + |
|
446 | + //adding included dump file to the included files list |
|
447 | + if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) { |
|
448 | + $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
|
449 | + $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
450 | + $this->files_counter++; |
|
451 | + } |
|
452 | + |
|
453 | + //adding a default index.html to the temp xcloner folder |
|
454 | + if (!$this->get_tmp_filesystem()->has("index.html")) { |
|
455 | + $this->get_tmp_filesystem()->write("index.html", ""); |
|
456 | + } |
|
457 | + |
|
458 | + //adding the default log file |
|
459 | + if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) { |
|
460 | + $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
|
461 | + $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
|
462 | + $this->files_counter++; |
|
463 | + } |
|
464 | + |
|
465 | + return false; |
|
466 | + } |
|
467 | + |
|
468 | + return true; |
|
469 | + } |
|
470 | + |
|
471 | + public function get_backup_attachments() |
|
472 | + { |
|
473 | + $return = array(); |
|
474 | + |
|
475 | + $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->get_included_files_handler(); |
|
476 | + if (file_exists($files_list_file)) { |
|
477 | + $return[] = $files_list_file; |
|
478 | + } |
|
479 | + |
|
480 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
481 | + $log_file = $this->xcloner_settings->get_xcloner_tmp_path() . DS . $this->xcloner_settings->get_logger_filename(1); |
|
482 | + if (!file_exists($log_file)) { |
|
483 | + $log_file = $this->xcloner_settings->get_xcloner_store_path() . DS . $this->xcloner_settings->get_logger_filename(); |
|
484 | + } |
|
485 | + |
|
486 | + if (file_exists($log_file)) { |
|
487 | + $return[] = $log_file; |
|
488 | + } |
|
489 | + } |
|
490 | + |
|
491 | + return $return; |
|
492 | + } |
|
493 | + |
|
494 | + public function remove_tmp_filesystem() |
|
495 | + { |
|
496 | + //delete the temporary folder |
|
497 | + $this->logger->debug(sprintf("Deleting the temporary storage folder %s", |
|
498 | + $this->xcloner_settings->get_xcloner_tmp_path())); |
|
499 | + |
|
500 | + $contents = $this->get_tmp_filesystem()->listContents(); |
|
501 | + |
|
502 | + if (is_array($contents)) { |
|
503 | + foreach ($contents as $file_info) { |
|
504 | + $this->get_tmp_filesystem()->delete($file_info['path']); |
|
505 | + } |
|
506 | + } |
|
507 | + |
|
508 | + @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
|
509 | + |
|
510 | + return; |
|
511 | + } |
|
512 | + |
|
513 | + public function cleanup_tmp_directories() |
|
514 | + { |
|
515 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
516 | + $tmp_filesystem = new Filesystem($adapter, new Config([ |
|
517 | + 'disable_asserts' => true, |
|
518 | + ])); |
|
519 | + |
|
520 | + $contents = $tmp_filesystem->listContents(); |
|
521 | + |
|
522 | + foreach ($contents as $file) { |
|
523 | + |
|
524 | + if (preg_match("/.xcloner-(.*)/", $file['path'])) { |
|
525 | + if ($file['timestamp'] < strtotime("-1days")) { |
|
526 | + $tmp_filesystem->deleteDir($file['path']); |
|
527 | + $this->logger->debug(sprintf("Delete temporary directory %s", $file['path'])); |
|
528 | + } |
|
529 | + } |
|
530 | + } |
|
531 | + |
|
532 | + return true; |
|
533 | + } |
|
534 | + |
|
535 | + private function do_system_init() |
|
536 | + { |
|
537 | + $this->files_counter = 0; |
|
538 | + |
|
539 | + if (!$this->storage_filesystem->has("index.html")) { |
|
540 | + $this->storage_filesystem->write("index.html", ""); |
|
541 | + } |
|
542 | + |
|
543 | + if (!$this->tmp_filesystem->has("index.html")) { |
|
544 | + $this->tmp_filesystem->write("index.html", ""); |
|
545 | + } |
|
546 | + |
|
547 | + if ($this->tmp_filesystem->has($this->get_included_files_handler())) { |
|
548 | + $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
549 | + } |
|
550 | + |
|
551 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
552 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
553 | + } |
|
554 | + } |
|
555 | + |
|
556 | + public function get_scanned_files_num() |
|
557 | + { |
|
558 | + return $this->files_counter; |
|
559 | + } |
|
560 | + |
|
561 | + public function get_scanned_files_total_size() |
|
562 | + { |
|
563 | + return $this->files_size; |
|
564 | + } |
|
565 | + |
|
566 | + public function last_logged_file() |
|
567 | + { |
|
568 | + return $this->last_logged_file; |
|
569 | + } |
|
570 | + |
|
571 | + public static function is_regex($regex) |
|
572 | + { |
|
573 | + return preg_match("/^\^(.*)\$$/i", $regex); |
|
574 | + } |
|
575 | 575 | |
576 | - public function set_excluded_files($excluded_files = array()) |
|
577 | - { |
|
578 | - if (!is_array($excluded_files)) { |
|
579 | - $excluded_files = array(); |
|
580 | - } |
|
576 | + public function set_excluded_files($excluded_files = array()) |
|
577 | + { |
|
578 | + if (!is_array($excluded_files)) { |
|
579 | + $excluded_files = array(); |
|
580 | + } |
|
581 | 581 | |
582 | - foreach ($excluded_files as $excl) { |
|
582 | + foreach ($excluded_files as $excl) { |
|
583 | 583 | |
584 | - if ($this->is_regex($excl)) { |
|
585 | - $this->additional_regex_patterns[] = $excl; |
|
586 | - } |
|
587 | - } |
|
584 | + if ($this->is_regex($excl)) { |
|
585 | + $this->additional_regex_patterns[] = $excl; |
|
586 | + } |
|
587 | + } |
|
588 | 588 | |
589 | - $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
|
589 | + $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
|
590 | 590 | |
591 | - return $this->excluded_files; |
|
592 | - } |
|
591 | + return $this->excluded_files; |
|
592 | + } |
|
593 | 593 | |
594 | - public function get_excluded_files() |
|
595 | - { |
|
596 | - return $this->excluded_files_by_default; |
|
597 | - } |
|
594 | + public function get_excluded_files() |
|
595 | + { |
|
596 | + return $this->excluded_files_by_default; |
|
597 | + } |
|
598 | 598 | |
599 | - public function list_directory($path) |
|
600 | - { |
|
601 | - return $this->start_filesystem->listContents($path); |
|
602 | - } |
|
599 | + public function list_directory($path) |
|
600 | + { |
|
601 | + return $this->start_filesystem->listContents($path); |
|
602 | + } |
|
603 | 603 | |
604 | - public function build_files_list($folder = "") |
|
605 | - { |
|
606 | - $this->logger->debug(sprintf(("Building the files system list"))); |
|
604 | + public function build_files_list($folder = "") |
|
605 | + { |
|
606 | + $this->logger->debug(sprintf(("Building the files system list"))); |
|
607 | 607 | |
608 | - //if we start with the root folder(empty value), we initializa the file system |
|
609 | - if (!$folder) { |
|
608 | + //if we start with the root folder(empty value), we initializa the file system |
|
609 | + if (!$folder) { |
|
610 | 610 | |
611 | - } |
|
611 | + } |
|
612 | 612 | |
613 | - try { |
|
613 | + try { |
|
614 | 614 | |
615 | - $files = $this->start_filesystem->listContents($folder); |
|
616 | - foreach ($files as $file) { |
|
617 | - if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) { |
|
618 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), |
|
619 | - $file['path']), array( |
|
620 | - "FILESYSTEM SCAN", |
|
621 | - "NOT READABLE" |
|
622 | - )); |
|
623 | - } elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
624 | - $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array( |
|
625 | - "FILESYSTEM SCAN", |
|
626 | - "INCLUDE" |
|
627 | - )); |
|
628 | - $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
|
629 | - if ($this->store_file($file)) { |
|
630 | - $this->files_counter++; |
|
631 | - } |
|
632 | - if (isset($file['size'])) { |
|
633 | - $this->files_size += $file['size']; |
|
634 | - } |
|
635 | - |
|
636 | - } else { |
|
637 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), |
|
638 | - $file['path'], $matching_pattern), array( |
|
639 | - "FILESYSTEM SCAN", |
|
640 | - "EXCLUDE" |
|
641 | - )); |
|
642 | - } |
|
643 | - } |
|
615 | + $files = $this->start_filesystem->listContents($folder); |
|
616 | + foreach ($files as $file) { |
|
617 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path() . DS . $file['path'])) { |
|
618 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), |
|
619 | + $file['path']), array( |
|
620 | + "FILESYSTEM SCAN", |
|
621 | + "NOT READABLE" |
|
622 | + )); |
|
623 | + } elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
624 | + $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array( |
|
625 | + "FILESYSTEM SCAN", |
|
626 | + "INCLUDE" |
|
627 | + )); |
|
628 | + $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
|
629 | + if ($this->store_file($file)) { |
|
630 | + $this->files_counter++; |
|
631 | + } |
|
632 | + if (isset($file['size'])) { |
|
633 | + $this->files_size += $file['size']; |
|
634 | + } |
|
635 | + |
|
636 | + } else { |
|
637 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), |
|
638 | + $file['path'], $matching_pattern), array( |
|
639 | + "FILESYSTEM SCAN", |
|
640 | + "EXCLUDE" |
|
641 | + )); |
|
642 | + } |
|
643 | + } |
|
644 | 644 | |
645 | - } catch (Exception $e) { |
|
645 | + } catch (Exception $e) { |
|
646 | 646 | |
647 | - $this->logger->error($e->getMessage()); |
|
647 | + $this->logger->error($e->getMessage()); |
|
648 | 648 | |
649 | - } |
|
649 | + } |
|
650 | 650 | |
651 | - } |
|
651 | + } |
|
652 | 652 | |
653 | - public function estimate_read_write_time() |
|
654 | - { |
|
655 | - $tmp_file = ".xcloner" . substr(md5(time()), 0, 5); |
|
653 | + public function estimate_read_write_time() |
|
654 | + { |
|
655 | + $tmp_file = ".xcloner" . substr(md5(time()), 0, 5); |
|
656 | 656 | |
657 | - $start_time = microtime(true); |
|
657 | + $start_time = microtime(true); |
|
658 | 658 | |
659 | - $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
659 | + $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
660 | 660 | |
661 | - try { |
|
662 | - $this->tmp_filesystem->write($tmp_file, $data); |
|
661 | + try { |
|
662 | + $this->tmp_filesystem->write($tmp_file, $data); |
|
663 | 663 | |
664 | - $end_time = microtime(true) - $start_time; |
|
664 | + $end_time = microtime(true) - $start_time; |
|
665 | 665 | |
666 | - $return['writing_time'] = $end_time; |
|
666 | + $return['writing_time'] = $end_time; |
|
667 | 667 | |
668 | - $return['reading_time'] = $this->estimate_reading_time($tmp_file); |
|
668 | + $return['reading_time'] = $this->estimate_reading_time($tmp_file); |
|
669 | 669 | |
670 | - $this->tmp_filesystem->delete($tmp_file); |
|
670 | + $this->tmp_filesystem->delete($tmp_file); |
|
671 | 671 | |
672 | - } catch (Exception $e) { |
|
672 | + } catch (Exception $e) { |
|
673 | 673 | |
674 | - $this->logger->error($e->getMessage()); |
|
674 | + $this->logger->error($e->getMessage()); |
|
675 | 675 | |
676 | - } |
|
676 | + } |
|
677 | 677 | |
678 | - return $return; |
|
679 | - } |
|
678 | + return $return; |
|
679 | + } |
|
680 | 680 | |
681 | - public function backup_storage_cleanup() |
|
682 | - { |
|
683 | - $this->logger->info(sprintf(("Cleaning the backup storage on matching rules"))); |
|
681 | + public function backup_storage_cleanup() |
|
682 | + { |
|
683 | + $this->logger->info(sprintf(("Cleaning the backup storage on matching rules"))); |
|
684 | 684 | |
685 | - $_storage_size = 0; |
|
686 | - $_backup_files_list = array(); |
|
685 | + $_storage_size = 0; |
|
686 | + $_backup_files_list = array(); |
|
687 | 687 | |
688 | - //rule date limit |
|
689 | - $current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days"); |
|
688 | + //rule date limit |
|
689 | + $current_timestamp = strtotime("-" . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') . " days"); |
|
690 | 690 | |
691 | - $files = $this->storage_filesystem->listContents(); |
|
691 | + $files = $this->storage_filesystem->listContents(); |
|
692 | 692 | |
693 | - if (is_array($files)) { |
|
694 | - foreach ($files as $file) { |
|
695 | - if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) { |
|
696 | - $_storage_size += $file['size']; //bytes |
|
697 | - $_backup_files_list[] = $file; |
|
698 | - } |
|
699 | - } |
|
700 | - } |
|
693 | + if (is_array($files)) { |
|
694 | + foreach ($files as $file) { |
|
695 | + if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) { |
|
696 | + $_storage_size += $file['size']; //bytes |
|
697 | + $_backup_files_list[] = $file; |
|
698 | + } |
|
699 | + } |
|
700 | + } |
|
701 | 701 | |
702 | 702 | |
703 | - $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
703 | + $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
704 | 704 | |
705 | - $_backups_counter = sizeof($_backup_files_list); |
|
705 | + $_backups_counter = sizeof($_backup_files_list); |
|
706 | 706 | |
707 | - foreach ($_backup_files_list as $file) { |
|
708 | - //processing rule folder capacity |
|
709 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
710 | - $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
711 | - { |
|
712 | - $this->storage_filesystem->delete($file['path']); |
|
713 | - $_storage_size -= $file['size']; |
|
714 | - $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
|
715 | - "STORAGE SIZE LIMIT", |
|
716 | - $_storage_size . " >= " . $set_storage_limit |
|
717 | - )); |
|
718 | - } |
|
719 | - |
|
720 | - //processing rule days limit |
|
721 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) { |
|
722 | - $this->storage_filesystem->delete($file['path']); |
|
723 | - $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
|
724 | - "RETENTION LIMIT TIMESTAMP", |
|
725 | - $file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') |
|
726 | - )); |
|
727 | - } |
|
728 | - |
|
729 | - //processing backup countert limit |
|
730 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) { |
|
731 | - $this->storage_filesystem->delete($file['path']); |
|
732 | - $_backups_counter--; |
|
733 | - $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
|
734 | - "BACKUP QUANTITY LIMIT", |
|
735 | - $_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') |
|
736 | - )); |
|
737 | - } |
|
707 | + foreach ($_backup_files_list as $file) { |
|
708 | + //processing rule folder capacity |
|
709 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
710 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
711 | + { |
|
712 | + $this->storage_filesystem->delete($file['path']); |
|
713 | + $_storage_size -= $file['size']; |
|
714 | + $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
|
715 | + "STORAGE SIZE LIMIT", |
|
716 | + $_storage_size . " >= " . $set_storage_limit |
|
717 | + )); |
|
718 | + } |
|
719 | + |
|
720 | + //processing rule days limit |
|
721 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) { |
|
722 | + $this->storage_filesystem->delete($file['path']); |
|
723 | + $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
|
724 | + "RETENTION LIMIT TIMESTAMP", |
|
725 | + $file['timestamp'] . " =< " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') |
|
726 | + )); |
|
727 | + } |
|
728 | + |
|
729 | + //processing backup countert limit |
|
730 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) { |
|
731 | + $this->storage_filesystem->delete($file['path']); |
|
732 | + $_backups_counter--; |
|
733 | + $this->logger->info("Deleting backup " . $file['path'] . " matching rule", array( |
|
734 | + "BACKUP QUANTITY LIMIT", |
|
735 | + $_backups_counter . " >= " . $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') |
|
736 | + )); |
|
737 | + } |
|
738 | 738 | |
739 | 739 | |
740 | - } |
|
740 | + } |
|
741 | 741 | |
742 | - } |
|
742 | + } |
|
743 | 743 | |
744 | - public function estimate_reading_time($tmp_file) |
|
745 | - { |
|
746 | - $this->logger->debug(sprintf(("Estimating file system reading time"))); |
|
744 | + public function estimate_reading_time($tmp_file) |
|
745 | + { |
|
746 | + $this->logger->debug(sprintf(("Estimating file system reading time"))); |
|
747 | 747 | |
748 | - $start_time = microtime(true); |
|
748 | + $start_time = microtime(true); |
|
749 | 749 | |
750 | - if ($this->tmp_filesystem->has($tmp_file)) { |
|
751 | - $this->tmp_filesystem->read($tmp_file); |
|
752 | - } |
|
753 | - |
|
754 | - $end_time = microtime(true) - $start_time; |
|
755 | - |
|
756 | - return $end_time; |
|
757 | - |
|
758 | - } |
|
759 | - |
|
760 | - public function process_backup_name($name = "", $max_length = 100) |
|
761 | - { |
|
762 | - if (!$name) { |
|
763 | - $name = $this->xcloner_settings->get_default_backup_name(); |
|
764 | - } |
|
765 | - |
|
766 | - foreach ($this->backup_name_tags as $tag) { |
|
767 | - if ($tag == '[time]') { |
|
768 | - $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
769 | - } elseif ($tag == '[hostname]') { |
|
770 | - $name = str_replace($tag, gethostname(), $name); |
|
771 | - } elseif ($tag == '[domain]') { |
|
772 | - $domain = parse_url(admin_url(), PHP_URL_HOST); |
|
773 | - $name = str_replace($tag, $domain, $name); |
|
774 | - } |
|
775 | - } |
|
776 | - |
|
777 | - if ($max_length) { |
|
778 | - $name = substr($name, 0, $max_length); |
|
779 | - } |
|
780 | - |
|
781 | - return $name; |
|
782 | - } |
|
783 | - |
|
784 | - public function sort_by(&$array, $field, $direction = 'asc') |
|
785 | - { |
|
786 | - if (strtolower($direction) == "desc" || $direction == SORT_DESC) { |
|
787 | - $direction = SORT_DESC; |
|
788 | - } else { |
|
789 | - $direction = SORT_ASC; |
|
790 | - } |
|
791 | - |
|
792 | - $array = $this->array_orderby($array, $field, $direction); |
|
793 | - |
|
794 | - return true; |
|
795 | - } |
|
796 | - |
|
797 | - private function array_orderby() |
|
798 | - { |
|
799 | - $args = func_get_args(); |
|
800 | - $data = array_shift($args); |
|
801 | - |
|
802 | - foreach ($args as $n => $field) { |
|
803 | - if (is_string($field)) { |
|
804 | - $tmp = array(); |
|
805 | - foreach ($data as $key => $row) { |
|
806 | - if (is_array($row)) { |
|
807 | - $tmp[$key] = $row[$field]; |
|
808 | - } else { |
|
809 | - $tmp[$key] = $row->$field; |
|
810 | - } |
|
811 | - } |
|
812 | - $args[$n] = $tmp; |
|
813 | - } |
|
814 | - } |
|
815 | - $args[] = &$data; |
|
816 | - |
|
817 | - call_user_func_array('array_multisort', $args); |
|
818 | - |
|
819 | - return array_pop($args); |
|
820 | - } |
|
821 | - |
|
822 | - private function check_file_diff_time($file) |
|
823 | - { |
|
824 | - if ($this->get_diff_timestamp_start() != "") { |
|
825 | - $fileMeta = $this->getMetadataFull("start_adapter", $file['path']); |
|
826 | - $timestamp = $fileMeta->getMTime(); |
|
827 | - if ($timestamp < $fileMeta->getCTime()) { |
|
828 | - $timestamp = $fileMeta->getCTime(); |
|
829 | - } |
|
830 | - |
|
831 | - if ($timestamp <= $this->get_diff_timestamp_start()) { |
|
832 | - return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start; |
|
833 | - } |
|
834 | - } |
|
835 | - |
|
836 | - return false; |
|
837 | - } |
|
838 | - |
|
839 | - public function is_excluded($file) |
|
840 | - { |
|
841 | - $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
|
842 | - |
|
843 | - if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) { |
|
844 | - if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
|
845 | - return "> " . $xcloner_exclude_files_larger_than_mb . "MB"; |
|
846 | - } |
|
847 | - } |
|
848 | - |
|
849 | - if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) { |
|
850 | - $this->set_excluded_files(); |
|
851 | - } |
|
852 | - |
|
853 | - if (is_array($this->excluded_files)) { |
|
854 | - foreach ($this->excluded_files as $excluded_file_pattern) { |
|
855 | - if ($excluded_file_pattern == "/") { |
|
856 | - $needle = "$"; |
|
857 | - } else { |
|
858 | - $needle = "$" . $excluded_file_pattern; |
|
859 | - } |
|
860 | - |
|
861 | - if (strstr("$" . $file['path'], $needle)) { |
|
862 | - return $excluded_file_pattern; |
|
863 | - } |
|
864 | - } |
|
865 | - } |
|
866 | - |
|
867 | - if ($regex = $this->is_excluded_regex($file)) { |
|
868 | - return $regex; |
|
869 | - } |
|
870 | - |
|
871 | - if ($file['type'] == "file") { |
|
872 | - $check_file_diff_timestamp = $this->check_file_diff_time($file); |
|
873 | - if ($check_file_diff_timestamp) { |
|
874 | - return $check_file_diff_timestamp; |
|
875 | - } |
|
876 | - } |
|
877 | - |
|
878 | - return false; |
|
879 | - } |
|
880 | - |
|
881 | - /*REGEX examples |
|
750 | + if ($this->tmp_filesystem->has($tmp_file)) { |
|
751 | + $this->tmp_filesystem->read($tmp_file); |
|
752 | + } |
|
753 | + |
|
754 | + $end_time = microtime(true) - $start_time; |
|
755 | + |
|
756 | + return $end_time; |
|
757 | + |
|
758 | + } |
|
759 | + |
|
760 | + public function process_backup_name($name = "", $max_length = 100) |
|
761 | + { |
|
762 | + if (!$name) { |
|
763 | + $name = $this->xcloner_settings->get_default_backup_name(); |
|
764 | + } |
|
765 | + |
|
766 | + foreach ($this->backup_name_tags as $tag) { |
|
767 | + if ($tag == '[time]') { |
|
768 | + $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
769 | + } elseif ($tag == '[hostname]') { |
|
770 | + $name = str_replace($tag, gethostname(), $name); |
|
771 | + } elseif ($tag == '[domain]') { |
|
772 | + $domain = parse_url(admin_url(), PHP_URL_HOST); |
|
773 | + $name = str_replace($tag, $domain, $name); |
|
774 | + } |
|
775 | + } |
|
776 | + |
|
777 | + if ($max_length) { |
|
778 | + $name = substr($name, 0, $max_length); |
|
779 | + } |
|
780 | + |
|
781 | + return $name; |
|
782 | + } |
|
783 | + |
|
784 | + public function sort_by(&$array, $field, $direction = 'asc') |
|
785 | + { |
|
786 | + if (strtolower($direction) == "desc" || $direction == SORT_DESC) { |
|
787 | + $direction = SORT_DESC; |
|
788 | + } else { |
|
789 | + $direction = SORT_ASC; |
|
790 | + } |
|
791 | + |
|
792 | + $array = $this->array_orderby($array, $field, $direction); |
|
793 | + |
|
794 | + return true; |
|
795 | + } |
|
796 | + |
|
797 | + private function array_orderby() |
|
798 | + { |
|
799 | + $args = func_get_args(); |
|
800 | + $data = array_shift($args); |
|
801 | + |
|
802 | + foreach ($args as $n => $field) { |
|
803 | + if (is_string($field)) { |
|
804 | + $tmp = array(); |
|
805 | + foreach ($data as $key => $row) { |
|
806 | + if (is_array($row)) { |
|
807 | + $tmp[$key] = $row[$field]; |
|
808 | + } else { |
|
809 | + $tmp[$key] = $row->$field; |
|
810 | + } |
|
811 | + } |
|
812 | + $args[$n] = $tmp; |
|
813 | + } |
|
814 | + } |
|
815 | + $args[] = &$data; |
|
816 | + |
|
817 | + call_user_func_array('array_multisort', $args); |
|
818 | + |
|
819 | + return array_pop($args); |
|
820 | + } |
|
821 | + |
|
822 | + private function check_file_diff_time($file) |
|
823 | + { |
|
824 | + if ($this->get_diff_timestamp_start() != "") { |
|
825 | + $fileMeta = $this->getMetadataFull("start_adapter", $file['path']); |
|
826 | + $timestamp = $fileMeta->getMTime(); |
|
827 | + if ($timestamp < $fileMeta->getCTime()) { |
|
828 | + $timestamp = $fileMeta->getCTime(); |
|
829 | + } |
|
830 | + |
|
831 | + if ($timestamp <= $this->get_diff_timestamp_start()) { |
|
832 | + return " file DIFF timestamp " . $timestamp . " < " . $this->diff_timestamp_start; |
|
833 | + } |
|
834 | + } |
|
835 | + |
|
836 | + return false; |
|
837 | + } |
|
838 | + |
|
839 | + public function is_excluded($file) |
|
840 | + { |
|
841 | + $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
|
842 | + |
|
843 | + if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) { |
|
844 | + if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
|
845 | + return "> " . $xcloner_exclude_files_larger_than_mb . "MB"; |
|
846 | + } |
|
847 | + } |
|
848 | + |
|
849 | + if (!is_array($this->excluded_files) || !sizeof($this->excluded_files)) { |
|
850 | + $this->set_excluded_files(); |
|
851 | + } |
|
852 | + |
|
853 | + if (is_array($this->excluded_files)) { |
|
854 | + foreach ($this->excluded_files as $excluded_file_pattern) { |
|
855 | + if ($excluded_file_pattern == "/") { |
|
856 | + $needle = "$"; |
|
857 | + } else { |
|
858 | + $needle = "$" . $excluded_file_pattern; |
|
859 | + } |
|
860 | + |
|
861 | + if (strstr("$" . $file['path'], $needle)) { |
|
862 | + return $excluded_file_pattern; |
|
863 | + } |
|
864 | + } |
|
865 | + } |
|
866 | + |
|
867 | + if ($regex = $this->is_excluded_regex($file)) { |
|
868 | + return $regex; |
|
869 | + } |
|
870 | + |
|
871 | + if ($file['type'] == "file") { |
|
872 | + $check_file_diff_timestamp = $this->check_file_diff_time($file); |
|
873 | + if ($check_file_diff_timestamp) { |
|
874 | + return $check_file_diff_timestamp; |
|
875 | + } |
|
876 | + } |
|
877 | + |
|
878 | + return false; |
|
879 | + } |
|
880 | + |
|
881 | + /*REGEX examples |
|
882 | 882 | * |
883 | 883 | * exclude all except .php file |
884 | 884 | * PATTERN: ^(.*)\.(.+)$(?<!(php)) |
@@ -910,163 +910,163 @@ discard block |
||
910 | 910 | * exclude the backup folders |
911 | 911 | * PATTERN: (^|^\/)(wp-content\/backups|administrator\/backups)(.*)$"; |
912 | 912 | */ |
913 | - private function is_excluded_regex($file) |
|
914 | - { |
|
915 | - //$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
|
916 | - |
|
917 | - $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude')); |
|
918 | - |
|
919 | - if (is_array($this->additional_regex_patterns)) { |
|
920 | - $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns); |
|
921 | - } |
|
922 | - |
|
923 | - //print_r($regex_patterns);exit; |
|
924 | - |
|
925 | - if (is_array($regex_patterns)) { |
|
926 | - //$this->excluded_files = array(); |
|
927 | - //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
|
928 | - //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
|
929 | - |
|
930 | - foreach ($regex_patterns as $excluded_file_pattern) { |
|
931 | - |
|
932 | - if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, |
|
933 | - strlen($excluded_file_pattern)) == "\r") { |
|
934 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
935 | - } |
|
936 | - |
|
937 | - if ($file['path'] == "/") { |
|
938 | - $needle = "/"; |
|
939 | - } else { |
|
940 | - $needle = "/" . $file['path']; |
|
941 | - } |
|
942 | - //echo $needle."---".$excluded_file_pattern."---\n"; |
|
943 | - |
|
944 | - if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) { |
|
945 | - return $excluded_file_pattern; |
|
946 | - } |
|
947 | - } |
|
948 | - } |
|
949 | - |
|
950 | - return false; |
|
951 | - } |
|
952 | - |
|
953 | - public function store_file($file, $storage = 'start_filesystem') |
|
954 | - { |
|
955 | - $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
|
956 | - |
|
957 | - if (!isset($file['size'])) { |
|
958 | - $file['size'] = 0; |
|
959 | - } |
|
960 | - if (!isset($file['visibility'])) { |
|
961 | - $file['visibility'] = "private"; |
|
962 | - } |
|
963 | - |
|
964 | - $csv_filename = str_replace('"', '""', $file['path']); |
|
965 | - |
|
966 | - $line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL; |
|
967 | - |
|
968 | - $this->last_logged_file = $file['path']; |
|
969 | - |
|
970 | - if ($file['type'] == "dir") { |
|
971 | - try { |
|
972 | - $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n"); |
|
973 | - } catch (Exception $e) { |
|
974 | - $this->logger->error($e->getMessage()); |
|
975 | - } |
|
976 | - } |
|
977 | - |
|
978 | - if ($this->get_diff_timestamp_start()) { |
|
979 | - if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) { |
|
980 | - $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], |
|
981 | - $response), array( |
|
982 | - "FILESYSTEM SCAN", |
|
983 | - "DIR DIFF" |
|
984 | - )); |
|
985 | - |
|
986 | - return false; |
|
987 | - } |
|
988 | - } |
|
989 | - |
|
990 | - try { |
|
991 | - if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) { |
|
992 | - //adding fix for UTF-8 CSV preview |
|
993 | - $start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL; |
|
994 | - $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line); |
|
995 | - } |
|
996 | - |
|
997 | - $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
|
998 | - |
|
999 | - } catch (Exception $e) { |
|
1000 | - |
|
1001 | - $this->logger->error($e->getMessage()); |
|
1002 | - } |
|
1003 | - |
|
1004 | - return true; |
|
1005 | - } |
|
1006 | - |
|
1007 | - public function get_fileystem_handler() |
|
1008 | - { |
|
1009 | - return $this; |
|
1010 | - } |
|
1011 | - |
|
1012 | - public function get_filesystem($system = "") |
|
1013 | - { |
|
1014 | - if ($system == "storage_filesystem_append") { |
|
1015 | - return $this->storage_filesystem_append; |
|
1016 | - } elseif ($system == "tmp_filesystem_append") { |
|
1017 | - return $this->tmp_filesystem_append; |
|
1018 | - } elseif ($system == "tmp_filesystem") { |
|
1019 | - return $this->tmp_filesystem; |
|
1020 | - } elseif ($system == "storage_filesystem") { |
|
1021 | - return $this->storage_filesystem; |
|
1022 | - } else { |
|
1023 | - return $this->start_filesystem; |
|
1024 | - } |
|
1025 | - } |
|
1026 | - |
|
1027 | - public function get_adapter($system) |
|
1028 | - { |
|
1029 | - if ($system == "tmp_filesystem") { |
|
1030 | - return $this->tmp_adapter; |
|
1031 | - } elseif ($system == "storage_filesystem") { |
|
1032 | - return $this->storage_adapter; |
|
1033 | - } else { |
|
1034 | - return $this->start_adapter; |
|
1035 | - } |
|
1036 | - } |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * File scan finished |
|
1040 | - * Method called when file scan is finished |
|
1041 | - * |
|
1042 | - * @return bool |
|
1043 | - */ |
|
1044 | - private function scan_finished() |
|
1045 | - { |
|
1046 | - if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && |
|
1047 | - $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { |
|
1048 | - return false; |
|
1049 | - } |
|
1050 | - |
|
1051 | - if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
1052 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
1053 | - } |
|
1054 | - |
|
1055 | - $this->logger->debug(sprintf(("File scan finished"))); |
|
1056 | - |
|
1057 | - return true; |
|
1058 | - } |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * Calculate bytes from MB value |
|
1062 | - * |
|
1063 | - * @param int $mb_size |
|
1064 | - * |
|
1065 | - * @return float|int |
|
1066 | - */ |
|
1067 | - private function calc_to_bytes($mb_size) |
|
1068 | - { |
|
1069 | - return $mb_size * (1024 * 1024); |
|
1070 | - } |
|
913 | + private function is_excluded_regex($file) |
|
914 | + { |
|
915 | + //$this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
|
916 | + |
|
917 | + $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude')); |
|
918 | + |
|
919 | + if (is_array($this->additional_regex_patterns)) { |
|
920 | + $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns); |
|
921 | + } |
|
922 | + |
|
923 | + //print_r($regex_patterns);exit; |
|
924 | + |
|
925 | + if (is_array($regex_patterns)) { |
|
926 | + //$this->excluded_files = array(); |
|
927 | + //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
|
928 | + //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
|
929 | + |
|
930 | + foreach ($regex_patterns as $excluded_file_pattern) { |
|
931 | + |
|
932 | + if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, |
|
933 | + strlen($excluded_file_pattern)) == "\r") { |
|
934 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
935 | + } |
|
936 | + |
|
937 | + if ($file['path'] == "/") { |
|
938 | + $needle = "/"; |
|
939 | + } else { |
|
940 | + $needle = "/" . $file['path']; |
|
941 | + } |
|
942 | + //echo $needle."---".$excluded_file_pattern."---\n"; |
|
943 | + |
|
944 | + if (@preg_match("/(^|^\/)" . $excluded_file_pattern . "/i", $needle)) { |
|
945 | + return $excluded_file_pattern; |
|
946 | + } |
|
947 | + } |
|
948 | + } |
|
949 | + |
|
950 | + return false; |
|
951 | + } |
|
952 | + |
|
953 | + public function store_file($file, $storage = 'start_filesystem') |
|
954 | + { |
|
955 | + $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
|
956 | + |
|
957 | + if (!isset($file['size'])) { |
|
958 | + $file['size'] = 0; |
|
959 | + } |
|
960 | + if (!isset($file['visibility'])) { |
|
961 | + $file['visibility'] = "private"; |
|
962 | + } |
|
963 | + |
|
964 | + $csv_filename = str_replace('"', '""', $file['path']); |
|
965 | + |
|
966 | + $line = '"' . ($csv_filename) . '","' . $file['timestamp'] . '","' . $file['size'] . '","' . $file['visibility'] . '","' . $storage . '"' . PHP_EOL; |
|
967 | + |
|
968 | + $this->last_logged_file = $file['path']; |
|
969 | + |
|
970 | + if ($file['type'] == "dir") { |
|
971 | + try { |
|
972 | + $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path'] . "\n"); |
|
973 | + } catch (Exception $e) { |
|
974 | + $this->logger->error($e->getMessage()); |
|
975 | + } |
|
976 | + } |
|
977 | + |
|
978 | + if ($this->get_diff_timestamp_start()) { |
|
979 | + if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) { |
|
980 | + $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], |
|
981 | + $response), array( |
|
982 | + "FILESYSTEM SCAN", |
|
983 | + "DIR DIFF" |
|
984 | + )); |
|
985 | + |
|
986 | + return false; |
|
987 | + } |
|
988 | + } |
|
989 | + |
|
990 | + try { |
|
991 | + if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) { |
|
992 | + //adding fix for UTF-8 CSV preview |
|
993 | + $start_line = "\xEF\xBB\xBF" . '"Filename","Timestamp","Size","Visibility","Storage"' . PHP_EOL; |
|
994 | + $this->tmp_filesystem_append->write($this->get_included_files_handler(), $start_line); |
|
995 | + } |
|
996 | + |
|
997 | + $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
|
998 | + |
|
999 | + } catch (Exception $e) { |
|
1000 | + |
|
1001 | + $this->logger->error($e->getMessage()); |
|
1002 | + } |
|
1003 | + |
|
1004 | + return true; |
|
1005 | + } |
|
1006 | + |
|
1007 | + public function get_fileystem_handler() |
|
1008 | + { |
|
1009 | + return $this; |
|
1010 | + } |
|
1011 | + |
|
1012 | + public function get_filesystem($system = "") |
|
1013 | + { |
|
1014 | + if ($system == "storage_filesystem_append") { |
|
1015 | + return $this->storage_filesystem_append; |
|
1016 | + } elseif ($system == "tmp_filesystem_append") { |
|
1017 | + return $this->tmp_filesystem_append; |
|
1018 | + } elseif ($system == "tmp_filesystem") { |
|
1019 | + return $this->tmp_filesystem; |
|
1020 | + } elseif ($system == "storage_filesystem") { |
|
1021 | + return $this->storage_filesystem; |
|
1022 | + } else { |
|
1023 | + return $this->start_filesystem; |
|
1024 | + } |
|
1025 | + } |
|
1026 | + |
|
1027 | + public function get_adapter($system) |
|
1028 | + { |
|
1029 | + if ($system == "tmp_filesystem") { |
|
1030 | + return $this->tmp_adapter; |
|
1031 | + } elseif ($system == "storage_filesystem") { |
|
1032 | + return $this->storage_adapter; |
|
1033 | + } else { |
|
1034 | + return $this->start_adapter; |
|
1035 | + } |
|
1036 | + } |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * File scan finished |
|
1040 | + * Method called when file scan is finished |
|
1041 | + * |
|
1042 | + * @return bool |
|
1043 | + */ |
|
1044 | + private function scan_finished() |
|
1045 | + { |
|
1046 | + if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && |
|
1047 | + $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { |
|
1048 | + return false; |
|
1049 | + } |
|
1050 | + |
|
1051 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
1052 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
1053 | + } |
|
1054 | + |
|
1055 | + $this->logger->debug(sprintf(("File scan finished"))); |
|
1056 | + |
|
1057 | + return true; |
|
1058 | + } |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * Calculate bytes from MB value |
|
1062 | + * |
|
1063 | + * @param int $mb_size |
|
1064 | + * |
|
1065 | + * @return float|int |
|
1066 | + */ |
|
1067 | + private function calc_to_bytes($mb_size) |
|
1068 | + { |
|
1069 | + return $mb_size * (1024 * 1024); |
|
1070 | + } |
|
1071 | 1071 | |
1072 | 1072 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | - * @return mixed |
|
55 | + * @return string |
|
56 | 56 | */ |
57 | 57 | public function get_target() |
58 | 58 | { |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
144 | - * @param $filename |
|
144 | + * @param string $filename |
|
145 | 145 | * @param string $mimetype |
146 | 146 | * @param string $postname |
147 | 147 | * |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | |
82 | 82 | $binary_data = fread($fp, $this->transfer_limit); |
83 | 83 | |
84 | - $tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5); |
|
84 | + $tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5); |
|
85 | 85 | |
86 | 86 | $this->get_tmp_filesystem()->write($tmp_filename, $binary_data); |
87 | 87 | |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $result = json_decode($original_result); |
123 | 123 | |
124 | 124 | if (!$result) { |
125 | - throw new Exception("We have received no valid response from the remote host, original message: " . $original_result); |
|
125 | + throw new Exception("We have received no valid response from the remote host, original message: ".$original_result); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | if ($result->status != 200) { |
@@ -29,137 +29,137 @@ |
||
29 | 29 | class Xcloner_File_Transfer extends Xcloner_File_System |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Target url web address of the restore script |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private $target_url; |
|
37 | - /** |
|
38 | - * Transfer data limit in bytes |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400 |
|
32 | + /** |
|
33 | + * Target url web address of the restore script |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private $target_url; |
|
37 | + /** |
|
38 | + * Transfer data limit in bytes |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400 |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param $target_url |
|
46 | - * |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public function set_target($target_url) |
|
50 | - { |
|
51 | - return $this->target_url = $target_url; |
|
52 | - } |
|
44 | + /** |
|
45 | + * @param $target_url |
|
46 | + * |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public function set_target($target_url) |
|
50 | + { |
|
51 | + return $this->target_url = $target_url; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return mixed |
|
56 | - */ |
|
57 | - public function get_target() |
|
58 | - { |
|
59 | - return $this->target_url; |
|
60 | - } |
|
54 | + /** |
|
55 | + * @return mixed |
|
56 | + */ |
|
57 | + public function get_target() |
|
58 | + { |
|
59 | + return $this->target_url; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * @param $file |
|
65 | - * @param int $start |
|
66 | - * @param string $hash |
|
67 | - * |
|
68 | - * @return bool|int |
|
69 | - * @throws Exception |
|
70 | - */ |
|
71 | - public function transfer_file($file, $start = 0, $hash = "") |
|
72 | - { |
|
73 | - if (!$this->target_url) { |
|
74 | - throw new Exception("Please setup a target url for upload"); |
|
75 | - } |
|
63 | + /** |
|
64 | + * @param $file |
|
65 | + * @param int $start |
|
66 | + * @param string $hash |
|
67 | + * |
|
68 | + * @return bool|int |
|
69 | + * @throws Exception |
|
70 | + */ |
|
71 | + public function transfer_file($file, $start = 0, $hash = "") |
|
72 | + { |
|
73 | + if (!$this->target_url) { |
|
74 | + throw new Exception("Please setup a target url for upload"); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - $fp = $this->get_storage_filesystem()->readStream($file); |
|
78 | + $fp = $this->get_storage_filesystem()->readStream($file); |
|
79 | 79 | |
80 | - fseek($fp, $start, SEEK_SET); |
|
80 | + fseek($fp, $start, SEEK_SET); |
|
81 | 81 | |
82 | - $binary_data = fread($fp, $this->transfer_limit); |
|
82 | + $binary_data = fread($fp, $this->transfer_limit); |
|
83 | 83 | |
84 | - $tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5); |
|
84 | + $tmp_filename = "xcloner_upload_" . substr(md5(time()), 0, 5); |
|
85 | 85 | |
86 | - $this->get_tmp_filesystem()->write($tmp_filename, $binary_data); |
|
86 | + $this->get_tmp_filesystem()->write($tmp_filename, $binary_data); |
|
87 | 87 | |
88 | - $tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename); |
|
88 | + $tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename); |
|
89 | 89 | |
90 | - $send_array = array(); |
|
90 | + $send_array = array(); |
|
91 | 91 | |
92 | - $send_array['file'] = $file; |
|
93 | - $send_array['start'] = $start; |
|
94 | - $send_array['xcloner_action'] = "write_file"; |
|
95 | - $send_array['hash'] = $hash; |
|
96 | - #$send_array['blob'] = $binary_data; |
|
97 | - $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename); |
|
92 | + $send_array['file'] = $file; |
|
93 | + $send_array['start'] = $start; |
|
94 | + $send_array['xcloner_action'] = "write_file"; |
|
95 | + $send_array['hash'] = $hash; |
|
96 | + #$send_array['blob'] = $binary_data; |
|
97 | + $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename); |
|
98 | 98 | |
99 | - //$data = http_build_query($send_array); |
|
99 | + //$data = http_build_query($send_array); |
|
100 | 100 | |
101 | - $this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s", |
|
102 | - $this->target_url, $this->transfer_limit, $file, $start, $tmp_filename)); |
|
101 | + $this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s", |
|
102 | + $this->target_url, $this->transfer_limit, $file, $start, $tmp_filename)); |
|
103 | 103 | |
104 | 104 | |
105 | - $ch = curl_init(); |
|
106 | - curl_setopt($ch, CURLOPT_URL, $this->target_url); |
|
105 | + $ch = curl_init(); |
|
106 | + curl_setopt($ch, CURLOPT_URL, $this->target_url); |
|
107 | 107 | |
108 | - curl_setopt($ch, CURLOPT_POST, 1); |
|
109 | - //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); |
|
110 | - //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); |
|
111 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); |
|
112 | - curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
|
113 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
108 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
109 | + //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); |
|
110 | + //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); |
|
111 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); |
|
112 | + curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
|
113 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
114 | 114 | |
115 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array); |
|
116 | - curl_setopt($ch, CURLOPT_VERBOSE, true); |
|
115 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array); |
|
116 | + curl_setopt($ch, CURLOPT_VERBOSE, true); |
|
117 | 117 | |
118 | - $original_result = curl_exec($ch); |
|
118 | + $original_result = curl_exec($ch); |
|
119 | 119 | |
120 | 120 | |
121 | - $this->get_tmp_filesystem()->delete($tmp_filename); |
|
121 | + $this->get_tmp_filesystem()->delete($tmp_filename); |
|
122 | 122 | |
123 | - $result = json_decode($original_result); |
|
123 | + $result = json_decode($original_result); |
|
124 | 124 | |
125 | - if (!$result) { |
|
126 | - throw new Exception("We have received no valid response from the remote host, original message: " . $original_result); |
|
127 | - } |
|
125 | + if (!$result) { |
|
126 | + throw new Exception("We have received no valid response from the remote host, original message: " . $original_result); |
|
127 | + } |
|
128 | 128 | |
129 | - if ($result->status != 200) { |
|
130 | - throw new Exception($result->response); |
|
131 | - } |
|
129 | + if ($result->status != 200) { |
|
130 | + throw new Exception($result->response); |
|
131 | + } |
|
132 | 132 | |
133 | - if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) { |
|
134 | - $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes", |
|
135 | - $file, $this->target_url, ftell($fp))); |
|
136 | - $this->remove_tmp_filesystem(); |
|
133 | + if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) { |
|
134 | + $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes", |
|
135 | + $file, $this->target_url, ftell($fp))); |
|
136 | + $this->remove_tmp_filesystem(); |
|
137 | 137 | |
138 | - return false; |
|
139 | - } |
|
138 | + return false; |
|
139 | + } |
|
140 | 140 | |
141 | - return ftell($fp); |
|
142 | - } |
|
141 | + return ftell($fp); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @param $filename |
|
146 | - * @param string $mimetype |
|
147 | - * @param string $postname |
|
148 | - * |
|
149 | - * @return CURLFile|string |
|
150 | - */ |
|
151 | - private function curl_file_create($filename, $mimetype = '', $postname = '') |
|
152 | - { |
|
153 | - if (!function_exists('curl_file_create')) { |
|
144 | + /** |
|
145 | + * @param $filename |
|
146 | + * @param string $mimetype |
|
147 | + * @param string $postname |
|
148 | + * |
|
149 | + * @return CURLFile|string |
|
150 | + */ |
|
151 | + private function curl_file_create($filename, $mimetype = '', $postname = '') |
|
152 | + { |
|
153 | + if (!function_exists('curl_file_create')) { |
|
154 | 154 | |
155 | - return "@$filename;filename=" |
|
156 | - . ($postname ?: basename($filename)) |
|
157 | - . ($mimetype ? ";type=$mimetype" : ''); |
|
155 | + return "@$filename;filename=" |
|
156 | + . ($postname ?: basename($filename)) |
|
157 | + . ($mimetype ? ";type=$mimetype" : ''); |
|
158 | 158 | |
159 | - } else { |
|
159 | + } else { |
|
160 | 160 | |
161 | - return curl_file_create($filename, $mimetype, $postname); |
|
161 | + return curl_file_create($filename, $mimetype, $postname); |
|
162 | 162 | |
163 | - } |
|
164 | - } |
|
163 | + } |
|
164 | + } |
|
165 | 165 | } |
@@ -281,6 +281,9 @@ |
||
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
284 | + /** |
|
285 | + * @param string $storage_type |
|
286 | + */ |
|
284 | 287 | public function verify_filesystem( $storage_type ) { |
285 | 288 | $method = "get_" . $storage_type . "_filesystem"; |
286 | 289 |
@@ -28,23 +28,16 @@ |
||
28 | 28 | |
29 | 29 | use League\Flysystem\Config; |
30 | 30 | use League\Flysystem\Filesystem; |
31 | - |
|
32 | 31 | use League\Flysystem\Adapter\Ftp as Adapter; |
33 | - |
|
34 | 32 | use League\Flysystem\Sftp\SftpAdapter; |
35 | - |
|
36 | 33 | use Srmklive\Dropbox\Client\DropboxClient; |
37 | 34 | use Srmklive\Dropbox\Adapter\DropboxAdapter; |
38 | - |
|
39 | 35 | use MicrosoftAzure\Storage\Common\ServicesBuilder; |
40 | 36 | use League\Flysystem\Azure\AzureAdapter; |
41 | - |
|
42 | 37 | use Aws\S3\S3Client; |
43 | 38 | use League\Flysystem\AwsS3v3\AwsS3Adapter; |
44 | - |
|
45 | 39 | use Mhetreramesh\Flysystem\BackblazeAdapter; |
46 | 40 | use BackblazeB2\Client as B2Client; |
47 | - |
|
48 | 41 | use Sabre\DAV\Client as SabreClient; |
49 | 42 | use League\Flysystem\WebDAV\WebDAVAdapter; |
50 | 43 |
@@ -170,60 +170,60 @@ |
||
170 | 170 | |
171 | 171 | foreach($this->storage_fields as $main_key=>$array){ |
172 | 172 | |
173 | - if(is_array($array)) { |
|
174 | - foreach ($array as $key => $type) { |
|
173 | + if(is_array($array)) { |
|
174 | + foreach ($array as $key => $type) { |
|
175 | 175 | |
176 | - if( $type == "raw") { |
|
177 | - add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key, |
|
178 | - function ($value) { |
|
176 | + if( $type == "raw") { |
|
177 | + add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key, |
|
178 | + function ($value) { |
|
179 | 179 | |
180 | - return $this->simple_crypt($value, 'e'); |
|
180 | + return $this->simple_crypt($value, 'e'); |
|
181 | 181 | |
182 | - }, 10, 1); |
|
182 | + }, 10, 1); |
|
183 | 183 | |
184 | - add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) { |
|
184 | + add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) { |
|
185 | 185 | |
186 | - return $this->simple_crypt($value, 'd'); |
|
186 | + return $this->simple_crypt($value, 'd'); |
|
187 | 187 | |
188 | - }, 10, 1); |
|
189 | - } |
|
188 | + }, 10, 1); |
|
189 | + } |
|
190 | 190 | |
191 | - } |
|
192 | - } |
|
193 | - } |
|
191 | + } |
|
192 | + } |
|
193 | + } |
|
194 | 194 | |
195 | 195 | } |
196 | 196 | |
197 | - /** |
|
198 | - * Encrypts and Decrypt a string based on openssl lib |
|
199 | - * |
|
200 | - * @param $string |
|
201 | - * @param string $action |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - private function simple_crypt( $string, $action = 'e' ) { |
|
205 | - // you may change these values to your own |
|
206 | - $secret_key = NONCE_KEY; |
|
207 | - $secret_iv = NONCE_SALT; |
|
208 | - |
|
209 | - $output = $string; |
|
210 | - $encrypt_method = "AES-256-CBC"; |
|
211 | - $key = hash( 'sha256', $secret_key ); |
|
212 | - $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 ); |
|
213 | - |
|
214 | - if( $action == 'e' && function_exists('openssl_encrypt')) { |
|
215 | - $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ); |
|
216 | - } |
|
217 | - else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
218 | - $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv ); |
|
219 | - if($decrypt) { |
|
220 | - //we check if decrypt was succesful |
|
221 | - $output = $decrypt; |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - return $output; |
|
226 | - } |
|
197 | + /** |
|
198 | + * Encrypts and Decrypt a string based on openssl lib |
|
199 | + * |
|
200 | + * @param $string |
|
201 | + * @param string $action |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + private function simple_crypt( $string, $action = 'e' ) { |
|
205 | + // you may change these values to your own |
|
206 | + $secret_key = NONCE_KEY; |
|
207 | + $secret_iv = NONCE_SALT; |
|
208 | + |
|
209 | + $output = $string; |
|
210 | + $encrypt_method = "AES-256-CBC"; |
|
211 | + $key = hash( 'sha256', $secret_key ); |
|
212 | + $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 ); |
|
213 | + |
|
214 | + if( $action == 'e' && function_exists('openssl_encrypt')) { |
|
215 | + $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ); |
|
216 | + } |
|
217 | + else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
218 | + $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv ); |
|
219 | + if($decrypt) { |
|
220 | + //we check if decrypt was succesful |
|
221 | + $output = $decrypt; |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + return $output; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | private function get_xcloner_container() { |
229 | 229 | return $this->xcloner_container; |
@@ -213,8 +213,7 @@ |
||
213 | 213 | |
214 | 214 | if( $action == 'e' && function_exists('openssl_encrypt')) { |
215 | 215 | $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ); |
216 | - } |
|
217 | - else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
216 | + } else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
218 | 217 | $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv ); |
219 | 218 | if($decrypt) { |
220 | 219 | //we check if decrypt was succesful |
@@ -162,26 +162,26 @@ discard block |
||
162 | 162 | private $logger; |
163 | 163 | private $xcloner; |
164 | 164 | |
165 | - public function __construct( Xcloner $xcloner_container ) { |
|
165 | + public function __construct(Xcloner $xcloner_container) { |
|
166 | 166 | $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
167 | 167 | $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
168 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName( "xcloner_remote_storage" ); |
|
168 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_remote_storage"); |
|
169 | 169 | $this->xcloner = $xcloner_container; |
170 | 170 | |
171 | - foreach($this->storage_fields as $main_key=>$array){ |
|
171 | + foreach ($this->storage_fields as $main_key=>$array) { |
|
172 | 172 | |
173 | - if(is_array($array)) { |
|
173 | + if (is_array($array)) { |
|
174 | 174 | foreach ($array as $key => $type) { |
175 | 175 | |
176 | - if( $type == "raw") { |
|
177 | - add_filter("pre_update_option_" . $this->storage_fields['option_prefix'] . $key, |
|
178 | - function ($value) { |
|
176 | + if ($type == "raw") { |
|
177 | + add_filter("pre_update_option_".$this->storage_fields['option_prefix'].$key, |
|
178 | + function($value) { |
|
179 | 179 | |
180 | 180 | return $this->simple_crypt($value, 'e'); |
181 | 181 | |
182 | 182 | }, 10, 1); |
183 | 183 | |
184 | - add_filter("option_" . $this->storage_fields['option_prefix'] . $key, function ($value) { |
|
184 | + add_filter("option_".$this->storage_fields['option_prefix'].$key, function($value) { |
|
185 | 185 | |
186 | 186 | return $this->simple_crypt($value, 'd'); |
187 | 187 | |
@@ -201,22 +201,22 @@ discard block |
||
201 | 201 | * @param string $action |
202 | 202 | * @return string |
203 | 203 | */ |
204 | - private function simple_crypt( $string, $action = 'e' ) { |
|
204 | + private function simple_crypt($string, $action = 'e') { |
|
205 | 205 | // you may change these values to your own |
206 | 206 | $secret_key = NONCE_KEY; |
207 | 207 | $secret_iv = NONCE_SALT; |
208 | 208 | |
209 | 209 | $output = $string; |
210 | 210 | $encrypt_method = "AES-256-CBC"; |
211 | - $key = hash( 'sha256', $secret_key ); |
|
212 | - $iv = substr( hash( 'sha256', $secret_iv ), 0, 16 ); |
|
211 | + $key = hash('sha256', $secret_key); |
|
212 | + $iv = substr(hash('sha256', $secret_iv), 0, 16); |
|
213 | 213 | |
214 | - if( $action == 'e' && function_exists('openssl_encrypt')) { |
|
215 | - $output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) ); |
|
214 | + if ($action == 'e' && function_exists('openssl_encrypt')) { |
|
215 | + $output = base64_encode(openssl_encrypt($string, $encrypt_method, $key, 0, $iv)); |
|
216 | 216 | } |
217 | - else if( $action == 'd' && function_exists('openssl_decrypt') && base64_decode( $string )){ |
|
218 | - $decrypt = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv ); |
|
219 | - if($decrypt) { |
|
217 | + else if ($action == 'd' && function_exists('openssl_decrypt') && base64_decode($string)) { |
|
218 | + $decrypt = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); |
|
219 | + if ($decrypt) { |
|
220 | 220 | //we check if decrypt was succesful |
221 | 221 | $output = $decrypt; |
222 | 222 | } |
@@ -231,118 +231,118 @@ discard block |
||
231 | 231 | |
232 | 232 | public function get_available_storages() { |
233 | 233 | $return = array(); |
234 | - foreach ( $this->storage_fields as $storage => $data ) { |
|
235 | - $check_field = $this->storage_fields["option_prefix"] . $storage . "_enable"; |
|
236 | - if ( get_option( $check_field ) ) { |
|
237 | - $return[ $storage ] = $data['text']; |
|
234 | + foreach ($this->storage_fields as $storage => $data) { |
|
235 | + $check_field = $this->storage_fields["option_prefix"].$storage."_enable"; |
|
236 | + if (get_option($check_field)) { |
|
237 | + $return[$storage] = $data['text']; |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | |
241 | 241 | return $return; |
242 | 242 | } |
243 | 243 | |
244 | - public function save( $action = "ftp" ) { |
|
245 | - if ( ! $action ) { |
|
244 | + public function save($action = "ftp") { |
|
245 | + if (!$action) { |
|
246 | 246 | return false; |
247 | 247 | } |
248 | 248 | |
249 | - $storage = $this->xcloner_sanitization->sanitize_input_as_string( $action ); |
|
250 | - $this->logger->debug( sprintf( "Saving the remote storage %s options", strtoupper( $action ) ) ); |
|
249 | + $storage = $this->xcloner_sanitization->sanitize_input_as_string($action); |
|
250 | + $this->logger->debug(sprintf("Saving the remote storage %s options", strtoupper($action))); |
|
251 | 251 | |
252 | - if ( is_array( $this->storage_fields[ $storage ] ) ) { |
|
253 | - foreach ( $this->storage_fields[ $storage ] as $field => $validation ) { |
|
254 | - $check_field = $this->storage_fields["option_prefix"] . $field; |
|
255 | - $sanitize_method = "sanitize_input_as_" . $validation; |
|
252 | + if (is_array($this->storage_fields[$storage])) { |
|
253 | + foreach ($this->storage_fields[$storage] as $field => $validation) { |
|
254 | + $check_field = $this->storage_fields["option_prefix"].$field; |
|
255 | + $sanitize_method = "sanitize_input_as_".$validation; |
|
256 | 256 | |
257 | - if ( ! isset( $_POST[ $check_field ] ) ) { |
|
258 | - $_POST[ $check_field ] = 0; |
|
257 | + if (!isset($_POST[$check_field])) { |
|
258 | + $_POST[$check_field] = 0; |
|
259 | 259 | } |
260 | 260 | |
261 | - if ( ! method_exists( $this->xcloner_sanitization, $sanitize_method ) ) { |
|
261 | + if (!method_exists($this->xcloner_sanitization, $sanitize_method)) { |
|
262 | 262 | $sanitize_method = "sanitize_input_as_string"; |
263 | 263 | } |
264 | 264 | |
265 | - $sanitized_value = $this->xcloner_sanitization->$sanitize_method( stripslashes( $_POST[ $check_field ] ) ); |
|
266 | - update_option( $check_field, $sanitized_value ); |
|
265 | + $sanitized_value = $this->xcloner_sanitization->$sanitize_method(stripslashes($_POST[$check_field])); |
|
266 | + update_option($check_field, $sanitized_value); |
|
267 | 267 | } |
268 | 268 | |
269 | - $this->xcloner->trigger_message( __( "%s storage settings saved.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] ); |
|
269 | + $this->xcloner->trigger_message(__("%s storage settings saved.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | } |
273 | 273 | |
274 | - public function check( $action = "ftp" ) { |
|
274 | + public function check($action = "ftp") { |
|
275 | 275 | try { |
276 | - $this->verify_filesystem( $action ); |
|
277 | - $this->xcloner->trigger_message( __( "%s connection is valid.", 'xcloner-backup-and-restore' ), "success", $this->storage_fields[ $action ]['text'] ); |
|
278 | - $this->logger->debug( sprintf( "Connection to remote storage %s is valid", strtoupper( $action ) ) ); |
|
279 | - } catch ( Exception $e ) { |
|
280 | - $this->xcloner->trigger_message( "%s connection error: " . $e->getMessage(), "error", $this->storage_fields[ $action ]['text'] ); |
|
276 | + $this->verify_filesystem($action); |
|
277 | + $this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", $this->storage_fields[$action]['text']); |
|
278 | + $this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action))); |
|
279 | + }catch (Exception $e) { |
|
280 | + $this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", $this->storage_fields[$action]['text']); |
|
281 | 281 | } |
282 | 282 | } |
283 | 283 | |
284 | - public function verify_filesystem( $storage_type ) { |
|
285 | - $method = "get_" . $storage_type . "_filesystem"; |
|
284 | + public function verify_filesystem($storage_type) { |
|
285 | + $method = "get_".$storage_type."_filesystem"; |
|
286 | 286 | |
287 | - $this->logger->info( sprintf( "Checking validity of the remote storage %s filesystem", strtoupper( $storage_type ) ) ); |
|
287 | + $this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type))); |
|
288 | 288 | |
289 | - if ( ! method_exists( $this, $method ) ) { |
|
289 | + if (!method_exists($this, $method)) { |
|
290 | 290 | return false; |
291 | 291 | } |
292 | 292 | |
293 | - list( $adapter, $filesystem ) = $this->$method(); |
|
293 | + list($adapter, $filesystem) = $this->$method(); |
|
294 | 294 | |
295 | - $test_file = substr( ".xcloner_" . md5( time() ), 0, 15 ); |
|
295 | + $test_file = substr(".xcloner_".md5(time()), 0, 15); |
|
296 | 296 | |
297 | - if ( $storage_type == "gdrive" ) { |
|
298 | - if ( ! is_array( $filesystem->listContents() ) ) { |
|
299 | - throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) ); |
|
297 | + if ($storage_type == "gdrive") { |
|
298 | + if (!is_array($filesystem->listContents())) { |
|
299 | + throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); |
|
300 | 300 | } |
301 | - $this->logger->debug( sprintf( "I can list data from remote storage %s", strtoupper( $storage_type ) ) ); |
|
301 | + $this->logger->debug(sprintf("I can list data from remote storage %s", strtoupper($storage_type))); |
|
302 | 302 | |
303 | 303 | return true; |
304 | 304 | } |
305 | 305 | |
306 | 306 | //testing write access |
307 | - if ( ! $filesystem->write( $test_file, "data" ) ) { |
|
308 | - throw new Exception( __( "Could not write data", 'xcloner-backup-and-restore' ) ); |
|
307 | + if (!$filesystem->write($test_file, "data")) { |
|
308 | + throw new Exception(__("Could not write data", 'xcloner-backup-and-restore')); |
|
309 | 309 | } |
310 | - $this->logger->debug( sprintf( "I can write data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
310 | + $this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type))); |
|
311 | 311 | |
312 | 312 | //testing read access |
313 | - if ( ! $filesystem->has( $test_file ) ) { |
|
314 | - throw new Exception( __( "Could not read data", 'xcloner-backup-and-restore' ) ); |
|
313 | + if (!$filesystem->has($test_file)) { |
|
314 | + throw new Exception(__("Could not read data", 'xcloner-backup-and-restore')); |
|
315 | 315 | } |
316 | - $this->logger->debug( sprintf( "I can read data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
316 | + $this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type))); |
|
317 | 317 | |
318 | 318 | //delete test file |
319 | - if ( ! $filesystem->delete( $test_file ) ) { |
|
320 | - throw new Exception( __( "Could not delete data", 'xcloner-backup-and-restore' ) ); |
|
319 | + if (!$filesystem->delete($test_file)) { |
|
320 | + throw new Exception(__("Could not delete data", 'xcloner-backup-and-restore')); |
|
321 | 321 | } |
322 | - $this->logger->debug( sprintf( "I can delete data to remote storage %s", strtoupper( $storage_type ) ) ); |
|
322 | + $this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type))); |
|
323 | 323 | |
324 | 324 | return true; |
325 | 325 | } |
326 | 326 | |
327 | - public function upload_backup_to_storage( $file, $storage ) { |
|
328 | - if ( ! $this->xcloner_file_system->get_storage_filesystem()->has( $file ) ) { |
|
329 | - $this->logger->info( sprintf( "File not found %s in local storage", $file ) ); |
|
327 | + public function upload_backup_to_storage($file, $storage) { |
|
328 | + if (!$this->xcloner_file_system->get_storage_filesystem()->has($file)) { |
|
329 | + $this->logger->info(sprintf("File not found %s in local storage", $file)); |
|
330 | 330 | |
331 | 331 | return false; |
332 | 332 | } |
333 | 333 | |
334 | - $method = "get_" . $storage . "_filesystem"; |
|
334 | + $method = "get_".$storage."_filesystem"; |
|
335 | 335 | |
336 | - if ( ! method_exists( $this, $method ) ) { |
|
336 | + if (!method_exists($this, $method)) { |
|
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | |
340 | - list( $remote_storage_adapter, $remote_storage_filesystem ) = $this->$method(); |
|
340 | + list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); |
|
341 | 341 | |
342 | 342 | //doing remote storage cleaning here |
343 | - $this->clean_remote_storage( $storage, $remote_storage_filesystem ); |
|
343 | + $this->clean_remote_storage($storage, $remote_storage_filesystem); |
|
344 | 344 | |
345 | - $this->logger->info( sprintf( "Transferring backup %s to remote storage %s", $file, strtoupper( $storage ) ), array( "" ) ); |
|
345 | + $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $file, strtoupper($storage)), array("")); |
|
346 | 346 | |
347 | 347 | /*if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
348 | 348 | { |
@@ -350,104 +350,104 @@ discard block |
||
350 | 350 | return false; |
351 | 351 | }*/ |
352 | 352 | |
353 | - $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream( $file ); |
|
353 | + $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($file); |
|
354 | 354 | |
355 | - if ( ! $remote_storage_filesystem->writeStream( $file, $backup_file_stream ) ) { |
|
356 | - $this->logger->info( sprintf( "Could not transfer file %s", $file ) ); |
|
355 | + if (!$remote_storage_filesystem->writeStream($file, $backup_file_stream)) { |
|
356 | + $this->logger->info(sprintf("Could not transfer file %s", $file)); |
|
357 | 357 | |
358 | 358 | return false; |
359 | 359 | } |
360 | 360 | |
361 | - if ( $this->xcloner_file_system->is_multipart( $file ) ) { |
|
362 | - $parts = $this->xcloner_file_system->get_multipart_files( $file ); |
|
363 | - if ( is_array( $parts ) ) { |
|
364 | - foreach ( $parts as $part_file ) { |
|
365 | - $this->logger->info( sprintf( "Transferring backup %s to remote storage %s", $part_file, strtoupper( $storage ) ), array( "" ) ); |
|
361 | + if ($this->xcloner_file_system->is_multipart($file)) { |
|
362 | + $parts = $this->xcloner_file_system->get_multipart_files($file); |
|
363 | + if (is_array($parts)) { |
|
364 | + foreach ($parts as $part_file) { |
|
365 | + $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file, strtoupper($storage)), array("")); |
|
366 | 366 | |
367 | - $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream( $part_file ); |
|
368 | - if ( ! $remote_storage_filesystem->writeStream( $part_file, $backup_file_stream ) ) { |
|
367 | + $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file); |
|
368 | + if (!$remote_storage_filesystem->writeStream($part_file, $backup_file_stream)) { |
|
369 | 369 | return false; |
370 | 370 | } |
371 | 371 | } |
372 | 372 | } |
373 | 373 | } |
374 | 374 | |
375 | - $this->logger->info( sprintf( "Upload done, disconnecting from remote storage %s", strtoupper( $storage ) ) ); |
|
375 | + $this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage))); |
|
376 | 376 | |
377 | 377 | return true; |
378 | 378 | |
379 | 379 | } |
380 | 380 | |
381 | - public function copy_backup_remote_to_local( $file, $storage ) { |
|
382 | - $method = "get_" . $storage . "_filesystem"; |
|
381 | + public function copy_backup_remote_to_local($file, $storage) { |
|
382 | + $method = "get_".$storage."_filesystem"; |
|
383 | 383 | |
384 | 384 | $target_filename = $file; |
385 | 385 | |
386 | - if ( ! method_exists( $this, $method ) ) { |
|
386 | + if (!method_exists($this, $method)) { |
|
387 | 387 | return false; |
388 | 388 | } |
389 | 389 | |
390 | - list( $remote_storage_adapter, $remote_storage_filesystem ) = $this->$method(); |
|
390 | + list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); |
|
391 | 391 | |
392 | - if ( ! $remote_storage_filesystem->has( $file ) ) { |
|
393 | - $this->logger->info( sprintf( "File not found %s in remote storage %s", $file, strtoupper( $storage ) ) ); |
|
392 | + if (!$remote_storage_filesystem->has($file)) { |
|
393 | + $this->logger->info(sprintf("File not found %s in remote storage %s", $file, strtoupper($storage))); |
|
394 | 394 | |
395 | 395 | return false; |
396 | 396 | } |
397 | 397 | |
398 | - if ( $storage == "gdrive" ) { |
|
399 | - $metadata = $remote_storage_filesystem->getMetadata( $file ); |
|
400 | - $target_filename = $metadata['filename'] . "." . $metadata['extension']; |
|
398 | + if ($storage == "gdrive") { |
|
399 | + $metadata = $remote_storage_filesystem->getMetadata($file); |
|
400 | + $target_filename = $metadata['filename'].".".$metadata['extension']; |
|
401 | 401 | } |
402 | 402 | |
403 | - $this->logger->info( sprintf( "Transferring backup %s to local storage from %s storage", $file, strtoupper( $storage ) ), array( "" ) ); |
|
403 | + $this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $file, strtoupper($storage)), array("")); |
|
404 | 404 | |
405 | - $backup_file_stream = $remote_storage_filesystem->readStream( $file ); |
|
405 | + $backup_file_stream = $remote_storage_filesystem->readStream($file); |
|
406 | 406 | |
407 | - if ( ! $this->xcloner_file_system->get_storage_filesystem()->writeStream( $target_filename, $backup_file_stream ) ) { |
|
408 | - $this->logger->info( sprintf( "Could not transfer file %s", $file ) ); |
|
407 | + if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($target_filename, $backup_file_stream)) { |
|
408 | + $this->logger->info(sprintf("Could not transfer file %s", $file)); |
|
409 | 409 | |
410 | 410 | return false; |
411 | 411 | } |
412 | 412 | |
413 | - if ( $this->xcloner_file_system->is_multipart( $target_filename ) ) { |
|
414 | - $parts = $this->xcloner_file_system->get_multipart_files( $file, $storage ); |
|
415 | - if ( is_array( $parts ) ) { |
|
416 | - foreach ( $parts as $part_file ) { |
|
417 | - $this->logger->info( sprintf( "Transferring backup %s to local storage from %s storage", $part_file, strtoupper( $storage ) ), array( "" ) ); |
|
413 | + if ($this->xcloner_file_system->is_multipart($target_filename)) { |
|
414 | + $parts = $this->xcloner_file_system->get_multipart_files($file, $storage); |
|
415 | + if (is_array($parts)) { |
|
416 | + foreach ($parts as $part_file) { |
|
417 | + $this->logger->info(sprintf("Transferring backup %s to local storage from %s storage", $part_file, strtoupper($storage)), array("")); |
|
418 | 418 | |
419 | - $backup_file_stream = $remote_storage_filesystem->readStream( $part_file ); |
|
420 | - if ( ! $this->xcloner_file_system->get_storage_filesystem()->writeStream( $part_file, $backup_file_stream ) ) { |
|
419 | + $backup_file_stream = $remote_storage_filesystem->readStream($part_file); |
|
420 | + if (!$this->xcloner_file_system->get_storage_filesystem()->writeStream($part_file, $backup_file_stream)) { |
|
421 | 421 | return false; |
422 | 422 | } |
423 | 423 | } |
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - $this->logger->info( sprintf( "Upload done, disconnecting from remote storage %s", strtoupper( $storage ) ) ); |
|
427 | + $this->logger->info(sprintf("Upload done, disconnecting from remote storage %s", strtoupper($storage))); |
|
428 | 428 | |
429 | 429 | return true; |
430 | 430 | |
431 | 431 | } |
432 | 432 | |
433 | - public function clean_remote_storage( $storage, $remote_storage_filesystem ) { |
|
434 | - $check_field = $this->storage_fields["option_prefix"] . $storage . "_cleanup_days"; |
|
435 | - if ( $expire_days = get_option( $check_field ) ) { |
|
436 | - $this->logger->info( sprintf( "Doing %s remote storage cleanup for %s days limit", strtoupper( $storage ), $expire_days ) ); |
|
433 | + public function clean_remote_storage($storage, $remote_storage_filesystem) { |
|
434 | + $check_field = $this->storage_fields["option_prefix"].$storage."_cleanup_days"; |
|
435 | + if ($expire_days = get_option($check_field)) { |
|
436 | + $this->logger->info(sprintf("Doing %s remote storage cleanup for %s days limit", strtoupper($storage), $expire_days)); |
|
437 | 437 | $files = $remote_storage_filesystem->listContents(); |
438 | 438 | |
439 | - $current_timestamp = strtotime( "-" . $expire_days . " days" ); |
|
439 | + $current_timestamp = strtotime("-".$expire_days." days"); |
|
440 | 440 | |
441 | - if ( is_array( $files ) ) { |
|
442 | - foreach ( $files as $file ) { |
|
443 | - $file['timestamp'] = $remote_storage_filesystem->getTimestamp( $file['path'] ); |
|
441 | + if (is_array($files)) { |
|
442 | + foreach ($files as $file) { |
|
443 | + $file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']); |
|
444 | 444 | |
445 | - if ( $current_timestamp >= $file['timestamp'] ) { |
|
446 | - $remote_storage_filesystem->delete( $file['path'] ); |
|
447 | - $this->logger->info( "Deleting remote file " . $file['path'] . " matching rule", array( |
|
445 | + if ($current_timestamp >= $file['timestamp']) { |
|
446 | + $remote_storage_filesystem->delete($file['path']); |
|
447 | + $this->logger->info("Deleting remote file ".$file['path']." matching rule", array( |
|
448 | 448 | "RETENTION LIMIT TIMESTAMP", |
449 | - $file['timestamp'] . " =< " . $expire_days |
|
450 | - ) ); |
|
449 | + $file['timestamp']." =< ".$expire_days |
|
450 | + )); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | } |
@@ -456,153 +456,153 @@ discard block |
||
456 | 456 | } |
457 | 457 | |
458 | 458 | public function get_azure_filesystem() { |
459 | - $this->logger->info( sprintf( "Creating the AZURE BLOB remote storage connection" ), array( "" ) ); |
|
459 | + $this->logger->info(sprintf("Creating the AZURE BLOB remote storage connection"), array("")); |
|
460 | 460 | |
461 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
462 | - throw new Exception( "AZURE BLOB requires PHP 5.6 to be installed!" ); |
|
461 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
462 | + throw new Exception("AZURE BLOB requires PHP 5.6 to be installed!"); |
|
463 | 463 | } |
464 | 464 | |
465 | - if ( ! class_exists( 'XmlWriter' ) ) { |
|
466 | - throw new Exception( "AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!" ); |
|
465 | + if (!class_exists('XmlWriter')) { |
|
466 | + throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!"); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | $endpoint = sprintf( |
470 | 470 | 'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s', |
471 | - get_option( "xcloner_azure_account_name" ), |
|
472 | - get_option( "xcloner_azure_api_key" ) |
|
471 | + get_option("xcloner_azure_account_name"), |
|
472 | + get_option("xcloner_azure_api_key") |
|
473 | 473 | ); |
474 | 474 | |
475 | - $blobRestProxy = ServicesBuilder::getInstance()->createBlobService( $endpoint ); |
|
475 | + $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint); |
|
476 | 476 | |
477 | - $adapter = new AzureAdapter( $blobRestProxy, get_option( "xcloner_azure_container" ) ); |
|
477 | + $adapter = new AzureAdapter($blobRestProxy, get_option("xcloner_azure_container")); |
|
478 | 478 | |
479 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
479 | + $filesystem = new Filesystem($adapter, new Config([ |
|
480 | 480 | 'disable_asserts' => true, |
481 | - ] ) ); |
|
481 | + ])); |
|
482 | 482 | |
483 | - return array( $adapter, $filesystem ); |
|
483 | + return array($adapter, $filesystem); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | public function get_dropbox_filesystem() { |
487 | - $this->logger->info( sprintf( "Creating the DROPBOX remote storage connection" ), array( "" ) ); |
|
487 | + $this->logger->info(sprintf("Creating the DROPBOX remote storage connection"), array("")); |
|
488 | 488 | |
489 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
490 | - throw new Exception( "DROPBOX requires PHP 5.6 to be installed!" ); |
|
489 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
490 | + throw new Exception("DROPBOX requires PHP 5.6 to be installed!"); |
|
491 | 491 | } |
492 | 492 | |
493 | - $client = new DropboxClient( get_option( "xcloner_dropbox_access_token" ) ); |
|
494 | - $adapter = new DropboxAdapter( $client, get_option( "xcloner_dropbox_prefix" ) ); |
|
493 | + $client = new DropboxClient(get_option("xcloner_dropbox_access_token")); |
|
494 | + $adapter = new DropboxAdapter($client, get_option("xcloner_dropbox_prefix")); |
|
495 | 495 | |
496 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
496 | + $filesystem = new Filesystem($adapter, new Config([ |
|
497 | 497 | 'disable_asserts' => true, |
498 | - ] ) ); |
|
498 | + ])); |
|
499 | 499 | |
500 | - return array( $adapter, $filesystem ); |
|
500 | + return array($adapter, $filesystem); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | public function get_aws_filesystem() { |
504 | - $this->logger->info( sprintf( "Creating the S3 remote storage connection" ), array( "" ) ); |
|
504 | + $this->logger->info(sprintf("Creating the S3 remote storage connection"), array("")); |
|
505 | 505 | |
506 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
507 | - throw new Exception( "S3 class requires PHP 5.6 to be installed!" ); |
|
506 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
507 | + throw new Exception("S3 class requires PHP 5.6 to be installed!"); |
|
508 | 508 | } |
509 | 509 | |
510 | - if ( ! class_exists( 'XmlWriter' ) ) { |
|
511 | - throw new Exception( "AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!" ); |
|
510 | + if (!class_exists('XmlWriter')) { |
|
511 | + throw new Exception("AZURE BLOB requires libxml PHP module to be installed with XmlWriter class enabled!"); |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | |
515 | 515 | $credentials = array( |
516 | 516 | 'credentials' => array( |
517 | - 'key' => get_option( "xcloner_aws_key" ), |
|
518 | - 'secret' => get_option( "xcloner_aws_secret" ) |
|
517 | + 'key' => get_option("xcloner_aws_key"), |
|
518 | + 'secret' => get_option("xcloner_aws_secret") |
|
519 | 519 | ), |
520 | - 'region' => get_option( "xcloner_aws_region" ), |
|
520 | + 'region' => get_option("xcloner_aws_region"), |
|
521 | 521 | 'version' => 'latest', |
522 | 522 | ); |
523 | 523 | |
524 | - if ( get_option( 'xcloner_aws_endpoint' ) != "" && ! get_option( "xcloner_aws_region" ) ) { |
|
524 | + if (get_option('xcloner_aws_endpoint') != "" && !get_option("xcloner_aws_region")) { |
|
525 | 525 | |
526 | - $credentials['endpoint'] = get_option( 'xcloner_aws_endpoint' ); |
|
526 | + $credentials['endpoint'] = get_option('xcloner_aws_endpoint'); |
|
527 | 527 | #$credentials['use_path_style_endpoint'] = true; |
528 | 528 | #$credentials['bucket_endpoint'] = false; |
529 | 529 | |
530 | 530 | |
531 | 531 | } |
532 | 532 | |
533 | - $client = new S3Client( $credentials ); |
|
533 | + $client = new S3Client($credentials); |
|
534 | 534 | |
535 | - $adapter = new AwsS3Adapter( $client, get_option( "xcloner_aws_bucket_name" ), get_option( "xcloner_aws_prefix" ) ); |
|
536 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
535 | + $adapter = new AwsS3Adapter($client, get_option("xcloner_aws_bucket_name"), get_option("xcloner_aws_prefix")); |
|
536 | + $filesystem = new Filesystem($adapter, new Config([ |
|
537 | 537 | 'disable_asserts' => true, |
538 | - ] ) ); |
|
538 | + ])); |
|
539 | 539 | |
540 | - return array( $adapter, $filesystem ); |
|
540 | + return array($adapter, $filesystem); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | public function get_backblaze_filesystem() { |
544 | - $this->logger->info( sprintf( "Creating the BACKBLAZE remote storage connection" ), array( "" ) ); |
|
544 | + $this->logger->info(sprintf("Creating the BACKBLAZE remote storage connection"), array("")); |
|
545 | 545 | |
546 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
547 | - throw new Exception( "BACKBLAZE API requires PHP 5.6 to be installed!" ); |
|
546 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
547 | + throw new Exception("BACKBLAZE API requires PHP 5.6 to be installed!"); |
|
548 | 548 | } |
549 | 549 | |
550 | 550 | |
551 | - $client = new B2Client( get_option( "xcloner_backblaze_account_id" ), get_option( "xcloner_backblaze_application_key" ) ); |
|
552 | - $adapter = new BackblazeAdapter( $client, get_option( "xcloner_backblaze_bucket_name" ) ); |
|
551 | + $client = new B2Client(get_option("xcloner_backblaze_account_id"), get_option("xcloner_backblaze_application_key")); |
|
552 | + $adapter = new BackblazeAdapter($client, get_option("xcloner_backblaze_bucket_name")); |
|
553 | 553 | |
554 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
554 | + $filesystem = new Filesystem($adapter, new Config([ |
|
555 | 555 | 'disable_asserts' => true, |
556 | - ] ) ); |
|
556 | + ])); |
|
557 | 557 | |
558 | - return array( $adapter, $filesystem ); |
|
558 | + return array($adapter, $filesystem); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | public function get_webdav_filesystem() { |
562 | - $this->logger->info( sprintf( "Creating the WEBDAV remote storage connection" ), array( "" ) ); |
|
562 | + $this->logger->info(sprintf("Creating the WEBDAV remote storage connection"), array("")); |
|
563 | 563 | |
564 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
565 | - throw new Exception( "WEBDAV API requires PHP 5.6 to be installed!" ); |
|
564 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
565 | + throw new Exception("WEBDAV API requires PHP 5.6 to be installed!"); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | $settings = array( |
569 | - 'baseUri' => get_option( "xcloner_webdav_url" ), |
|
570 | - 'userName' => get_option( "xcloner_webdav_username" ), |
|
571 | - 'password' => get_option( "xcloner_webdav_password" ), |
|
569 | + 'baseUri' => get_option("xcloner_webdav_url"), |
|
570 | + 'userName' => get_option("xcloner_webdav_username"), |
|
571 | + 'password' => get_option("xcloner_webdav_password"), |
|
572 | 572 | //'proxy' => 'locahost:8888', |
573 | 573 | ); |
574 | 574 | |
575 | 575 | |
576 | - $client = new SabreClient( $settings ); |
|
577 | - $adapter = new WebDAVAdapter( $client, get_option( "xcloner_webdav_target_folder" ) ); |
|
578 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
576 | + $client = new SabreClient($settings); |
|
577 | + $adapter = new WebDAVAdapter($client, get_option("xcloner_webdav_target_folder")); |
|
578 | + $filesystem = new Filesystem($adapter, new Config([ |
|
579 | 579 | 'disable_asserts' => true, |
580 | - ] ) ); |
|
580 | + ])); |
|
581 | 581 | |
582 | - return array( $adapter, $filesystem ); |
|
582 | + return array($adapter, $filesystem); |
|
583 | 583 | } |
584 | 584 | |
585 | 585 | |
586 | 586 | public function gdrive_construct() { |
587 | 587 | |
588 | 588 | //if((function_exists("is_plugin_active") && !is_plugin_active("xcloner-google-drive/xcloner-google-drive.php")) || !file_exists(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php")) |
589 | - if ( ! class_exists( 'Google_Client' ) ) { |
|
589 | + if (!class_exists('Google_Client')) { |
|
590 | 590 | return false; |
591 | 591 | } |
592 | 592 | |
593 | 593 | //require_once(__DIR__ . "/../../xcloner-google-drive/vendor/autoload.php"); |
594 | 594 | |
595 | 595 | $client = new \Google_Client(); |
596 | - $client->setApplicationName( $this->gdrive_app_name ); |
|
597 | - $client->setClientId( get_option( "xcloner_gdrive_client_id" ) ); |
|
598 | - $client->setClientSecret( get_option( "xcloner_gdrive_client_secret" ) ); |
|
596 | + $client->setApplicationName($this->gdrive_app_name); |
|
597 | + $client->setClientId(get_option("xcloner_gdrive_client_id")); |
|
598 | + $client->setClientSecret(get_option("xcloner_gdrive_client_secret")); |
|
599 | 599 | |
600 | 600 | //$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']."?page=xcloner_remote_storage_page&action=set_gdrive_code"; |
601 | 601 | $redirect_uri = "urn:ietf:wg:oauth:2.0:oob"; |
602 | 602 | |
603 | - $client->setRedirectUri( $redirect_uri ); //urn:ietf:wg:oauth:2.0:oob |
|
604 | - $client->addScope( "https://www.googleapis.com/auth/drive" ); |
|
605 | - $client->setAccessType( 'offline' ); |
|
603 | + $client->setRedirectUri($redirect_uri); //urn:ietf:wg:oauth:2.0:oob |
|
604 | + $client->addScope("https://www.googleapis.com/auth/drive"); |
|
605 | + $client->setAccessType('offline'); |
|
606 | 606 | |
607 | 607 | return $client; |
608 | 608 | } |
@@ -610,30 +610,30 @@ discard block |
||
610 | 610 | public function get_gdrive_auth_url() { |
611 | 611 | $client = $this->gdrive_construct(); |
612 | 612 | |
613 | - if ( ! $client ) { |
|
613 | + if (!$client) { |
|
614 | 614 | return false; |
615 | 615 | } |
616 | 616 | |
617 | 617 | return $authUrl = $client->createAuthUrl(); |
618 | 618 | } |
619 | 619 | |
620 | - public function set_access_token( $code ) { |
|
620 | + public function set_access_token($code) { |
|
621 | 621 | $client = $this->gdrive_construct(); |
622 | 622 | |
623 | - if ( ! $client ) { |
|
623 | + if (!$client) { |
|
624 | 624 | $error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled..."; |
625 | - $this->logger->error( $error_msg ); |
|
625 | + $this->logger->error($error_msg); |
|
626 | 626 | |
627 | 627 | return false; |
628 | 628 | } |
629 | 629 | |
630 | - $token = $client->fetchAccessTokenWithAuthCode( $code ); |
|
631 | - $client->setAccessToken( $token ); |
|
630 | + $token = $client->fetchAccessTokenWithAuthCode($code); |
|
631 | + $client->setAccessToken($token); |
|
632 | 632 | |
633 | - update_option( "xcloner_gdrive_access_token", $token['access_token'] ); |
|
634 | - update_option( "xcloner_gdrive_refresh_token", $token['refresh_token'] ); |
|
633 | + update_option("xcloner_gdrive_access_token", $token['access_token']); |
|
634 | + update_option("xcloner_gdrive_refresh_token", $token['refresh_token']); |
|
635 | 635 | |
636 | - $redirect_url = ( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?page=xcloner_remote_storage_page#gdrive" ); |
|
636 | + $redirect_url = ('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?page=xcloner_remote_storage_page#gdrive"); |
|
637 | 637 | |
638 | 638 | ?> |
639 | 639 | <script> |
@@ -649,126 +649,126 @@ discard block |
||
649 | 649 | */ |
650 | 650 | public function get_gdrive_filesystem() { |
651 | 651 | |
652 | - if ( version_compare( phpversion(), '5.6.0', '<' ) ) { |
|
653 | - throw new Exception( "Google Drive API requires PHP 5.6 to be installed!" ); |
|
652 | + if (version_compare(phpversion(), '5.6.0', '<')) { |
|
653 | + throw new Exception("Google Drive API requires PHP 5.6 to be installed!"); |
|
654 | 654 | } |
655 | 655 | |
656 | - $this->logger->info( sprintf( "Creating the Google Drive remote storage connection" ), array( "" ) ); |
|
656 | + $this->logger->info(sprintf("Creating the Google Drive remote storage connection"), array("")); |
|
657 | 657 | |
658 | 658 | $client = $this->gdrive_construct(); |
659 | 659 | |
660 | - if ( ! $client ) { |
|
660 | + if (!$client) { |
|
661 | 661 | $error_msg = "Could not initialize the Google Drive Class, please check that the xcloner-google-drive plugin is enabled..."; |
662 | - $this->logger->error( $error_msg ); |
|
663 | - throw new Exception( $error_msg ); |
|
662 | + $this->logger->error($error_msg); |
|
663 | + throw new Exception($error_msg); |
|
664 | 664 | } |
665 | 665 | |
666 | - $client->refreshToken( get_option( "xcloner_gdrive_refresh_token" ) ); |
|
666 | + $client->refreshToken(get_option("xcloner_gdrive_refresh_token")); |
|
667 | 667 | |
668 | - $service = new \Google_Service_Drive( $client ); |
|
668 | + $service = new \Google_Service_Drive($client); |
|
669 | 669 | |
670 | - if( get_option("xcloner_gdrive_empty_trash",0) ){ |
|
670 | + if (get_option("xcloner_gdrive_empty_trash", 0)) { |
|
671 | 671 | $this->logger->info(sprintf("Doing a Google Drive emptyTrash call"), array("")); |
672 | 672 | $service->files->emptyTrash(); |
673 | 673 | } |
674 | 674 | |
675 | 675 | $parent = 'root'; |
676 | - $dir = basename( get_option( "xcloner_gdrive_target_folder" ) ); |
|
676 | + $dir = basename(get_option("xcloner_gdrive_target_folder")); |
|
677 | 677 | |
678 | - $folderID = get_option( "xcloner_gdrive_target_folder" ); |
|
678 | + $folderID = get_option("xcloner_gdrive_target_folder"); |
|
679 | 679 | |
680 | - $tmp = parse_url( $folderID ); |
|
680 | + $tmp = parse_url($folderID); |
|
681 | 681 | |
682 | - if ( isset( $tmp['query'] ) ) { |
|
683 | - $folderID = str_replace( "id=", "", $tmp['query'] ); |
|
682 | + if (isset($tmp['query'])) { |
|
683 | + $folderID = str_replace("id=", "", $tmp['query']); |
|
684 | 684 | } |
685 | 685 | |
686 | - if ( stristr( $folderID, "/" ) ) { |
|
687 | - $query = sprintf( 'mimeType = \'application/vnd.google-apps.folder\' and \'%s\' in parents and name contains \'%s\'', $parent, $dir ); |
|
688 | - $response = $service->files->listFiles( [ |
|
686 | + if (stristr($folderID, "/")) { |
|
687 | + $query = sprintf('mimeType = \'application/vnd.google-apps.folder\' and \'%s\' in parents and name contains \'%s\'', $parent, $dir); |
|
688 | + $response = $service->files->listFiles([ |
|
689 | 689 | 'pageSize' => 1, |
690 | 690 | 'q' => $query |
691 | - ] ); |
|
691 | + ]); |
|
692 | 692 | |
693 | - if ( sizeof( $response ) ) { |
|
694 | - foreach ( $response as $obj ) { |
|
693 | + if (sizeof($response)) { |
|
694 | + foreach ($response as $obj) { |
|
695 | 695 | $folderID = $obj->getId(); |
696 | 696 | } |
697 | 697 | } else { |
698 | - $this->xcloner->trigger_message( sprintf( __( "Could not find folder ID by name %s", 'xcloner-backup-and-restore' ), $folderID ), "error" ); |
|
698 | + $this->xcloner->trigger_message(sprintf(__("Could not find folder ID by name %s", 'xcloner-backup-and-restore'), $folderID), "error"); |
|
699 | 699 | } |
700 | 700 | } |
701 | 701 | |
702 | - $this->logger->info( sprintf( "Using target folder with ID %s on the remote storage", $folderID ) ); |
|
702 | + $this->logger->info(sprintf("Using target folder with ID %s on the remote storage", $folderID)); |
|
703 | 703 | |
704 | - if ( class_exists( 'XCloner_Google_Drive_Adapter' ) ) { |
|
705 | - $adapter = new XCloner_Google_Drive_Adapter( $service, $folderID ); |
|
704 | + if (class_exists('XCloner_Google_Drive_Adapter')) { |
|
705 | + $adapter = new XCloner_Google_Drive_Adapter($service, $folderID); |
|
706 | 706 | } else { |
707 | - $adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter( $service, $folderID ); |
|
707 | + $adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $folderID); |
|
708 | 708 | } |
709 | 709 | |
710 | - $filesystem = new \League\Flysystem\Filesystem( $adapter, new Config( [ |
|
710 | + $filesystem = new \League\Flysystem\Filesystem($adapter, new Config([ |
|
711 | 711 | 'disable_asserts' => true, |
712 | - ] ) ); |
|
712 | + ])); |
|
713 | 713 | |
714 | 714 | |
715 | - return array( $adapter, $filesystem ); |
|
715 | + return array($adapter, $filesystem); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | public function get_ftp_filesystem() { |
719 | - $this->logger->info( sprintf( "Creating the FTP remote storage connection" ), array( "" ) ); |
|
719 | + $this->logger->info(sprintf("Creating the FTP remote storage connection"), array("")); |
|
720 | 720 | |
721 | - $adapter = new Adapter( [ |
|
722 | - 'host' => get_option( "xcloner_ftp_hostname" ), |
|
723 | - 'username' => get_option( "xcloner_ftp_username" ), |
|
724 | - 'password' => get_option( "xcloner_ftp_password" ), |
|
721 | + $adapter = new Adapter([ |
|
722 | + 'host' => get_option("xcloner_ftp_hostname"), |
|
723 | + 'username' => get_option("xcloner_ftp_username"), |
|
724 | + 'password' => get_option("xcloner_ftp_password"), |
|
725 | 725 | |
726 | 726 | /** optional config settings */ |
727 | - 'port' => get_option( "xcloner_ftp_port", 21 ), |
|
728 | - 'root' => get_option( "xcloner_ftp_path" ), |
|
729 | - 'passive' => get_option( "xcloner_ftp_transfer_mode" ), |
|
730 | - 'ssl' => get_option( "xcloner_ftp_ssl_mode" ), |
|
731 | - 'timeout' => get_option( "xcloner_ftp_timeout", 30 ), |
|
732 | - ] ); |
|
727 | + 'port' => get_option("xcloner_ftp_port", 21), |
|
728 | + 'root' => get_option("xcloner_ftp_path"), |
|
729 | + 'passive' => get_option("xcloner_ftp_transfer_mode"), |
|
730 | + 'ssl' => get_option("xcloner_ftp_ssl_mode"), |
|
731 | + 'timeout' => get_option("xcloner_ftp_timeout", 30), |
|
732 | + ]); |
|
733 | 733 | |
734 | 734 | $adapter->connect(); |
735 | 735 | |
736 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
736 | + $filesystem = new Filesystem($adapter, new Config([ |
|
737 | 737 | 'disable_asserts' => true, |
738 | - ] ) ); |
|
738 | + ])); |
|
739 | 739 | |
740 | - return array( $adapter, $filesystem ); |
|
740 | + return array($adapter, $filesystem); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | public function get_sftp_filesystem() { |
744 | - $this->logger->info( sprintf( "Creating the SFTP remote storage connection" ), array( "" ) ); |
|
744 | + $this->logger->info(sprintf("Creating the SFTP remote storage connection"), array("")); |
|
745 | 745 | |
746 | - $adapter = new SftpAdapter( [ |
|
747 | - 'host' => get_option( "xcloner_sftp_hostname" ), |
|
748 | - 'username' => get_option( "xcloner_sftp_username" ), |
|
749 | - 'password' => get_option( "xcloner_sftp_password" ), |
|
746 | + $adapter = new SftpAdapter([ |
|
747 | + 'host' => get_option("xcloner_sftp_hostname"), |
|
748 | + 'username' => get_option("xcloner_sftp_username"), |
|
749 | + 'password' => get_option("xcloner_sftp_password"), |
|
750 | 750 | |
751 | 751 | /** optional config settings */ |
752 | - 'port' => get_option( "xcloner_sftp_port", 22 ), |
|
753 | - 'root' => get_option( "xcloner_sftp_path" ), |
|
754 | - 'privateKey' => get_option( "xcloner_sftp_private_key" ), |
|
755 | - 'timeout' => get_option( "xcloner_ftp_timeout", 30 ), |
|
756 | - ] ); |
|
752 | + 'port' => get_option("xcloner_sftp_port", 22), |
|
753 | + 'root' => get_option("xcloner_sftp_path"), |
|
754 | + 'privateKey' => get_option("xcloner_sftp_private_key"), |
|
755 | + 'timeout' => get_option("xcloner_ftp_timeout", 30), |
|
756 | + ]); |
|
757 | 757 | |
758 | 758 | $adapter->connect(); |
759 | 759 | |
760 | - $filesystem = new Filesystem( $adapter, new Config( [ |
|
760 | + $filesystem = new Filesystem($adapter, new Config([ |
|
761 | 761 | 'disable_asserts' => true, |
762 | - ] ) ); |
|
762 | + ])); |
|
763 | 763 | |
764 | - return array( $adapter, $filesystem ); |
|
764 | + return array($adapter, $filesystem); |
|
765 | 765 | } |
766 | 766 | |
767 | - public function change_storage_status( $field, $value ) { |
|
768 | - $field = $this->xcloner_sanitization->sanitize_input_as_string( $field ); |
|
769 | - $value = $this->xcloner_sanitization->sanitize_input_as_int( $value ); |
|
767 | + public function change_storage_status($field, $value) { |
|
768 | + $field = $this->xcloner_sanitization->sanitize_input_as_string($field); |
|
769 | + $value = $this->xcloner_sanitization->sanitize_input_as_int($value); |
|
770 | 770 | |
771 | - return update_option( $field, $value ); |
|
771 | + return update_option($field, $value); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | public function get_aws_regions() { |