@@ -1,12 +1,14 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if(!isset($argv)) |
|
| 3 | +if(!isset($argv)) { |
|
| 4 | 4 | die('Access denied from web.'); |
| 5 | +} |
|
| 5 | 6 | |
| 6 | 7 | $file = 'restore/vendor.phar'; |
| 7 | 8 | |
| 8 | -if(file_exists($file)) |
|
| 9 | +if(file_exists($file)) { |
|
| 9 | 10 | unlink($file); |
| 11 | +} |
|
| 10 | 12 | $phar2 = new Phar($file, 0, 'vendor.phar'); |
| 11 | 13 | |
| 12 | 14 | // add all files in the project, only include php files |
@@ -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 | |
@@ -69,44 +69,57 @@ |
||
| 69 | 69 | update_option( "xcloner_db_version", $xcloner_db_version ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if(!get_option('xcloner_backup_compression_level')) |
|
| 73 | - update_option('xcloner_backup_compression_level', 0); |
|
| 72 | + if(!get_option('xcloner_backup_compression_level')) { |
|
| 73 | + update_option('xcloner_backup_compression_level', 0); |
|
| 74 | + } |
|
| 74 | 75 | |
| 75 | - if(!get_option('xcloner_enable_log')) |
|
| 76 | - update_option('xcloner_enable_log', 1); |
|
| 76 | + if(!get_option('xcloner_enable_log')) { |
|
| 77 | + update_option('xcloner_enable_log', 1); |
|
| 78 | + } |
|
| 77 | 79 | |
| 78 | - if(!get_option('xcloner_enable_mysql_backup')) |
|
| 79 | - update_option('xcloner_enable_mysql_backup', 1); |
|
| 80 | + if(!get_option('xcloner_enable_mysql_backup')) { |
|
| 81 | + update_option('xcloner_enable_mysql_backup', 1); |
|
| 82 | + } |
|
| 80 | 83 | |
| 81 | - if(!get_option('xcloner_system_settings_page')) |
|
| 82 | - update_option('xcloner_system_settings_page', 100); |
|
| 84 | + if(!get_option('xcloner_system_settings_page')) { |
|
| 85 | + update_option('xcloner_system_settings_page', 100); |
|
| 86 | + } |
|
| 83 | 87 | |
| 84 | - if(!get_option('xcloner_files_to_process_per_request')) |
|
| 85 | - update_option('xcloner_files_to_process_per_request', 250); |
|
| 88 | + if(!get_option('xcloner_files_to_process_per_request')) { |
|
| 89 | + update_option('xcloner_files_to_process_per_request', 250); |
|
| 90 | + } |
|
| 86 | 91 | |
| 87 | - if(!get_option('xcloner_database_records_per_request')) |
|
| 88 | - update_option('xcloner_database_records_per_request', 10000); |
|
| 92 | + if(!get_option('xcloner_database_records_per_request')) { |
|
| 93 | + update_option('xcloner_database_records_per_request', 10000); |
|
| 94 | + } |
|
| 89 | 95 | |
| 90 | - if(!get_option('xcloner_exclude_files_larger_than_mb')) |
|
| 91 | - update_option('xcloner_exclude_files_larger_than_mb', 0); |
|
| 96 | + if(!get_option('xcloner_exclude_files_larger_than_mb')) { |
|
| 97 | + update_option('xcloner_exclude_files_larger_than_mb', 0); |
|
| 98 | + } |
|
| 92 | 99 | |
| 93 | - if(!get_option('xcloner_split_backup_limit')) |
|
| 94 | - update_option('xcloner_split_backup_limit', 2048); |
|
| 100 | + if(!get_option('xcloner_split_backup_limit')) { |
|
| 101 | + update_option('xcloner_split_backup_limit', 2048); |
|
| 102 | + } |
|
| 95 | 103 | |
| 96 | - if(!get_option('xcloner_size_limit_per_request')) |
|
| 97 | - update_option('xcloner_size_limit_per_request', 50); |
|
| 104 | + if(!get_option('xcloner_size_limit_per_request')) { |
|
| 105 | + update_option('xcloner_size_limit_per_request', 50); |
|
| 106 | + } |
|
| 98 | 107 | |
| 99 | - if(!get_option('xcloner_cleanup_retention_limit_days')) |
|
| 100 | - update_option('xcloner_cleanup_retention_limit_days', 60); |
|
| 108 | + if(!get_option('xcloner_cleanup_retention_limit_days')) { |
|
| 109 | + update_option('xcloner_cleanup_retention_limit_days', 60); |
|
| 110 | + } |
|
| 101 | 111 | |
| 102 | - if(!get_option('xcloner_cleanup_retention_limit_archives')) |
|
| 103 | - update_option('xcloner_cleanup_retention_limit_archives', 100); |
|
| 112 | + if(!get_option('xcloner_cleanup_retention_limit_archives')) { |
|
| 113 | + update_option('xcloner_cleanup_retention_limit_archives', 100); |
|
| 114 | + } |
|
| 104 | 115 | |
| 105 | - if(!get_option('xcloner_directories_to_scan_per_request')) |
|
| 106 | - update_option('xcloner_directories_to_scan_per_request', 25); |
|
| 116 | + if(!get_option('xcloner_directories_to_scan_per_request')) { |
|
| 117 | + update_option('xcloner_directories_to_scan_per_request', 25); |
|
| 118 | + } |
|
| 107 | 119 | |
| 108 | - if(!get_option('xcloner_regex_exclude')) |
|
| 109 | - update_option('xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$".PHP_EOL."(.*)\.(svn|git)(.*)$".PHP_EOL."wp-content\/cache(.*)$"); |
|
| 120 | + if(!get_option('xcloner_regex_exclude')) { |
|
| 121 | + update_option('xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$".PHP_EOL."(.*)\.(svn|git)(.*)$".PHP_EOL."wp-content\/cache(.*)$"); |
|
| 122 | + } |
|
| 110 | 123 | |
| 111 | 124 | } |
| 112 | 125 | |
@@ -8,26 +8,29 @@ discard block |
||
| 8 | 8 | |
| 9 | 9 | public function __construct($hash = "") |
| 10 | 10 | { |
| 11 | - if(isset($hash)) |
|
| 12 | - $this->set_hash($hash); |
|
| 11 | + if(isset($hash)) { |
|
| 12 | + $this->set_hash($hash); |
|
| 13 | + } |
|
| 13 | 14 | } |
| 14 | 15 | |
| 15 | 16 | public function get_logger_filename($include_hash = 0) |
| 16 | 17 | { |
| 17 | - if($include_hash) |
|
| 18 | - $filename = sprintf($this->logger_file_hash, $this->get_hash()); |
|
| 19 | - else |
|
| 20 | - $filename = sprintf($this->logger_file, $this->get_server_unique_hash(5)); |
|
| 18 | + if($include_hash) { |
|
| 19 | + $filename = sprintf($this->logger_file_hash, $this->get_hash()); |
|
| 20 | + } else { |
|
| 21 | + $filename = sprintf($this->logger_file, $this->get_server_unique_hash(5)); |
|
| 22 | + } |
|
| 21 | 23 | |
| 22 | 24 | return $filename; |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | public function get_xcloner_start_path() |
| 26 | 28 | { |
| 27 | - if(!get_option('xcloner_start_path') or !is_dir(get_option('xcloner_start_path'))) |
|
| 28 | - $path = realpath(ABSPATH); |
|
| 29 | - else |
|
| 30 | - $path = get_option('xcloner_start_path'); |
|
| 29 | + if(!get_option('xcloner_start_path') or !is_dir(get_option('xcloner_start_path'))) { |
|
| 30 | + $path = realpath(ABSPATH); |
|
| 31 | + } else { |
|
| 32 | + $path = get_option('xcloner_start_path'); |
|
| 33 | + } |
|
| 31 | 34 | |
| 32 | 35 | return $path; |
| 33 | 36 | } |
@@ -41,10 +44,11 @@ discard block |
||
| 41 | 44 | |
| 42 | 45 | public function get_xcloner_store_path() |
| 43 | 46 | { |
| 44 | - if(!get_option('xcloner_store_path') or !is_dir(get_option('xcloner_store_path'))) |
|
| 45 | - $path = realpath(XCLONER_STORAGE_PATH); |
|
| 46 | - else |
|
| 47 | - $path = get_option('xcloner_store_path'); |
|
| 47 | + if(!get_option('xcloner_store_path') or !is_dir(get_option('xcloner_store_path'))) { |
|
| 48 | + $path = realpath(XCLONER_STORAGE_PATH); |
|
| 49 | + } else { |
|
| 50 | + $path = get_option('xcloner_store_path'); |
|
| 51 | + } |
|
| 48 | 52 | |
| 49 | 53 | return $path; |
| 50 | 54 | } |
@@ -64,16 +68,18 @@ discard block |
||
| 64 | 68 | @chmod($path, 0777); |
| 65 | 69 | } |
| 66 | 70 | |
| 67 | - if(!is_dir($path) or !is_writeable($path) or get_option('xcloner_force_tmp_path_site_root')) |
|
| 68 | - $path = $this->get_xcloner_store_path().DS.".".$this->get_xcloner_tmp_path_suffix(); |
|
| 71 | + if(!is_dir($path) or !is_writeable($path) or get_option('xcloner_force_tmp_path_site_root')) { |
|
| 72 | + $path = $this->get_xcloner_store_path().DS.".".$this->get_xcloner_tmp_path_suffix(); |
|
| 73 | + } |
|
| 69 | 74 | |
| 70 | 75 | return $path; |
| 71 | 76 | } |
| 72 | 77 | |
| 73 | 78 | public function get_enable_mysql_backup() |
| 74 | 79 | { |
| 75 | - if(get_option('xcloner_enable_mysql_backup')) |
|
| 76 | - return true; |
|
| 80 | + if(get_option('xcloner_enable_mysql_backup')) { |
|
| 81 | + return true; |
|
| 82 | + } |
|
| 77 | 83 | |
| 78 | 84 | return false; |
| 79 | 85 | } |
@@ -82,10 +88,11 @@ discard block |
||
| 82 | 88 | { |
| 83 | 89 | if(!$ext) |
| 84 | 90 | { |
| 85 | - if(get_option('xcloner_backup_compression_level')) |
|
| 86 | - $ext = ".tgz"; |
|
| 87 | - else |
|
| 88 | - $ext = ".tar"; |
|
| 91 | + if(get_option('xcloner_backup_compression_level')) { |
|
| 92 | + $ext = ".tgz"; |
|
| 93 | + } else { |
|
| 94 | + $ext = ".tar"; |
|
| 95 | + } |
|
| 89 | 96 | } |
| 90 | 97 | return ($this->get_hash()).$ext; |
| 91 | 98 | } |
@@ -111,8 +118,9 @@ discard block |
||
| 111 | 118 | |
| 112 | 119 | public function set_hash($hash = "") |
| 113 | 120 | { |
| 114 | - if(substr($hash, 0, 1) != "-" and strlen($hash)) |
|
| 115 | - $hash = "-".$hash; |
|
| 121 | + if(substr($hash, 0, 1) != "-" and strlen($hash)) { |
|
| 122 | + $hash = "-".$hash; |
|
| 123 | + } |
|
| 116 | 124 | |
| 117 | 125 | $this->hash = substr( $hash, 0, 6); |
| 118 | 126 | |
@@ -132,8 +140,9 @@ discard block |
||
| 132 | 140 | { |
| 133 | 141 | global $wpdb; |
| 134 | 142 | |
| 135 | - if(!$data = get_option('xcloner_mysql_hostname')) |
|
| 136 | - $data = $wpdb->dbhost; |
|
| 143 | + if(!$data = get_option('xcloner_mysql_hostname')) { |
|
| 144 | + $data = $wpdb->dbhost; |
|
| 145 | + } |
|
| 137 | 146 | |
| 138 | 147 | return $data; |
| 139 | 148 | } |
@@ -142,8 +151,9 @@ discard block |
||
| 142 | 151 | { |
| 143 | 152 | global $wpdb; |
| 144 | 153 | |
| 145 | - if(!$data = get_option('xcloner_mysql_username')) |
|
| 146 | - $data = $wpdb->dbuser; |
|
| 154 | + if(!$data = get_option('xcloner_mysql_username')) { |
|
| 155 | + $data = $wpdb->dbuser; |
|
| 156 | + } |
|
| 147 | 157 | |
| 148 | 158 | return $data; |
| 149 | 159 | } |
@@ -152,8 +162,9 @@ discard block |
||
| 152 | 162 | { |
| 153 | 163 | global $wpdb; |
| 154 | 164 | |
| 155 | - if(!$data = get_option('xcloner_mysql_password')) |
|
| 156 | - $data = $wpdb->dbpassword; |
|
| 165 | + if(!$data = get_option('xcloner_mysql_password')) { |
|
| 166 | + $data = $wpdb->dbpassword; |
|
| 167 | + } |
|
| 157 | 168 | |
| 158 | 169 | return $data; |
| 159 | 170 | } |
@@ -162,8 +173,9 @@ discard block |
||
| 162 | 173 | { |
| 163 | 174 | global $wpdb; |
| 164 | 175 | |
| 165 | - if(!$data = get_option('xcloner_mysql_database')) |
|
| 166 | - $data = $wpdb->dbname; |
|
| 176 | + if(!$data = get_option('xcloner_mysql_database')) { |
|
| 177 | + $data = $wpdb->dbname; |
|
| 178 | + } |
|
| 167 | 179 | |
| 168 | 180 | return $data; |
| 169 | 181 | } |
@@ -186,8 +198,9 @@ discard block |
||
| 186 | 198 | { |
| 187 | 199 | $hash = md5(get_home_url().__DIR__); |
| 188 | 200 | |
| 189 | - if($strlen) |
|
| 190 | - $hash = substr($hash, 0, $strlen); |
|
| 201 | + if($strlen) { |
|
| 202 | + $hash = substr($hash, 0, $strlen); |
|
| 203 | + } |
|
| 191 | 204 | |
| 192 | 205 | return $hash; |
| 193 | 206 | } |
@@ -554,15 +567,18 @@ discard block |
||
| 554 | 567 | // text field content cb |
| 555 | 568 | public function do_form_text_field($params) |
| 556 | 569 | { |
| 557 | - if(!isset($params['3'])) |
|
| 558 | - $params[3] = 0; |
|
| 559 | - if(!isset($params['2'])) |
|
| 560 | - $params[2] = 0; |
|
| 570 | + if(!isset($params['3'])) { |
|
| 571 | + $params[3] = 0; |
|
| 572 | + } |
|
| 573 | + if(!isset($params['2'])) { |
|
| 574 | + $params[2] = 0; |
|
| 575 | + } |
|
| 561 | 576 | |
| 562 | 577 | list($fieldname, $label, $value, $disabled) = $params; |
| 563 | 578 | |
| 564 | - if(!$value) |
|
| 565 | - $value = get_option($fieldname); |
|
| 579 | + if(!$value) { |
|
| 580 | + $value = get_option($fieldname); |
|
| 581 | + } |
|
| 566 | 582 | // output the field |
| 567 | 583 | ?> |
| 568 | 584 | <div class="row"> |
@@ -581,15 +597,18 @@ discard block |
||
| 581 | 597 | // textarea field content cb |
| 582 | 598 | public function do_form_textarea_field($params) |
| 583 | 599 | { |
| 584 | - if(!isset($params['3'])) |
|
| 585 | - $params[3] = 0; |
|
| 586 | - if(!isset($params['2'])) |
|
| 587 | - $params[2] = 0; |
|
| 600 | + if(!isset($params['3'])) { |
|
| 601 | + $params[3] = 0; |
|
| 602 | + } |
|
| 603 | + if(!isset($params['2'])) { |
|
| 604 | + $params[2] = 0; |
|
| 605 | + } |
|
| 588 | 606 | |
| 589 | 607 | list($fieldname, $label, $value, $disabled) = $params; |
| 590 | 608 | |
| 591 | - if(!$value) |
|
| 592 | - $value = get_option($fieldname); |
|
| 609 | + if(!$value) { |
|
| 610 | + $value = get_option($fieldname); |
|
| 611 | + } |
|
| 593 | 612 | // output the field |
| 594 | 613 | ?> |
| 595 | 614 | <div class="row"> |
@@ -624,15 +643,18 @@ discard block |
||
| 624 | 643 | // number field content cb |
| 625 | 644 | public function do_form_number_field($params) |
| 626 | 645 | { |
| 627 | - if(!isset($params['3'])) |
|
| 628 | - $params[3] = 0; |
|
| 629 | - if(!isset($params['2'])) |
|
| 630 | - $params[2] = 0; |
|
| 646 | + if(!isset($params['3'])) { |
|
| 647 | + $params[3] = 0; |
|
| 648 | + } |
|
| 649 | + if(!isset($params['2'])) { |
|
| 650 | + $params[2] = 0; |
|
| 651 | + } |
|
| 631 | 652 | |
| 632 | 653 | list($fieldname, $label, $value, $disabled) = $params; |
| 633 | 654 | |
| 634 | - if(!$value) |
|
| 635 | - $value = get_option($fieldname); |
|
| 655 | + if(!$value) { |
|
| 656 | + $value = get_option($fieldname); |
|
| 657 | + } |
|
| 636 | 658 | // output the field |
| 637 | 659 | ?> |
| 638 | 660 | <div class="row"> |
@@ -650,8 +672,9 @@ discard block |
||
| 650 | 672 | |
| 651 | 673 | public function do_form_range_field($params) |
| 652 | 674 | { |
| 653 | - if(!isset($params['4'])) |
|
| 654 | - $params[4] = 0; |
|
| 675 | + if(!isset($params['4'])) { |
|
| 676 | + $params[4] = 0; |
|
| 677 | + } |
|
| 655 | 678 | |
| 656 | 679 | list($fieldname, $label, $range_start, $range_end, $disabled) = $params; |
| 657 | 680 | $value = get_option($fieldname); |
@@ -672,8 +695,9 @@ discard block |
||
| 672 | 695 | |
| 673 | 696 | public function do_form_switch_field($params) |
| 674 | 697 | { |
| 675 | - if(!isset($params['2'])) |
|
| 676 | - $params[2] = 0; |
|
| 698 | + if(!isset($params['2'])) { |
|
| 699 | + $params[2] = 0; |
|
| 700 | + } |
|
| 677 | 701 | list($fieldname, $label, $disabled) = $params; |
| 678 | 702 | $value = get_option($fieldname); |
| 679 | 703 | ?> |
@@ -27,8 +27,9 @@ discard block |
||
| 27 | 27 | global $wpdb; |
| 28 | 28 | |
| 29 | 29 | error_reporting(0); |
| 30 | - if( ob_get_length() ) |
|
| 31 | - ob_end_clean(); |
|
| 30 | + if( ob_get_length() ) { |
|
| 31 | + ob_end_clean(); |
|
| 32 | + } |
|
| 32 | 33 | ob_start(); |
| 33 | 34 | |
| 34 | 35 | $wpdb->show_errors = false; |
@@ -38,10 +39,11 @@ discard block |
||
| 38 | 39 | //generating the hash suffix for tmp xcloner store folder |
| 39 | 40 | if(isset($_POST['hash'])){ |
| 40 | 41 | |
| 41 | - if($_POST['hash'] == "generate_hash") |
|
| 42 | - $this->xcloner_settings->generate_new_hash(); |
|
| 43 | - else |
|
| 44 | - $this->xcloner_settings->set_hash($_POST['hash']); |
|
| 42 | + if($_POST['hash'] == "generate_hash") { |
|
| 43 | + $this->xcloner_settings->generate_new_hash(); |
|
| 44 | + } else { |
|
| 45 | + $this->xcloner_settings->set_hash($_POST['hash']); |
|
| 46 | + } |
|
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | $this->logger = new XCloner_Logger("xcloner_api", $this->xcloner_settings->get_hash()); |
@@ -78,7 +80,7 @@ discard block |
||
| 78 | 80 | //$xcloner_db = new XCloner_Database($data['dbUsername'], $data['dbPassword'], $data['dbDatabase'], $data['dbHostname']); |
| 79 | 81 | $this->xcloner_database->init($data); |
| 80 | 82 | |
| 81 | - }catch(Exception $e) |
|
| 83 | + } catch(Exception $e) |
|
| 82 | 84 | { |
| 83 | 85 | $this->send_response($e->getMessage()); |
| 84 | 86 | $this->logger->error($e->getMessage()); |
@@ -106,8 +108,9 @@ discard block |
||
| 106 | 108 | $params = array(); |
| 107 | 109 | $schedule = array(); |
| 108 | 110 | |
| 109 | - if(isset($_POST['data'])) |
|
| 110 | - $params = json_decode(stripslashes($_POST['data'])); |
|
| 111 | + if(isset($_POST['data'])) { |
|
| 112 | + $params = json_decode(stripslashes($_POST['data'])); |
|
| 113 | + } |
|
| 111 | 114 | |
| 112 | 115 | $this->process_params($params); |
| 113 | 116 | |
@@ -130,8 +133,9 @@ discard block |
||
| 130 | 133 | { |
| 131 | 134 | $table = str_replace("\r","", $table); |
| 132 | 135 | $data = explode(".", $table); |
| 133 | - if(isset($data[1])) |
|
| 134 | - $return[$data[0]][] = $data[1]; |
|
| 136 | + if(isset($data[1])) { |
|
| 137 | + $return[$data[0]][] = $data[1]; |
|
| 138 | + } |
|
| 135 | 139 | } |
| 136 | 140 | |
| 137 | 141 | $this->form_params['database'] = ($return); |
@@ -142,8 +146,9 @@ discard block |
||
| 142 | 146 | foreach($excluded_files as $file) |
| 143 | 147 | { |
| 144 | 148 | $file = str_replace("\r","", $file); |
| 145 | - if($file) |
|
| 146 | - $return[] = $file; |
|
| 149 | + if($file) { |
|
| 150 | + $return[] = $file; |
|
| 151 | + } |
|
| 147 | 152 | } |
| 148 | 153 | |
| 149 | 154 | $this->form_params['excluded_files'] = ($return); |
@@ -153,19 +158,21 @@ discard block |
||
| 153 | 158 | |
| 154 | 159 | $schedule['start_at'] = $this->form_params['backup_params']['start_at'] ; |
| 155 | 160 | |
| 156 | - if(!isset($_POST['status'])) |
|
| 157 | - $schedule['status'] = 0; |
|
| 158 | - else |
|
| 159 | - $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
|
| 160 | - }else{ |
|
| 161 | + if(!isset($_POST['status'])) { |
|
| 162 | + $schedule['status'] = 0; |
|
| 163 | + } else { |
|
| 164 | + $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
|
| 165 | + } |
|
| 166 | + } else{ |
|
| 161 | 167 | |
| 162 | 168 | $schedule['status'] = 1; |
| 163 | 169 | $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
| 164 | 170 | " ".$this->form_params['backup_params']['schedule_start_time']); |
| 165 | 171 | } |
| 166 | 172 | |
| 167 | - if(!$schedule['start_at']) |
|
| 168 | - $schedule['start_at'] = time(); |
|
| 173 | + if(!$schedule['start_at']) { |
|
| 174 | + $schedule['start_at'] = time(); |
|
| 175 | + } |
|
| 169 | 176 | |
| 170 | 177 | $schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at']); |
| 171 | 178 | |
@@ -185,7 +192,7 @@ discard block |
||
| 185 | 192 | '%s' |
| 186 | 193 | ) |
| 187 | 194 | ); |
| 188 | - }else { |
|
| 195 | + } else { |
|
| 189 | 196 | $insert = $wpdb->update( |
| 190 | 197 | $wpdb->prefix.'xcloner_scheduler', |
| 191 | 198 | $schedule, |
@@ -196,8 +203,9 @@ discard block |
||
| 196 | 203 | ) |
| 197 | 204 | ); |
| 198 | 205 | } |
| 199 | - if(isset($_POST['id'])) |
|
| 200 | - $scheduler->update_cron_hook($_POST['id']); |
|
| 206 | + if(isset($_POST['id'])) { |
|
| 207 | + $scheduler->update_cron_hook($_POST['id']); |
|
| 208 | + } |
|
| 201 | 209 | |
| 202 | 210 | if( $wpdb->last_error ) { |
| 203 | 211 | $response['error'] = 1; |
@@ -226,8 +234,9 @@ discard block |
||
| 226 | 234 | |
| 227 | 235 | $init = (int)$_POST['init']; |
| 228 | 236 | |
| 229 | - if($params === NULL) |
|
| 230 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 237 | + if($params === NULL) { |
|
| 238 | + die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 239 | + } |
|
| 231 | 240 | |
| 232 | 241 | $this->process_params($params); |
| 233 | 242 | |
@@ -236,7 +245,7 @@ discard block |
||
| 236 | 245 | //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
| 237 | 246 | try{ |
| 238 | 247 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
| 239 | - }catch(Exception $e) |
|
| 248 | + } catch(Exception $e) |
|
| 240 | 249 | { |
| 241 | 250 | $return = array(); |
| 242 | 251 | $return['error'] = true; |
@@ -248,8 +257,9 @@ discard block |
||
| 248 | 257 | if($return['finished']) |
| 249 | 258 | { |
| 250 | 259 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
| 251 | - if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
| 252 | - $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
|
| 260 | + if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) { |
|
| 261 | + $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
|
| 262 | + } |
|
| 253 | 263 | } |
| 254 | 264 | |
| 255 | 265 | $data = $return; |
@@ -263,7 +273,7 @@ discard block |
||
| 263 | 273 | $from = ""; |
| 264 | 274 | $subject = ""; |
| 265 | 275 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params); |
| 266 | - }catch(Exception $e) |
|
| 276 | + } catch(Exception $e) |
|
| 267 | 277 | { |
| 268 | 278 | $this->logger->error($e->getMessage()); |
| 269 | 279 | } |
@@ -289,18 +299,20 @@ discard block |
||
| 289 | 299 | |
| 290 | 300 | $init = (int)$_POST['init']; |
| 291 | 301 | |
| 292 | - if($params === NULL) |
|
| 293 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 302 | + if($params === NULL) { |
|
| 303 | + die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 304 | + } |
|
| 294 | 305 | |
| 295 | 306 | $this->process_params($params); |
| 296 | 307 | |
| 297 | 308 | //$xcloner_database = $this->init_db(); |
| 298 | 309 | $return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init); |
| 299 | 310 | |
| 300 | - if(isset($return['error']) and $return['error']) |
|
| 301 | - $data['finished'] = 1; |
|
| 302 | - else |
|
| 303 | - $data['finished'] = $return['finished']; |
|
| 311 | + if(isset($return['error']) and $return['error']) { |
|
| 312 | + $data['finished'] = 1; |
|
| 313 | + } else { |
|
| 314 | + $data['finished'] = $return['finished']; |
|
| 315 | + } |
|
| 304 | 316 | |
| 305 | 317 | $data['extra'] = $return; |
| 306 | 318 | |
@@ -321,8 +333,9 @@ discard block |
||
| 321 | 333 | $params = json_decode(stripslashes($_POST['data'])); |
| 322 | 334 | $init = (int)$_POST['init']; |
| 323 | 335 | |
| 324 | - if($params === NULL) |
|
| 325 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 336 | + if($params === NULL) { |
|
| 337 | + die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
| 338 | + } |
|
| 326 | 339 | |
| 327 | 340 | $hash = $this->process_params($params); |
| 328 | 341 | |
@@ -345,8 +358,9 @@ discard block |
||
| 345 | 358 | */ |
| 346 | 359 | private function process_params($params) |
| 347 | 360 | { |
| 348 | - if(isset($params->hash)) |
|
| 349 | - $this->xcloner_settings->set_hash($params->hash); |
|
| 361 | + if(isset($params->hash)) { |
|
| 362 | + $this->xcloner_settings->set_hash($params->hash); |
|
| 363 | + } |
|
| 350 | 364 | |
| 351 | 365 | $this->form_params['extra'] = array(); |
| 352 | 366 | $this->form_params['backup_params'] = array(); |
@@ -399,8 +413,9 @@ discard block |
||
| 399 | 413 | |
| 400 | 414 | if(isset($params->extra)) |
| 401 | 415 | { |
| 402 | - foreach($params->extra as $key=>$value) |
|
| 403 | - $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
|
| 416 | + foreach($params->extra as $key=>$value) { |
|
| 417 | + $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
|
| 418 | + } |
|
| 404 | 419 | } |
| 405 | 420 | |
| 406 | 421 | return $this->xcloner_settings->get_hash(); |
@@ -437,7 +452,7 @@ discard block |
||
| 437 | 452 | |
| 438 | 453 | try{ |
| 439 | 454 | $files = $this->xcloner_file_system->list_directory($folder); |
| 440 | - }catch(Exception $e){ |
|
| 455 | + } catch(Exception $e){ |
|
| 441 | 456 | |
| 442 | 457 | print $e->getMessage(); |
| 443 | 458 | $this->logger->error($e->getMessage()); |
@@ -457,17 +472,19 @@ discard block |
||
| 457 | 472 | $children = false; |
| 458 | 473 | $text = $file['basename']; |
| 459 | 474 | |
| 460 | - if($file['type'] == "dir") |
|
| 461 | - $children = true; |
|
| 462 | - else |
|
| 463 | - $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; |
|
| 475 | + if($file['type'] == "dir") { |
|
| 476 | + $children = true; |
|
| 477 | + } else { |
|
| 478 | + $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; |
|
| 479 | + } |
|
| 464 | 480 | |
| 465 | 481 | //if(in_array($file['path'], $this->xcloner_file_system->get_excluded_files())) |
| 466 | 482 | //echo $file['path']."--".$this->xcloner_file_system->is_excluded($file); |
| 467 | - if($excluded_pattern = $this->xcloner_file_system->is_excluded($file)) |
|
| 468 | - $selected = true; |
|
| 469 | - else |
|
| 470 | - $selected = false; |
|
| 483 | + if($excluded_pattern = $this->xcloner_file_system->is_excluded($file)) { |
|
| 484 | + $selected = true; |
|
| 485 | + } else { |
|
| 486 | + $selected = false; |
|
| 487 | + } |
|
| 471 | 488 | |
| 472 | 489 | $data[] = array( |
| 473 | 490 | 'id' => $file['path'], |
@@ -505,22 +522,24 @@ discard block |
||
| 505 | 522 | { |
| 506 | 523 | try{ |
| 507 | 524 | $return = $this->xcloner_database->get_all_databases(); |
| 508 | - }catch(Exception $e){ |
|
| 525 | + } catch(Exception $e){ |
|
| 509 | 526 | $this->logger->error($e->getMessage()); |
| 510 | 527 | } |
| 511 | 528 | |
| 512 | 529 | foreach($return as $database) |
| 513 | 530 | { |
| 514 | - if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) |
|
| 515 | - continue; |
|
| 531 | + if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) { |
|
| 532 | + continue; |
|
| 533 | + } |
|
| 516 | 534 | |
| 517 | 535 | $state = array(); |
| 518 | 536 | |
| 519 | 537 | if($database['name'] == $this->xcloner_settings->get_db_database()) |
| 520 | 538 | { |
| 521 | 539 | $state['selected'] = true; |
| 522 | - if($database['num_tables'] < 25) |
|
| 523 | - $state['opened'] = false; |
|
| 540 | + if($database['num_tables'] < 25) { |
|
| 541 | + $state['opened'] = false; |
|
| 542 | + } |
|
| 524 | 543 | } |
| 525 | 544 | |
| 526 | 545 | $data[] = array( |
@@ -533,13 +552,11 @@ discard block |
||
| 533 | 552 | ); |
| 534 | 553 | } |
| 535 | 554 | |
| 536 | - } |
|
| 537 | - |
|
| 538 | - else{ |
|
| 555 | + } else{ |
|
| 539 | 556 | |
| 540 | 557 | try{ |
| 541 | 558 | $return = $this->xcloner_database->list_tables($database, "", 1); |
| 542 | - }catch(Exception $e){ |
|
| 559 | + } catch(Exception $e){ |
|
| 543 | 560 | $this->logger->error($e->getMessage()); |
| 544 | 561 | } |
| 545 | 562 | |
@@ -547,11 +564,13 @@ discard block |
||
| 547 | 564 | { |
| 548 | 565 | $state = array(); |
| 549 | 566 | |
| 550 | - if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) |
|
| 551 | - continue; |
|
| 567 | + if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) { |
|
| 568 | + continue; |
|
| 569 | + } |
|
| 552 | 570 | |
| 553 | - if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) |
|
| 554 | - $state = array('selected' => true); |
|
| 571 | + if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) { |
|
| 572 | + $state = array('selected' => true); |
|
| 573 | + } |
|
| 555 | 574 | |
| 556 | 575 | $data[] = array( |
| 557 | 576 | 'id' => $table['name'], |
@@ -604,10 +623,11 @@ discard block |
||
| 604 | 623 | { |
| 605 | 624 | $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
| 606 | 625 | <a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
| 607 | - if($res->status) |
|
| 608 | - $status = '<i class="material-icons active status">timer</i>'; |
|
| 609 | - else |
|
| 610 | - $status = '<i class="material-icons status inactive">timer_off</i>'; |
|
| 626 | + if($res->status) { |
|
| 627 | + $status = '<i class="material-icons active status">timer</i>'; |
|
| 628 | + } else { |
|
| 629 | + $status = '<i class="material-icons status inactive">timer_off</i>'; |
|
| 630 | + } |
|
| 611 | 631 | |
| 612 | 632 | $next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)); |
| 613 | 633 | |
@@ -615,17 +635,19 @@ discard block |
||
| 615 | 635 | |
| 616 | 636 | $remote_storage = $res->remote_storage; |
| 617 | 637 | |
| 618 | - if(!$next_run_time >= time()) |
|
| 619 | - $next_run = " "; |
|
| 638 | + if(!$next_run_time >= time()) { |
|
| 639 | + $next_run = " "; |
|
| 640 | + } |
|
| 620 | 641 | |
| 621 | 642 | if(trim($next_run)) |
| 622 | 643 | { |
| 623 | 644 | $date_text = $next_run; |
| 624 | 645 | |
| 625 | - if($next_run_time >= time()) |
|
| 626 | - $next_run = "in ".human_time_diff($next_run_time, time()); |
|
| 627 | - else |
|
| 628 | - $next_run = __("executed", 'xcloner-backup-and-restore'); |
|
| 646 | + if($next_run_time >= time()) { |
|
| 647 | + $next_run = "in ".human_time_diff($next_run_time, time()); |
|
| 648 | + } else { |
|
| 649 | + $next_run = __("executed", 'xcloner-backup-and-restore'); |
|
| 650 | + } |
|
| 629 | 651 | |
| 630 | 652 | $next_run = "<a href='#' title='".$date_text."'>".$next_run."</a>"; |
| 631 | 653 | //$next_run .=" ($date_text)"; |
@@ -712,7 +734,7 @@ discard block |
||
| 712 | 734 | $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); |
| 713 | 735 | |
| 714 | 736 | $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
| 715 | - }catch(Exception $e) |
|
| 737 | + } catch(Exception $e) |
|
| 716 | 738 | { |
| 717 | 739 | $return['error'] = true; |
| 718 | 740 | $return['message'] = $e->getMessage(); |
@@ -740,15 +762,16 @@ discard block |
||
| 740 | 762 | { |
| 741 | 763 | $return['start'] = $data['start']; |
| 742 | 764 | $return['finished'] = 0; |
| 743 | - }else{ |
|
| 765 | + } else{ |
|
| 744 | 766 | if($this->xcloner_file_system->is_multipart($source_backup_file)) |
| 745 | 767 | { |
| 746 | 768 | $return['start'] = 0; |
| 747 | 769 | |
| 748 | 770 | ++$return['part']; |
| 749 | 771 | |
| 750 | - if($return['part'] < sizeof($backup_parts)) |
|
| 751 | - $return['finished'] = 0; |
|
| 772 | + if($return['part'] < sizeof($backup_parts)) { |
|
| 773 | + $return['finished'] = 0; |
|
| 774 | + } |
|
| 752 | 775 | |
| 753 | 776 | } |
| 754 | 777 | } |
@@ -780,7 +803,7 @@ discard block |
||
| 780 | 803 | { |
| 781 | 804 | $return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type)); |
| 782 | 805 | } |
| 783 | - }catch(Exception $e){ |
|
| 806 | + } catch(Exception $e){ |
|
| 784 | 807 | |
| 785 | 808 | $return['error'] = 1; |
| 786 | 809 | $return['message'] = $e->getMessage(); |
@@ -925,11 +948,13 @@ discard block |
||
| 925 | 948 | $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
| 926 | 949 | $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']); |
| 927 | 950 | |
| 928 | - if(isset($_POST['part'])) |
|
| 929 | - $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
| 951 | + if(isset($_POST['part'])) { |
|
| 952 | + $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
|
| 953 | + } |
|
| 930 | 954 | |
| 931 | - if(isset($_POST['uploaded_size'])) |
|
| 932 | - $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
|
| 955 | + if(isset($_POST['uploaded_size'])) { |
|
| 956 | + $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
|
| 957 | + } |
|
| 933 | 958 | |
| 934 | 959 | $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']); |
| 935 | 960 | $target_url = $this->xcloner_sanitization->sanitize_input_as_string($_POST['target_url']); |
@@ -956,7 +981,7 @@ discard block |
||
| 956 | 981 | $xcloner_file_transfer->set_target($target_url); |
| 957 | 982 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
| 958 | 983 | |
| 959 | - }catch(Exception $e){ |
|
| 984 | + } catch(Exception $e){ |
|
| 960 | 985 | |
| 961 | 986 | $return = array(); |
| 962 | 987 | $return['error'] = true; |
@@ -990,8 +1015,9 @@ discard block |
||
| 990 | 1015 | $data['hash'] = $this->xcloner_settings->get_hash(); |
| 991 | 1016 | } |
| 992 | 1017 | |
| 993 | - if( ob_get_length() ) |
|
| 994 | - ob_clean(); |
|
| 1018 | + if( ob_get_length() ) { |
|
| 1019 | + ob_clean(); |
|
| 1020 | + } |
|
| 995 | 1021 | wp_send_json($data); |
| 996 | 1022 | |
| 997 | 1023 | die(); |
@@ -44,11 +44,13 @@ discard block |
||
| 44 | 44 | $this->xcloner_settings = new Xcloner_Settings($hash); |
| 45 | 45 | $this->fs = new Xcloner_File_System($hash); |
| 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 | $wp_host = $this->xcloner_settings->get_db_hostname(); |
| 54 | 56 | $wp_user = $this->xcloner_settings->get_db_username(); |
@@ -105,37 +107,43 @@ discard block |
||
| 105 | 107 | { |
| 106 | 108 | foreach($params['#'] as $database) |
| 107 | 109 | { |
| 108 | - if(!isset($params[$database]) or !is_array($params[$database])) |
|
| 109 | - $params[$database] = array(); |
|
| 110 | + if(!isset($params[$database]) or !is_array($params[$database])) { |
|
| 111 | + $params[$database] = array(); |
|
| 112 | + } |
|
| 110 | 113 | } |
| 111 | 114 | $db_count = -1; |
| 112 | 115 | } |
| 113 | 116 | |
| 114 | - if(isset($params) and is_array($params)) |
|
| 115 | - foreach($params as $database=>$tables) |
|
| 117 | + if(isset($params) and is_array($params)) { |
|
| 118 | + foreach($params as $database=>$tables) |
|
| 116 | 119 | { |
| 117 | 120 | if($database != "#") |
| 118 | 121 | { |
| 119 | - $stats = $this->write_backup_process_list($database, $tables); |
|
| 122 | + $stats = $this->write_backup_process_list($database, $tables); |
|
| 123 | + } |
|
| 120 | 124 | $return['stats']['tables_count'] += $stats['tables_count']; |
| 121 | 125 | $return['stats']['total_records'] += $stats['total_records']; |
| 122 | 126 | } |
| 123 | 127 | } |
| 124 | 128 | |
| 125 | - if(sizeof($params)) |
|
| 126 | - $return['stats']['database_count'] = sizeof($params)+$db_count; |
|
| 127 | - else |
|
| 128 | - $return['stats']['database_count'] = 0; |
|
| 129 | + if(sizeof($params)) { |
|
| 130 | + $return['stats']['database_count'] = sizeof($params)+$db_count; |
|
| 131 | + } else { |
|
| 132 | + $return['stats']['database_count'] = 0; |
|
| 133 | + } |
|
| 129 | 134 | |
| 130 | 135 | return $return; |
| 131 | 136 | } |
| 132 | 137 | |
| 133 | - if(!isset($extra_params['startAtLine'])) |
|
| 134 | - $extra_params['startAtLine'] = 0; |
|
| 135 | - if(!isset($extra_params['startAtRecord'])) |
|
| 136 | - $extra_params['startAtRecord'] = 0; |
|
| 137 | - if(!isset($extra_params['dumpfile'])) |
|
| 138 | - $extra_params['dumpfile'] = ""; |
|
| 138 | + if(!isset($extra_params['startAtLine'])) { |
|
| 139 | + $extra_params['startAtLine'] = 0; |
|
| 140 | + } |
|
| 141 | + if(!isset($extra_params['startAtRecord'])) { |
|
| 142 | + $extra_params['startAtRecord'] = 0; |
|
| 143 | + } |
|
| 144 | + if(!isset($extra_params['dumpfile'])) { |
|
| 145 | + $extra_params['dumpfile'] = ""; |
|
| 146 | + } |
|
| 139 | 147 | |
| 140 | 148 | $return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']); |
| 141 | 149 | |
@@ -147,11 +155,13 @@ discard block |
||
| 147 | 155 | |
| 148 | 156 | if($message){ |
| 149 | 157 | $this->logger->info( $message, array("")); |
| 150 | - }else{ |
|
| 151 | - if($this->last_query) |
|
| 152 | - $this->logger->debug( $this->last_query, array("")); |
|
| 153 | - if($this->last_error) |
|
| 154 | - $this->logger->error( $this->last_error, array("")); |
|
| 158 | + } else{ |
|
| 159 | + if($this->last_query) { |
|
| 160 | + $this->logger->debug( $this->last_query, array("")); |
|
| 161 | + } |
|
| 162 | + if($this->last_error) { |
|
| 163 | + $this->logger->error( $this->last_error, array("")); |
|
| 164 | + } |
|
| 155 | 165 | } |
| 156 | 166 | |
| 157 | 167 | return; |
@@ -222,11 +232,12 @@ discard block |
||
| 222 | 232 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname); |
| 223 | 233 | $i++; |
| 224 | 234 | |
| 225 | - if(is_array($databases)) |
|
| 226 | - foreach( $databases as $db){ |
|
| 235 | + if(is_array($databases)) { |
|
| 236 | + foreach( $databases as $db){ |
|
| 227 | 237 | if($db->Database != $this->dbname) |
| 228 | 238 | { |
| 229 | 239 | $databases_list[$i]['name'] = $db->Database; |
| 240 | + } |
|
| 230 | 241 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database); |
| 231 | 242 | $i++; |
| 232 | 243 | } |
@@ -247,8 +258,9 @@ discard block |
||
| 247 | 258 | $tablesList[0] = array( ); |
| 248 | 259 | $inc = 0; |
| 249 | 260 | |
| 250 | - if(!$database) |
|
| 251 | - $database = $this->dbname; |
|
| 261 | + if(!$database) { |
|
| 262 | + $database = $this->dbname; |
|
| 263 | + } |
|
| 252 | 264 | |
| 253 | 265 | $this->logger->debug(sprintf(("Listing tables in %s database"), $database)); |
| 254 | 266 | |
@@ -272,10 +284,11 @@ discard block |
||
| 272 | 284 | |
| 273 | 285 | $tablesList[$inc]['excluded'] = 0; |
| 274 | 286 | |
| 275 | - if(sizeof($included) and is_array($included)) |
|
| 276 | - if(!in_array($table, $included) ) |
|
| 287 | + if(sizeof($included) and is_array($included)) { |
|
| 288 | + if(!in_array($table, $included) ) |
|
| 277 | 289 | { |
| 278 | 290 | $tablesList[$inc]['excluded'] = 1; |
| 291 | + } |
|
| 279 | 292 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
| 280 | 293 | } |
| 281 | 294 | $inc++; |
@@ -294,19 +307,21 @@ discard block |
||
| 294 | 307 | |
| 295 | 308 | $tables = $this->list_tables($dbname, $incl_tables, 1); |
| 296 | 309 | |
| 297 | - if($this->dbname != $dbname) |
|
| 298 | - $dumpfile = $dbname."-backup.sql"; |
|
| 299 | - else |
|
| 300 | - $dumpfile = $this->TEMP_DUMP_FILE; |
|
| 310 | + if($this->dbname != $dbname) { |
|
| 311 | + $dumpfile = $dbname."-backup.sql"; |
|
| 312 | + } else { |
|
| 313 | + $dumpfile = $this->TEMP_DUMP_FILE; |
|
| 314 | + } |
|
| 301 | 315 | |
| 302 | 316 | $line = sprintf("###newdump###\t%s\t%s\n", $dbname, $dumpfile); |
| 303 | 317 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
| 304 | 318 | |
| 305 | 319 | // write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records |
| 306 | - foreach($tables as $key=>$table) |
|
| 307 | - if($table!= "" and !$tables[$key]['excluded']){ |
|
| 320 | + foreach($tables as $key=>$table) { |
|
| 321 | + if($table!= "" and !$tables[$key]['excluded']){ |
|
| 308 | 322 | |
| 309 | 323 | $line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']); |
| 324 | + } |
|
| 310 | 325 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
| 311 | 326 | $return['tables_count']++; |
| 312 | 327 | $return['total_records'] += $tables[$key]['records']; |
@@ -354,8 +369,9 @@ discard block |
||
| 354 | 369 | $return['finished'] = 0; |
| 355 | 370 | $lines = array(); |
| 356 | 371 | |
| 357 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 358 | - $lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
| 372 | + if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
| 373 | + $lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
| 374 | + } |
|
| 359 | 375 | |
| 360 | 376 | foreach ($lines as $buffer){ |
| 361 | 377 | |
@@ -380,14 +396,16 @@ discard block |
||
| 380 | 396 | $startAtLine++; |
| 381 | 397 | $return['new_dump'] = 1; |
| 382 | 398 | //break; |
| 383 | - }else{ |
|
| 399 | + } else{ |
|
| 384 | 400 | //we export the table |
| 385 | - if($tableInfo[0] == "###enddump###") |
|
| 386 | - $return['endDump'] = 1; |
|
| 401 | + if($tableInfo[0] == "###enddump###") { |
|
| 402 | + $return['endDump'] = 1; |
|
| 403 | + } |
|
| 387 | 404 | |
| 388 | 405 | //table is excluded |
| 389 | - if($tableInfo[2]) |
|
| 390 | - continue; |
|
| 406 | + if($tableInfo[2]) { |
|
| 407 | + continue; |
|
| 408 | + } |
|
| 391 | 409 | |
| 392 | 410 | $next = $startAtRecord + $this->recordsPerSession; |
| 393 | 411 | |
@@ -404,16 +422,19 @@ discard block |
||
| 404 | 422 | //if(intval($return['totalRecords']) != 0) |
| 405 | 423 | //print_r($tableInfo); |
| 406 | 424 | |
| 407 | - if(trim($tableName) !="" and !$tableInfo[2]) |
|
| 408 | - $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
|
| 425 | + if(trim($tableName) !="" and !$tableInfo[2]) { |
|
| 426 | + $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
|
| 427 | + } |
|
| 409 | 428 | |
| 410 | 429 | $return['processedRecords'] = $startAtRecord+$processed_records; |
| 411 | 430 | |
| 412 | - if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
| 431 | + if($next >= $tableInfo[1]) { |
|
| 432 | + //we finished loading the records for next sessions, will go to the new record |
|
| 413 | 433 | { |
| 414 | 434 | $startAtLine ++; |
| 435 | + } |
|
| 415 | 436 | $startAtRecord = 0; |
| 416 | - }else{ |
|
| 437 | + } else{ |
|
| 417 | 438 | $startAtRecord = $startAtRecord + $this->recordsPerSession; |
| 418 | 439 | } |
| 419 | 440 | |
@@ -446,8 +467,9 @@ discard block |
||
| 446 | 467 | $return['finished'] = 1; |
| 447 | 468 | $return['startAtLine'] = $startAtLine; |
| 448 | 469 | |
| 449 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
| 450 | - $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
|
| 470 | + if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
| 471 | + $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
|
| 472 | + } |
|
| 451 | 473 | |
| 452 | 474 | $this->logger->debug(sprintf(("Database backup finished!"))); |
| 453 | 475 | |
@@ -475,8 +497,9 @@ discard block |
||
| 475 | 497 | |
| 476 | 498 | $records = 0; |
| 477 | 499 | |
| 478 | - if($start == 0) |
|
| 479 | - $this->dump_structure($databaseName, $tableName, $dumpfile); |
|
| 500 | + if($start == 0) { |
|
| 501 | + $this->dump_structure($databaseName, $tableName, $dumpfile); |
|
| 502 | + } |
|
| 480 | 503 | |
| 481 | 504 | $start = intval($start); |
| 482 | 505 | $limit = intval($limit); |
@@ -488,7 +511,7 @@ discard block |
||
| 488 | 511 | $result = mysqli_query($this->dbh, $query); |
| 489 | 512 | $mysql_fetch_function = "mysqli_fetch_array"; |
| 490 | 513 | |
| 491 | - }else{ |
|
| 514 | + } else{ |
|
| 492 | 515 | $result = mysql_query($query, $this->dbh); |
| 493 | 516 | $mysql_fetch_function = "mysql_fetch_array"; |
| 494 | 517 | } |
@@ -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 | } |
@@ -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 | |
@@ -59,13 +59,14 @@ discard block |
||
| 59 | 59 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
| 60 | 60 | 'disable_asserts' => true, |
| 61 | 61 | ])); |
| 62 | - }catch(Exception $e){ |
|
| 62 | + } catch(Exception $e){ |
|
| 63 | 63 | return false; |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | |
| 67 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
| 68 | - $this->folders_to_process_per_session = $value; |
|
| 67 | + if($value = get_option('xcloner_directories_to_scan_per_request')) { |
|
| 68 | + $this->folders_to_process_per_session = $value; |
|
| 69 | + } |
|
| 69 | 70 | |
| 70 | 71 | } |
| 71 | 72 | |
@@ -128,8 +129,9 @@ discard block |
||
| 128 | 129 | public function get_included_files_handler($metadata = 0) |
| 129 | 130 | { |
| 130 | 131 | $path = $this->included_files_handler; |
| 131 | - if(!$metadata) |
|
| 132 | - return $path; |
|
| 132 | + if(!$metadata) { |
|
| 133 | + return $path; |
|
| 134 | + } |
|
| 133 | 135 | |
| 134 | 136 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
| 135 | 137 | return $spl_info; |
@@ -145,31 +147,36 @@ discard block |
||
| 145 | 147 | { |
| 146 | 148 | $files = $this->get_backup_archives_list(); |
| 147 | 149 | |
| 148 | - if(is_array($files)) |
|
| 149 | - $this->sort_by($files, "timestamp","desc"); |
|
| 150 | + if(is_array($files)) { |
|
| 151 | + $this->sort_by($files, "timestamp","desc"); |
|
| 152 | + } |
|
| 150 | 153 | |
| 151 | 154 | $new_list = array(); |
| 152 | 155 | |
| 153 | - foreach($files as $key=>$file) |
|
| 154 | - if(!isset($file['parent'])) |
|
| 156 | + foreach($files as $key=>$file) { |
|
| 157 | + if(!isset($file['parent'])) |
|
| 155 | 158 | $new_list[] = ($files[$key]); |
| 159 | + } |
|
| 156 | 160 | |
| 157 | - if(isset($new_list[0])) |
|
| 158 | - return $new_list[0]; |
|
| 161 | + if(isset($new_list[0])) { |
|
| 162 | + return $new_list[0]; |
|
| 163 | + } |
|
| 159 | 164 | } |
| 160 | 165 | |
| 161 | 166 | public function get_latest_backups() |
| 162 | 167 | { |
| 163 | 168 | $files = $this->get_backup_archives_list(); |
| 164 | 169 | |
| 165 | - if(is_array($files)) |
|
| 166 | - $this->sort_by($files, "timestamp","desc"); |
|
| 170 | + if(is_array($files)) { |
|
| 171 | + $this->sort_by($files, "timestamp","desc"); |
|
| 172 | + } |
|
| 167 | 173 | |
| 168 | 174 | $new_list = array(); |
| 169 | 175 | |
| 170 | - foreach($files as $key=>$file) |
|
| 171 | - if(!isset($file['parent'])) |
|
| 176 | + foreach($files as $key=>$file) { |
|
| 177 | + if(!isset($file['parent'])) |
|
| 172 | 178 | $new_list[] = ($files[$key]); |
| 179 | + } |
|
| 173 | 180 | |
| 174 | 181 | return $new_list; |
| 175 | 182 | } |
@@ -179,25 +186,28 @@ discard block |
||
| 179 | 186 | $files = $this->get_backup_archives_list(); |
| 180 | 187 | $total = 0; |
| 181 | 188 | |
| 182 | - if(is_array($files)) |
|
| 183 | - foreach($files as $file) |
|
| 189 | + if(is_array($files)) { |
|
| 190 | + foreach($files as $file) |
|
| 184 | 191 | $total += $file['size']; |
| 192 | + } |
|
| 185 | 193 | |
| 186 | 194 | return $total; |
| 187 | 195 | } |
| 188 | 196 | |
| 189 | 197 | public function is_part($backup_name) |
| 190 | 198 | { |
| 191 | - if(stristr($backup_name, "-part")) |
|
| 192 | - return true; |
|
| 199 | + if(stristr($backup_name, "-part")) { |
|
| 200 | + return true; |
|
| 201 | + } |
|
| 193 | 202 | |
| 194 | 203 | return false; |
| 195 | 204 | } |
| 196 | 205 | |
| 197 | 206 | public function is_multipart($backup_name) |
| 198 | 207 | { |
| 199 | - if(stristr($backup_name, "-multipart")) |
|
| 200 | - return true; |
|
| 208 | + if(stristr($backup_name, "-multipart")) { |
|
| 209 | + return true; |
|
| 210 | + } |
|
| 201 | 211 | |
| 202 | 212 | return false; |
| 203 | 213 | } |
@@ -208,8 +218,9 @@ discard block |
||
| 208 | 218 | if($this->is_multipart($backup_name)) |
| 209 | 219 | { |
| 210 | 220 | $backup_parts = $this->get_multipart_files($backup_name); |
| 211 | - foreach($backup_parts as $part_file) |
|
| 212 | - $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
| 221 | + foreach($backup_parts as $part_file) { |
|
| 222 | + $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
|
| 223 | + } |
|
| 213 | 224 | } |
| 214 | 225 | |
| 215 | 226 | return $backup_size; |
@@ -250,10 +261,11 @@ discard block |
||
| 250 | 261 | } |
| 251 | 262 | } |
| 252 | 263 | |
| 253 | - if($this->get_storage_filesystem()->delete($backup_name)) |
|
| 254 | - $return = true; |
|
| 255 | - else |
|
| 256 | - $return = false; |
|
| 264 | + if($this->get_storage_filesystem()->delete($backup_name)) { |
|
| 265 | + $return = true; |
|
| 266 | + } else { |
|
| 267 | + $return = false; |
|
| 268 | + } |
|
| 257 | 269 | |
| 258 | 270 | return $return; |
| 259 | 271 | } |
@@ -271,8 +283,9 @@ discard block |
||
| 271 | 283 | { |
| 272 | 284 | $list = array(); |
| 273 | 285 | |
| 274 | - if(method_exists($this->get_storage_filesystem(), "listContents")) |
|
| 275 | - $list = $this->get_storage_filesystem()->listContents(); |
|
| 286 | + if(method_exists($this->get_storage_filesystem(), "listContents")) { |
|
| 287 | + $list = $this->get_storage_filesystem()->listContents(); |
|
| 288 | + } |
|
| 276 | 289 | |
| 277 | 290 | |
| 278 | 291 | $backup_files = array(); |
@@ -285,10 +298,11 @@ discard block |
||
| 285 | 298 | if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
| 286 | 299 | { |
| 287 | 300 | $lines = explode(PHP_EOL, $this->get_storage_filesystem()->read($file_info['path'])); |
| 288 | - foreach($lines as $line) |
|
| 289 | - if($line) |
|
| 301 | + foreach($lines as $line) { |
|
| 302 | + if($line) |
|
| 290 | 303 | { |
| 291 | 304 | $data = str_getcsv($line); |
| 305 | + } |
|
| 292 | 306 | if(is_array($data)){ |
| 293 | 307 | $parents[$data[0]] = $file_info['path']; |
| 294 | 308 | $file_info['childs'][] = $data; |
@@ -298,14 +312,16 @@ discard block |
||
| 298 | 312 | |
| 299 | 313 | } |
| 300 | 314 | |
| 301 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
| 302 | - $backup_files[$file_info['path']] = $file_info; |
|
| 315 | + if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) { |
|
| 316 | + $backup_files[$file_info['path']] = $file_info; |
|
| 317 | + } |
|
| 303 | 318 | } |
| 304 | 319 | |
| 305 | 320 | foreach($backup_files as $key=>$file_info) |
| 306 | 321 | { |
| 307 | - if(isset($parents[$file_info['path']])) |
|
| 308 | - $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 322 | + if(isset($parents[$file_info['path']])) { |
|
| 323 | + $backup_files[$key]['parent'] = $parents[$file_info['path']]; |
|
| 324 | + } |
|
| 309 | 325 | } |
| 310 | 326 | |
| 311 | 327 | return $backup_files; |
@@ -331,11 +347,11 @@ discard block |
||
| 331 | 347 | if($counter < $this->folders_to_process_per_session){ |
| 332 | 348 | $this->build_files_list($file); |
| 333 | 349 | $counter++; |
| 334 | - }else{ |
|
| 350 | + } else{ |
|
| 335 | 351 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
| 336 | 352 | } |
| 337 | 353 | } |
| 338 | - }else{ |
|
| 354 | + } else{ |
|
| 339 | 355 | $this->build_files_list(); |
| 340 | 356 | } |
| 341 | 357 | |
@@ -377,8 +393,9 @@ discard block |
||
| 377 | 393 | { |
| 378 | 394 | $return = array(); |
| 379 | 395 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
| 380 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 381 | - $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
| 396 | + if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
| 397 | + $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
|
| 398 | + } |
|
| 382 | 399 | |
| 383 | 400 | return $return; |
| 384 | 401 | } |
@@ -390,9 +407,10 @@ discard block |
||
| 390 | 407 | |
| 391 | 408 | $contents = $this->get_tmp_filesystem()->listContents(); |
| 392 | 409 | |
| 393 | - if(is_array($contents)) |
|
| 394 | - foreach($contents as $file_info) |
|
| 410 | + if(is_array($contents)) { |
|
| 411 | + foreach($contents as $file_info) |
|
| 395 | 412 | $this->get_tmp_filesystem()->delete($file_info['path']); |
| 413 | + } |
|
| 396 | 414 | |
| 397 | 415 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
| 398 | 416 | |
@@ -403,17 +421,21 @@ discard block |
||
| 403 | 421 | { |
| 404 | 422 | $this->files_counter = 0; |
| 405 | 423 | |
| 406 | - if(!$this->storage_filesystem->has("index.html")) |
|
| 407 | - $this->storage_filesystem->write("index.html",""); |
|
| 424 | + if(!$this->storage_filesystem->has("index.html")) { |
|
| 425 | + $this->storage_filesystem->write("index.html",""); |
|
| 426 | + } |
|
| 408 | 427 | |
| 409 | - if(!$this->tmp_filesystem->has("index.html")) |
|
| 410 | - $this->tmp_filesystem->write("index.html",""); |
|
| 428 | + if(!$this->tmp_filesystem->has("index.html")) { |
|
| 429 | + $this->tmp_filesystem->write("index.html",""); |
|
| 430 | + } |
|
| 411 | 431 | |
| 412 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
| 413 | - $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
| 432 | + if($this->tmp_filesystem->has($this->get_included_files_handler())) { |
|
| 433 | + $this->tmp_filesystem->delete($this->get_included_files_handler()); |
|
| 434 | + } |
|
| 414 | 435 | |
| 415 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 416 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 436 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
| 437 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 438 | + } |
|
| 417 | 439 | } |
| 418 | 440 | |
| 419 | 441 | public function get_scanned_files_num() |
@@ -433,8 +455,9 @@ discard block |
||
| 433 | 455 | |
| 434 | 456 | public function set_excluded_files($excluded_files = array()) |
| 435 | 457 | { |
| 436 | - if(!is_array($excluded_files)) |
|
| 437 | - $excluded_files = array(); |
|
| 458 | + if(!is_array($excluded_files)) { |
|
| 459 | + $excluded_files = array(); |
|
| 460 | + } |
|
| 438 | 461 | |
| 439 | 462 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
| 440 | 463 | |
@@ -468,21 +491,21 @@ discard block |
||
| 468 | 491 | if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
| 469 | 492 | { |
| 470 | 493 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
| 471 | - } |
|
| 472 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
| 494 | + } elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
| 473 | 495 | $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
| 474 | 496 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
| 475 | 497 | $this->store_file($file); |
| 476 | 498 | $this->files_counter++; |
| 477 | - if(isset($file['size'])) |
|
| 478 | - $this->files_size += $file['size']; |
|
| 499 | + if(isset($file['size'])) { |
|
| 500 | + $this->files_size += $file['size']; |
|
| 501 | + } |
|
| 479 | 502 | |
| 480 | - }else{ |
|
| 503 | + } else{ |
|
| 481 | 504 | $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
| 482 | 505 | } |
| 483 | 506 | } |
| 484 | 507 | |
| 485 | - }catch(Exception $e){ |
|
| 508 | + } catch(Exception $e){ |
|
| 486 | 509 | |
| 487 | 510 | $this->logger->error($e->getMessage()); |
| 488 | 511 | |
@@ -509,7 +532,7 @@ discard block |
||
| 509 | 532 | |
| 510 | 533 | $this->tmp_filesystem->delete($tmp_file); |
| 511 | 534 | |
| 512 | - }catch(Exception $e){ |
|
| 535 | + } catch(Exception $e){ |
|
| 513 | 536 | |
| 514 | 537 | $this->logger->error($e->getMessage()); |
| 515 | 538 | |
@@ -530,12 +553,14 @@ discard block |
||
| 530 | 553 | |
| 531 | 554 | $files = $this->storage_filesystem->listContents(); |
| 532 | 555 | |
| 533 | - if(is_array($files)) |
|
| 534 | - foreach($files as $file) |
|
| 556 | + if(is_array($files)) { |
|
| 557 | + foreach($files as $file) |
|
| 535 | 558 | { |
| 536 | 559 | if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
| 537 | 560 | { |
| 538 | - $_storage_size += $file['size']; //bytes |
|
| 561 | + $_storage_size += $file['size']; |
|
| 562 | + } |
|
| 563 | + //bytes |
|
| 539 | 564 | $_backup_files_list[] = $file; |
| 540 | 565 | } |
| 541 | 566 | } |
@@ -549,9 +574,11 @@ discard block |
||
| 549 | 574 | { |
| 550 | 575 | //processing rule folder capacity |
| 551 | 576 | if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
| 552 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
| 577 | + $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) { |
|
| 578 | + //bytes |
|
| 553 | 579 | { |
| 554 | 580 | $this->storage_filesystem->delete($file['path']); |
| 581 | + } |
|
| 555 | 582 | $_storage_size -= $file['size']; |
| 556 | 583 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array("STORAGE SIZE LIMIT", $_storage_size." >= ".$set_storage_limit)); |
| 557 | 584 | } |
@@ -592,24 +619,26 @@ discard block |
||
| 592 | 619 | |
| 593 | 620 | public function process_backup_name($name = "", $max_length=100) |
| 594 | 621 | { |
| 595 | - if(!$name) |
|
| 596 | - $name = $this->xcloner_settings->get_default_backup_name(); |
|
| 622 | + if(!$name) { |
|
| 623 | + $name = $this->xcloner_settings->get_default_backup_name(); |
|
| 624 | + } |
|
| 597 | 625 | |
| 598 | 626 | foreach($this->backup_name_tags as $tag) |
| 599 | 627 | { |
| 600 | - if($tag == '[time]') |
|
| 601 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
| 602 | - elseif($tag == '[hostname]') |
|
| 603 | - $name = str_replace($tag, gethostname() ,$name); |
|
| 604 | - elseif($tag == '[domain]') |
|
| 628 | + if($tag == '[time]') { |
|
| 629 | + $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
| 630 | + } elseif($tag == '[hostname]') { |
|
| 631 | + $name = str_replace($tag, gethostname() ,$name); |
|
| 632 | + } elseif($tag == '[domain]') |
|
| 605 | 633 | { |
| 606 | 634 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
| 607 | 635 | $name = str_replace($tag, $domain ,$name); |
| 608 | 636 | } |
| 609 | 637 | } |
| 610 | 638 | |
| 611 | - if($max_length) |
|
| 612 | - $name = substr($name, 0, $max_length); |
|
| 639 | + if($max_length) { |
|
| 640 | + $name = substr($name, 0, $max_length); |
|
| 641 | + } |
|
| 613 | 642 | |
| 614 | 643 | return $name; |
| 615 | 644 | } |
@@ -639,28 +668,32 @@ discard block |
||
| 639 | 668 | |
| 640 | 669 | if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
| 641 | 670 | { |
| 642 | - if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
| 643 | - return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
| 671 | + if(isset($file['size']) and $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) { |
|
| 672 | + return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
|
| 673 | + } |
|
| 644 | 674 | } |
| 645 | 675 | |
| 646 | - if(!sizeof($this->excluded_files)) |
|
| 647 | - $this->set_excluded_files(); |
|
| 676 | + if(!sizeof($this->excluded_files)) { |
|
| 677 | + $this->set_excluded_files(); |
|
| 678 | + } |
|
| 648 | 679 | |
| 649 | - if(is_array($this->excluded_files)) |
|
| 650 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
| 680 | + if(is_array($this->excluded_files)) { |
|
| 681 | + foreach($this->excluded_files as $excluded_file_pattern) |
|
| 651 | 682 | { |
| 652 | 683 | if($excluded_file_pattern == "/") |
| 653 | 684 | $needle = "$"; |
| 654 | - else |
|
| 655 | - $needle = "$".$excluded_file_pattern; |
|
| 685 | + } else { |
|
| 686 | + $needle = "$".$excluded_file_pattern; |
|
| 687 | + } |
|
| 656 | 688 | |
| 657 | 689 | if(strstr("$".$file['path'], $needle)){ |
| 658 | 690 | return $excluded_file_pattern; |
| 659 | 691 | } |
| 660 | 692 | } |
| 661 | 693 | |
| 662 | - if( $regex = $this->is_excluded_regex($file)) |
|
| 663 | - return $regex; |
|
| 694 | + if( $regex = $this->is_excluded_regex($file)) { |
|
| 695 | + return $regex; |
|
| 696 | + } |
|
| 664 | 697 | |
| 665 | 698 | return false; |
| 666 | 699 | } |
@@ -714,13 +747,15 @@ discard block |
||
| 714 | 747 | foreach($regex_patterns as $excluded_file_pattern) |
| 715 | 748 | { |
| 716 | 749 | |
| 717 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
| 718 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
| 750 | + if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") { |
|
| 751 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
| 752 | + } |
|
| 719 | 753 | |
| 720 | - if($file['path'] == "/") |
|
| 721 | - $needle = "/"; |
|
| 722 | - else |
|
| 723 | - $needle = "/".$file['path']; |
|
| 754 | + if($file['path'] == "/") { |
|
| 755 | + $needle = "/"; |
|
| 756 | + } else { |
|
| 757 | + $needle = "/".$file['path']; |
|
| 758 | + } |
|
| 724 | 759 | //echo $needle."---".$excluded_file_pattern."---\n"; |
| 725 | 760 | |
| 726 | 761 | if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
@@ -736,10 +771,12 @@ discard block |
||
| 736 | 771 | { |
| 737 | 772 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
| 738 | 773 | |
| 739 | - if(!isset($file['size'])) |
|
| 740 | - $file['size'] = 0; |
|
| 741 | - if(!isset($file['visibility'])) |
|
| 742 | - $file['visibility'] = "private"; |
|
| 774 | + if(!isset($file['size'])) { |
|
| 775 | + $file['size'] = 0; |
|
| 776 | + } |
|
| 777 | + if(!isset($file['visibility'])) { |
|
| 778 | + $file['visibility'] = "private"; |
|
| 779 | + } |
|
| 743 | 780 | |
| 744 | 781 | $line = '"'.addslashes($file['path']).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
| 745 | 782 | |
@@ -748,7 +785,7 @@ discard block |
||
| 748 | 785 | try{ |
| 749 | 786 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
| 750 | 787 | |
| 751 | - }catch(Exception $e){ |
|
| 788 | + } catch(Exception $e){ |
|
| 752 | 789 | |
| 753 | 790 | $this->logger->error($e->getMessage()); |
| 754 | 791 | } |
@@ -756,7 +793,7 @@ discard block |
||
| 756 | 793 | if($file['type'] == "dir"){ |
| 757 | 794 | try{ |
| 758 | 795 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
| 759 | - }catch(Exception $e){ |
|
| 796 | + } catch(Exception $e){ |
|
| 760 | 797 | $this->logger->error($e->getMessage()); |
| 761 | 798 | } |
| 762 | 799 | } |
@@ -769,35 +806,39 @@ discard block |
||
| 769 | 806 | |
| 770 | 807 | public function get_filesystem($system = "") |
| 771 | 808 | { |
| 772 | - if($system == "storage_filesystem_append") |
|
| 773 | - return $this->storage_filesystem_append; |
|
| 774 | - elseif($system == "tmp_filesystem_append") |
|
| 775 | - return $this->tmp_filesystem_append; |
|
| 776 | - elseif($system == "tmp_filesystem") |
|
| 777 | - return $this->tmp_filesystem; |
|
| 778 | - elseif($system == "storage_filesystem") |
|
| 779 | - return $this->storage_filesystem; |
|
| 780 | - else |
|
| 781 | - return $this->start_filesystem; |
|
| 809 | + if($system == "storage_filesystem_append") { |
|
| 810 | + return $this->storage_filesystem_append; |
|
| 811 | + } elseif($system == "tmp_filesystem_append") { |
|
| 812 | + return $this->tmp_filesystem_append; |
|
| 813 | + } elseif($system == "tmp_filesystem") { |
|
| 814 | + return $this->tmp_filesystem; |
|
| 815 | + } elseif($system == "storage_filesystem") { |
|
| 816 | + return $this->storage_filesystem; |
|
| 817 | + } else { |
|
| 818 | + return $this->start_filesystem; |
|
| 819 | + } |
|
| 782 | 820 | } |
| 783 | 821 | |
| 784 | 822 | public function get_adapter($system) |
| 785 | 823 | { |
| 786 | - if($system == "tmp_filesystem") |
|
| 787 | - return $this->tmp_adapter; |
|
| 788 | - elseif($system == "storage_filesystem") |
|
| 789 | - return $this->storage_adapter; |
|
| 790 | - else |
|
| 791 | - return $this->start_adapter; |
|
| 824 | + if($system == "tmp_filesystem") { |
|
| 825 | + return $this->tmp_adapter; |
|
| 826 | + } elseif($system == "storage_filesystem") { |
|
| 827 | + return $this->storage_adapter; |
|
| 828 | + } else { |
|
| 829 | + return $this->start_adapter; |
|
| 830 | + } |
|
| 792 | 831 | } |
| 793 | 832 | |
| 794 | 833 | private function scan_finished() |
| 795 | 834 | { |
| 796 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
| 797 | - return false; |
|
| 835 | + if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) { |
|
| 836 | + return false; |
|
| 837 | + } |
|
| 798 | 838 | |
| 799 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
| 800 | - $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 839 | + if($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
| 840 | + $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
|
| 841 | + } |
|
| 801 | 842 | |
| 802 | 843 | $this->logger->debug(sprintf(("File scan finished"))); |
| 803 | 844 | |