@@ -2,13 +2,8 @@ |
||
2 | 2 | |
3 | 3 | use League\Flysystem\Config; |
4 | 4 | use League\Flysystem\Filesystem; |
5 | -use League\Flysystem\Util; |
|
6 | 5 | use League\Flysystem\Adapter\Local; |
7 | - |
|
8 | 6 | use splitbrain\PHPArchive\Tar; |
9 | -use splitbrain\PHPArchive\Zip; |
|
10 | -use splitbrain\PHPArchive\Archive; |
|
11 | -use splitbrain\PHPArchive\FileInfo; |
|
12 | 7 | |
13 | 8 | |
14 | 9 | class Xcloner_Api{ |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | } |
221 | 221 | |
222 | 222 | if( $wpdb->last_error ) { |
223 | - $response['error'] = 1; |
|
224 | - $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/; |
|
223 | + $response['error'] = 1; |
|
224 | + $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/; |
|
225 | 225 | |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | - $scheduler->update_wp_cron_hooks(); |
|
228 | + $scheduler->update_wp_cron_hooks(); |
|
229 | 229 | $response['finished'] = 1; |
230 | 230 | |
231 | 231 | $this->send_response($response); |
@@ -916,14 +916,14 @@ discard block |
||
916 | 916 | $tar->close(); |
917 | 917 | |
918 | 918 | if (file_exists($tmp_file)) { |
919 | - header('Content-Description: File Transfer'); |
|
920 | - header('Content-Type: application/octet-stream'); |
|
921 | - header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"'); |
|
922 | - header('Expires: 0'); |
|
923 | - header('Cache-Control: must-revalidate'); |
|
924 | - header('Pragma: public'); |
|
925 | - header('Content-Length: ' . filesize($tmp_file)); |
|
926 | - readfile($tmp_file); |
|
919 | + header('Content-Description: File Transfer'); |
|
920 | + header('Content-Type: application/octet-stream'); |
|
921 | + header('Content-Disposition: attachment; filename="'.basename($tmp_file).'"'); |
|
922 | + header('Expires: 0'); |
|
923 | + header('Cache-Control: must-revalidate'); |
|
924 | + header('Pragma: public'); |
|
925 | + header('Content-Length: ' . filesize($tmp_file)); |
|
926 | + readfile($tmp_file); |
|
927 | 927 | |
928 | 928 | } |
929 | 929 | |
@@ -950,24 +950,24 @@ discard block |
||
950 | 950 | |
951 | 951 | |
952 | 952 | header('Pragma: public'); |
953 | - header('Expires: 0'); |
|
954 | - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
955 | - header('Cache-Control: private', false); |
|
956 | - header('Content-Transfer-Encoding: binary'); |
|
957 | - header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
|
958 | - header('Content-Type: application/octet-stream'); |
|
959 | - header('Content-Length: ' . $metadata['size']); |
|
953 | + header('Expires: 0'); |
|
954 | + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
|
955 | + header('Cache-Control: private', false); |
|
956 | + header('Content-Transfer-Encoding: binary'); |
|
957 | + header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
|
958 | + header('Content-Type: application/octet-stream'); |
|
959 | + header('Content-Length: ' . $metadata['size']); |
|
960 | 960 | |
961 | - @ob_end_clean(); |
|
961 | + @ob_end_clean(); |
|
962 | 962 | |
963 | - $chunkSize = 1024 * 1024; |
|
964 | - while (!feof($read_stream)) |
|
965 | - { |
|
966 | - $buffer = fread($read_stream, $chunkSize); |
|
967 | - echo $buffer; |
|
968 | - } |
|
969 | - fclose($read_stream); |
|
970 | - exit; |
|
963 | + $chunkSize = 1024 * 1024; |
|
964 | + while (!feof($read_stream)) |
|
965 | + { |
|
966 | + $buffer = fread($read_stream, $chunkSize); |
|
967 | + echo $buffer; |
|
968 | + } |
|
969 | + fclose($read_stream); |
|
970 | + exit; |
|
971 | 971 | |
972 | 972 | } |
973 | 973 |
@@ -32,8 +32,9 @@ discard block |
||
32 | 32 | error_reporting(0); |
33 | 33 | } |
34 | 34 | |
35 | - if( ob_get_length() ) |
|
36 | - ob_end_clean(); |
|
35 | + if( ob_get_length() ) { |
|
36 | + ob_end_clean(); |
|
37 | + } |
|
37 | 38 | ob_start(); |
38 | 39 | |
39 | 40 | $wpdb->show_errors = false; |
@@ -86,7 +87,7 @@ discard block |
||
86 | 87 | { |
87 | 88 | $this->xcloner_database->init($data); |
88 | 89 | |
89 | - }catch(Exception $e){ |
|
90 | + } catch(Exception $e){ |
|
90 | 91 | |
91 | 92 | $this->send_response($e->getMessage()); |
92 | 93 | $this->logger->error($e->getMessage()); |
@@ -113,8 +114,9 @@ discard block |
||
113 | 114 | $schedule = array(); |
114 | 115 | $response = array(); |
115 | 116 | |
116 | - if(isset($_POST['data'])) |
|
117 | - $params = json_decode(stripslashes($_POST['data'])); |
|
117 | + if(isset($_POST['data'])) { |
|
118 | + $params = json_decode(stripslashes($_POST['data'])); |
|
119 | + } |
|
118 | 120 | |
119 | 121 | $this->process_params($params); |
120 | 122 | |
@@ -125,7 +127,7 @@ discard block |
||
125 | 127 | $this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']); |
126 | 128 | if($_POST['diff_start_date']){ |
127 | 129 | $this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date'])); |
128 | - }else{ |
|
130 | + } else{ |
|
129 | 131 | $this->form_params['backup_params']['diff_start_date'] = ""; |
130 | 132 | } |
131 | 133 | $this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']); |
@@ -144,8 +146,9 @@ discard block |
||
144 | 146 | { |
145 | 147 | $table = str_replace("\r","", $table); |
146 | 148 | $data = explode(".", $table); |
147 | - if(isset($data[1])) |
|
148 | - $return[$data[0]][] = $data[1]; |
|
149 | + if(isset($data[1])) { |
|
150 | + $return[$data[0]][] = $data[1]; |
|
151 | + } |
|
149 | 152 | } |
150 | 153 | |
151 | 154 | $this->form_params['database'] = ($return); |
@@ -156,19 +159,21 @@ discard block |
||
156 | 159 | foreach($excluded_files as $file) |
157 | 160 | { |
158 | 161 | $file = str_replace("\r","", $file); |
159 | - if($file) |
|
160 | - $return[] = $file; |
|
162 | + if($file) { |
|
163 | + $return[] = $file; |
|
164 | + } |
|
161 | 165 | } |
162 | 166 | |
163 | 167 | $this->form_params['excluded_files'] = ($return); |
164 | 168 | |
165 | 169 | $schedule['start_at'] = $this->form_params['backup_params']['start_at']; |
166 | 170 | |
167 | - if(!isset($_POST['status'])) |
|
168 | - $schedule['status'] = 0; |
|
169 | - else |
|
170 | - $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
|
171 | - }else{ |
|
171 | + if(!isset($_POST['status'])) { |
|
172 | + $schedule['status'] = 0; |
|
173 | + } else { |
|
174 | + $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
|
175 | + } |
|
176 | + } else{ |
|
172 | 177 | |
173 | 178 | $schedule['status'] = 1; |
174 | 179 | $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
@@ -183,7 +188,7 @@ discard block |
||
183 | 188 | if(!$schedule['start_at']) |
184 | 189 | { |
185 | 190 | $schedule['start_at'] = date('Y-m-d H:i:s', time()); |
186 | - }else{ |
|
191 | + } else{ |
|
187 | 192 | $schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at'] - (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS) ); |
188 | 193 | } |
189 | 194 | |
@@ -203,7 +208,7 @@ discard block |
||
203 | 208 | '%s' |
204 | 209 | ) |
205 | 210 | ); |
206 | - }else { |
|
211 | + } else { |
|
207 | 212 | $wpdb->update( |
208 | 213 | $wpdb->prefix.'xcloner_scheduler', |
209 | 214 | $schedule, |
@@ -244,8 +249,9 @@ discard block |
||
244 | 249 | |
245 | 250 | $init = (int)$_POST['init']; |
246 | 251 | |
247 | - if($params === NULL) |
|
248 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
252 | + if($params === NULL) { |
|
253 | + die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
254 | + } |
|
249 | 255 | |
250 | 256 | $this->process_params($params); |
251 | 257 | |
@@ -254,7 +260,7 @@ discard block |
||
254 | 260 | //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
255 | 261 | try{ |
256 | 262 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
257 | - }catch(Exception $e) |
|
263 | + } catch(Exception $e) |
|
258 | 264 | { |
259 | 265 | $return = array(); |
260 | 266 | $return['error'] = true; |
@@ -266,8 +272,9 @@ discard block |
||
266 | 272 | if($return['finished']) |
267 | 273 | { |
268 | 274 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
269 | - if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
270 | - $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
|
275 | + if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { |
|
276 | + $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
|
277 | + } |
|
271 | 278 | } |
272 | 279 | |
273 | 280 | $data = $return; |
@@ -282,7 +289,7 @@ discard block |
||
282 | 289 | $subject = ""; |
283 | 290 | $additional['lines_total'] = $return['extra']['lines_total']; |
284 | 291 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params,"", $additional); |
285 | - }catch(Exception $e) |
|
292 | + } catch(Exception $e) |
|
286 | 293 | { |
287 | 294 | $this->logger->error($e->getMessage()); |
288 | 295 | } |
@@ -306,18 +313,20 @@ discard block |
||
306 | 313 | |
307 | 314 | $init = (int)$_POST['init']; |
308 | 315 | |
309 | - if($params === NULL) |
|
310 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
316 | + if($params === NULL) { |
|
317 | + die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
318 | + } |
|
311 | 319 | |
312 | 320 | $this->process_params($params); |
313 | 321 | |
314 | 322 | //$xcloner_database = $this->init_db(); |
315 | 323 | $return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init); |
316 | 324 | |
317 | - if(isset($return['error']) and $return['error']) |
|
318 | - $data['finished'] = 1; |
|
319 | - else |
|
320 | - $data['finished'] = $return['finished']; |
|
325 | + if(isset($return['error']) and $return['error']) { |
|
326 | + $data['finished'] = 1; |
|
327 | + } else { |
|
328 | + $data['finished'] = $return['finished']; |
|
329 | + } |
|
321 | 330 | |
322 | 331 | $data['extra'] = $return; |
323 | 332 | |
@@ -336,8 +345,9 @@ discard block |
||
336 | 345 | $params = json_decode(stripslashes($_POST['data'])); |
337 | 346 | $init = (int)$_POST['init']; |
338 | 347 | |
339 | - if($params === NULL) |
|
340 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
348 | + if($params === NULL) { |
|
349 | + die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
350 | + } |
|
341 | 351 | |
342 | 352 | $hash = $this->process_params($params); |
343 | 353 | |
@@ -360,8 +370,9 @@ discard block |
||
360 | 370 | */ |
361 | 371 | private function process_params($params) |
362 | 372 | { |
363 | - if(isset($params->hash)) |
|
364 | - $this->xcloner_settings->set_hash($params->hash); |
|
373 | + if(isset($params->hash)) { |
|
374 | + $this->xcloner_settings->set_hash($params->hash); |
|
375 | + } |
|
365 | 376 | |
366 | 377 | $this->form_params['extra'] = array(); |
367 | 378 | $this->form_params['backup_params'] = array(); |
@@ -414,8 +425,9 @@ discard block |
||
414 | 425 | |
415 | 426 | if(isset($params->extra)) |
416 | 427 | { |
417 | - foreach($params->extra as $key=>$value) |
|
418 | - $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
|
428 | + foreach($params->extra as $key=>$value) { |
|
429 | + $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
|
430 | + } |
|
419 | 431 | } |
420 | 432 | |
421 | 433 | if(isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) |
@@ -455,7 +467,7 @@ discard block |
||
455 | 467 | |
456 | 468 | try{ |
457 | 469 | $files = $this->xcloner_file_system->list_directory($folder); |
458 | - }catch(Exception $e){ |
|
470 | + } catch(Exception $e){ |
|
459 | 471 | |
460 | 472 | print $e->getMessage(); |
461 | 473 | $this->logger->error($e->getMessage()); |
@@ -475,15 +487,17 @@ discard block |
||
475 | 487 | $children = false; |
476 | 488 | $text = $file['basename']; |
477 | 489 | |
478 | - if($file['type'] == "dir") |
|
479 | - $children = true; |
|
480 | - else |
|
481 | - $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; |
|
490 | + if($file['type'] == "dir") { |
|
491 | + $children = true; |
|
492 | + } else { |
|
493 | + $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; |
|
494 | + } |
|
482 | 495 | |
483 | - if($this->xcloner_file_system->is_excluded($file)) |
|
484 | - $selected = true; |
|
485 | - else |
|
486 | - $selected = false; |
|
496 | + if($this->xcloner_file_system->is_excluded($file)) { |
|
497 | + $selected = true; |
|
498 | + } else { |
|
499 | + $selected = false; |
|
500 | + } |
|
487 | 501 | |
488 | 502 | $data[] = array( |
489 | 503 | 'id' => $file['path'], |
@@ -519,22 +533,24 @@ discard block |
||
519 | 533 | { |
520 | 534 | try{ |
521 | 535 | $return = $this->xcloner_database->get_all_databases(); |
522 | - }catch(Exception $e){ |
|
536 | + } catch(Exception $e){ |
|
523 | 537 | $this->logger->error($e->getMessage()); |
524 | 538 | } |
525 | 539 | |
526 | 540 | foreach($return as $database) |
527 | 541 | { |
528 | - if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) |
|
529 | - continue; |
|
542 | + if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) { |
|
543 | + continue; |
|
544 | + } |
|
530 | 545 | |
531 | 546 | $state = array(); |
532 | 547 | |
533 | 548 | if($database['name'] == $this->xcloner_settings->get_db_database()) |
534 | 549 | { |
535 | 550 | $state['selected'] = true; |
536 | - if($database['num_tables'] < 25) |
|
537 | - $state['opened'] = false; |
|
551 | + if($database['num_tables'] < 25) { |
|
552 | + $state['opened'] = false; |
|
553 | + } |
|
538 | 554 | } |
539 | 555 | |
540 | 556 | $data[] = array( |
@@ -547,13 +563,11 @@ discard block |
||
547 | 563 | ); |
548 | 564 | } |
549 | 565 | |
550 | - } |
|
551 | - |
|
552 | - else{ |
|
566 | + } else{ |
|
553 | 567 | |
554 | 568 | try{ |
555 | 569 | $return = $this->xcloner_database->list_tables($database, "", 1); |
556 | - }catch(Exception $e){ |
|
570 | + } catch(Exception $e){ |
|
557 | 571 | $this->logger->error($e->getMessage()); |
558 | 572 | } |
559 | 573 | |
@@ -561,11 +575,13 @@ discard block |
||
561 | 575 | { |
562 | 576 | $state = array(); |
563 | 577 | |
564 | - if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) |
|
565 | - continue; |
|
578 | + if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) { |
|
579 | + continue; |
|
580 | + } |
|
566 | 581 | |
567 | - if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) |
|
568 | - $state = array('selected' => true); |
|
582 | + if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) { |
|
583 | + $state = array('selected' => true); |
|
584 | + } |
|
569 | 585 | |
570 | 586 | $data[] = array( |
571 | 587 | 'id' => $table['name'], |
@@ -620,10 +636,11 @@ discard block |
||
620 | 636 | { |
621 | 637 | $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
622 | 638 | <a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
623 | - if($res->status) |
|
624 | - $status = '<i class="material-icons active status">timer</i>'; |
|
625 | - else |
|
626 | - $status = '<i class="material-icons status inactive">timer_off</i>'; |
|
639 | + if($res->status) { |
|
640 | + $status = '<i class="material-icons active status">timer</i>'; |
|
641 | + } else { |
|
642 | + $status = '<i class="material-icons status inactive">timer_off</i>'; |
|
643 | + } |
|
627 | 644 | |
628 | 645 | $next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)); |
629 | 646 | |
@@ -631,17 +648,19 @@ discard block |
||
631 | 648 | |
632 | 649 | $remote_storage = $res->remote_storage; |
633 | 650 | |
634 | - if(!$next_run_time >= time()) |
|
635 | - $next_run = " "; |
|
651 | + if(!$next_run_time >= time()) { |
|
652 | + $next_run = " "; |
|
653 | + } |
|
636 | 654 | |
637 | 655 | if(trim($next_run)) |
638 | 656 | { |
639 | 657 | $date_text = date(get_option('date_format')." ".get_option('time_format'), $next_run_time + (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS)); |
640 | 658 | |
641 | - if($next_run_time >= time()) |
|
642 | - $next_run = "in ".human_time_diff($next_run_time, time()); |
|
643 | - else |
|
644 | - $next_run = __("executed", 'xcloner-backup-and-restore'); |
|
659 | + if($next_run_time >= time()) { |
|
660 | + $next_run = "in ".human_time_diff($next_run_time, time()); |
|
661 | + } else { |
|
662 | + $next_run = __("executed", 'xcloner-backup-and-restore'); |
|
663 | + } |
|
645 | 664 | |
646 | 665 | $next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>"; |
647 | 666 | //$next_run .=" ($date_text)"; |
@@ -732,7 +751,7 @@ discard block |
||
732 | 751 | $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); |
733 | 752 | |
734 | 753 | $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
735 | - }catch(Exception $e) |
|
754 | + } catch(Exception $e) |
|
736 | 755 | { |
737 | 756 | $return['error'] = true; |
738 | 757 | $return['message'] = $e->getMessage(); |
@@ -760,15 +779,16 @@ discard block |
||
760 | 779 | { |
761 | 780 | $return['start'] = $data['start']; |
762 | 781 | $return['finished'] = 0; |
763 | - }else{ |
|
782 | + } else{ |
|
764 | 783 | if($this->xcloner_file_system->is_multipart($source_backup_file)) |
765 | 784 | { |
766 | 785 | $return['start'] = 0; |
767 | 786 | |
768 | 787 | ++$return['part']; |
769 | 788 | |
770 | - if($return['part'] < sizeof($backup_parts)) |
|
771 | - $return['finished'] = 0; |
|
789 | + if($return['part'] < sizeof($backup_parts)) { |
|
790 | + $return['finished'] = 0; |
|
791 | + } |
|
772 | 792 | |
773 | 793 | } |
774 | 794 | } |
@@ -794,7 +814,7 @@ discard block |
||
794 | 814 | { |
795 | 815 | $return = call_user_func_array(array($xcloner_remote_storage, "copy_backup_remote_to_local"), array($backup_file, $storage_type)); |
796 | 816 | } |
797 | - }catch(Exception $e){ |
|
817 | + } catch(Exception $e){ |
|
798 | 818 | |
799 | 819 | $return['error'] = 1; |
800 | 820 | $return['message'] = $e->getMessage(); |
@@ -833,7 +853,7 @@ discard block |
||
833 | 853 | { |
834 | 854 | $return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type)); |
835 | 855 | } |
836 | - }catch(Exception $e){ |
|
856 | + } catch(Exception $e){ |
|
837 | 857 | |
838 | 858 | $return['error'] = 1; |
839 | 859 | $return['message'] = $e->getMessage(); |
@@ -984,11 +1004,13 @@ discard block |
||
984 | 1004 | $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
985 | 1005 | $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']); |
986 | 1006 | |
987 | - if(isset($_POST['part'])) |
|
988 | - $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
1007 | + if(isset($_POST['part'])) { |
|
1008 | + $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
1009 | + } |
|
989 | 1010 | |
990 | - if(isset($_POST['uploaded_size'])) |
|
991 | - $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
|
1011 | + if(isset($_POST['uploaded_size'])) { |
|
1012 | + $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
|
1013 | + } |
|
992 | 1014 | |
993 | 1015 | $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']); |
994 | 1016 | $target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']); |
@@ -1015,7 +1037,7 @@ discard block |
||
1015 | 1037 | $xcloner_file_transfer->set_target($target_url); |
1016 | 1038 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
1017 | 1039 | |
1018 | - }catch(Exception $e){ |
|
1040 | + } catch(Exception $e){ |
|
1019 | 1041 | |
1020 | 1042 | $return = array(); |
1021 | 1043 | $return['error'] = true; |
@@ -1059,8 +1081,9 @@ discard block |
||
1059 | 1081 | $data['hash'] = $this->xcloner_settings->get_hash(); |
1060 | 1082 | } |
1061 | 1083 | |
1062 | - if( ob_get_length() ) |
|
1063 | - ob_clean(); |
|
1084 | + if( ob_get_length() ) { |
|
1085 | + ob_clean(); |
|
1086 | + } |
|
1064 | 1087 | wp_send_json($data); |
1065 | 1088 | |
1066 | 1089 | die(); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | use splitbrain\PHPArchive\FileInfo; |
12 | 12 | |
13 | 13 | |
14 | -class Xcloner_Api{ |
|
14 | +class Xcloner_Api { |
|
15 | 15 | |
16 | 16 | private $xcloner_database; |
17 | 17 | private $xcloner_settings; |
@@ -27,30 +27,30 @@ discard block |
||
27 | 27 | { |
28 | 28 | global $wpdb; |
29 | 29 | |
30 | - if(WP_DEBUG) |
|
30 | + if (WP_DEBUG) |
|
31 | 31 | { |
32 | 32 | error_reporting(0); |
33 | 33 | } |
34 | 34 | |
35 | - if( ob_get_length() ) |
|
35 | + if (ob_get_length()) |
|
36 | 36 | ob_end_clean(); |
37 | 37 | ob_start(); |
38 | 38 | |
39 | - $wpdb->show_errors = false; |
|
39 | + $wpdb->show_errors = false; |
|
40 | 40 | |
41 | 41 | $this->xcloner_container = $xcloner_container; |
42 | 42 | |
43 | 43 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
44 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api"); |
|
44 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api"); |
|
45 | 45 | $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
46 | 46 | $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
47 | 47 | $this->xcloner_requirements = $xcloner_container->get_xcloner_requirements(); |
48 | - $this->archive_system = $xcloner_container->get_archive_system(); |
|
49 | - $this->xcloner_database = $xcloner_container->get_xcloner_database(); |
|
50 | - $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler(); |
|
48 | + $this->archive_system = $xcloner_container->get_archive_system(); |
|
49 | + $this->xcloner_database = $xcloner_container->get_xcloner_database(); |
|
50 | + $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler(); |
|
51 | 51 | |
52 | - if(isset($_POST['API_ID'])){ |
|
53 | - $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0 , 15)); |
|
52 | + if (isset($_POST['API_ID'])) { |
|
53 | + $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0, 15)); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | } |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | $data['dbDatabase'] = $this->xcloner_settings->get_db_database(); |
79 | 79 | |
80 | 80 | |
81 | - $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
82 | - $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database"; |
|
83 | - $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql"; |
|
81 | + $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
82 | + $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database"; |
|
83 | + $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql"; |
|
84 | 84 | |
85 | 85 | try |
86 | 86 | { |
87 | 87 | $this->xcloner_database->init($data); |
88 | 88 | |
89 | - }catch(Exception $e){ |
|
89 | + }catch (Exception $e) { |
|
90 | 90 | |
91 | 91 | $this->send_response($e->getMessage()); |
92 | 92 | $this->logger->error($e->getMessage()); |
@@ -113,19 +113,19 @@ discard block |
||
113 | 113 | $schedule = array(); |
114 | 114 | $response = array(); |
115 | 115 | |
116 | - if(isset($_POST['data'])) |
|
116 | + if (isset($_POST['data'])) |
|
117 | 117 | $params = json_decode(stripslashes($_POST['data'])); |
118 | 118 | |
119 | 119 | $this->process_params($params); |
120 | 120 | |
121 | - if(isset($_POST['id'])) |
|
121 | + if (isset($_POST['id'])) |
|
122 | 122 | { |
123 | 123 | |
124 | 124 | $this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']); |
125 | 125 | $this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']); |
126 | - if($_POST['diff_start_date']){ |
|
126 | + if ($_POST['diff_start_date']) { |
|
127 | 127 | $this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date'])); |
128 | - }else{ |
|
128 | + } else { |
|
129 | 129 | $this->form_params['backup_params']['diff_start_date'] = ""; |
130 | 130 | } |
131 | 131 | $this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']); |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | $tables = explode(PHP_EOL, $this->form_params['database']); |
141 | 141 | $return = array(); |
142 | 142 | |
143 | - foreach($tables as $table) |
|
143 | + foreach ($tables as $table) |
|
144 | 144 | { |
145 | - $table = str_replace("\r","", $table); |
|
145 | + $table = str_replace("\r", "", $table); |
|
146 | 146 | $data = explode(".", $table); |
147 | - if(isset($data[1])) |
|
147 | + if (isset($data[1])) |
|
148 | 148 | $return[$data[0]][] = $data[1]; |
149 | 149 | } |
150 | 150 | |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | $excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']); |
154 | 154 | $return = array(); |
155 | 155 | |
156 | - foreach($excluded_files as $file) |
|
156 | + foreach ($excluded_files as $file) |
|
157 | 157 | { |
158 | - $file = str_replace("\r","", $file); |
|
159 | - if($file) |
|
158 | + $file = str_replace("\r", "", $file); |
|
159 | + if ($file) |
|
160 | 160 | $return[] = $file; |
161 | 161 | } |
162 | 162 | |
@@ -164,32 +164,32 @@ discard block |
||
164 | 164 | |
165 | 165 | $schedule['start_at'] = $this->form_params['backup_params']['start_at']; |
166 | 166 | |
167 | - if(!isset($_POST['status'])) |
|
167 | + if (!isset($_POST['status'])) |
|
168 | 168 | $schedule['status'] = 0; |
169 | 169 | else |
170 | 170 | $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
171 | - }else{ |
|
171 | + } else { |
|
172 | 172 | |
173 | 173 | $schedule['status'] = 1; |
174 | - $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
|
174 | + $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date']. |
|
175 | 175 | " ".$this->form_params['backup_params']['schedule_start_time']); |
176 | 176 | |
177 | - if($schedule['start_at'] <= time()) |
|
177 | + if ($schedule['start_at'] <= time()) |
|
178 | 178 | { |
179 | 179 | $schedule['start_at'] = ""; |
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - if(!$schedule['start_at']) |
|
183 | + if (!$schedule['start_at']) |
|
184 | 184 | { |
185 | 185 | $schedule['start_at'] = date('Y-m-d H:i:s', time()); |
186 | - }else{ |
|
187 | - $schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at'] - (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS) ); |
|
186 | + } else { |
|
187 | + $schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | $schedule['name'] = $this->form_params['backup_params']['schedule_name']; |
191 | 191 | $schedule['recurrence'] = $this->form_params['backup_params']['schedule_frequency']; |
192 | - if(!isset($this->form_params['backup_params']['schedule_storage'])) |
|
192 | + if (!isset($this->form_params['backup_params']['schedule_storage'])) |
|
193 | 193 | { |
194 | 194 | $this->form_params['backup_params']['schedule_storage'] = ""; |
195 | 195 | } |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | //$schedule['backup_type'] = $this->form_params['backup_params']['backup_type']; |
198 | 198 | $schedule['params'] = json_encode($this->form_params); |
199 | 199 | |
200 | - if(!isset($_POST['id'])) |
|
200 | + if (!isset($_POST['id'])) |
|
201 | 201 | { |
202 | 202 | $wpdb->insert( |
203 | 203 | $wpdb->prefix.'xcloner_scheduler', |
@@ -207,23 +207,23 @@ discard block |
||
207 | 207 | '%s' |
208 | 208 | ) |
209 | 209 | ); |
210 | - }else { |
|
210 | + } else { |
|
211 | 211 | $wpdb->update( |
212 | 212 | $wpdb->prefix.'xcloner_scheduler', |
213 | 213 | $schedule, |
214 | - array( 'id' => $_POST['id'] ), |
|
214 | + array('id' => $_POST['id']), |
|
215 | 215 | array( |
216 | 216 | '%s', |
217 | 217 | '%s' |
218 | 218 | ) |
219 | 219 | ); |
220 | 220 | } |
221 | - if(isset($_POST['id'])) |
|
221 | + if (isset($_POST['id'])) |
|
222 | 222 | { |
223 | 223 | $scheduler->update_cron_hook($_POST['id']); |
224 | 224 | } |
225 | 225 | |
226 | - if( $wpdb->last_error ) { |
|
226 | + if ($wpdb->last_error) { |
|
227 | 227 | $response['error'] = 1; |
228 | 228 | $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/; |
229 | 229 | |
@@ -246,19 +246,19 @@ discard block |
||
246 | 246 | |
247 | 247 | $params = json_decode(stripslashes($_POST['data'])); |
248 | 248 | |
249 | - $init = (int)$_POST['init']; |
|
249 | + $init = (int)$_POST['init']; |
|
250 | 250 | |
251 | - if($params === NULL) |
|
252 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
251 | + if ($params === NULL) |
|
252 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
253 | 253 | |
254 | 254 | $this->process_params($params); |
255 | 255 | |
256 | 256 | $return['finished'] = 1; |
257 | 257 | |
258 | 258 | //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
259 | - try{ |
|
259 | + try { |
|
260 | 260 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
261 | - }catch(Exception $e) |
|
261 | + }catch (Exception $e) |
|
262 | 262 | { |
263 | 263 | $return = array(); |
264 | 264 | $return['error'] = true; |
@@ -267,26 +267,26 @@ discard block |
||
267 | 267 | return $this->send_response($return, $hash = 1); |
268 | 268 | } |
269 | 269 | |
270 | - if($return['finished']) |
|
270 | + if ($return['finished']) |
|
271 | 271 | { |
272 | 272 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
273 | - if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
273 | + if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
274 | 274 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
275 | 275 | } |
276 | 276 | |
277 | 277 | $data = $return; |
278 | 278 | |
279 | 279 | //check if backup is finished |
280 | - if($return['finished'] ) |
|
280 | + if ($return['finished']) |
|
281 | 281 | { |
282 | - if(isset($this->form_params['backup_params']['email_notification']) and $to=$this->form_params['backup_params']['email_notification']) |
|
282 | + if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) |
|
283 | 283 | { |
284 | - try{ |
|
284 | + try { |
|
285 | 285 | $from = ""; |
286 | 286 | $subject = ""; |
287 | 287 | $additional['lines_total'] = $return['extra']['lines_total']; |
288 | - $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params,"", $additional); |
|
289 | - }catch(Exception $e) |
|
288 | + $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params, "", $additional); |
|
289 | + }catch (Exception $e) |
|
290 | 290 | { |
291 | 291 | $this->logger->error($e->getMessage()); |
292 | 292 | } |
@@ -308,17 +308,17 @@ discard block |
||
308 | 308 | |
309 | 309 | $params = json_decode(stripslashes($_POST['data'])); |
310 | 310 | |
311 | - $init = (int)$_POST['init']; |
|
311 | + $init = (int)$_POST['init']; |
|
312 | 312 | |
313 | - if($params === NULL) |
|
314 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
313 | + if ($params === NULL) |
|
314 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
315 | 315 | |
316 | 316 | $this->process_params($params); |
317 | 317 | |
318 | 318 | //$xcloner_database = $this->init_db(); |
319 | 319 | $return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init); |
320 | 320 | |
321 | - if(isset($return['error']) and $return['error']) |
|
321 | + if (isset($return['error']) and $return['error']) |
|
322 | 322 | $data['finished'] = 1; |
323 | 323 | else |
324 | 324 | $data['finished'] = $return['finished']; |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | $this->check_access(); |
339 | 339 | |
340 | 340 | $params = json_decode(stripslashes($_POST['data'])); |
341 | - $init = (int)$_POST['init']; |
|
341 | + $init = (int)$_POST['init']; |
|
342 | 342 | |
343 | - if($params === NULL) |
|
344 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
343 | + if ($params === NULL) |
|
344 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
345 | 345 | |
346 | 346 | $hash = $this->process_params($params); |
347 | 347 | |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | $data["finished"] = !$return; |
353 | 353 | $data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num(); |
354 | 354 | $data["last_logged_file"] = $this->xcloner_file_system->last_logged_file(); |
355 | - $data["total_files_size"] = sprintf("%.2f",$this->xcloner_file_system->get_scanned_files_total_size()/(1024*1024)); |
|
355 | + $data["total_files_size"] = sprintf("%.2f", $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024)); |
|
356 | 356 | |
357 | 357 | return $this->send_response($data, $hash = 1); |
358 | 358 | } |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | */ |
365 | 365 | private function process_params($params) |
366 | 366 | { |
367 | - if(isset($params->hash)) |
|
367 | + if (isset($params->hash)) |
|
368 | 368 | $this->xcloner_settings->set_hash($params->hash); |
369 | 369 | |
370 | 370 | $this->form_params['extra'] = array(); |
@@ -372,9 +372,9 @@ discard block |
||
372 | 372 | |
373 | 373 | $this->form_params['database'] = array(); |
374 | 374 | |
375 | - if(isset($params->backup_params)) |
|
375 | + if (isset($params->backup_params)) |
|
376 | 376 | { |
377 | - foreach($params->backup_params as $param) |
|
377 | + foreach ($params->backup_params as $param) |
|
378 | 378 | { |
379 | 379 | $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value); |
380 | 380 | $this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array('POST', 'fields filter')); |
@@ -383,28 +383,28 @@ discard block |
||
383 | 383 | |
384 | 384 | $this->form_params['database'] = array(); |
385 | 385 | |
386 | - if(isset($params->table_params)) |
|
386 | + if (isset($params->table_params)) |
|
387 | 387 | { |
388 | - foreach($params->table_params as $param) |
|
388 | + foreach ($params->table_params as $param) |
|
389 | 389 | { |
390 | 390 | $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id); |
391 | 391 | $this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array('POST', 'database filter')); |
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
395 | - $this->form_params['excluded_files'] = array(); |
|
396 | - if(isset($params->files_params)) |
|
395 | + $this->form_params['excluded_files'] = array(); |
|
396 | + if (isset($params->files_params)) |
|
397 | 397 | { |
398 | - foreach($params->files_params as $param) |
|
398 | + foreach ($params->files_params as $param) |
|
399 | 399 | { |
400 | 400 | $this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
401 | 401 | } |
402 | 402 | |
403 | 403 | $unique_exclude_files = array(); |
404 | 404 | |
405 | - foreach($params->files_params as $key=>$param) |
|
405 | + foreach ($params->files_params as $key=>$param) |
|
406 | 406 | { |
407 | - if(!in_array($param->parent, $this->form_params['excluded_files'])){ |
|
407 | + if (!in_array($param->parent, $this->form_params['excluded_files'])) { |
|
408 | 408 | //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
409 | 409 | $unique_exclude_files[] = $param->id; |
410 | 410 | $this->logger->debug("Adding file filter ".$param->id."\n", array('POST', 'exclude files filter')); |
@@ -416,13 +416,13 @@ discard block |
||
416 | 416 | |
417 | 417 | //$this->form_params['excluded_files'] = array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default); |
418 | 418 | |
419 | - if(isset($params->extra)) |
|
419 | + if (isset($params->extra)) |
|
420 | 420 | { |
421 | - foreach($params->extra as $key=>$value) |
|
421 | + foreach ($params->extra as $key=>$value) |
|
422 | 422 | $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
423 | 423 | } |
424 | 424 | |
425 | - if(isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) |
|
425 | + if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) |
|
426 | 426 | { |
427 | 427 | $this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']); |
428 | 428 | $this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']); |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | |
445 | 445 | $data = array(); |
446 | 446 | |
447 | - if($folder == "#"){ |
|
447 | + if ($folder == "#") { |
|
448 | 448 | |
449 | 449 | $folder = "/"; |
450 | 450 | $data[] = array( |
@@ -457,9 +457,9 @@ discard block |
||
457 | 457 | ); |
458 | 458 | } |
459 | 459 | |
460 | - try{ |
|
460 | + try { |
|
461 | 461 | $files = $this->xcloner_file_system->list_directory($folder); |
462 | - }catch(Exception $e){ |
|
462 | + }catch (Exception $e) { |
|
463 | 463 | |
464 | 464 | print $e->getMessage(); |
465 | 465 | $this->logger->error($e->getMessage()); |
@@ -474,17 +474,17 @@ discard block |
||
474 | 474 | } |
475 | 475 | array_multisort($type, SORT_ASC, $files); |
476 | 476 | |
477 | - foreach($files as $file) |
|
477 | + foreach ($files as $file) |
|
478 | 478 | { |
479 | 479 | $children = false; |
480 | 480 | $text = $file['basename']; |
481 | 481 | |
482 | - if($file['type'] == "dir") |
|
482 | + if ($file['type'] == "dir") |
|
483 | 483 | $children = true; |
484 | 484 | else |
485 | - $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; |
|
485 | + $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")"; |
|
486 | 486 | |
487 | - if($this->xcloner_file_system->is_excluded($file)) |
|
487 | + if ($this->xcloner_file_system->is_excluded($file)) |
|
488 | 488 | $selected = true; |
489 | 489 | else |
490 | 490 | $selected = false; |
@@ -519,25 +519,25 @@ discard block |
||
519 | 519 | |
520 | 520 | $xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables'); |
521 | 521 | |
522 | - if($database == "#") |
|
522 | + if ($database == "#") |
|
523 | 523 | { |
524 | - try{ |
|
524 | + try { |
|
525 | 525 | $return = $this->xcloner_database->get_all_databases(); |
526 | - }catch(Exception $e){ |
|
526 | + }catch (Exception $e) { |
|
527 | 527 | $this->logger->error($e->getMessage()); |
528 | 528 | } |
529 | 529 | |
530 | - foreach($return as $database) |
|
530 | + foreach ($return as $database) |
|
531 | 531 | { |
532 | - if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) |
|
532 | + if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) |
|
533 | 533 | continue; |
534 | 534 | |
535 | 535 | $state = array(); |
536 | 536 | |
537 | - if($database['name'] == $this->xcloner_settings->get_db_database()) |
|
537 | + if ($database['name'] == $this->xcloner_settings->get_db_database()) |
|
538 | 538 | { |
539 | 539 | $state['selected'] = true; |
540 | - if($database['num_tables'] < 25) |
|
540 | + if ($database['num_tables'] < 25) |
|
541 | 541 | $state['opened'] = false; |
542 | 542 | } |
543 | 543 | |
@@ -553,22 +553,22 @@ discard block |
||
553 | 553 | |
554 | 554 | } |
555 | 555 | |
556 | - else{ |
|
556 | + else { |
|
557 | 557 | |
558 | - try{ |
|
558 | + try { |
|
559 | 559 | $return = $this->xcloner_database->list_tables($database, "", 1); |
560 | - }catch(Exception $e){ |
|
560 | + }catch (Exception $e) { |
|
561 | 561 | $this->logger->error($e->getMessage()); |
562 | 562 | } |
563 | 563 | |
564 | - foreach($return as $table) |
|
564 | + foreach ($return as $table) |
|
565 | 565 | { |
566 | 566 | $state = array(); |
567 | 567 | |
568 | - if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) |
|
568 | + if ($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) |
|
569 | 569 | continue; |
570 | 570 | |
571 | - if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) |
|
571 | + if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) |
|
572 | 572 | $state = array('selected' => true); |
573 | 573 | |
574 | 574 | $data[] = array( |
@@ -596,12 +596,12 @@ discard block |
||
596 | 596 | |
597 | 597 | $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
598 | 598 | $scheduler = $this->xcloner_scheduler; |
599 | - $data = $scheduler->get_schedule_by_id($schedule_id); |
|
599 | + $data = $scheduler->get_schedule_by_id($schedule_id); |
|
600 | 600 | |
601 | - $data['start_at'] = date("Y-m-d H:i", strtotime($data['start_at']) + (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS)); |
|
602 | - if(isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") |
|
601 | + $data['start_at'] = date("Y-m-d H:i", strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
602 | + if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") |
|
603 | 603 | { |
604 | - $data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date) ); |
|
604 | + $data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date)); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | return $this->send_response($data); |
@@ -617,14 +617,14 @@ discard block |
||
617 | 617 | $this->check_access(); |
618 | 618 | |
619 | 619 | $scheduler = $this->xcloner_scheduler; |
620 | - $data = $scheduler->get_scheduler_list(); |
|
620 | + $data = $scheduler->get_scheduler_list(); |
|
621 | 621 | $return['data'] = array(); |
622 | 622 | |
623 | - foreach($data as $res) |
|
623 | + foreach ($data as $res) |
|
624 | 624 | { |
625 | 625 | $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
626 | 626 | <a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
627 | - if($res->status) |
|
627 | + if ($res->status) |
|
628 | 628 | $status = '<i class="material-icons active status">timer</i>'; |
629 | 629 | else |
630 | 630 | $status = '<i class="material-icons status inactive">timer_off</i>'; |
@@ -635,14 +635,14 @@ discard block |
||
635 | 635 | |
636 | 636 | $remote_storage = $res->remote_storage; |
637 | 637 | |
638 | - if(!$next_run_time >= time()) |
|
638 | + if (!$next_run_time >= time()) |
|
639 | 639 | $next_run = " "; |
640 | 640 | |
641 | - if(trim($next_run)) |
|
641 | + if (trim($next_run)) |
|
642 | 642 | { |
643 | - $date_text = date(get_option('date_format')." ".get_option('time_format'), $next_run_time + (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS)); |
|
643 | + $date_text = date(get_option('date_format')." ".get_option('time_format'), $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
644 | 644 | |
645 | - if($next_run_time >= time()) |
|
645 | + if ($next_run_time >= time()) |
|
646 | 646 | $next_run = "in ".human_time_diff($next_run_time, time()); |
647 | 647 | else |
648 | 648 | $next_run = __("executed", 'xcloner-backup-and-restore'); |
@@ -655,13 +655,13 @@ discard block |
||
655 | 655 | $backup_size = ""; |
656 | 656 | $backup_time = ""; |
657 | 657 | |
658 | - if($res->last_backup) |
|
658 | + if ($res->last_backup) |
|
659 | 659 | { |
660 | - if( $this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) |
|
660 | + if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) |
|
661 | 661 | { |
662 | 662 | $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup); |
663 | 663 | $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup)); |
664 | - $backup_time = date(get_option('date_format')." ".get_option('time_format'), $metadata['timestamp']+(get_option( 'gmt_offset' ) * HOUR_IN_SECONDS)); |
|
664 | + $backup_time = date(get_option('date_format')." ".get_option('time_format'), $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | $backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>"; |
@@ -669,12 +669,12 @@ discard block |
||
669 | 669 | |
670 | 670 | $schedules = wp_get_schedules(); |
671 | 671 | |
672 | - if(isset($schedules[$res->recurrence])) |
|
672 | + if (isset($schedules[$res->recurrence])) |
|
673 | 673 | { |
674 | 674 | $res->recurrence = $schedules[$res->recurrence]['display']; |
675 | 675 | } |
676 | 676 | |
677 | - $return['data'][] = array($res->id, $res->name, $res->recurrence,/*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action); |
|
677 | + $return['data'][] = array($res->id, $res->name, $res->recurrence, /*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | return $this->send_response($return, 0); |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | |
692 | 692 | $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
693 | 693 | $scheduler = $this->xcloner_scheduler; |
694 | - $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id); |
|
694 | + $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id); |
|
695 | 695 | |
696 | 696 | return $this->send_response($data); |
697 | 697 | } |
@@ -725,32 +725,32 @@ discard block |
||
725 | 725 | |
726 | 726 | $backup_file = $source_backup_file; |
727 | 727 | |
728 | - if($this->xcloner_file_system->is_multipart($backup_file)) |
|
728 | + if ($this->xcloner_file_system->is_multipart($backup_file)) |
|
729 | 729 | { |
730 | 730 | $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file); |
731 | 731 | $backup_file = $backup_parts[$return['part']]; |
732 | 732 | } |
733 | 733 | |
734 | - try{ |
|
734 | + try { |
|
735 | 735 | $tar = new Tar(); |
736 | 736 | $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); |
737 | 737 | |
738 | 738 | $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
739 | - }catch(Exception $e) |
|
739 | + }catch (Exception $e) |
|
740 | 740 | { |
741 | 741 | $return['error'] = true; |
742 | 742 | $return['message'] = $e->getMessage(); |
743 | 743 | $this->send_response($return, 0); |
744 | 744 | } |
745 | 745 | |
746 | - $return['files'] = array(); |
|
747 | - $return['finished'] = 1; |
|
748 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
746 | + $return['files'] = array(); |
|
747 | + $return['finished'] = 1; |
|
748 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
749 | 749 | $i = 0; |
750 | 750 | |
751 | - if(isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
751 | + if (isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
752 | 752 | { |
753 | - foreach($data['extracted_files'] as $file) |
|
753 | + foreach ($data['extracted_files'] as $file) |
|
754 | 754 | { |
755 | 755 | $return['files'][$i]['path'] = $file->getPath(); |
756 | 756 | $return['files'][$i]['size'] = $file->getSize(); |
@@ -760,18 +760,18 @@ discard block |
||
760 | 760 | } |
761 | 761 | } |
762 | 762 | |
763 | - if(isset($data['start'])) |
|
763 | + if (isset($data['start'])) |
|
764 | 764 | { |
765 | 765 | $return['start'] = $data['start']; |
766 | 766 | $return['finished'] = 0; |
767 | - }else{ |
|
768 | - if($this->xcloner_file_system->is_multipart($source_backup_file)) |
|
767 | + } else { |
|
768 | + if ($this->xcloner_file_system->is_multipart($source_backup_file)) |
|
769 | 769 | { |
770 | 770 | $return['start'] = 0; |
771 | 771 | |
772 | 772 | ++$return['part']; |
773 | 773 | |
774 | - if($return['part'] < sizeof($backup_parts)) |
|
774 | + if ($return['part'] < sizeof($backup_parts)) |
|
775 | 775 | $return['finished'] = 0; |
776 | 776 | |
777 | 777 | } |
@@ -794,17 +794,17 @@ discard block |
||
794 | 794 | |
795 | 795 | try |
796 | 796 | { |
797 | - if(method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) |
|
797 | + if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) |
|
798 | 798 | { |
799 | 799 | $return = call_user_func_array(array($xcloner_remote_storage, "copy_backup_remote_to_local"), array($backup_file, $storage_type)); |
800 | 800 | } |
801 | - }catch(Exception $e){ |
|
801 | + }catch (Exception $e) { |
|
802 | 802 | |
803 | 803 | $return['error'] = 1; |
804 | 804 | $return['message'] = $e->getMessage(); |
805 | 805 | } |
806 | 806 | |
807 | - if(!$return) |
|
807 | + if (!$return) |
|
808 | 808 | { |
809 | 809 | $return['error'] = 1; |
810 | 810 | $return['message'] = "Upload failed, please check the error log for more information!"; |
@@ -833,17 +833,17 @@ discard block |
||
833 | 833 | |
834 | 834 | try |
835 | 835 | { |
836 | - if(method_exists($xcloner_remote_storage, "upload_backup_to_storage")) |
|
836 | + if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) |
|
837 | 837 | { |
838 | 838 | $return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type)); |
839 | 839 | } |
840 | - }catch(Exception $e){ |
|
840 | + }catch (Exception $e) { |
|
841 | 841 | |
842 | 842 | $return['error'] = 1; |
843 | 843 | $return['message'] = $e->getMessage(); |
844 | 844 | } |
845 | 845 | |
846 | - if(!$return) |
|
846 | + if (!$return) |
|
847 | 847 | { |
848 | 848 | $return['error'] = 1; |
849 | 849 | $return['message'] = "Upload failed, please check the error log for more information!"; |
@@ -877,7 +877,7 @@ discard block |
||
877 | 877 | |
878 | 878 | @ob_end_clean(); |
879 | 879 | |
880 | - $adapter = new Local(dirname(__DIR__) ,LOCK_EX, 'SKIP_LINKS'); |
|
880 | + $adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS'); |
|
881 | 881 | $xcloner_plugin_filesystem = new Filesystem($adapter, new Config([ |
882 | 882 | 'disable_asserts' => true, |
883 | 883 | ])); |
@@ -907,7 +907,7 @@ discard block |
||
907 | 907 | //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz"); |
908 | 908 | |
909 | 909 | $files = $xcloner_plugin_filesystem->listContents("vendor/", true); |
910 | - foreach($files as $file) |
|
910 | + foreach ($files as $file) |
|
911 | 911 | { |
912 | 912 | $tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']); |
913 | 913 | } |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | header('Expires: 0'); |
927 | 927 | header('Cache-Control: must-revalidate'); |
928 | 928 | header('Pragma: public'); |
929 | - header('Content-Length: ' . filesize($tmp_file)); |
|
929 | + header('Content-Length: '.filesize($tmp_file)); |
|
930 | 930 | readfile($tmp_file); |
931 | 931 | |
932 | 932 | } |
@@ -949,8 +949,8 @@ discard block |
||
949 | 949 | $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']); |
950 | 950 | |
951 | 951 | |
952 | - $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name); |
|
953 | - $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name); |
|
952 | + $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name); |
|
953 | + $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name); |
|
954 | 954 | |
955 | 955 | |
956 | 956 | header('Pragma: public'); |
@@ -960,7 +960,7 @@ discard block |
||
960 | 960 | header('Content-Transfer-Encoding: binary'); |
961 | 961 | header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
962 | 962 | header('Content-Type: application/octet-stream'); |
963 | - header('Content-Length: ' . $metadata['size']); |
|
963 | + header('Content-Length: '.$metadata['size']); |
|
964 | 964 | |
965 | 965 | @ob_end_clean(); |
966 | 966 | |
@@ -988,10 +988,10 @@ discard block |
||
988 | 988 | $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
989 | 989 | $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']); |
990 | 990 | |
991 | - if(isset($_POST['part'])) |
|
991 | + if (isset($_POST['part'])) |
|
992 | 992 | $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
993 | 993 | |
994 | - if(isset($_POST['uploaded_size'])) |
|
994 | + if (isset($_POST['uploaded_size'])) |
|
995 | 995 | $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
996 | 996 | |
997 | 997 | $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']); |
@@ -999,46 +999,46 @@ discard block |
||
999 | 999 | |
1000 | 1000 | $return['total_size'] = $this->xcloner_file_system->get_backup_size($file); |
1001 | 1001 | |
1002 | - if($this->xcloner_file_system->is_multipart($file)) |
|
1002 | + if ($this->xcloner_file_system->is_multipart($file)) |
|
1003 | 1003 | { |
1004 | 1004 | $backup_parts = $this->xcloner_file_system->get_multipart_files($file); |
1005 | 1005 | |
1006 | - $return['total_parts'] = sizeof($backup_parts)+1; |
|
1006 | + $return['total_parts'] = sizeof($backup_parts) + 1; |
|
1007 | 1007 | |
1008 | - if($return['part'] and isset($backup_parts[$return['part']-1])) |
|
1008 | + if ($return['part'] and isset($backup_parts[$return['part'] - 1])) |
|
1009 | 1009 | { |
1010 | - $file = $backup_parts[$return['part']-1]; |
|
1010 | + $file = $backup_parts[$return['part'] - 1]; |
|
1011 | 1011 | } |
1012 | 1012 | |
1013 | 1013 | $is_multipart = 1; |
1014 | 1014 | } |
1015 | 1015 | |
1016 | - try{ |
|
1016 | + try { |
|
1017 | 1017 | |
1018 | 1018 | $xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer(); |
1019 | 1019 | $xcloner_file_transfer->set_target($target_url); |
1020 | 1020 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
1021 | 1021 | |
1022 | - }catch(Exception $e){ |
|
1022 | + }catch (Exception $e) { |
|
1023 | 1023 | |
1024 | 1024 | $return = array(); |
1025 | 1025 | $return['error'] = true; |
1026 | 1026 | $return['status'] = 500; |
1027 | 1027 | $return['message'] = "CURL communication error with the restore host. ".$e->getMessage(); |
1028 | - $this->send_response( $return, 0); |
|
1028 | + $this->send_response($return, 0); |
|
1029 | 1029 | |
1030 | 1030 | } |
1031 | 1031 | |
1032 | 1032 | $return['status'] = 200; |
1033 | 1033 | |
1034 | 1034 | //we have finished the upload |
1035 | - if(!$return['start'] and $is_multipart) |
|
1035 | + if (!$return['start'] and $is_multipart) |
|
1036 | 1036 | { |
1037 | 1037 | $return['part']++; |
1038 | 1038 | $return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file); |
1039 | 1039 | } |
1040 | 1040 | |
1041 | - $this->send_response( $return, 0); |
|
1041 | + $this->send_response($return, 0); |
|
1042 | 1042 | } |
1043 | 1043 | |
1044 | 1044 | public function restore_backup() |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | $this->check_access(); |
1047 | 1047 | |
1048 | 1048 | define("XCLONER_PLUGIN_ACCESS", 1); |
1049 | - include_once(dirname(__DIR__) .DS."restore".DS."xcloner_restore.php"); |
|
1049 | + include_once(dirname(__DIR__).DS."restore".DS."xcloner_restore.php"); |
|
1050 | 1050 | return; |
1051 | 1051 | } |
1052 | 1052 | |
@@ -1058,12 +1058,12 @@ discard block |
||
1058 | 1058 | private function send_response($data, $attach_hash = 1) |
1059 | 1059 | { |
1060 | 1060 | |
1061 | - if($attach_hash and null !== $this->xcloner_settings->get_hash()) |
|
1061 | + if ($attach_hash and null !== $this->xcloner_settings->get_hash()) |
|
1062 | 1062 | { |
1063 | 1063 | $data['hash'] = $this->xcloner_settings->get_hash(); |
1064 | 1064 | } |
1065 | 1065 | |
1066 | - if( ob_get_length() ) |
|
1066 | + if (ob_get_length()) |
|
1067 | 1067 | ob_clean(); |
1068 | 1068 | wp_send_json($data); |
1069 | 1069 |
@@ -1,6 +1,5 @@ |
||
1 | 1 | <?php |
2 | 2 | use splitbrain\PHPArchive\Tar; |
3 | -use splitbrain\PHPArchive\Archive; |
|
4 | 3 | use splitbrain\PHPArchive\FileInfo; |
5 | 4 | |
6 | 5 | class Xcloner_Archive extends Tar |
@@ -555,15 +555,15 @@ discard block |
||
555 | 555 | return array($bytes_wrote, $last_position); |
556 | 556 | } |
557 | 557 | |
558 | - /** |
|
559 | - * Open a TAR archive and put the file cursor at the end for data appending |
|
560 | - * |
|
561 | - * If $file is empty, the tar file will be created in memory |
|
562 | - * |
|
563 | - * @param string $file |
|
564 | - * @throws ArchiveIOException |
|
565 | - */ |
|
566 | - /* |
|
558 | + /** |
|
559 | + * Open a TAR archive and put the file cursor at the end for data appending |
|
560 | + * |
|
561 | + * If $file is empty, the tar file will be created in memory |
|
562 | + * |
|
563 | + * @param string $file |
|
564 | + * @throws ArchiveIOException |
|
565 | + */ |
|
566 | + /* |
|
567 | 567 | public function openForAppend($file = '') |
568 | 568 | { |
569 | 569 | $this->file = $file; |
@@ -593,16 +593,16 @@ discard block |
||
593 | 593 | } |
594 | 594 | */ |
595 | 595 | |
596 | - /** |
|
597 | - * Append data to a file to the current TAR archive using an existing file in the filesystem |
|
598 | - * |
|
599 | - * @param string $file path to the original file |
|
600 | - * @param int $start starting reading position in file |
|
601 | - * @param int $end end position in reading multiple with 512 |
|
602 | - * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original |
|
603 | - * @throws ArchiveIOException |
|
604 | - */ |
|
605 | - /* |
|
596 | + /** |
|
597 | + * Append data to a file to the current TAR archive using an existing file in the filesystem |
|
598 | + * |
|
599 | + * @param string $file path to the original file |
|
600 | + * @param int $start starting reading position in file |
|
601 | + * @param int $end end position in reading multiple with 512 |
|
602 | + * @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original |
|
603 | + * @throws ArchiveIOException |
|
604 | + */ |
|
605 | + /* |
|
606 | 606 | * public function appendFileData($file, $fileinfo = '', $start = 0, $limit = 0) |
607 | 607 | { |
608 | 608 | $end = $start+($limit*512); |
@@ -658,14 +658,14 @@ discard block |
||
658 | 658 | return $last_position; |
659 | 659 | }*/ |
660 | 660 | |
661 | - /** |
|
662 | - * Adds a file to a TAR archive by appending it's data |
|
663 | - * |
|
664 | - * @param string $archive name of the archive file |
|
665 | - * @param string $file name of the file to read data from |
|
666 | - * @param string $start start position from where to start reading data |
|
667 | - * @throws ArchiveIOException |
|
668 | - */ |
|
661 | + /** |
|
662 | + * Adds a file to a TAR archive by appending it's data |
|
663 | + * |
|
664 | + * @param string $archive name of the archive file |
|
665 | + * @param string $file name of the file to read data from |
|
666 | + * @param string $start start position from where to start reading data |
|
667 | + * @throws ArchiveIOException |
|
668 | + */ |
|
669 | 669 | /*public function addFileToArchive($archive, $file, $start = 0) |
670 | 670 | { |
671 | 671 | $this->openForAppend($archive); |
@@ -49,6 +49,11 @@ discard block |
||
49 | 49 | * Rename backup archive |
50 | 50 | * |
51 | 51 | */ |
52 | + |
|
53 | + /** |
|
54 | + * @param string $old_name |
|
55 | + * @param string $new_name |
|
56 | + */ |
|
52 | 57 | public function rename_archive($old_name, $new_name) |
53 | 58 | { |
54 | 59 | $this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name)); |
@@ -113,6 +118,10 @@ discard block |
||
113 | 118 | * Send notification error by E-Mail |
114 | 119 | * |
115 | 120 | */ |
121 | + |
|
122 | + /** |
|
123 | + * @param string $error_message |
|
124 | + */ |
|
116 | 125 | public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
117 | 126 | { |
118 | 127 | |
@@ -137,6 +146,11 @@ discard block |
||
137 | 146 | * Send backup archive notfication by E-Mail |
138 | 147 | * |
139 | 148 | */ |
149 | + |
|
150 | + /** |
|
151 | + * @param string $from |
|
152 | + * @param string $subject |
|
153 | + */ |
|
140 | 154 | public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="", $additional = array()) |
141 | 155 | { |
142 | 156 | if(!$from) |
@@ -215,6 +229,10 @@ discard block |
||
215 | 229 | * Incremental Backup method |
216 | 230 | * |
217 | 231 | */ |
232 | + |
|
233 | + /** |
|
234 | + * @param integer $init |
|
235 | + */ |
|
218 | 236 | public function start_incremental_backup($backup_params, $extra_params, $init) |
219 | 237 | { |
220 | 238 | $return = array(); |
@@ -438,6 +456,10 @@ discard block |
||
438 | 456 | * Write multipart file components |
439 | 457 | * |
440 | 458 | */ |
459 | + |
|
460 | + /** |
|
461 | + * @param string $path |
|
462 | + */ |
|
441 | 463 | private function write_multipart_file($path) |
442 | 464 | { |
443 | 465 | $path = $this->get_archive_name_with_extension(); |
@@ -497,6 +519,10 @@ discard block |
||
497 | 519 | * Add file to archive |
498 | 520 | * |
499 | 521 | */ |
522 | + |
|
523 | + /** |
|
524 | + * @param integer $append |
|
525 | + */ |
|
500 | 526 | public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem) |
501 | 527 | { |
502 | 528 |
@@ -26,17 +26,22 @@ discard block |
||
26 | 26 | $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive"); |
27 | 27 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
28 | 28 | |
29 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) |
|
30 | - $this->file_size_per_request_limit = $value*1024*1024; //MB |
|
29 | + if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) { |
|
30 | + $this->file_size_per_request_limit = $value*1024*1024; |
|
31 | + } |
|
32 | + //MB |
|
31 | 33 | |
32 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
33 | - $this->files_to_process_per_request = $value; |
|
34 | + if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) { |
|
35 | + $this->files_to_process_per_request = $value; |
|
36 | + } |
|
34 | 37 | |
35 | - if($value = get_option('xcloner_backup_compression_level')) |
|
36 | - $this->compression_level = $value; |
|
38 | + if($value = get_option('xcloner_backup_compression_level')) { |
|
39 | + $this->compression_level = $value; |
|
40 | + } |
|
37 | 41 | |
38 | - if($value = get_option('xcloner_split_backup_limit')) |
|
39 | - $this->xcloner_split_backup_limit = $value; |
|
42 | + if($value = get_option('xcloner_split_backup_limit')) { |
|
43 | + $this->xcloner_split_backup_limit = $value; |
|
44 | + } |
|
40 | 45 | |
41 | 46 | $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes |
42 | 47 | |
@@ -73,8 +78,9 @@ discard block |
||
73 | 78 | //$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start); |
74 | 79 | $new_name = $this->archive_name; |
75 | 80 | |
76 | - if(!stristr($new_name, "-diff")) |
|
77 | - $new_name = $this->archive_name . "-diff".date("Y-m-d_H-i",$diff_timestamp_start); |
|
81 | + if(!stristr($new_name, "-diff")) { |
|
82 | + $new_name = $this->archive_name . "-diff".date("Y-m-d_H-i",$diff_timestamp_start); |
|
83 | + } |
|
78 | 84 | |
79 | 85 | $this->archive_name = $new_name; |
80 | 86 | |
@@ -83,8 +89,9 @@ discard block |
||
83 | 89 | if(isset($part) and $part) |
84 | 90 | { |
85 | 91 | $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
86 | - if(!stristr($new_name, "-part")) |
|
87 | - $new_name = $this->archive_name . "-part".$part; |
|
92 | + if(!stristr($new_name, "-part")) { |
|
93 | + $new_name = $this->archive_name . "-part".$part; |
|
94 | + } |
|
88 | 95 | |
89 | 96 | $this->archive_name = $new_name; |
90 | 97 | } |
@@ -139,8 +146,9 @@ discard block |
||
139 | 146 | |
140 | 147 | $headers = array('Content-Type: text/html; charset=UTF-8'); |
141 | 148 | |
142 | - if($admin_email and $from ) |
|
143 | - $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
|
149 | + if($admin_email and $from ) { |
|
150 | + $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
|
151 | + } |
|
144 | 152 | |
145 | 153 | $return = wp_mail( $to, $subject, $body, $headers ); |
146 | 154 | |
@@ -182,8 +190,9 @@ discard block |
||
182 | 190 | |
183 | 191 | $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
184 | 192 | |
185 | - if(!$backups_counter = sizeof($backup_parts)) |
|
186 | - $backups_counter = 1; |
|
193 | + if(!$backups_counter = sizeof($backup_parts)) { |
|
194 | + $backups_counter = 1; |
|
195 | + } |
|
187 | 196 | |
188 | 197 | $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
189 | 198 | $body .= "<br />"; |
@@ -202,8 +211,9 @@ discard block |
||
202 | 211 | $body .= "<br /><br />"; |
203 | 212 | } |
204 | 213 | |
205 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
206 | - $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
|
214 | + if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
215 | + $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
|
216 | + } |
|
207 | 217 | |
208 | 218 | $attachments = $this->filesystem->get_backup_attachments(); |
209 | 219 | |
@@ -238,18 +248,21 @@ discard block |
||
238 | 248 | { |
239 | 249 | $return = array(); |
240 | 250 | |
241 | - if(!isset($extra_params['backup_part'])) |
|
242 | - $extra_params['backup_part'] = 0; |
|
251 | + if(!isset($extra_params['backup_part'])) { |
|
252 | + $extra_params['backup_part'] = 0; |
|
253 | + } |
|
243 | 254 | |
244 | 255 | $return['extra']['backup_part'] = $extra_params['backup_part']; |
245 | 256 | |
246 | - if(isset( $extra_params['backup_archive_name'])) |
|
247 | - $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
248 | - else |
|
249 | - $this->set_archive_name($backup_params['backup_name']); |
|
257 | + if(isset( $extra_params['backup_archive_name'])) { |
|
258 | + $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
259 | + } else { |
|
260 | + $this->set_archive_name($backup_params['backup_name']); |
|
261 | + } |
|
250 | 262 | |
251 | - if(!$this->get_archive_name()) |
|
252 | - $this->set_archive_name(); |
|
263 | + if(!$this->get_archive_name()) { |
|
264 | + $this->set_archive_name(); |
|
265 | + } |
|
253 | 266 | |
254 | 267 | $this->backup_archive = new Tar(); |
255 | 268 | $this->backup_archive->setCompression($this->compression_level); |
@@ -264,7 +277,7 @@ discard block |
||
264 | 277 | |
265 | 278 | $return['extra']['backup_init'] = 1; |
266 | 279 | |
267 | - }else{ |
|
280 | + } else{ |
|
268 | 281 | $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
269 | 282 | |
270 | 283 | $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
@@ -276,11 +289,13 @@ discard block |
||
276 | 289 | $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
277 | 290 | $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
278 | 291 | |
279 | - if(!isset($extra_params['start_at_line'])) |
|
280 | - $extra_params['start_at_line'] = 0; |
|
292 | + if(!isset($extra_params['start_at_line'])) { |
|
293 | + $extra_params['start_at_line'] = 0; |
|
294 | + } |
|
281 | 295 | |
282 | - if(!isset($extra_params['start_at_byte'])) |
|
283 | - $extra_params['start_at_byte'] = 0; |
|
296 | + if(!isset($extra_params['start_at_byte'])) { |
|
297 | + $extra_params['start_at_byte'] = 0; |
|
298 | + } |
|
284 | 299 | |
285 | 300 | if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
286 | 301 | { |
@@ -302,7 +317,7 @@ discard block |
||
302 | 317 | if(!$extra_params['start_at_line']) |
303 | 318 | { |
304 | 319 | $file->seek(1); |
305 | - }else{ |
|
320 | + } else{ |
|
306 | 321 | $file->seek($extra_params['start_at_line']+1); |
307 | 322 | } |
308 | 323 | |
@@ -344,8 +359,9 @@ discard block |
||
344 | 359 | |
345 | 360 | $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
346 | 361 | |
347 | - if(!isset($file_info['size'])) |
|
348 | - $file_info['size'] = 0; |
|
362 | + if(!isset($file_info['size'])) { |
|
363 | + $file_info['size'] = 0; |
|
364 | + } |
|
349 | 365 | |
350 | 366 | if($start_filesystem == "tmp_filesystem") |
351 | 367 | { |
@@ -356,11 +372,13 @@ discard block |
||
356 | 372 | |
357 | 373 | $append = 0; |
358 | 374 | |
359 | - if($file_info['size'] > $byte_limit*512 or $start_byte) |
|
360 | - $append = 1; |
|
375 | + if($file_info['size'] > $byte_limit*512 or $start_byte) { |
|
376 | + $append = 1; |
|
377 | + } |
|
361 | 378 | |
362 | - if(!isset($return['extra']['backup_size'])) |
|
363 | - $return['extra']['backup_size'] =0; |
|
379 | + if(!isset($return['extra']['backup_size'])) { |
|
380 | + $return['extra']['backup_size'] =0; |
|
381 | + } |
|
364 | 382 | |
365 | 383 | $return['extra']['backup_size'] = $archive_info->getSize(); |
366 | 384 | |
@@ -396,8 +414,7 @@ discard block |
||
396 | 414 | |
397 | 415 | if($last_position>0){ |
398 | 416 | $start_byte = $last_position; |
399 | - } |
|
400 | - else{ |
|
417 | + } else{ |
|
401 | 418 | $extra_params['start_at_line']++; |
402 | 419 | $file->next(); |
403 | 420 | $start_byte = 0; |
@@ -434,8 +451,9 @@ discard block |
||
434 | 451 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
435 | 452 | $this->backup_archive->close(); |
436 | 453 | |
437 | - if($return['extra']['backup_part']) |
|
438 | - $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
454 | + if($return['extra']['backup_part']) { |
|
455 | + $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
456 | + } |
|
439 | 457 | |
440 | 458 | $return['extra']['start_at_line'] = $extra_params['start_at_line']-1; |
441 | 459 | |
@@ -487,12 +505,13 @@ discard block |
||
487 | 505 | $this->set_archive_name($this->get_archive_name(), ++$part); |
488 | 506 | $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
489 | 507 | |
490 | - if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
491 | - $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
508 | + if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) { |
|
509 | + $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
510 | + } |
|
492 | 511 | |
493 | 512 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
494 | 513 | |
495 | - }else |
|
514 | + } else |
|
496 | 515 | { |
497 | 516 | $this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension())); |
498 | 517 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
@@ -522,13 +541,15 @@ discard block |
||
522 | 541 | $start_adapter = $this->filesystem->get_adapter($filesystem); |
523 | 542 | $start_filesystem = $this->filesystem->get_adapter($filesystem); |
524 | 543 | |
525 | - if(!$file_info['path']) |
|
526 | - return; |
|
544 | + if(!$file_info['path']) { |
|
545 | + return; |
|
546 | + } |
|
527 | 547 | |
528 | - if(isset($file_info['archive_prefix_path'])) |
|
529 | - $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
|
530 | - else |
|
531 | - $file_info['target_path'] = $file_info['path']; |
|
548 | + if(isset($file_info['archive_prefix_path'])) { |
|
549 | + $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
|
550 | + } else { |
|
551 | + $file_info['target_path'] = $file_info['path']; |
|
552 | + } |
|
532 | 553 | |
533 | 554 | $last_position = $start_at_byte; |
534 | 555 | |
@@ -538,8 +559,7 @@ discard block |
||
538 | 559 | $bytes_wrote = $file_info['size']; |
539 | 560 | $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, $file_info['target_path'], $this->get_archive_name_with_extension())); |
540 | 561 | $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']); |
541 | - } |
|
542 | - else{ |
|
562 | + } else{ |
|
543 | 563 | $tmp_file = md5($file_info['path']); |
544 | 564 | |
545 | 565 | //we isolate file to tmp if we are at byte 0, the starting point of file reading |
@@ -548,16 +568,16 @@ discard block |
||
548 | 568 | $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file)); |
549 | 569 | $file_stream = $start_filesystem->readStream($file_info['path']); |
550 | 570 | |
551 | - if(is_resource($file_stream['stream'])) |
|
552 | - $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
571 | + if(is_resource($file_stream['stream'])) { |
|
572 | + $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
573 | + } |
|
553 | 574 | } |
554 | 575 | |
555 | 576 | if($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
556 | 577 | { |
557 | 578 | $is_tmp = 1; |
558 | 579 | $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_file), $file_info['target_path'], $start_at_byte, $byte_limit); |
559 | - } |
|
560 | - else{ |
|
580 | + } else{ |
|
561 | 581 | $is_tmp = 0; |
562 | 582 | $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit); |
563 | 583 | } |
@@ -566,8 +586,7 @@ discard block |
||
566 | 586 | if($last_position == -1) |
567 | 587 | { |
568 | 588 | $bytes_wrote = $file_info['size'] - $start_at_byte; |
569 | - } |
|
570 | - else |
|
589 | + } else |
|
571 | 590 | { |
572 | 591 | $bytes_wrote = $last_position - $start_at_byte; |
573 | 592 | } |
@@ -576,8 +595,7 @@ discard block |
||
576 | 595 | if($is_tmp) |
577 | 596 | { |
578 | 597 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name())); |
579 | - } |
|
580 | - else{ |
|
598 | + } else{ |
|
581 | 599 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name())); |
582 | 600 | } |
583 | 601 |
@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | /* |
9 | 9 | * bytes |
10 | 10 | */ |
11 | - private $file_size_per_request_limit = 52428800 ; //50MB = 52428800; 1MB = 1048576 |
|
12 | - private $files_to_process_per_request = 250; //block of 512 bytes |
|
13 | - private $compression_level = 0; //0-9 , 0 uncompressed |
|
11 | + private $file_size_per_request_limit = 52428800; //50MB = 52428800; 1MB = 1048576 |
|
12 | + private $files_to_process_per_request = 250; //block of 512 bytes |
|
13 | + private $compression_level = 0; //0-9 , 0 uncompressed |
|
14 | 14 | private $xcloner_split_backup_limit = 2048; //2048MB |
15 | - private $processed_size_bytes = 0 ; |
|
15 | + private $processed_size_bytes = 0; |
|
16 | 16 | |
17 | 17 | private $archive_name; |
18 | 18 | private $backup_archive; |
@@ -22,25 +22,25 @@ discard block |
||
22 | 22 | |
23 | 23 | public function __construct(Xcloner $xcloner_container, $archive_name = "") |
24 | 24 | { |
25 | - $this->filesystem = $xcloner_container->get_xcloner_filesystem(); |
|
26 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive"); |
|
25 | + $this->filesystem = $xcloner_container->get_xcloner_filesystem(); |
|
26 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive"); |
|
27 | 27 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
28 | 28 | |
29 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) |
|
30 | - $this->file_size_per_request_limit = $value*1024*1024; //MB |
|
29 | + if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) |
|
30 | + $this->file_size_per_request_limit = $value * 1024 * 1024; //MB |
|
31 | 31 | |
32 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
32 | + if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
33 | 33 | $this->files_to_process_per_request = $value; |
34 | 34 | |
35 | - if($value = get_option('xcloner_backup_compression_level')) |
|
35 | + if ($value = get_option('xcloner_backup_compression_level')) |
|
36 | 36 | $this->compression_level = $value; |
37 | 37 | |
38 | - if($value = get_option('xcloner_split_backup_limit')) |
|
38 | + if ($value = get_option('xcloner_split_backup_limit')) |
|
39 | 39 | $this->xcloner_split_backup_limit = $value; |
40 | 40 | |
41 | - $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes |
|
41 | + $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes |
|
42 | 42 | |
43 | - if(isset($archive_name) && $archive_name) |
|
43 | + if (isset($archive_name) && $archive_name) |
|
44 | 44 | { |
45 | 45 | $this->set_archive_name($archive_name); |
46 | 46 | } |
@@ -68,23 +68,23 @@ discard block |
||
68 | 68 | |
69 | 69 | $this->archive_name = $this->filesystem->process_backup_name($name); |
70 | 70 | |
71 | - if($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) |
|
71 | + if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) |
|
72 | 72 | { |
73 | 73 | //$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start); |
74 | 74 | $new_name = $this->archive_name; |
75 | 75 | |
76 | - if(!stristr($new_name, "-diff")) |
|
77 | - $new_name = $this->archive_name . "-diff".date("Y-m-d_H-i",$diff_timestamp_start); |
|
76 | + if (!stristr($new_name, "-diff")) |
|
77 | + $new_name = $this->archive_name."-diff".date("Y-m-d_H-i", $diff_timestamp_start); |
|
78 | 78 | |
79 | 79 | $this->archive_name = $new_name; |
80 | 80 | |
81 | 81 | } |
82 | 82 | |
83 | - if(isset($part) and $part) |
|
83 | + if (isset($part) and $part) |
|
84 | 84 | { |
85 | - $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
|
86 | - if(!stristr($new_name, "-part")) |
|
87 | - $new_name = $this->archive_name . "-part".$part; |
|
85 | + $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
|
86 | + if (!stristr($new_name, "-part")) |
|
87 | + $new_name = $this->archive_name."-part".$part; |
|
88 | 88 | |
89 | 89 | $this->archive_name = $new_name; |
90 | 90 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function get_archive_name_multipart() |
111 | 111 | { |
112 | - $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
112 | + $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
113 | 113 | return $new_name."-multipart".$this->xcloner_settings->get_backup_extension_name(".csv"); |
114 | 114 | } |
115 | 115 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $body .= sprintf(__("Backup Site Url: %s"), get_site_url()); |
136 | 136 | $body .= "<br /><>"; |
137 | 137 | |
138 | - $body .= sprintf(__("Error Message: %s"), $error_message); |
|
138 | + $body .= sprintf(__("Error Message: %s"), $error_message); |
|
139 | 139 | |
140 | 140 | $this->logger->info(sprintf("Sending backup error notification to %s", $to)); |
141 | 141 | |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | |
144 | 144 | $headers = array('Content-Type: text/html; charset=UTF-8'); |
145 | 145 | |
146 | - if($admin_email and $from ) |
|
146 | + if ($admin_email and $from) |
|
147 | 147 | $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
148 | 148 | |
149 | - $return = wp_mail( $to, $subject, $body, $headers ); |
|
149 | + $return = wp_mail($to, $subject, $body, $headers); |
|
150 | 150 | |
151 | 151 | return $return; |
152 | 152 | } |
@@ -156,29 +156,29 @@ discard block |
||
156 | 156 | * Send backup archive notfication by E-Mail |
157 | 157 | * |
158 | 158 | */ |
159 | - public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="", $additional = array()) |
|
159 | + public function send_notification($to, $from, $subject, $backup_name, $params, $error_message = "", $additional = array()) |
|
160 | 160 | { |
161 | - if(!$from) |
|
161 | + if (!$from) |
|
162 | 162 | { |
163 | 163 | $from = "XCloner Backup"; |
164 | 164 | } |
165 | 165 | |
166 | - if(($error_message)) |
|
166 | + if (($error_message)) |
|
167 | 167 | { |
168 | 168 | return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message); |
169 | 169 | } |
170 | 170 | |
171 | 171 | $params = (array)$params; |
172 | 172 | |
173 | - if(!$subject) |
|
173 | + if (!$subject) |
|
174 | 174 | { |
175 | - $subject = sprintf(__("New backup generated %s") ,$backup_name); |
|
175 | + $subject = sprintf(__("New backup generated %s"), $backup_name); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
179 | 179 | $body .= "<br /><br />"; |
180 | 180 | |
181 | - if(isset($additional['lines_total'])) |
|
181 | + if (isset($additional['lines_total'])) |
|
182 | 182 | { |
183 | 183 | $body .= sprintf(__("Total files added: %s"), $additional['lines_total']); |
184 | 184 | $body .= "<br /><br />"; |
@@ -186,30 +186,30 @@ discard block |
||
186 | 186 | |
187 | 187 | $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
188 | 188 | |
189 | - if(!$backups_counter = sizeof($backup_parts)) |
|
189 | + if (!$backups_counter = sizeof($backup_parts)) |
|
190 | 190 | $backups_counter = 1; |
191 | 191 | |
192 | 192 | $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
193 | 193 | $body .= "<br />"; |
194 | 194 | |
195 | - if(sizeof($backup_parts)) |
|
195 | + if (sizeof($backup_parts)) |
|
196 | 196 | { |
197 | - $body .= implode("<br />",$backup_parts); |
|
197 | + $body .= implode("<br />", $backup_parts); |
|
198 | 198 | $body .= "<br />"; |
199 | 199 | } |
200 | 200 | |
201 | - $body.= "<br />"; |
|
201 | + $body .= "<br />"; |
|
202 | 202 | |
203 | 203 | $body .= sprintf(__("Backup Site Url: %s"), get_site_url()); |
204 | 204 | $body .= "<br />"; |
205 | 205 | |
206 | - if(isset($params['backup_params']->backup_comments)) |
|
206 | + if (isset($params['backup_params']->backup_comments)) |
|
207 | 207 | { |
208 | 208 | $body .= __("Backup Comments: ").$params['backup_params']->backup_comments; |
209 | 209 | $body .= "<br /><br />"; |
210 | 210 | } |
211 | 211 | |
212 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
212 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
213 | 213 | $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
214 | 214 | |
215 | 215 | $attachments = $this->filesystem->get_backup_attachments(); |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $tar = new Tar(); |
220 | 220 | $tar->create($attachments_archive); |
221 | 221 | |
222 | - foreach($attachments as $key => $file) |
|
222 | + foreach ($attachments as $key => $file) |
|
223 | 223 | { |
224 | 224 | $tar->addFile($file, basename($file)); |
225 | 225 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | |
232 | 232 | $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>'); |
233 | 233 | |
234 | - $return = wp_mail( $to, $subject, $body, $headers, array($attachments_archive) ); |
|
234 | + $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive)); |
|
235 | 235 | |
236 | 236 | return $return; |
237 | 237 | } |
@@ -245,17 +245,17 @@ discard block |
||
245 | 245 | { |
246 | 246 | $return = array(); |
247 | 247 | |
248 | - if(!isset($extra_params['backup_part'])) |
|
248 | + if (!isset($extra_params['backup_part'])) |
|
249 | 249 | $extra_params['backup_part'] = 0; |
250 | 250 | |
251 | 251 | $return['extra']['backup_part'] = $extra_params['backup_part']; |
252 | 252 | |
253 | - if(isset( $extra_params['backup_archive_name'])) |
|
253 | + if (isset($extra_params['backup_archive_name'])) |
|
254 | 254 | $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
255 | 255 | else |
256 | 256 | $this->set_archive_name($backup_params['backup_name']); |
257 | 257 | |
258 | - if(!$this->get_archive_name()) |
|
258 | + if (!$this->get_archive_name()) |
|
259 | 259 | $this->set_archive_name(); |
260 | 260 | |
261 | 261 | $this->backup_archive = new Tar(); |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | |
264 | 264 | $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
265 | 265 | |
266 | - if($init) |
|
266 | + if ($init) |
|
267 | 267 | { |
268 | 268 | $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name())); |
269 | 269 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | |
272 | 272 | $return['extra']['backup_init'] = 1; |
273 | 273 | |
274 | - }else{ |
|
274 | + } else { |
|
275 | 275 | $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
276 | 276 | |
277 | 277 | $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
@@ -283,13 +283,13 @@ discard block |
||
283 | 283 | $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
284 | 284 | $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
285 | 285 | |
286 | - if(!isset($extra_params['start_at_line'])) |
|
286 | + if (!isset($extra_params['start_at_line'])) |
|
287 | 287 | $extra_params['start_at_line'] = 0; |
288 | 288 | |
289 | - if(!isset($extra_params['start_at_byte'])) |
|
289 | + if (!isset($extra_params['start_at_byte'])) |
|
290 | 290 | $extra_params['start_at_byte'] = 0; |
291 | 291 | |
292 | - if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
|
292 | + if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
|
293 | 293 | { |
294 | 294 | $this->logger->error(sprintf("Missing the includes file handler %s, aborting...", $this->filesystem->get_included_files_handler())); |
295 | 295 | |
@@ -303,14 +303,14 @@ discard block |
||
303 | 303 | |
304 | 304 | $file->seek(PHP_INT_MAX); |
305 | 305 | |
306 | - $return['extra']['lines_total'] = ($file->key()-1); |
|
306 | + $return['extra']['lines_total'] = ($file->key() - 1); |
|
307 | 307 | |
308 | 308 | //we skip the first CSV line with headers |
309 | - if(!$extra_params['start_at_line']) |
|
309 | + if (!$extra_params['start_at_line']) |
|
310 | 310 | { |
311 | 311 | $file->seek(1); |
312 | - }else{ |
|
313 | - $file->seek($extra_params['start_at_line']+1); |
|
312 | + } else { |
|
313 | + $file->seek($extra_params['start_at_line'] + 1); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | $this->processed_size_bytes = 0; |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | |
322 | 322 | $byte_limit = 0; |
323 | 323 | |
324 | - while(!$file->eof() and $counter<=$this->files_to_process_per_request) |
|
324 | + while (!$file->eof() and $counter <= $this->files_to_process_per_request) |
|
325 | 325 | { |
326 | 326 | $current_line_str = $file->current(); |
327 | 327 | |
@@ -331,15 +331,15 @@ discard block |
||
331 | 331 | |
332 | 332 | $start_filesystem = "start_filesystem"; |
333 | 333 | |
334 | - if(isset($line[4])){ |
|
334 | + if (isset($line[4])) { |
|
335 | 335 | $start_filesystem = $line[4]; |
336 | 336 | } |
337 | 337 | |
338 | 338 | //$adapter = $this->filesystem->get_adapter($start_filesystem); |
339 | 339 | |
340 | - if(!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) |
|
340 | + if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) |
|
341 | 341 | { |
342 | - if($relative_path != "") |
|
342 | + if ($relative_path != "") |
|
343 | 343 | { |
344 | 344 | $this->logger->error(sprintf("Could not add file %b to backup archive, file not found", $relative_path)); |
345 | 345 | } |
@@ -351,37 +351,37 @@ discard block |
||
351 | 351 | |
352 | 352 | $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
353 | 353 | |
354 | - if(!isset($file_info['size'])) |
|
354 | + if (!isset($file_info['size'])) |
|
355 | 355 | $file_info['size'] = 0; |
356 | 356 | |
357 | - if($start_filesystem == "tmp_filesystem") |
|
357 | + if ($start_filesystem == "tmp_filesystem") |
|
358 | 358 | { |
359 | 359 | $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
360 | 360 | } |
361 | 361 | |
362 | - $byte_limit = (int)$this->file_size_per_request_limit/512; |
|
362 | + $byte_limit = (int)$this->file_size_per_request_limit / 512; |
|
363 | 363 | |
364 | 364 | $append = 0; |
365 | 365 | |
366 | - if($file_info['size'] > $byte_limit*512 or $start_byte) |
|
366 | + if ($file_info['size'] > $byte_limit * 512 or $start_byte) |
|
367 | 367 | $append = 1; |
368 | 368 | |
369 | - if(!isset($return['extra']['backup_size'])) |
|
370 | - $return['extra']['backup_size'] =0; |
|
369 | + if (!isset($return['extra']['backup_size'])) |
|
370 | + $return['extra']['backup_size'] = 0; |
|
371 | 371 | |
372 | 372 | $return['extra']['backup_size'] = $archive_info->getSize(); |
373 | 373 | |
374 | 374 | $estimated_new_size = $return['extra']['backup_size'] + $file_info['size']; |
375 | 375 | |
376 | 376 | //we create a new backup part if we reach the Split Achive Limit |
377 | - if($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) |
|
377 | + if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) |
|
378 | 378 | { |
379 | - $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ",$this->xcloner_split_backup_limit, $estimated_new_size)); |
|
379 | + $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ", $this->xcloner_split_backup_limit, $estimated_new_size)); |
|
380 | 380 | list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']); |
381 | 381 | |
382 | - if($file_info['size'] > $this->xcloner_split_backup_limit) |
|
382 | + if ($file_info['size'] > $this->xcloner_split_backup_limit) |
|
383 | 383 | { |
384 | - $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file",$file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
384 | + $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file", $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
385 | 385 | $extra_params['start_at_line']++; |
386 | 386 | } |
387 | 387 | |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | return $return; |
394 | 394 | } |
395 | 395 | |
396 | - list($bytes_wrote, $last_position) = $this->add_file_to_archive( $file_info, $start_byte, $byte_limit, $append, $start_filesystem); |
|
396 | + list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, $append, $start_filesystem); |
|
397 | 397 | $this->processed_size_bytes += $bytes_wrote; |
398 | 398 | |
399 | 399 | //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n"; |
@@ -401,17 +401,17 @@ discard block |
||
401 | 401 | $return['extra']['processed_file_size'] = $file_info['size']; |
402 | 402 | $return['extra']['backup_size'] = $archive_info->getSize(); |
403 | 403 | |
404 | - if($last_position>0){ |
|
404 | + if ($last_position > 0) { |
|
405 | 405 | $start_byte = $last_position; |
406 | 406 | } |
407 | - else{ |
|
407 | + else { |
|
408 | 408 | $extra_params['start_at_line']++; |
409 | 409 | $file->next(); |
410 | 410 | $start_byte = 0; |
411 | 411 | $counter++; |
412 | 412 | } |
413 | 413 | |
414 | - if($this->processed_size_bytes >= $this->file_size_per_request_limit) |
|
414 | + if ($this->processed_size_bytes >= $this->file_size_per_request_limit) |
|
415 | 415 | { |
416 | 416 | clearstatcache(); |
417 | 417 | $return['extra']['backup_size'] = $archive_info->getSize(); |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - if(!$file->eof()) |
|
427 | + if (!$file->eof()) |
|
428 | 428 | { |
429 | 429 | clearstatcache(); |
430 | 430 | $return['extra']['backup_size'] = $archive_info->getSize(); |
@@ -441,12 +441,12 @@ discard block |
||
441 | 441 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
442 | 442 | $this->backup_archive->close(); |
443 | 443 | |
444 | - if($return['extra']['backup_part']) |
|
444 | + if ($return['extra']['backup_part']) |
|
445 | 445 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
446 | 446 | |
447 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']-1; |
|
447 | + $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1; |
|
448 | 448 | |
449 | - if(isset($file_info)) |
|
449 | + if (isset($file_info)) |
|
450 | 450 | { |
451 | 451 | $return['extra']['processed_file'] = $file_info['path']; |
452 | 452 | $return['extra']['processed_file_size'] = $file_info['size']; |
@@ -488,20 +488,20 @@ discard block |
||
488 | 488 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
489 | 489 | $this->backup_archive->close(); |
490 | 490 | |
491 | - if(!$part) |
|
491 | + if (!$part) |
|
492 | 492 | { |
493 | 493 | $old_name = $this->get_archive_name_with_extension(); |
494 | 494 | $this->set_archive_name($this->get_archive_name(), ++$part); |
495 | 495 | $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
496 | 496 | |
497 | - if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
497 | + if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
498 | 498 | $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
499 | 499 | |
500 | 500 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
501 | 501 | |
502 | - }else |
|
502 | + } else |
|
503 | 503 | { |
504 | - $this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension())); |
|
504 | + $this->logger->info(sprintf("Creating new multipart info file %s", $this->get_archive_name_with_extension())); |
|
505 | 505 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
506 | 506 | } |
507 | 507 | |
@@ -529,10 +529,10 @@ discard block |
||
529 | 529 | $start_adapter = $this->filesystem->get_adapter($filesystem); |
530 | 530 | $start_filesystem = $this->filesystem->get_adapter($filesystem); |
531 | 531 | |
532 | - if(!$file_info['path']) |
|
532 | + if (!$file_info['path']) |
|
533 | 533 | return; |
534 | 534 | |
535 | - if(isset($file_info['archive_prefix_path'])) |
|
535 | + if (isset($file_info['archive_prefix_path'])) |
|
536 | 536 | $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
537 | 537 | else |
538 | 538 | $file_info['target_path'] = $file_info['path']; |
@@ -541,36 +541,36 @@ discard block |
||
541 | 541 | |
542 | 542 | //$start_adapter = $this->filesystem->get_start_adapter(); |
543 | 543 | |
544 | - if(!$append){ |
|
544 | + if (!$append) { |
|
545 | 545 | $bytes_wrote = $file_info['size']; |
546 | 546 | $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, $file_info['target_path'], $this->get_archive_name_with_extension())); |
547 | 547 | $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']); |
548 | 548 | } |
549 | - else{ |
|
549 | + else { |
|
550 | 550 | $tmp_file = md5($file_info['path']); |
551 | 551 | |
552 | 552 | //we isolate file to tmp if we are at byte 0, the starting point of file reading |
553 | - if(!$start_at_byte) |
|
553 | + if (!$start_at_byte) |
|
554 | 554 | { |
555 | 555 | $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file)); |
556 | 556 | $file_stream = $start_filesystem->readStream($file_info['path']); |
557 | 557 | |
558 | - if(is_resource($file_stream['stream'])) |
|
558 | + if (is_resource($file_stream['stream'])) |
|
559 | 559 | $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
560 | 560 | } |
561 | 561 | |
562 | - if($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
|
562 | + if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
|
563 | 563 | { |
564 | 564 | $is_tmp = 1; |
565 | 565 | $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_file), $file_info['target_path'], $start_at_byte, $byte_limit); |
566 | 566 | } |
567 | - else{ |
|
567 | + else { |
|
568 | 568 | $is_tmp = 0; |
569 | 569 | $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit); |
570 | 570 | } |
571 | 571 | |
572 | 572 | |
573 | - if($last_position == -1) |
|
573 | + if ($last_position == -1) |
|
574 | 574 | { |
575 | 575 | $bytes_wrote = $file_info['size'] - $start_at_byte; |
576 | 576 | } |
@@ -580,18 +580,18 @@ discard block |
||
580 | 580 | } |
581 | 581 | |
582 | 582 | |
583 | - if($is_tmp) |
|
583 | + if ($is_tmp) |
|
584 | 584 | { |
585 | 585 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name())); |
586 | 586 | } |
587 | - else{ |
|
587 | + else { |
|
588 | 588 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name())); |
589 | 589 | } |
590 | 590 | |
591 | 591 | //we delete here the isolated tmp file |
592 | - if($last_position == -1) |
|
592 | + if ($last_position == -1) |
|
593 | 593 | { |
594 | - if($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) |
|
594 | + if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) |
|
595 | 595 | { |
596 | 596 | $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file)); |
597 | 597 | $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file); |
@@ -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)); |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
280 | 280 | } |
281 | 281 | $inc++; |
282 | - } |
|
282 | + } |
|
283 | 283 | |
284 | 284 | return $tablesList; |
285 | 285 | |
@@ -503,7 +503,7 @@ discard block |
||
503 | 503 | $buffer = ""; |
504 | 504 | $this->countRecords++; |
505 | 505 | |
506 | - foreach ($arr as $key => $value) { |
|
506 | + foreach ($arr as $key => $value) { |
|
507 | 507 | $value = $this->_real_escape($value); |
508 | 508 | $buffer .= "'".$value."', "; |
509 | 509 | } |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | $line = ("\n#\n# Table structure for table `$tableName`\n#\n\n"); |
530 | 530 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
531 | 531 | |
532 | - if ($this->dbDropSyntax) |
|
533 | - { |
|
532 | + if ($this->dbDropSyntax) |
|
533 | + { |
|
534 | 534 | $line = ("\nDROP table IF EXISTS `$tableName`;\n"); |
535 | 535 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
536 | 536 | } |
@@ -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 = "mysql_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; |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | $value = $this->_real_escape($value); |
512 | 512 | $buffer .= "'".$value."', "; |
513 | 513 | } |
514 | - $buffer = rtrim($buffer, ', ') . ");\n"; |
|
514 | + $buffer = rtrim($buffer, ', ').");\n"; |
|
515 | 515 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $buffer); |
516 | 516 | unset($buffer); |
517 | 517 | |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | |
527 | 527 | } |
528 | 528 | |
529 | - public function dump_structure($databaseName, $tableName ,$dumpfile) |
|
529 | + public function dump_structure($databaseName, $tableName, $dumpfile) |
|
530 | 530 | { |
531 | 531 | $this->log(sprintf(__("Dumping the structure for %s.%s table"), $databaseName, $tableName)); |
532 | 532 | |
@@ -541,14 +541,14 @@ discard block |
||
541 | 541 | |
542 | 542 | //$result = mysqli_query($this->dbh,"SHOW CREATE table `$databaseName`.`$tableName`;"); |
543 | 543 | $result = $this->get_row("SHOW CREATE table `$databaseName`.`$tableName`;", ARRAY_N); |
544 | - if($result){ |
|
544 | + if ($result) { |
|
545 | 545 | //$row = mysqli_fetch_row( $result); |
546 | 546 | $line = ($result[1].";\n"); |
547 | 547 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
548 | 548 | } |
549 | 549 | |
550 | - $line = ( "\n#\n# End Structure for table `$tableName`\n#\n\n"); |
|
551 | - $line .=("#\n# Dumping data for table `$tableName`\n#\n\n"); |
|
550 | + $line = ("\n#\n# End Structure for table `$tableName`\n#\n\n"); |
|
551 | + $line .= ("#\n# Dumping data for table `$tableName`\n#\n\n"); |
|
552 | 552 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
553 | 553 | |
554 | 554 | return; |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | |
572 | 572 | } |
573 | 573 | |
574 | - public function resetcountRecords(){ |
|
574 | + public function resetcountRecords() { |
|
575 | 575 | |
576 | 576 | $this->countRecords = 0; |
577 | 577 | |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | |
580 | 580 | } |
581 | 581 | |
582 | - public function getcountRecords(){ |
|
582 | + public function getcountRecords() { |
|
583 | 583 | |
584 | 584 | return $this->countRecords; |
585 | 585 | |
@@ -596,14 +596,14 @@ discard block |
||
596 | 596 | $return .= "# Powered by XCloner Site Backup\n"; |
597 | 597 | $return .= "# http://www.xcloner.com\n"; |
598 | 598 | $return .= "#\n"; |
599 | - $return .= "# Host: " . get_site_url() . "\n"; |
|
600 | - $return .= "# Generation Time: " . date("M j, Y \a\\t H:i") . "\n"; |
|
601 | - $return .= "# PHP Version: " . phpversion() . "\n"; |
|
602 | - $return .= "# Database Charset: ". $this->charset . "\n"; |
|
599 | + $return .= "# Host: ".get_site_url()."\n"; |
|
600 | + $return .= "# Generation Time: ".date("M j, Y \a\\t H:i")."\n"; |
|
601 | + $return .= "# PHP Version: ".phpversion()."\n"; |
|
602 | + $return .= "# Database Charset: ".$this->charset."\n"; |
|
603 | 603 | |
604 | 604 | $results = $this->get_results("SHOW VARIABLES LIKE \"%version%\";", ARRAY_N); |
605 | - if(isset($results)){ |
|
606 | - foreach($results as $result){ |
|
605 | + if (isset($results)) { |
|
606 | + foreach ($results as $result) { |
|
607 | 607 | |
608 | 608 | $return .= "# MYSQL ".$result[0].": ".$result[1]."\n"; |
609 | 609 | |
@@ -613,13 +613,13 @@ discard block |
||
613 | 613 | $results = $this->get_results("SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME |
614 | 614 | FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".$database."';"); |
615 | 615 | |
616 | - if(isset($results[0])){ |
|
616 | + if (isset($results[0])) { |
|
617 | 617 | |
618 | 618 | $return .= "# MYSQL DEFAULT_CHARACTER_SET_NAME: ".$results[0]->DEFAULT_CHARACTER_SET_NAME."\n"; |
619 | 619 | $return .= "# MYSQL SCHEMA_NAME: ".$results[0]->DEFAULT_COLLATION_NAME."\n"; |
620 | 620 | } |
621 | 621 | |
622 | - $return .= "#\n# Database : `" . $database . "`\n# --------------------------------------------------------\n\n"; |
|
622 | + $return .= "#\n# Database : `".$database."`\n# --------------------------------------------------------\n\n"; |
|
623 | 623 | |
624 | 624 | $this->log(sprintf(__("Writing %s database dump headers"), $database)); |
625 | 625 |
@@ -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 = "mysql_fetch_array"; |
498 | 521 | } |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | use League\Flysystem\Config; |
3 | 3 | use League\Flysystem\Filesystem; |
4 | -use League\Flysystem\Util; |
|
5 | 4 | use League\Flysystem\Adapter\Local; |
6 | 5 | |
7 | 6 | class Xcloner_File_System{ |
@@ -122,6 +122,9 @@ discard block |
||
122 | 122 | return $this->start_filesystem->normalizeFileInfo($info); |
123 | 123 | } |
124 | 124 | |
125 | + /** |
|
126 | + * @param string $file |
|
127 | + */ |
|
125 | 128 | public function get_storage_path_file_info($file) |
126 | 129 | { |
127 | 130 | return $this->getMetadataFull('storage_adapter', $file); |
@@ -188,6 +191,9 @@ discard block |
||
188 | 191 | return $total; |
189 | 192 | } |
190 | 193 | |
194 | + /** |
|
195 | + * @param string $backup_name |
|
196 | + */ |
|
191 | 197 | public function is_part($backup_name) |
192 | 198 | { |
193 | 199 | if(stristr($backup_name, "-part")) |
@@ -578,6 +584,9 @@ discard block |
||
578 | 584 | |
579 | 585 | } |
580 | 586 | |
587 | + /** |
|
588 | + * @param string $tmp_file |
|
589 | + */ |
|
581 | 590 | public function estimate_reading_time($tmp_file) |
582 | 591 | { |
583 | 592 | $this->logger->debug(sprintf(("Estimating file system reading time"))); |
@@ -616,6 +625,9 @@ discard block |
||
616 | 625 | return $name; |
617 | 626 | } |
618 | 627 | |
628 | + /** |
|
629 | + * @param string $field |
|
630 | + */ |
|
619 | 631 | public function sort_by( &$array, $field, $direction = 'asc') |
620 | 632 | { |
621 | 633 | if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
@@ -299,12 +299,12 @@ discard block |
||
299 | 299 | } |
300 | 300 | |
301 | 301 | public function getMetadataFull($adapter = "storage_adapter" , $path) |
302 | - { |
|
303 | - $location = $this->$adapter->applyPathPrefix($path); |
|
304 | - $spl_info = new SplFileInfo($location); |
|
302 | + { |
|
303 | + $location = $this->$adapter->applyPathPrefix($path); |
|
304 | + $spl_info = new SplFileInfo($location); |
|
305 | 305 | |
306 | - return ($spl_info); |
|
307 | - } |
|
306 | + return ($spl_info); |
|
307 | + } |
|
308 | 308 | |
309 | 309 | |
310 | 310 | public function get_backup_archives_list($storage_selection = "") |
@@ -697,27 +697,27 @@ discard block |
||
697 | 697 | |
698 | 698 | private function array_orderby() |
699 | 699 | { |
700 | - $args = func_get_args(); |
|
701 | - $data = array_shift($args); |
|
700 | + $args = func_get_args(); |
|
701 | + $data = array_shift($args); |
|
702 | 702 | |
703 | - foreach ($args as $n => $field) { |
|
704 | - if (is_string($field)) { |
|
705 | - $tmp = array(); |
|
706 | - foreach ($data as $key => $row) |
|
707 | - { |
|
703 | + foreach ($args as $n => $field) { |
|
704 | + if (is_string($field)) { |
|
705 | + $tmp = array(); |
|
706 | + foreach ($data as $key => $row) |
|
707 | + { |
|
708 | 708 | if(is_array($row)) |
709 | 709 | $tmp[$key] = $row[$field]; |
710 | 710 | else |
711 | 711 | $tmp[$key] = $row->$field; |
712 | 712 | } |
713 | - $args[$n] = $tmp; |
|
714 | - } |
|
715 | - } |
|
716 | - $args[] = &$data; |
|
713 | + $args[$n] = $tmp; |
|
714 | + } |
|
715 | + } |
|
716 | + $args[] = &$data; |
|
717 | 717 | |
718 | - call_user_func_array('array_multisort', $args); |
|
718 | + call_user_func_array('array_multisort', $args); |
|
719 | 719 | |
720 | - return array_pop($args); |
|
720 | + return array_pop($args); |
|
721 | 721 | } |
722 | 722 | |
723 | 723 | private function check_file_diff_time($file) |
@@ -4,19 +4,19 @@ discard block |
||
4 | 4 | use League\Flysystem\Util; |
5 | 5 | use League\Flysystem\Adapter\Local; |
6 | 6 | |
7 | -class Xcloner_File_System{ |
|
7 | +class Xcloner_File_System { |
|
8 | 8 | |
9 | - private $excluded_files = ""; |
|
9 | + private $excluded_files = ""; |
|
10 | 10 | private $additional_regex_patterns = array(); |
11 | 11 | private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
12 | - private $included_files_handler = "backup_files.csv"; |
|
13 | - private $temp_dir_handler = ".dir"; |
|
12 | + private $included_files_handler = "backup_files.csv"; |
|
13 | + private $temp_dir_handler = ".dir"; |
|
14 | 14 | public $filesystem; |
15 | 15 | public $tmp_filesystem; |
16 | 16 | public $storage_filesystem; |
17 | 17 | private $xcloner_settings_append; |
18 | 18 | private $xcloner_container; |
19 | - private $diff_timestamp_start = ""; |
|
19 | + private $diff_timestamp_start = ""; |
|
20 | 20 | |
21 | 21 | private $logger; |
22 | 22 | private $start_adapter; |
@@ -39,47 +39,47 @@ discard block |
||
39 | 39 | { |
40 | 40 | $this->xcloner_container = $xcloner_container; |
41 | 41 | |
42 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system"); |
|
42 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system"); |
|
43 | 43 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
44 | 44 | |
45 | - try{ |
|
45 | + try { |
|
46 | 46 | |
47 | - $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS'); |
|
47 | + $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
48 | 48 | $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
49 | 49 | 'disable_asserts' => true, |
50 | 50 | ])); |
51 | 51 | |
52 | - $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS'); |
|
52 | + $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
53 | 53 | $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
54 | 54 | 'disable_asserts' => true, |
55 | 55 | ])); |
56 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS'); |
|
56 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
57 | 57 | $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
58 | 58 | 'disable_asserts' => true, |
59 | 59 | ])); |
60 | 60 | |
61 | - $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS'); |
|
61 | + $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
62 | 62 | $this->storage_filesystem = new Filesystem($adapter, new Config([ |
63 | 63 | 'disable_asserts' => true, |
64 | 64 | ])); |
65 | 65 | |
66 | - $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS'); |
|
66 | + $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS'); |
|
67 | 67 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
68 | 68 | 'disable_asserts' => true, |
69 | 69 | ])); |
70 | - }catch(Exception $e){ |
|
70 | + }catch (Exception $e) { |
|
71 | 71 | $this->logger->error("Filesystem Initialization Error: ".$e->getMessage()); |
72 | 72 | } |
73 | 73 | |
74 | 74 | |
75 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
75 | + if ($value = get_option('xcloner_directories_to_scan_per_request')) |
|
76 | 76 | $this->folders_to_process_per_session = $value; |
77 | 77 | |
78 | 78 | } |
79 | 79 | |
80 | 80 | public function set_diff_timestamp_start($timestamp = "") |
81 | 81 | { |
82 | - if($timestamp) |
|
82 | + if ($timestamp) |
|
83 | 83 | { |
84 | 84 | $this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array("FILESYSTEM", "DIFF")); |
85 | 85 | $this->diff_timestamp_start = $timestamp; |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | |
115 | 115 | public function get_storage_filesystem($remote_storage_selection = "") |
116 | 116 | { |
117 | - if($remote_storage_selection != "") |
|
117 | + if ($remote_storage_selection != "") |
|
118 | 118 | { |
119 | 119 | $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
120 | 120 | $method = "get_".$remote_storage_selection."_filesystem"; |
121 | 121 | |
122 | - if(!method_exists($remote_storage, $method)) |
|
122 | + if (!method_exists($remote_storage, $method)) |
|
123 | 123 | return false; |
124 | 124 | |
125 | 125 | list($adapter, $filesystem) = $remote_storage->$method(); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | public function get_start_path_file_info($file) |
159 | 159 | { |
160 | - $info= $this->getMetadataFull('start_adapter', $file); |
|
160 | + $info = $this->getMetadataFull('start_adapter', $file); |
|
161 | 161 | return $this->start_filesystem->normalizeFileInfo($info); |
162 | 162 | } |
163 | 163 | |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | return $this->getMetadataFull('storage_adapter', $file); |
167 | 167 | } |
168 | 168 | |
169 | - public function get_included_files_handler($metadata = 0) |
|
169 | + public function get_included_files_handler($metadata = 0) |
|
170 | 170 | { |
171 | 171 | $path = $this->included_files_handler; |
172 | - if(!$metadata) |
|
172 | + if (!$metadata) |
|
173 | 173 | return $path; |
174 | 174 | |
175 | 175 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
@@ -186,16 +186,16 @@ discard block |
||
186 | 186 | { |
187 | 187 | $files = $this->get_backup_archives_list(); |
188 | 188 | |
189 | - if(is_array($files)) |
|
190 | - $this->sort_by($files, "timestamp","desc"); |
|
189 | + if (is_array($files)) |
|
190 | + $this->sort_by($files, "timestamp", "desc"); |
|
191 | 191 | |
192 | 192 | $new_list = array(); |
193 | 193 | |
194 | - foreach($files as $key=>$file) |
|
195 | - if(!isset($file['parent'])) |
|
194 | + foreach ($files as $key=>$file) |
|
195 | + if (!isset($file['parent'])) |
|
196 | 196 | $new_list[] = ($files[$key]); |
197 | 197 | |
198 | - if(isset($new_list[0])) |
|
198 | + if (isset($new_list[0])) |
|
199 | 199 | return $new_list[0]; |
200 | 200 | } |
201 | 201 | |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | { |
204 | 204 | $files = $this->get_backup_archives_list(); |
205 | 205 | |
206 | - if(is_array($files)) |
|
207 | - $this->sort_by($files, "timestamp","desc"); |
|
206 | + if (is_array($files)) |
|
207 | + $this->sort_by($files, "timestamp", "desc"); |
|
208 | 208 | |
209 | 209 | $new_list = array(); |
210 | 210 | |
211 | - foreach($files as $key=>$file) |
|
212 | - if(!isset($file['parent'])) |
|
211 | + foreach ($files as $key=>$file) |
|
212 | + if (!isset($file['parent'])) |
|
213 | 213 | $new_list[] = ($files[$key]); |
214 | 214 | |
215 | 215 | return $new_list; |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | $files = $this->get_backup_archives_list(); |
221 | 221 | $total = 0; |
222 | 222 | |
223 | - if(is_array($files)) |
|
224 | - foreach($files as $file) |
|
223 | + if (is_array($files)) |
|
224 | + foreach ($files as $file) |
|
225 | 225 | $total += $file['size']; |
226 | 226 | |
227 | 227 | return $total; |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | |
230 | 230 | public function is_part($backup_name) |
231 | 231 | { |
232 | - if(stristr($backup_name, "-part")) |
|
232 | + if (stristr($backup_name, "-part")) |
|
233 | 233 | return true; |
234 | 234 | |
235 | 235 | return false; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | |
238 | 238 | public function is_multipart($backup_name) |
239 | 239 | { |
240 | - if(stristr($backup_name, "-multipart")) |
|
240 | + if (stristr($backup_name, "-multipart")) |
|
241 | 241 | return true; |
242 | 242 | |
243 | 243 | return false; |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | public function get_backup_size($backup_name) |
247 | 247 | { |
248 | 248 | $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
249 | - if($this->is_multipart($backup_name)) |
|
249 | + if ($this->is_multipart($backup_name)) |
|
250 | 250 | { |
251 | 251 | $backup_parts = $this->get_multipart_files($backup_name); |
252 | - foreach($backup_parts as $part_file) |
|
252 | + foreach ($backup_parts as $part_file) |
|
253 | 253 | $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
254 | 254 | } |
255 | 255 | |
@@ -260,12 +260,12 @@ discard block |
||
260 | 260 | { |
261 | 261 | $files = array(); |
262 | 262 | |
263 | - if($this->is_multipart($backup_name)) |
|
263 | + if ($this->is_multipart($backup_name)) |
|
264 | 264 | { |
265 | 265 | $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
266 | - foreach($lines as $line) |
|
266 | + foreach ($lines as $line) |
|
267 | 267 | { |
268 | - if($line) |
|
268 | + if ($line) |
|
269 | 269 | { |
270 | 270 | $data = str_getcsv($line); |
271 | 271 | $files[] = $data[0]; |
@@ -278,12 +278,12 @@ discard block |
||
278 | 278 | |
279 | 279 | public function delete_backup_by_name($backup_name, $storage_selection = "") |
280 | 280 | { |
281 | - if($this->is_multipart($backup_name)) |
|
281 | + if ($this->is_multipart($backup_name)) |
|
282 | 282 | { |
283 | 283 | $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
284 | - foreach($lines as $line) |
|
284 | + foreach ($lines as $line) |
|
285 | 285 | { |
286 | - if($line) |
|
286 | + if ($line) |
|
287 | 287 | { |
288 | 288 | $data = str_getcsv($line); |
289 | 289 | $this->get_storage_filesystem($storage_selection)->delete($data[0]); |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
294 | - if($this->get_storage_filesystem($storage_selection)->delete($backup_name)) |
|
294 | + if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) |
|
295 | 295 | $return = true; |
296 | 296 | else |
297 | 297 | $return = false; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | return $return; |
300 | 300 | } |
301 | 301 | |
302 | - public function getMetadataFull($adapter = "storage_adapter" , $path) |
|
302 | + public function getMetadataFull($adapter = "storage_adapter", $path) |
|
303 | 303 | { |
304 | 304 | $location = $this->$adapter->applyPathPrefix($path); |
305 | 305 | $spl_info = new SplFileInfo($location); |
@@ -313,25 +313,25 @@ discard block |
||
313 | 313 | $list = array(); |
314 | 314 | |
315 | 315 | |
316 | - if(method_exists($this->get_storage_filesystem($storage_selection), "listContents")) |
|
316 | + if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) |
|
317 | 317 | $list = $this->get_storage_filesystem($storage_selection)->listContents(); |
318 | 318 | |
319 | 319 | |
320 | 320 | $backup_files = array(); |
321 | 321 | $parents = array(); |
322 | 322 | |
323 | - foreach($list as $file_info) |
|
323 | + foreach ($list as $file_info) |
|
324 | 324 | { |
325 | - if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
325 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
326 | 326 | { |
327 | 327 | $data = array(); |
328 | 328 | |
329 | 329 | $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path'])); |
330 | - foreach($lines as $line) |
|
331 | - if($line) |
|
330 | + foreach ($lines as $line) |
|
331 | + if ($line) |
|
332 | 332 | { |
333 | 333 | $data = str_getcsv($line); |
334 | - if(is_array($data)){ |
|
334 | + if (is_array($data)) { |
|
335 | 335 | $parents[$data[0]] = $file_info['basename']; |
336 | 336 | $file_info['childs'][] = $data; |
337 | 337 | $file_info['size'] += $data[2]; |
@@ -340,18 +340,18 @@ discard block |
||
340 | 340 | |
341 | 341 | } |
342 | 342 | |
343 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
343 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
344 | 344 | $backup_files[$file_info['path']] = $file_info; |
345 | 345 | } |
346 | 346 | |
347 | - foreach($backup_files as $key=>$file_info) |
|
347 | + foreach ($backup_files as $key=>$file_info) |
|
348 | 348 | { |
349 | - if(!isset($backup_files[$key]['timestamp'])) |
|
349 | + if (!isset($backup_files[$key]['timestamp'])) |
|
350 | 350 | { |
351 | 351 | //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']); |
352 | 352 | } |
353 | 353 | |
354 | - if(isset($parents[$file_info['basename']])) |
|
354 | + if (isset($parents[$file_info['basename']])) |
|
355 | 355 | $backup_files[$key]['parent'] = $parents[$file_info['basename']]; |
356 | 356 | } |
357 | 357 | |
@@ -360,40 +360,40 @@ discard block |
||
360 | 360 | |
361 | 361 | public function start_file_recursion($init = 0) |
362 | 362 | { |
363 | - if($init) |
|
363 | + if ($init) |
|
364 | 364 | { |
365 | 365 | $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path())); |
366 | 366 | $this->do_system_init(); |
367 | 367 | } |
368 | 368 | |
369 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())){ |
|
369 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
370 | 370 | //.dir exists, we presume we have files to iterate |
371 | 371 | $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
372 | 372 | $files = array_filter(explode("\n", $content)); |
373 | 373 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
374 | 374 | |
375 | 375 | $counter = 0; |
376 | - foreach($files as $file) |
|
376 | + foreach ($files as $file) |
|
377 | 377 | { |
378 | - if($counter < $this->folders_to_process_per_session){ |
|
378 | + if ($counter < $this->folders_to_process_per_session) { |
|
379 | 379 | $this->build_files_list($file); |
380 | 380 | $counter++; |
381 | - }else{ |
|
381 | + } else { |
|
382 | 382 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
383 | 383 | } |
384 | 384 | } |
385 | - }else{ |
|
385 | + } else { |
|
386 | 386 | $this->build_files_list(); |
387 | 387 | } |
388 | 388 | |
389 | - if($this->scan_finished()) |
|
389 | + if ($this->scan_finished()) |
|
390 | 390 | { |
391 | 391 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
392 | 392 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
393 | 393 | $this->files_counter++; |
394 | 394 | |
395 | 395 | //adding included dump file to the included files list |
396 | - if($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
396 | + if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
397 | 397 | { |
398 | 398 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
399 | 399 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -401,13 +401,13 @@ discard block |
||
401 | 401 | } |
402 | 402 | |
403 | 403 | //adding a default index.html to the temp xcloner folder |
404 | - if(!$this->get_tmp_filesystem()->has("index.html")) |
|
404 | + if (!$this->get_tmp_filesystem()->has("index.html")) |
|
405 | 405 | { |
406 | - $this->get_tmp_filesystem()->write("index.html",""); |
|
406 | + $this->get_tmp_filesystem()->write("index.html", ""); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | //adding the default log file |
410 | - if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
410 | + if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
411 | 411 | { |
412 | 412 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
413 | 413 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -425,20 +425,20 @@ discard block |
||
425 | 425 | $return = array(); |
426 | 426 | |
427 | 427 | $files_list_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
428 | - if(file_exists($files_list_file)) |
|
428 | + if (file_exists($files_list_file)) |
|
429 | 429 | { |
430 | 430 | $return[] = $files_list_file; |
431 | 431 | } |
432 | 432 | |
433 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
433 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
434 | 434 | { |
435 | 435 | $log_file = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
436 | - if(!file_exists($log_file)) |
|
436 | + if (!file_exists($log_file)) |
|
437 | 437 | { |
438 | 438 | $log_file = $this->xcloner_settings->get_xcloner_store_path().DS.$this->xcloner_settings->get_logger_filename(); |
439 | 439 | } |
440 | 440 | |
441 | - if(file_exists($log_file)) |
|
441 | + if (file_exists($log_file)) |
|
442 | 442 | { |
443 | 443 | $return[] = $log_file; |
444 | 444 | } |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | |
455 | 455 | $contents = $this->get_tmp_filesystem()->listContents(); |
456 | 456 | |
457 | - if(is_array($contents)) |
|
458 | - foreach($contents as $file_info) |
|
457 | + if (is_array($contents)) |
|
458 | + foreach ($contents as $file_info) |
|
459 | 459 | $this->get_tmp_filesystem()->delete($file_info['path']); |
460 | 460 | |
461 | 461 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
@@ -465,16 +465,16 @@ discard block |
||
465 | 465 | |
466 | 466 | public function cleanup_tmp_directories() |
467 | 467 | { |
468 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false),LOCK_EX|FILE_APPEND, 'SKIP_LINKS'); |
|
468 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
469 | 469 | $tmp_filesystem = new Filesystem($adapter, new Config([ |
470 | 470 | 'disable_asserts' => true, |
471 | 471 | ])); |
472 | 472 | |
473 | 473 | $contents = $tmp_filesystem->listContents(); |
474 | 474 | |
475 | - foreach($contents as $file) |
|
475 | + foreach ($contents as $file) |
|
476 | 476 | { |
477 | - if(preg_match("/.xcloner-(.*)/",$file['path'])) |
|
477 | + if (preg_match("/.xcloner-(.*)/", $file['path'])) |
|
478 | 478 | { |
479 | 479 | $tmp_filesystem->deleteDir($file['path']); |
480 | 480 | $this->logger->info(sprintf("Delete temporary directory %s", $file['path'])); |
@@ -488,16 +488,16 @@ discard block |
||
488 | 488 | { |
489 | 489 | $this->files_counter = 0; |
490 | 490 | |
491 | - if(!$this->storage_filesystem->has("index.html")) |
|
492 | - $this->storage_filesystem->write("index.html",""); |
|
491 | + if (!$this->storage_filesystem->has("index.html")) |
|
492 | + $this->storage_filesystem->write("index.html", ""); |
|
493 | 493 | |
494 | - if(!$this->tmp_filesystem->has("index.html")) |
|
495 | - $this->tmp_filesystem->write("index.html",""); |
|
494 | + if (!$this->tmp_filesystem->has("index.html")) |
|
495 | + $this->tmp_filesystem->write("index.html", ""); |
|
496 | 496 | |
497 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
497 | + if ($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
498 | 498 | $this->tmp_filesystem->delete($this->get_included_files_handler()); |
499 | 499 | |
500 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
500 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
501 | 501 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
502 | 502 | } |
503 | 503 | |
@@ -517,20 +517,20 @@ discard block |
||
517 | 517 | } |
518 | 518 | |
519 | 519 | public static function is_regex($regex) { |
520 | - return preg_match("/^\^(.*)\$$/i",$regex); |
|
520 | + return preg_match("/^\^(.*)\$$/i", $regex); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | public function set_excluded_files($excluded_files = array()) |
524 | 524 | { |
525 | - if(!is_array($excluded_files)) |
|
525 | + if (!is_array($excluded_files)) |
|
526 | 526 | { |
527 | 527 | $excluded_files = array(); |
528 | 528 | } |
529 | 529 | |
530 | - foreach($excluded_files as $excl) |
|
530 | + foreach ($excluded_files as $excl) |
|
531 | 531 | { |
532 | 532 | |
533 | - if($this->is_regex($excl)) |
|
533 | + if ($this->is_regex($excl)) |
|
534 | 534 | { |
535 | 535 | $this->additional_regex_patterns[] = $excl; |
536 | 536 | } |
@@ -556,35 +556,35 @@ discard block |
||
556 | 556 | $this->logger->debug(sprintf(("Building the files system list"))); |
557 | 557 | |
558 | 558 | //if we start with the root folder(empty value), we initializa the file system |
559 | - if(!$folder){ |
|
559 | + if (!$folder) { |
|
560 | 560 | |
561 | 561 | } |
562 | 562 | |
563 | - try{ |
|
563 | + try { |
|
564 | 564 | |
565 | 565 | $files = $this->start_filesystem->listContents($folder); |
566 | - foreach($files as $file) |
|
566 | + foreach ($files as $file) |
|
567 | 567 | { |
568 | - if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
568 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
569 | 569 | { |
570 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
|
570 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE")); |
|
571 | 571 | } |
572 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
573 | - $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
|
572 | + elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
573 | + $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE")); |
|
574 | 574 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
575 | - if($this->store_file($file)) |
|
575 | + if ($this->store_file($file)) |
|
576 | 576 | { |
577 | 577 | $this->files_counter++; |
578 | 578 | } |
579 | - if(isset($file['size'])) |
|
579 | + if (isset($file['size'])) |
|
580 | 580 | $this->files_size += $file['size']; |
581 | 581 | |
582 | - }else{ |
|
583 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
|
582 | + } else { |
|
583 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE")); |
|
584 | 584 | } |
585 | 585 | } |
586 | 586 | |
587 | - }catch(Exception $e){ |
|
587 | + }catch (Exception $e) { |
|
588 | 588 | |
589 | 589 | $this->logger->error($e->getMessage()); |
590 | 590 | |
@@ -598,9 +598,9 @@ discard block |
||
598 | 598 | |
599 | 599 | $start_time = microtime(); |
600 | 600 | |
601 | - $data = str_repeat(rand(0,9), 1024*1024); //write 1MB data |
|
601 | + $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
602 | 602 | |
603 | - try{ |
|
603 | + try { |
|
604 | 604 | $this->tmp_filesystem->write($tmp_file, $data); |
605 | 605 | |
606 | 606 | $end_time = microtime() - $start_time; |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | |
612 | 612 | $this->tmp_filesystem->delete($tmp_file); |
613 | 613 | |
614 | - }catch(Exception $e){ |
|
614 | + }catch (Exception $e) { |
|
615 | 615 | |
616 | 616 | $this->logger->error($e->getMessage()); |
617 | 617 | |
@@ -632,10 +632,10 @@ discard block |
||
632 | 632 | |
633 | 633 | $files = $this->storage_filesystem->listContents(); |
634 | 634 | |
635 | - if(is_array($files)) |
|
636 | - foreach($files as $file) |
|
635 | + if (is_array($files)) |
|
636 | + foreach ($files as $file) |
|
637 | 637 | { |
638 | - if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
638 | + if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
639 | 639 | { |
640 | 640 | $_storage_size += $file['size']; //bytes |
641 | 641 | $_backup_files_list[] = $file; |
@@ -643,15 +643,15 @@ discard block |
||
643 | 643 | } |
644 | 644 | |
645 | 645 | |
646 | - $this->sort_by($_backup_files_list, "timestamp","asc"); |
|
646 | + $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
647 | 647 | |
648 | 648 | $_backups_counter = sizeof($_backup_files_list); |
649 | 649 | |
650 | - foreach($_backup_files_list as $file) |
|
650 | + foreach ($_backup_files_list as $file) |
|
651 | 651 | { |
652 | 652 | //processing rule folder capacity |
653 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
654 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
653 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
654 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
655 | 655 | { |
656 | 656 | $this->storage_filesystem->delete($file['path']); |
657 | 657 | $_storage_size -= $file['size']; |
@@ -659,14 +659,14 @@ discard block |
||
659 | 659 | } |
660 | 660 | |
661 | 661 | //processing rule days limit |
662 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
662 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
663 | 663 | { |
664 | 664 | $this->storage_filesystem->delete($file['path']); |
665 | 665 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array("RETENTION LIMIT TIMESTAMP", $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days'))); |
666 | 666 | } |
667 | 667 | |
668 | 668 | //processing backup countert limit |
669 | - 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')) |
|
669 | + 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')) |
|
670 | 670 | { |
671 | 671 | $this->storage_filesystem->delete($file['path']); |
672 | 672 | $_backups_counter--; |
@@ -692,33 +692,33 @@ discard block |
||
692 | 692 | |
693 | 693 | } |
694 | 694 | |
695 | - public function process_backup_name($name = "", $max_length=100) |
|
695 | + public function process_backup_name($name = "", $max_length = 100) |
|
696 | 696 | { |
697 | - if(!$name) |
|
697 | + if (!$name) |
|
698 | 698 | $name = $this->xcloner_settings->get_default_backup_name(); |
699 | 699 | |
700 | - foreach($this->backup_name_tags as $tag) |
|
700 | + foreach ($this->backup_name_tags as $tag) |
|
701 | 701 | { |
702 | - if($tag == '[time]') |
|
703 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
704 | - elseif($tag == '[hostname]') |
|
705 | - $name = str_replace($tag, gethostname() ,$name); |
|
706 | - elseif($tag == '[domain]') |
|
702 | + if ($tag == '[time]') |
|
703 | + $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
704 | + elseif ($tag == '[hostname]') |
|
705 | + $name = str_replace($tag, gethostname(), $name); |
|
706 | + elseif ($tag == '[domain]') |
|
707 | 707 | { |
708 | 708 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
709 | - $name = str_replace($tag, $domain ,$name); |
|
709 | + $name = str_replace($tag, $domain, $name); |
|
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
713 | - if($max_length) |
|
713 | + if ($max_length) |
|
714 | 714 | $name = substr($name, 0, $max_length); |
715 | 715 | |
716 | 716 | return $name; |
717 | 717 | } |
718 | 718 | |
719 | - public function sort_by( &$array, $field, $direction = 'asc') |
|
719 | + public function sort_by(&$array, $field, $direction = 'asc') |
|
720 | 720 | { |
721 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
721 | + if (strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
722 | 722 | $direction = SORT_DESC; |
723 | 723 | else |
724 | 724 | $direction = SORT_ASC; |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | $tmp = array(); |
739 | 739 | foreach ($data as $key => $row) |
740 | 740 | { |
741 | - if(is_array($row)) |
|
741 | + if (is_array($row)) |
|
742 | 742 | $tmp[$key] = $row[$field]; |
743 | 743 | else |
744 | 744 | $tmp[$key] = $row->$field; |
@@ -755,18 +755,18 @@ discard block |
||
755 | 755 | |
756 | 756 | private function check_file_diff_time($file) |
757 | 757 | { |
758 | - if($this->get_diff_timestamp_start() != "") |
|
758 | + if ($this->get_diff_timestamp_start() != "") |
|
759 | 759 | { |
760 | 760 | $fileMeta = $this->getMetadataFull("start_adapter", $file['path']); |
761 | 761 | $timestamp = $fileMeta->getMTime(); |
762 | - if($timestamp < $fileMeta->getCTime()) |
|
762 | + if ($timestamp < $fileMeta->getCTime()) |
|
763 | 763 | { |
764 | 764 | $timestamp = $fileMeta->getCTime(); |
765 | 765 | } |
766 | 766 | |
767 | - if($timestamp <= $this->get_diff_timestamp_start()) |
|
767 | + if ($timestamp <= $this->get_diff_timestamp_start()) |
|
768 | 768 | { |
769 | - return " file DIFF timestamp ".$timestamp." < ". $this->diff_timestamp_start; |
|
769 | + return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start; |
|
770 | 770 | } |
771 | 771 | } |
772 | 772 | |
@@ -777,37 +777,37 @@ discard block |
||
777 | 777 | { |
778 | 778 | $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
779 | 779 | |
780 | - if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
780 | + if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
781 | 781 | { |
782 | - if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
782 | + if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
783 | 783 | return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
784 | 784 | } |
785 | 785 | |
786 | - if(!sizeof($this->excluded_files)) |
|
786 | + if (!sizeof($this->excluded_files)) |
|
787 | 787 | { |
788 | 788 | $this->set_excluded_files(); |
789 | 789 | } |
790 | 790 | |
791 | - if(is_array($this->excluded_files)) |
|
792 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
791 | + if (is_array($this->excluded_files)) |
|
792 | + foreach ($this->excluded_files as $excluded_file_pattern) |
|
793 | 793 | { |
794 | - if($excluded_file_pattern == "/") |
|
794 | + if ($excluded_file_pattern == "/") |
|
795 | 795 | $needle = "$"; |
796 | 796 | else |
797 | 797 | $needle = "$".$excluded_file_pattern; |
798 | 798 | |
799 | - if(strstr("$".$file['path'], $needle)){ |
|
799 | + if (strstr("$".$file['path'], $needle)) { |
|
800 | 800 | return $excluded_file_pattern; |
801 | 801 | } |
802 | 802 | } |
803 | 803 | |
804 | - if( $regex = $this->is_excluded_regex($file)) |
|
804 | + if ($regex = $this->is_excluded_regex($file)) |
|
805 | 805 | return $regex; |
806 | 806 | |
807 | - if($file['type'] == "file") |
|
807 | + if ($file['type'] == "file") |
|
808 | 808 | { |
809 | 809 | $check_file_diff_timestamp = $this->check_file_diff_time($file); |
810 | - if($check_file_diff_timestamp) |
|
810 | + if ($check_file_diff_timestamp) |
|
811 | 811 | { |
812 | 812 | return $check_file_diff_timestamp; |
813 | 813 | } |
@@ -854,32 +854,32 @@ discard block |
||
854 | 854 | |
855 | 855 | $regex_patterns = explode(PHP_EOL, $this->xcloner_settings->get_xcloner_option('xcloner_regex_exclude')); |
856 | 856 | |
857 | - if(is_array($this->additional_regex_patterns)) |
|
857 | + if (is_array($this->additional_regex_patterns)) |
|
858 | 858 | { |
859 | 859 | $regex_patterns = array_merge($regex_patterns, $this->additional_regex_patterns); |
860 | 860 | } |
861 | 861 | |
862 | 862 | //print_r($regex_patterns);exit; |
863 | 863 | |
864 | - if(is_array($regex_patterns)) |
|
864 | + if (is_array($regex_patterns)) |
|
865 | 865 | { |
866 | 866 | //$this->excluded_files = array(); |
867 | 867 | //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
868 | 868 | //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
869 | 869 | |
870 | - foreach($regex_patterns as $excluded_file_pattern) |
|
870 | + foreach ($regex_patterns as $excluded_file_pattern) |
|
871 | 871 | { |
872 | 872 | |
873 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
874 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
873 | + if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r") |
|
874 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
875 | 875 | |
876 | - if($file['path'] == "/") |
|
876 | + if ($file['path'] == "/") |
|
877 | 877 | $needle = "/"; |
878 | 878 | else |
879 | 879 | $needle = "/".$file['path']; |
880 | 880 | //echo $needle."---".$excluded_file_pattern."---\n"; |
881 | 881 | |
882 | - if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
|
882 | + if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { |
|
883 | 883 | return $excluded_file_pattern; |
884 | 884 | } |
885 | 885 | } |
@@ -892,36 +892,36 @@ discard block |
||
892 | 892 | { |
893 | 893 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
894 | 894 | |
895 | - if(!isset($file['size'])) |
|
895 | + if (!isset($file['size'])) |
|
896 | 896 | $file['size'] = 0; |
897 | - if(!isset($file['visibility'])) |
|
897 | + if (!isset($file['visibility'])) |
|
898 | 898 | $file['visibility'] = "private"; |
899 | 899 | |
900 | - $csv_filename = str_replace('"','""', $file['path']); |
|
900 | + $csv_filename = str_replace('"', '""', $file['path']); |
|
901 | 901 | |
902 | 902 | $line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
903 | 903 | |
904 | 904 | $this->last_logged_file = $file['path']; |
905 | 905 | |
906 | - if($file['type'] == "dir"){ |
|
907 | - try{ |
|
906 | + if ($file['type'] == "dir") { |
|
907 | + try { |
|
908 | 908 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
909 | - }catch(Exception $e){ |
|
909 | + }catch (Exception $e) { |
|
910 | 910 | $this->logger->error($e->getMessage()); |
911 | 911 | } |
912 | 912 | } |
913 | 913 | |
914 | - if($this->get_diff_timestamp_start()) |
|
914 | + if ($this->get_diff_timestamp_start()) |
|
915 | 915 | { |
916 | - if($file['type'] != "file" && $response = $this->check_file_diff_time($file)) |
|
916 | + if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) |
|
917 | 917 | { |
918 | - $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], $response), array("FILESYSTEM SCAN","DIR DIFF")); |
|
918 | + $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], $response), array("FILESYSTEM SCAN", "DIR DIFF")); |
|
919 | 919 | return false; |
920 | 920 | } |
921 | 921 | } |
922 | 922 | |
923 | - try{ |
|
924 | - if(!$this->tmp_filesystem_append->has($this->get_included_files_handler())) |
|
923 | + try { |
|
924 | + if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) |
|
925 | 925 | { |
926 | 926 | //adding fix for UTF-8 CSV preview |
927 | 927 | $start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL; |
@@ -930,7 +930,7 @@ discard block |
||
930 | 930 | |
931 | 931 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
932 | 932 | |
933 | - }catch(Exception $e){ |
|
933 | + }catch (Exception $e) { |
|
934 | 934 | |
935 | 935 | $this->logger->error($e->getMessage()); |
936 | 936 | } |
@@ -945,13 +945,13 @@ discard block |
||
945 | 945 | |
946 | 946 | public function get_filesystem($system = "") |
947 | 947 | { |
948 | - if($system == "storage_filesystem_append") |
|
948 | + if ($system == "storage_filesystem_append") |
|
949 | 949 | return $this->storage_filesystem_append; |
950 | - elseif($system == "tmp_filesystem_append") |
|
950 | + elseif ($system == "tmp_filesystem_append") |
|
951 | 951 | return $this->tmp_filesystem_append; |
952 | - elseif($system == "tmp_filesystem") |
|
952 | + elseif ($system == "tmp_filesystem") |
|
953 | 953 | return $this->tmp_filesystem; |
954 | - elseif($system == "storage_filesystem") |
|
954 | + elseif ($system == "storage_filesystem") |
|
955 | 955 | return $this->storage_filesystem; |
956 | 956 | else |
957 | 957 | return $this->start_filesystem; |
@@ -959,9 +959,9 @@ discard block |
||
959 | 959 | |
960 | 960 | public function get_adapter($system) |
961 | 961 | { |
962 | - if($system == "tmp_filesystem") |
|
962 | + if ($system == "tmp_filesystem") |
|
963 | 963 | return $this->tmp_adapter; |
964 | - elseif($system == "storage_filesystem") |
|
964 | + elseif ($system == "storage_filesystem") |
|
965 | 965 | return $this->storage_adapter; |
966 | 966 | else |
967 | 967 | return $this->start_adapter; |
@@ -969,10 +969,10 @@ discard block |
||
969 | 969 | |
970 | 970 | private function scan_finished() |
971 | 971 | { |
972 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
972 | + if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
973 | 973 | return false; |
974 | 974 | |
975 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
975 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
976 | 976 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
977 | 977 | |
978 | 978 | $this->logger->debug(sprintf(("File scan finished"))); |
@@ -982,7 +982,7 @@ discard block |
||
982 | 982 | |
983 | 983 | private function calc_to_bytes($mb_size) |
984 | 984 | { |
985 | - return $mb_size*(1024*1024); |
|
985 | + return $mb_size * (1024 * 1024); |
|
986 | 986 | } |
987 | 987 | |
988 | 988 | } |
@@ -67,13 +67,14 @@ discard block |
||
67 | 67 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
68 | 68 | 'disable_asserts' => true, |
69 | 69 | ])); |
70 | - }catch(Exception $e){ |
|
70 | + } catch(Exception $e){ |
|
71 | 71 | $this->logger->error("Filesystem Initialization Error: ".$e->getMessage()); |
72 | 72 | } |
73 | 73 | |
74 | 74 | |
75 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
76 | - $this->folders_to_process_per_session = $value; |
|
75 | + if($value = get_option('xcloner_directories_to_scan_per_request')) { |
|
76 | + $this->folders_to_process_per_session = $value; |
|
77 | + } |
|
77 | 78 | |
78 | 79 | } |
79 | 80 | |
@@ -119,8 +120,9 @@ discard block |
||
119 | 120 | $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
120 | 121 | $method = "get_".$remote_storage_selection."_filesystem"; |
121 | 122 | |
122 | - if(!method_exists($remote_storage, $method)) |
|
123 | - return false; |
|
123 | + if(!method_exists($remote_storage, $method)) { |
|
124 | + return false; |
|
125 | + } |
|
124 | 126 | |
125 | 127 | list($adapter, $filesystem) = $remote_storage->$method(); |
126 | 128 | |
@@ -169,8 +171,9 @@ discard block |
||
169 | 171 | public function get_included_files_handler($metadata = 0) |
170 | 172 | { |
171 | 173 | $path = $this->included_files_handler; |
172 | - if(!$metadata) |
|
173 | - return $path; |
|
174 | + if(!$metadata) { |
|
175 | + return $path; |
|
176 | + } |
|
174 | 177 | |
175 | 178 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
176 | 179 | return $spl_info; |
@@ -186,31 +189,36 @@ discard block |
||
186 | 189 | { |
187 | 190 | $files = $this->get_backup_archives_list(); |
188 | 191 | |
189 | - if(is_array($files)) |
|
190 | - $this->sort_by($files, "timestamp","desc"); |
|
192 | + if(is_array($files)) { |
|
193 | + $this->sort_by($files, "timestamp","desc"); |
|
194 | + } |
|
191 | 195 | |
192 | 196 | $new_list = array(); |
193 | 197 | |
194 | - foreach($files as $key=>$file) |
|
195 | - if(!isset($file['parent'])) |
|
198 | + foreach($files as $key=>$file) { |
|
199 | + if(!isset($file['parent'])) |
|
196 | 200 | $new_list[] = ($files[$key]); |
201 | + } |
|
197 | 202 | |
198 | - if(isset($new_list[0])) |
|
199 | - return $new_list[0]; |
|
203 | + if(isset($new_list[0])) { |
|
204 | + return $new_list[0]; |
|
205 | + } |
|
200 | 206 | } |
201 | 207 | |
202 | 208 | public function get_latest_backups() |
203 | 209 | { |
204 | 210 | $files = $this->get_backup_archives_list(); |
205 | 211 | |
206 | - if(is_array($files)) |
|
207 | - $this->sort_by($files, "timestamp","desc"); |
|
212 | + if(is_array($files)) { |
|
213 | + $this->sort_by($files, "timestamp","desc"); |
|
214 | + } |
|
208 | 215 | |
209 | 216 | $new_list = array(); |
210 | 217 | |
211 | - foreach($files as $key=>$file) |
|
212 | - if(!isset($file['parent'])) |
|
218 | + foreach($files as $key=>$file) { |
|
219 | + if(!isset($file['parent'])) |
|
213 | 220 | $new_list[] = ($files[$key]); |
221 | + } |
|
214 | 222 | |
215 | 223 | return $new_list; |
216 | 224 | } |
@@ -220,25 +228,28 @@ discard block |
||
220 | 228 | $files = $this->get_backup_archives_list(); |
221 | 229 | $total = 0; |
222 | 230 | |
223 | - if(is_array($files)) |
|
224 | - foreach($files as $file) |
|
231 | + if(is_array($files)) { |
|
232 | + foreach($files as $file) |
|
225 | 233 | $total += $file['size']; |
234 | + } |
|
226 | 235 | |
227 | 236 | return $total; |
228 | 237 | } |
229 | 238 | |
230 | 239 | public function is_part($backup_name) |
231 | 240 | { |
232 | - if(stristr($backup_name, "-part")) |
|
233 | - return true; |
|
241 | + if(stristr($backup_name, "-part")) { |
|
242 | + return true; |
|
243 | + } |
|
234 | 244 | |
235 | 245 | return false; |
236 | 246 | } |
237 | 247 | |
238 | 248 | public function is_multipart($backup_name) |
239 | 249 | { |
240 | - if(stristr($backup_name, "-multipart")) |
|
241 | - return true; |
|
250 | + if(stristr($backup_name, "-multipart")) { |
|
251 | + return true; |
|
252 | + } |
|
242 | 253 | |
243 | 254 | return false; |
244 | 255 | } |
@@ -249,8 +260,9 @@ discard block |
||
249 | 260 | if($this->is_multipart($backup_name)) |
250 | 261 | { |
251 | 262 | $backup_parts = $this->get_multipart_files($backup_name); |
252 | - foreach($backup_parts as $part_file) |
|
253 | - $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
263 | + foreach($backup_parts as $part_file) { |
|
264 | + $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
265 | + } |
|
254 | 266 | } |
255 | 267 | |
256 | 268 | return $backup_size; |
@@ -291,10 +303,11 @@ discard block |
||
291 | 303 | } |
292 | 304 | } |
293 | 305 | |
294 | - if($this->get_storage_filesystem($storage_selection)->delete($backup_name)) |
|
295 | - $return = true; |
|
296 | - else |
|
297 | - $return = false; |
|
306 | + if($this->get_storage_filesystem($storage_selection)->delete($backup_name)) { |
|
307 | + $return = true; |
|
308 | + } else { |
|
309 | + $return = false; |
|
310 | + } |
|
298 | 311 | |
299 | 312 | return $return; |
300 | 313 | } |
@@ -313,8 +326,9 @@ discard block |
||
313 | 326 | $list = array(); |
314 | 327 | |
315 | 328 | |
316 | - if(method_exists($this->get_storage_filesystem($storage_selection), "listContents")) |
|
317 | - $list = $this->get_storage_filesystem($storage_selection)->listContents(); |
|
329 | + if(method_exists($this->get_storage_filesystem($storage_selection), "listContents")) { |
|
330 | + $list = $this->get_storage_filesystem($storage_selection)->listContents(); |
|
331 | + } |
|
318 | 332 | |
319 | 333 | |
320 | 334 | $backup_files = array(); |
@@ -327,10 +341,11 @@ discard block |
||
327 | 341 | $data = array(); |
328 | 342 | |
329 | 343 | $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path'])); |
330 | - foreach($lines as $line) |
|
331 | - if($line) |
|
344 | + foreach($lines as $line) { |
|
345 | + if($line) |
|
332 | 346 | { |
333 | 347 | $data = str_getcsv($line); |
348 | + } |
|
334 | 349 | if(is_array($data)){ |
335 | 350 | $parents[$data[0]] = $file_info['basename']; |
336 | 351 | $file_info['childs'][] = $data; |
@@ -340,8 +355,9 @@ discard block |
||
340 | 355 | |
341 | 356 | } |
342 | 357 | |
343 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
344 | - $backup_files[$file_info['path']] = $file_info; |
|
358 | + if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
359 | + $backup_files[$file_info['path']] = $file_info; |
|
360 | + } |
|
345 | 361 | } |
346 | 362 | |
347 | 363 | foreach($backup_files as $key=>$file_info) |
@@ -351,8 +367,9 @@ discard block |
||
351 | 367 | //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']); |
352 | 368 | } |
353 | 369 | |
354 | - if(isset($parents[$file_info['basename']])) |
|
355 | - $backup_files[$key]['parent'] = $parents[$file_info['basename']]; |
|
370 | + if(isset($parents[$file_info['basename']])) { |
|
371 | + $backup_files[$key]['parent'] = $parents[$file_info['basename']]; |
|
372 | + } |
|
356 | 373 | } |
357 | 374 | |
358 | 375 | return $backup_files; |
@@ -378,11 +395,11 @@ discard block |
||
378 | 395 | if($counter < $this->folders_to_process_per_session){ |
379 | 396 | $this->build_files_list($file); |
380 | 397 | $counter++; |
381 | - }else{ |
|
398 | + } else{ |
|
382 | 399 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
383 | 400 | } |
384 | 401 | } |
385 | - }else{ |
|
402 | + } else{ |
|
386 | 403 | $this->build_files_list(); |
387 | 404 | } |
388 | 405 | |
@@ -454,9 +471,10 @@ discard block |
||
454 | 471 | |
455 | 472 | $contents = $this->get_tmp_filesystem()->listContents(); |
456 | 473 | |
457 | - if(is_array($contents)) |
|
458 | - foreach($contents as $file_info) |
|
474 | + if(is_array($contents)) { |
|
475 | + foreach($contents as $file_info) |
|
459 | 476 | $this->get_tmp_filesystem()->delete($file_info['path']); |
477 | + } |
|
460 | 478 | |
461 | 479 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
462 | 480 | |
@@ -488,17 +506,21 @@ discard block |
||
488 | 506 | { |
489 | 507 | $this->files_counter = 0; |
490 | 508 | |
491 | - if(!$this->storage_filesystem->has("index.html")) |
|
492 | - $this->storage_filesystem->write("index.html",""); |
|
509 | + if(!$this->storage_filesystem->has("index.html")) { |
|
510 | + $this->storage_filesystem->write("index.html",""); |
|
511 | + } |
|
493 | 512 | |
494 | - if(!$this->tmp_filesystem->has("index.html")) |
|
495 | - $this->tmp_filesystem->write("index.html",""); |
|
513 | + if(!$this->tmp_filesystem->has("index.html")) { |
|
514 | + $this->tmp_filesystem->write("index.html",""); |
|
515 | + } |
|
496 | 516 | |
497 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
498 | - $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
517 | + if($this->tmp_filesystem->has($this->get_included_files_handler())) { |
|
518 | + $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
519 | + } |
|
499 | 520 | |
500 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
501 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
521 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
522 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
523 | + } |
|
502 | 524 | } |
503 | 525 | |
504 | 526 | public function get_scanned_files_num() |
@@ -568,23 +590,23 @@ discard block |
||
568 | 590 | if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
569 | 591 | { |
570 | 592 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
571 | - } |
|
572 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
593 | + } elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
573 | 594 | $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
574 | 595 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
575 | 596 | if($this->store_file($file)) |
576 | 597 | { |
577 | 598 | $this->files_counter++; |
578 | 599 | } |
579 | - if(isset($file['size'])) |
|
580 | - $this->files_size += $file['size']; |
|
600 | + if(isset($file['size'])) { |
|
601 | + $this->files_size += $file['size']; |
|
602 | + } |
|
581 | 603 | |
582 | - }else{ |
|
604 | + } else{ |
|
583 | 605 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
584 | 606 | } |
585 | 607 | } |
586 | 608 | |
587 | - }catch(Exception $e){ |
|
609 | + } catch(Exception $e){ |
|
588 | 610 | |
589 | 611 | $this->logger->error($e->getMessage()); |
590 | 612 | |
@@ -611,7 +633,7 @@ discard block |
||
611 | 633 | |
612 | 634 | $this->tmp_filesystem->delete($tmp_file); |
613 | 635 | |
614 | - }catch(Exception $e){ |
|
636 | + } catch(Exception $e){ |
|
615 | 637 | |
616 | 638 | $this->logger->error($e->getMessage()); |
617 | 639 | |
@@ -632,12 +654,14 @@ discard block |
||
632 | 654 | |
633 | 655 | $files = $this->storage_filesystem->listContents(); |
634 | 656 | |
635 | - if(is_array($files)) |
|
636 | - foreach($files as $file) |
|
657 | + if(is_array($files)) { |
|
658 | + foreach($files as $file) |
|
637 | 659 | { |
638 | 660 | if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
639 | 661 | { |
640 | - $_storage_size += $file['size']; //bytes |
|
662 | + $_storage_size += $file['size']; |
|
663 | + } |
|
664 | + //bytes |
|
641 | 665 | $_backup_files_list[] = $file; |
642 | 666 | } |
643 | 667 | } |
@@ -651,9 +675,11 @@ discard block |
||
651 | 675 | { |
652 | 676 | //processing rule folder capacity |
653 | 677 | if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
654 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
678 | + $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) { |
|
679 | + //bytes |
|
655 | 680 | { |
656 | 681 | $this->storage_filesystem->delete($file['path']); |
682 | + } |
|
657 | 683 | $_storage_size -= $file['size']; |
658 | 684 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit)); |
659 | 685 | } |
@@ -694,34 +720,37 @@ discard block |
||
694 | 720 | |
695 | 721 | public function process_backup_name($name = "", $max_length=100) |
696 | 722 | { |
697 | - if(!$name) |
|
698 | - $name = $this->xcloner_settings->get_default_backup_name(); |
|
723 | + if(!$name) { |
|
724 | + $name = $this->xcloner_settings->get_default_backup_name(); |
|
725 | + } |
|
699 | 726 | |
700 | 727 | foreach($this->backup_name_tags as $tag) |
701 | 728 | { |
702 | - if($tag == '[time]') |
|
703 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
704 | - elseif($tag == '[hostname]') |
|
705 | - $name = str_replace($tag, gethostname() ,$name); |
|
706 | - elseif($tag == '[domain]') |
|
729 | + if($tag == '[time]') { |
|
730 | + $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
731 | + } elseif($tag == '[hostname]') { |
|
732 | + $name = str_replace($tag, gethostname() ,$name); |
|
733 | + } elseif($tag == '[domain]') |
|
707 | 734 | { |
708 | 735 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
709 | 736 | $name = str_replace($tag, $domain ,$name); |
710 | 737 | } |
711 | 738 | } |
712 | 739 | |
713 | - if($max_length) |
|
714 | - $name = substr($name, 0, $max_length); |
|
740 | + if($max_length) { |
|
741 | + $name = substr($name, 0, $max_length); |
|
742 | + } |
|
715 | 743 | |
716 | 744 | return $name; |
717 | 745 | } |
718 | 746 | |
719 | 747 | public function sort_by( &$array, $field, $direction = 'asc') |
720 | 748 | { |
721 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
722 | - $direction = SORT_DESC; |
|
723 | - else |
|
724 | - $direction = SORT_ASC; |
|
749 | + if(strtolower($direction) == "desc" || $direction == SORT_DESC) { |
|
750 | + $direction = SORT_DESC; |
|
751 | + } else { |
|
752 | + $direction = SORT_ASC; |
|
753 | + } |
|
725 | 754 | |
726 | 755 | $array = $this->array_orderby($array, $field, $direction); |
727 | 756 | |
@@ -738,10 +767,11 @@ discard block |
||
738 | 767 | $tmp = array(); |
739 | 768 | foreach ($data as $key => $row) |
740 | 769 | { |
741 | - if(is_array($row)) |
|
742 | - $tmp[$key] = $row[$field]; |
|
743 | - else |
|
744 | - $tmp[$key] = $row->$field; |
|
770 | + if(is_array($row)) { |
|
771 | + $tmp[$key] = $row[$field]; |
|
772 | + } else { |
|
773 | + $tmp[$key] = $row->$field; |
|
774 | + } |
|
745 | 775 | } |
746 | 776 | $args[$n] = $tmp; |
747 | 777 | } |
@@ -779,8 +809,9 @@ discard block |
||
779 | 809 | |
780 | 810 | if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
781 | 811 | { |
782 | - if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
783 | - return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
812 | + if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
|
813 | + return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
814 | + } |
|
784 | 815 | } |
785 | 816 | |
786 | 817 | if(!sizeof($this->excluded_files)) |
@@ -788,21 +819,23 @@ discard block |
||
788 | 819 | $this->set_excluded_files(); |
789 | 820 | } |
790 | 821 | |
791 | - if(is_array($this->excluded_files)) |
|
792 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
822 | + if(is_array($this->excluded_files)) { |
|
823 | + foreach($this->excluded_files as $excluded_file_pattern) |
|
793 | 824 | { |
794 | 825 | if($excluded_file_pattern == "/") |
795 | 826 | $needle = "$"; |
796 | - else |
|
797 | - $needle = "$".$excluded_file_pattern; |
|
827 | + } else { |
|
828 | + $needle = "$".$excluded_file_pattern; |
|
829 | + } |
|
798 | 830 | |
799 | 831 | if(strstr("$".$file['path'], $needle)){ |
800 | 832 | return $excluded_file_pattern; |
801 | 833 | } |
802 | 834 | } |
803 | 835 | |
804 | - if( $regex = $this->is_excluded_regex($file)) |
|
805 | - return $regex; |
|
836 | + if( $regex = $this->is_excluded_regex($file)) { |
|
837 | + return $regex; |
|
838 | + } |
|
806 | 839 | |
807 | 840 | if($file['type'] == "file") |
808 | 841 | { |
@@ -870,13 +903,15 @@ discard block |
||
870 | 903 | foreach($regex_patterns as $excluded_file_pattern) |
871 | 904 | { |
872 | 905 | |
873 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
874 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
906 | + if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") { |
|
907 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
908 | + } |
|
875 | 909 | |
876 | - if($file['path'] == "/") |
|
877 | - $needle = "/"; |
|
878 | - else |
|
879 | - $needle = "/".$file['path']; |
|
910 | + if($file['path'] == "/") { |
|
911 | + $needle = "/"; |
|
912 | + } else { |
|
913 | + $needle = "/".$file['path']; |
|
914 | + } |
|
880 | 915 | //echo $needle."---".$excluded_file_pattern."---\n"; |
881 | 916 | |
882 | 917 | if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
@@ -892,10 +927,12 @@ discard block |
||
892 | 927 | { |
893 | 928 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
894 | 929 | |
895 | - if(!isset($file['size'])) |
|
896 | - $file['size'] = 0; |
|
897 | - if(!isset($file['visibility'])) |
|
898 | - $file['visibility'] = "private"; |
|
930 | + if(!isset($file['size'])) { |
|
931 | + $file['size'] = 0; |
|
932 | + } |
|
933 | + if(!isset($file['visibility'])) { |
|
934 | + $file['visibility'] = "private"; |
|
935 | + } |
|
899 | 936 | |
900 | 937 | $csv_filename = str_replace('"','""', $file['path']); |
901 | 938 | |
@@ -906,7 +943,7 @@ discard block |
||
906 | 943 | if($file['type'] == "dir"){ |
907 | 944 | try{ |
908 | 945 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
909 | - }catch(Exception $e){ |
|
946 | + } catch(Exception $e){ |
|
910 | 947 | $this->logger->error($e->getMessage()); |
911 | 948 | } |
912 | 949 | } |
@@ -930,7 +967,7 @@ discard block |
||
930 | 967 | |
931 | 968 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
932 | 969 | |
933 | - }catch(Exception $e){ |
|
970 | + } catch(Exception $e){ |
|
934 | 971 | |
935 | 972 | $this->logger->error($e->getMessage()); |
936 | 973 | } |
@@ -945,35 +982,39 @@ discard block |
||
945 | 982 | |
946 | 983 | public function get_filesystem($system = "") |
947 | 984 | { |
948 | - if($system == "storage_filesystem_append") |
|
949 | - return $this->storage_filesystem_append; |
|
950 | - elseif($system == "tmp_filesystem_append") |
|
951 | - return $this->tmp_filesystem_append; |
|
952 | - elseif($system == "tmp_filesystem") |
|
953 | - return $this->tmp_filesystem; |
|
954 | - elseif($system == "storage_filesystem") |
|
955 | - return $this->storage_filesystem; |
|
956 | - else |
|
957 | - return $this->start_filesystem; |
|
985 | + if($system == "storage_filesystem_append") { |
|
986 | + return $this->storage_filesystem_append; |
|
987 | + } elseif($system == "tmp_filesystem_append") { |
|
988 | + return $this->tmp_filesystem_append; |
|
989 | + } elseif($system == "tmp_filesystem") { |
|
990 | + return $this->tmp_filesystem; |
|
991 | + } elseif($system == "storage_filesystem") { |
|
992 | + return $this->storage_filesystem; |
|
993 | + } else { |
|
994 | + return $this->start_filesystem; |
|
995 | + } |
|
958 | 996 | } |
959 | 997 | |
960 | 998 | public function get_adapter($system) |
961 | 999 | { |
962 | - if($system == "tmp_filesystem") |
|
963 | - return $this->tmp_adapter; |
|
964 | - elseif($system == "storage_filesystem") |
|
965 | - return $this->storage_adapter; |
|
966 | - else |
|
967 | - return $this->start_adapter; |
|
1000 | + if($system == "tmp_filesystem") { |
|
1001 | + return $this->tmp_adapter; |
|
1002 | + } elseif($system == "storage_filesystem") { |
|
1003 | + return $this->storage_adapter; |
|
1004 | + } else { |
|
1005 | + return $this->start_adapter; |
|
1006 | + } |
|
968 | 1007 | } |
969 | 1008 | |
970 | 1009 | private function scan_finished() |
971 | 1010 | { |
972 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
973 | - return false; |
|
1011 | + if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { |
|
1012 | + return false; |
|
1013 | + } |
|
974 | 1014 | |
975 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
976 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
1015 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
1016 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
1017 | + } |
|
977 | 1018 | |
978 | 1019 | $this->logger->debug(sprintf(("File scan finished"))); |
979 | 1020 |
@@ -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 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | |
25 | 25 | try{ |
26 | 26 | $option = Util::normalizePath($path); |
27 | - }catch(Exception $e){ |
|
27 | + } catch(Exception $e){ |
|
28 | 28 | add_settings_error('xcloner_error_message', '', __($e->getMessage()), 'error'); |
29 | 29 | } |
30 | 30 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | class Xcloner_Sanitization { |
5 | 5 | |
6 | - public function __construct(){} |
|
6 | + public function __construct() {} |
|
7 | 7 | |
8 | 8 | public function sanitize_input_as_int($option) |
9 | 9 | { |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | { |
25 | 25 | $path = filter_var($option, FILTER_SANITIZE_URL); |
26 | 26 | |
27 | - try{ |
|
27 | + try { |
|
28 | 28 | $option = Util::normalizePath($path); |
29 | - }catch(Exception $e){ |
|
29 | + }catch (Exception $e) { |
|
30 | 30 | add_settings_error('xcloner_error_message', '', __($e->getMessage()), 'error'); |
31 | 31 | } |
32 | 32 | |
33 | - if($path and !is_dir($path)){ |
|
34 | - add_settings_error('xcloner_error_message', '', __(sprintf('Invalid Server Path %s',$option)), 'error'); |
|
33 | + if ($path and !is_dir($path)) { |
|
34 | + add_settings_error('xcloner_error_message', '', __(sprintf('Invalid Server Path %s', $option)), 'error'); |
|
35 | 35 | return false; |
36 | 36 | } |
37 | 37 |
@@ -147,14 +147,14 @@ |
||
147 | 147 | $unit_list = array('B', 'KB', 'MB', 'GB', 'PB'); |
148 | 148 | |
149 | 149 | if ($bytes == 0) { |
150 | - return $bytes . ' ' . $unit_list[0]; |
|
150 | + return $bytes . ' ' . $unit_list[0]; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | $unit_count = count($unit_list); |
154 | 154 | for ($i = $unit_count - 1; $i >= 0; $i--) { |
155 | - $power = $i * 10; |
|
156 | - if (($bytes >> $power) >= 1) |
|
157 | - return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i]; |
|
155 | + $power = $i * 10; |
|
156 | + if (($bytes >> $power) >= 1) |
|
157 | + return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i]; |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
@@ -13,20 +13,25 @@ discard block |
||
13 | 13 | |
14 | 14 | public function check_backup_ready_status() |
15 | 15 | { |
16 | - if(!$this->check_min_php_version(1)) |
|
17 | - return false; |
|
16 | + if(!$this->check_min_php_version(1)) { |
|
17 | + return false; |
|
18 | + } |
|
18 | 19 | |
19 | - if(!$this->check_safe_mode(1)) |
|
20 | - return false; |
|
20 | + if(!$this->check_safe_mode(1)) { |
|
21 | + return false; |
|
22 | + } |
|
21 | 23 | |
22 | - if(!$this->check_xcloner_start_path(1)) |
|
23 | - return false; |
|
24 | + if(!$this->check_xcloner_start_path(1)) { |
|
25 | + return false; |
|
26 | + } |
|
24 | 27 | |
25 | - if(!$this->check_xcloner_store_path(1)) |
|
26 | - return false; |
|
28 | + if(!$this->check_xcloner_store_path(1)) { |
|
29 | + return false; |
|
30 | + } |
|
27 | 31 | |
28 | - if(!$this->check_xcloner_tmp_path(1)) |
|
29 | - return false; |
|
32 | + if(!$this->check_xcloner_tmp_path(1)) { |
|
33 | + return false; |
|
34 | + } |
|
30 | 35 | |
31 | 36 | return true; |
32 | 37 | } |
@@ -41,10 +46,11 @@ discard block |
||
41 | 46 | |
42 | 47 | if($return_bool == 1) |
43 | 48 | { |
44 | - if(version_compare(phpversion(), $this->min_php_version, '<')) |
|
45 | - return false; |
|
46 | - else |
|
47 | - return true; |
|
49 | + if(version_compare(phpversion(), $this->min_php_version, '<')) { |
|
50 | + return false; |
|
51 | + } else { |
|
52 | + return true; |
|
53 | + } |
|
48 | 54 | } |
49 | 55 | |
50 | 56 | return phpversion(); |
@@ -56,14 +62,16 @@ discard block |
||
56 | 62 | |
57 | 63 | if($return_bool) |
58 | 64 | { |
59 | - if( ini_get('safe_mode') ) |
|
60 | - return false; |
|
61 | - else |
|
62 | - return true; |
|
65 | + if( ini_get('safe_mode') ) { |
|
66 | + return false; |
|
67 | + } else { |
|
68 | + return true; |
|
69 | + } |
|
63 | 70 | } |
64 | 71 | |
65 | - if( ini_get('safe_mode') ) |
|
66 | - $safe_mode = "On"; |
|
72 | + if( ini_get('safe_mode') ) { |
|
73 | + $safe_mode = "On"; |
|
74 | + } |
|
67 | 75 | |
68 | 76 | return $safe_mode; |
69 | 77 | } |
@@ -74,8 +82,9 @@ discard block |
||
74 | 82 | |
75 | 83 | if($return_bool) |
76 | 84 | { |
77 | - if(!file_exists($path)) |
|
78 | - return false; |
|
85 | + if(!file_exists($path)) { |
|
86 | + return false; |
|
87 | + } |
|
79 | 88 | |
80 | 89 | return is_readable($path); |
81 | 90 | } |
@@ -89,11 +98,13 @@ discard block |
||
89 | 98 | |
90 | 99 | if($return_bool) |
91 | 100 | { |
92 | - if(!file_exists($path)) |
|
93 | - return false; |
|
101 | + if(!file_exists($path)) { |
|
102 | + return false; |
|
103 | + } |
|
94 | 104 | |
95 | - if(!is_writeable($path)) |
|
96 | - @chmod($path, 0777); |
|
105 | + if(!is_writeable($path)) { |
|
106 | + @chmod($path, 0777); |
|
107 | + } |
|
97 | 108 | |
98 | 109 | return is_writeable($path); |
99 | 110 | } |
@@ -107,11 +118,13 @@ discard block |
||
107 | 118 | |
108 | 119 | if($return_bool) |
109 | 120 | { |
110 | - if(!file_exists($path)) |
|
111 | - return false; |
|
121 | + if(!file_exists($path)) { |
|
122 | + return false; |
|
123 | + } |
|
112 | 124 | |
113 | - if(!is_writeable($path)) |
|
114 | - @chmod($path, 0777); |
|
125 | + if(!is_writeable($path)) { |
|
126 | + @chmod($path, 0777); |
|
127 | + } |
|
115 | 128 | |
116 | 129 | return is_writeable($path); |
117 | 130 | } |
@@ -133,8 +146,9 @@ discard block |
||
133 | 146 | { |
134 | 147 | $open_basedir = ini_get('open_basedir'); |
135 | 148 | |
136 | - if(!$open_basedir) |
|
137 | - $open_basedir = "none"; |
|
149 | + if(!$open_basedir) { |
|
150 | + $open_basedir = "none"; |
|
151 | + } |
|
138 | 152 | return $open_basedir; |
139 | 153 | } |
140 | 154 | |
@@ -153,8 +167,9 @@ discard block |
||
153 | 167 | $unit_count = count($unit_list); |
154 | 168 | for ($i = $unit_count - 1; $i >= 0; $i--) { |
155 | 169 | $power = $i * 10; |
156 | - if (($bytes >> $power) >= 1) |
|
157 | - return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i]; |
|
170 | + if (($bytes >> $power) >= 1) { |
|
171 | + return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i]; |
|
172 | + } |
|
158 | 173 | } |
159 | 174 | } |
160 | 175 | } |
@@ -3,8 +3,8 @@ discard block |
||
3 | 3 | class Xcloner_Requirements |
4 | 4 | { |
5 | 5 | |
6 | - var $min_php_version = "5.4.0"; |
|
7 | - var $safe_mode = "Off"; |
|
6 | + var $min_php_version = "5.4.0"; |
|
7 | + var $safe_mode = "Off"; |
|
8 | 8 | |
9 | 9 | private $xcloner_settings; |
10 | 10 | private $xcloner_container; |
@@ -22,19 +22,19 @@ discard block |
||
22 | 22 | |
23 | 23 | public function check_backup_ready_status() |
24 | 24 | { |
25 | - if(!$this->check_min_php_version(1)) |
|
25 | + if (!$this->check_min_php_version(1)) |
|
26 | 26 | return false; |
27 | 27 | |
28 | - if(!$this->check_safe_mode(1)) |
|
28 | + if (!$this->check_safe_mode(1)) |
|
29 | 29 | return false; |
30 | 30 | |
31 | - if(!$this->check_xcloner_start_path(1)) |
|
31 | + if (!$this->check_xcloner_start_path(1)) |
|
32 | 32 | return false; |
33 | 33 | |
34 | - if(!$this->check_xcloner_store_path(1)) |
|
34 | + if (!$this->check_xcloner_store_path(1)) |
|
35 | 35 | return false; |
36 | 36 | |
37 | - if(!$this->check_xcloner_tmp_path(1)) |
|
37 | + if (!$this->check_xcloner_tmp_path(1)) |
|
38 | 38 | return false; |
39 | 39 | |
40 | 40 | return true; |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | public function check_min_php_version($return_bool = 0) |
49 | 49 | { |
50 | 50 | |
51 | - if($return_bool == 1) |
|
51 | + if ($return_bool == 1) |
|
52 | 52 | { |
53 | - if(version_compare(phpversion(), $this->min_php_version, '<')) |
|
53 | + if (version_compare(phpversion(), $this->min_php_version, '<')) |
|
54 | 54 | return false; |
55 | 55 | else |
56 | 56 | return true; |
@@ -59,31 +59,31 @@ discard block |
||
59 | 59 | return phpversion(); |
60 | 60 | } |
61 | 61 | |
62 | - public function check_safe_mode($return_bool=0) |
|
62 | + public function check_safe_mode($return_bool = 0) |
|
63 | 63 | { |
64 | 64 | $safe_mode = "Off"; |
65 | 65 | |
66 | - if($return_bool) |
|
66 | + if ($return_bool) |
|
67 | 67 | { |
68 | - if( ini_get('safe_mode') ) |
|
68 | + if (ini_get('safe_mode')) |
|
69 | 69 | return false; |
70 | 70 | else |
71 | 71 | return true; |
72 | 72 | } |
73 | 73 | |
74 | - if( ini_get('safe_mode') ) |
|
74 | + if (ini_get('safe_mode')) |
|
75 | 75 | $safe_mode = "On"; |
76 | 76 | |
77 | 77 | return $safe_mode; |
78 | 78 | } |
79 | 79 | |
80 | - public function check_xcloner_start_path($return_bool=0) |
|
80 | + public function check_xcloner_start_path($return_bool = 0) |
|
81 | 81 | { |
82 | 82 | $path = $this->xcloner_settings->get_xcloner_start_path(); |
83 | 83 | |
84 | - if($return_bool) |
|
84 | + if ($return_bool) |
|
85 | 85 | { |
86 | - if(!file_exists($path)) |
|
86 | + if (!file_exists($path)) |
|
87 | 87 | return false; |
88 | 88 | |
89 | 89 | return is_readable($path); |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | return $path; |
93 | 93 | } |
94 | 94 | |
95 | - public function check_xcloner_tmp_path($return_bool=0) |
|
95 | + public function check_xcloner_tmp_path($return_bool = 0) |
|
96 | 96 | { |
97 | 97 | $path = $this->xcloner_settings->get_xcloner_tmp_path(); |
98 | 98 | |
99 | - if($return_bool) |
|
99 | + if ($return_bool) |
|
100 | 100 | { |
101 | - if(!file_exists($path)) |
|
101 | + if (!file_exists($path)) |
|
102 | 102 | return false; |
103 | 103 | |
104 | - if(!is_writeable($path)) |
|
104 | + if (!is_writeable($path)) |
|
105 | 105 | @chmod($path, 0777); |
106 | 106 | |
107 | 107 | return is_writeable($path); |
@@ -110,16 +110,16 @@ discard block |
||
110 | 110 | return $path; |
111 | 111 | } |
112 | 112 | |
113 | - public function check_xcloner_store_path($return_bool=0) |
|
113 | + public function check_xcloner_store_path($return_bool = 0) |
|
114 | 114 | { |
115 | 115 | $path = $this->xcloner_settings->get_xcloner_store_path(); |
116 | 116 | |
117 | - if($return_bool) |
|
117 | + if ($return_bool) |
|
118 | 118 | { |
119 | - if(!file_exists($path)) |
|
119 | + if (!file_exists($path)) |
|
120 | 120 | return false; |
121 | 121 | |
122 | - if(!is_writeable($path)) |
|
122 | + if (!is_writeable($path)) |
|
123 | 123 | @chmod($path, 0777); |
124 | 124 | |
125 | 125 | return is_writeable($path); |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | |
141 | 141 | public function get_open_basedir() |
142 | 142 | { |
143 | - $open_basedir = ini_get('open_basedir'); |
|
143 | + $open_basedir = ini_get('open_basedir'); |
|
144 | 144 | |
145 | - if(!$open_basedir) |
|
145 | + if (!$open_basedir) |
|
146 | 146 | $open_basedir = "none"; |
147 | 147 | return $open_basedir; |
148 | 148 | } |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | $unit_list = array('B', 'KB', 'MB', 'GB', 'PB'); |
157 | 157 | |
158 | 158 | if ($bytes == 0) { |
159 | - return $bytes . ' ' . $unit_list[0]; |
|
159 | + return $bytes.' '.$unit_list[0]; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | $unit_count = count($unit_list); |
163 | 163 | for ($i = $unit_count - 1; $i >= 0; $i--) { |
164 | 164 | $power = $i * 10; |
165 | 165 | if (($bytes >> $power) >= 1) |
166 | - return round($bytes / (1 << $power), $decimals) . ' ' . $unit_list[$i]; |
|
166 | + return round($bytes / (1 << $power), $decimals).' '.$unit_list[$i]; |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | } |
@@ -19,8 +19,9 @@ discard block |
||
19 | 19 | |
20 | 20 | public function transfer_file($file, $start = 0, $hash = "") |
21 | 21 | { |
22 | - if(!$this->target_url) |
|
23 | - throw new Exception("Please setup a target url for upload"); |
|
22 | + if(!$this->target_url) { |
|
23 | + throw new Exception("Please setup a target url for upload"); |
|
24 | + } |
|
24 | 25 | |
25 | 26 | |
26 | 27 | $fp = $this->get_storage_filesystem()->readStream($file); |
@@ -68,8 +69,9 @@ discard block |
||
68 | 69 | |
69 | 70 | $result = json_decode($original_result); |
70 | 71 | |
71 | - if(!$result) |
|
72 | - throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); |
|
72 | + if(!$result) { |
|
73 | + throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); |
|
74 | + } |
|
73 | 75 | |
74 | 76 | if($result->status != 200) |
75 | 77 | { |
@@ -94,7 +96,7 @@ discard block |
||
94 | 96 | . ($postname ?: basename($filename)) |
95 | 97 | . ($mimetype ? ";type=$mimetype" : ''); |
96 | 98 | |
97 | - }else{ |
|
99 | + } else{ |
|
98 | 100 | |
99 | 101 | return curl_file_create($filename, $mimetype, $postname); |
100 | 102 |
@@ -86,6 +86,9 @@ |
||
86 | 86 | return ftell($fp); |
87 | 87 | } |
88 | 88 | |
89 | + /** |
|
90 | + * @param string $filename |
|
91 | + */ |
|
89 | 92 | private function curl_file_create($filename, $mimetype = '', $postname = '') { |
90 | 93 | if (!function_exists('curl_file_create')) { |
91 | 94 |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | |
55 | 55 | curl_setopt($ch, CURLOPT_POST, 1); |
56 | 56 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
57 | - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
58 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); |
|
59 | - curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
|
60 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
57 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
58 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); |
|
59 | + curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
|
60 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
61 | 61 | |
62 | 62 | curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array ); |
63 | 63 | curl_setopt($ch, CURLOPT_VERBOSE, true); |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | private function curl_file_create($filename, $mimetype = '', $postname = '') { |
90 | 90 | if (!function_exists('curl_file_create')) { |
91 | 91 | |
92 | - return "@$filename;filename=" |
|
93 | - . ($postname ?: basename($filename)) |
|
94 | - . ($mimetype ? ";type=$mimetype" : ''); |
|
92 | + return "@$filename;filename=" |
|
93 | + . ($postname ?: basename($filename)) |
|
94 | + . ($mimetype ? ";type=$mimetype" : ''); |
|
95 | 95 | |
96 | 96 | }else{ |
97 | 97 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class Xcloner_File_Transfer extends Xcloner_File_System{ |
|
3 | +class Xcloner_File_Transfer extends Xcloner_File_System { |
|
4 | 4 | |
5 | 5 | private $target_url; |
6 | 6 | private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | public function set_target($target_url) |
10 | 10 | { |
11 | - return $this->target_url= $target_url; |
|
11 | + return $this->target_url = $target_url; |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | public function get_target() |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | public function transfer_file($file, $start = 0, $hash = "") |
21 | 21 | { |
22 | - if(!$this->target_url) |
|
22 | + if (!$this->target_url) |
|
23 | 23 | throw new Exception("Please setup a target url for upload"); |
24 | 24 | |
25 | 25 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | fseek($fp, $start, SEEK_SET); |
29 | 29 | |
30 | - $binary_data = fread($fp, $this->transfer_limit); |
|
30 | + $binary_data = fread($fp, $this->transfer_limit); |
|
31 | 31 | |
32 | 32 | $tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5); |
33 | 33 | |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | $send_array = array(); |
39 | 39 | |
40 | 40 | $send_array['file'] = $file; |
41 | - $send_array['start'] = $start; |
|
42 | - $send_array['xcloner_action'] = "write_file"; |
|
41 | + $send_array['start'] = $start; |
|
42 | + $send_array['xcloner_action'] = "write_file"; |
|
43 | 43 | $send_array['hash'] = $hash; |
44 | 44 | #$send_array['blob'] = $binary_data; |
45 | - $send_array['blob'] = $this->curl_file_create($tmp_file_path,'application/x-binary',$tmp_filename); |
|
45 | + $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename); |
|
46 | 46 | |
47 | 47 | //$data = http_build_query($send_array); |
48 | 48 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | |
52 | 52 | $ch = curl_init(); |
53 | - curl_setopt($ch, CURLOPT_URL,$this->target_url); |
|
53 | + curl_setopt($ch, CURLOPT_URL, $this->target_url); |
|
54 | 54 | |
55 | 55 | curl_setopt($ch, CURLOPT_POST, 1); |
56 | 56 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
@@ -59,24 +59,24 @@ discard block |
||
59 | 59 | curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
60 | 60 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
61 | 61 | |
62 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array ); |
|
62 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array); |
|
63 | 63 | curl_setopt($ch, CURLOPT_VERBOSE, true); |
64 | 64 | |
65 | - $original_result = curl_exec ($ch); |
|
65 | + $original_result = curl_exec($ch); |
|
66 | 66 | |
67 | 67 | $this->get_tmp_filesystem()->delete($tmp_filename); |
68 | 68 | |
69 | 69 | $result = json_decode($original_result); |
70 | 70 | |
71 | - if(!$result) |
|
72 | - throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); |
|
71 | + if (!$result) |
|
72 | + throw new Exception("We have received no valid response from the remote host, original message: ".$original_result); |
|
73 | 73 | |
74 | - if($result->status != 200) |
|
74 | + if ($result->status != 200) |
|
75 | 75 | { |
76 | 76 | throw new Exception($result->response); |
77 | 77 | } |
78 | 78 | |
79 | - if(ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) |
|
79 | + if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) |
|
80 | 80 | { |
81 | 81 | $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes", $file, $this->target_url, ftell($fp))); |
82 | 82 | $this->remove_tmp_filesystem(); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | . ($postname ?: basename($filename)) |
94 | 94 | . ($mimetype ? ";type=$mimetype" : ''); |
95 | 95 | |
96 | - }else{ |
|
96 | + } else { |
|
97 | 97 | |
98 | 98 | return curl_file_create($filename, $mimetype, $postname); |
99 | 99 |
@@ -37,7 +37,7 @@ |
||
37 | 37 | load_plugin_textdomain( |
38 | 38 | 'xcloner-backup-and-restore', |
39 | 39 | false, |
40 | - dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/' |
|
40 | + dirname(dirname(plugin_basename(__FILE__))).'/languages/' |
|
41 | 41 | ); |
42 | 42 | |
43 | 43 | } |