@@ -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 |
@@ -97,8 +97,9 @@ discard block |
||
97 | 97 | foreach($this->storage_fields as $storage=>$data) |
98 | 98 | { |
99 | 99 | $check_field = $this->storage_fields["option_prefix"].$storage."_enable"; |
100 | - if(get_option($check_field)) |
|
101 | - $return[$storage] = $data['text']; |
|
100 | + if(get_option($check_field)) { |
|
101 | + $return[$storage] = $data['text']; |
|
102 | + } |
|
102 | 103 | } |
103 | 104 | |
104 | 105 | return $return; |
@@ -116,11 +117,13 @@ discard block |
||
116 | 117 | $check_field = $this->storage_fields["option_prefix"].$field; |
117 | 118 | $sanitize_method = "sanitize_input_as_".$validation; |
118 | 119 | |
119 | - if(!isset($_POST[$check_field])) |
|
120 | - $_POST[$check_field] = 0; |
|
120 | + if(!isset($_POST[$check_field])) { |
|
121 | + $_POST[$check_field] = 0; |
|
122 | + } |
|
121 | 123 | |
122 | - if(!method_exists($this->xcloner_sanitization, $sanitize_method)) |
|
123 | - $sanitize_method = "sanitize_input_as_string"; |
|
124 | + if(!method_exists($this->xcloner_sanitization, $sanitize_method)) { |
|
125 | + $sanitize_method = "sanitize_input_as_string"; |
|
126 | + } |
|
124 | 127 | |
125 | 128 | $sanitized_value = $this->xcloner_sanitization->$sanitize_method($_POST[$check_field]); |
126 | 129 | update_option($check_field, $sanitized_value); |
@@ -135,7 +138,7 @@ discard block |
||
135 | 138 | $this->verify_filesystem($action); |
136 | 139 | $this->xcloner->trigger_message(__("%s connection is valid.", 'xcloner-backup-and-restore'), "success", ucfirst($action)); |
137 | 140 | $this->logger->debug(sprintf("Connection to remote storage %s is valid", strtoupper($action))); |
138 | - }catch(Exception $e){ |
|
141 | + } catch(Exception $e){ |
|
139 | 142 | $this->xcloner->trigger_message("%s connection error: ".$e->getMessage(), "error", ucfirst($action)); |
140 | 143 | } |
141 | 144 | } |
@@ -148,38 +151,44 @@ discard block |
||
148 | 151 | |
149 | 152 | $this->logger->info(sprintf("Checking validity of the remote storage %s filesystem", strtoupper($storage_type))); |
150 | 153 | |
151 | - if(!method_exists($this, $method)) |
|
152 | - return false; |
|
154 | + if(!method_exists($this, $method)) { |
|
155 | + return false; |
|
156 | + } |
|
153 | 157 | |
154 | 158 | list($adapter, $filesystem) = $this->$method(); |
155 | 159 | |
156 | 160 | $test_file = substr(".xcloner_".md5(time()), 0, 15); |
157 | 161 | |
158 | 162 | //testing write access |
159 | - if(!$filesystem->write($test_file, "data")) |
|
160 | - throw new Exception(__("Could not write data",'xcloner-backup-and-restore')); |
|
163 | + if(!$filesystem->write($test_file, "data")) { |
|
164 | + throw new Exception(__("Could not write data",'xcloner-backup-and-restore')); |
|
165 | + } |
|
161 | 166 | $this->logger->debug(sprintf("I can write data to remote storage %s", strtoupper($storage_type))); |
162 | 167 | |
163 | 168 | //testing read access |
164 | - if(!$filesystem->read($test_file)) |
|
165 | - throw new Exception(__("Could not read data",'xcloner-backup-and-restore')); |
|
169 | + if(!$filesystem->read($test_file)) { |
|
170 | + throw new Exception(__("Could not read data",'xcloner-backup-and-restore')); |
|
171 | + } |
|
166 | 172 | $this->logger->debug(sprintf("I can read data to remote storage %s", strtoupper($storage_type))); |
167 | 173 | |
168 | 174 | //delete test file |
169 | - if(!$filesystem->delete($test_file)) |
|
170 | - throw new Exception(__("Could not delete data",'xcloner-backup-and-restore')); |
|
175 | + if(!$filesystem->delete($test_file)) { |
|
176 | + throw new Exception(__("Could not delete data",'xcloner-backup-and-restore')); |
|
177 | + } |
|
171 | 178 | $this->logger->debug(sprintf("I can delete data to remote storage %s", strtoupper($storage_type))); |
172 | 179 | } |
173 | 180 | |
174 | 181 | public function upload_backup_to_storage($file, $storage) |
175 | 182 | { |
176 | - if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) |
|
177 | - return false; |
|
183 | + if(!$this->xcloner_file_system->get_storage_filesystem()->has($file)) { |
|
184 | + return false; |
|
185 | + } |
|
178 | 186 | |
179 | 187 | $method = "get_".$storage."_filesystem"; |
180 | 188 | |
181 | - if(!method_exists($this, $method)) |
|
182 | - return false; |
|
189 | + if(!method_exists($this, $method)) { |
|
190 | + return false; |
|
191 | + } |
|
183 | 192 | |
184 | 193 | list($remote_storage_adapter, $remote_storage_filesystem) = $this->$method(); |
185 | 194 | |
@@ -205,14 +214,16 @@ discard block |
||
205 | 214 | if($this->xcloner_file_system->is_multipart($file)) |
206 | 215 | { |
207 | 216 | $parts = $this->xcloner_file_system->get_multipart_files($file); |
208 | - if(is_array($parts)) |
|
209 | - foreach($parts as $part_file) |
|
217 | + if(is_array($parts)) { |
|
218 | + foreach($parts as $part_file) |
|
210 | 219 | { |
211 | 220 | $this->logger->info(sprintf("Transferring backup %s to remote storage %s", $part_file, strtoupper($storage)), array("")); |
221 | + } |
|
212 | 222 | |
213 | 223 | $backup_file_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($part_file); |
214 | - if(!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) |
|
215 | - return false; |
|
224 | + if(!$remote_storage_filesystem->updateStream($part_file, $backup_file_stream)) { |
|
225 | + return false; |
|
226 | + } |
|
216 | 227 | } |
217 | 228 | } |
218 | 229 | |
@@ -234,10 +245,11 @@ discard block |
||
234 | 245 | |
235 | 246 | $current_timestamp = strtotime("-".$expire_days." days"); |
236 | 247 | |
237 | - if(is_array($files)) |
|
238 | - foreach($files as $file) |
|
248 | + if(is_array($files)) { |
|
249 | + foreach($files as $file) |
|
239 | 250 | { |
240 | 251 | $file['timestamp'] = $remote_storage_filesystem->getTimestamp($file['path']); |
252 | + } |
|
241 | 253 | |
242 | 254 | if($current_timestamp >= $file['timestamp']) |
243 | 255 | { |