@@ -8,11 +8,11 @@ discard block |
||
8 | 8 | /* |
9 | 9 | * bytes |
10 | 10 | */ |
11 | - private $file_size_per_request_limit = 52428800 ; //50MB = 52428800; 1MB = 1048576 |
|
12 | - private $files_to_process_per_request = 250; //block of 512 bytes |
|
13 | - private $compression_level = 0; //0-9 , 0 uncompressed |
|
11 | + private $file_size_per_request_limit = 52428800; //50MB = 52428800; 1MB = 1048576 |
|
12 | + private $files_to_process_per_request = 250; //block of 512 bytes |
|
13 | + private $compression_level = 0; //0-9 , 0 uncompressed |
|
14 | 14 | private $xcloner_split_backup_limit = 2048; //2048MB |
15 | - private $processed_size_bytes = 0 ; |
|
15 | + private $processed_size_bytes = 0; |
|
16 | 16 | |
17 | 17 | private $archive_name; |
18 | 18 | private $backup_archive; |
@@ -22,25 +22,25 @@ discard block |
||
22 | 22 | |
23 | 23 | public function __construct(Xcloner $xcloner_container, $archive_name = "") |
24 | 24 | { |
25 | - $this->filesystem = $xcloner_container->get_xcloner_filesystem(); |
|
26 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive"); |
|
25 | + $this->filesystem = $xcloner_container->get_xcloner_filesystem(); |
|
26 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_archive"); |
|
27 | 27 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
28 | 28 | |
29 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) |
|
30 | - $this->file_size_per_request_limit = $value*1024*1024; //MB |
|
29 | + if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) |
|
30 | + $this->file_size_per_request_limit = $value * 1024 * 1024; //MB |
|
31 | 31 | |
32 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
32 | + if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
33 | 33 | $this->files_to_process_per_request = $value; |
34 | 34 | |
35 | - if($value = get_option('xcloner_backup_compression_level')) |
|
35 | + if ($value = get_option('xcloner_backup_compression_level')) |
|
36 | 36 | $this->compression_level = $value; |
37 | 37 | |
38 | - if($value = get_option('xcloner_split_backup_limit')) |
|
38 | + if ($value = get_option('xcloner_split_backup_limit')) |
|
39 | 39 | $this->xcloner_split_backup_limit = $value; |
40 | 40 | |
41 | - $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes |
|
41 | + $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes |
|
42 | 42 | |
43 | - if(isset($archive_name) && $archive_name) |
|
43 | + if (isset($archive_name) && $archive_name) |
|
44 | 44 | { |
45 | 45 | $this->set_archive_name($archive_name); |
46 | 46 | } |
@@ -68,23 +68,23 @@ discard block |
||
68 | 68 | |
69 | 69 | $this->archive_name = $this->filesystem->process_backup_name($name); |
70 | 70 | |
71 | - if($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) |
|
71 | + if ($diff_timestamp_start = $this->filesystem->get_diff_timestamp_start()) |
|
72 | 72 | { |
73 | 73 | //$this->archive_name = $this->archive_name."-diff-".date("Y-m-d_H-i",$diff_timestamp_start); |
74 | 74 | $new_name = $this->archive_name; |
75 | 75 | |
76 | - if(!stristr($new_name, "-diff")) |
|
77 | - $new_name = $this->archive_name . "-diff".date("Y-m-d_H-i",$diff_timestamp_start); |
|
76 | + if (!stristr($new_name, "-diff")) |
|
77 | + $new_name = $this->archive_name."-diff".date("Y-m-d_H-i", $diff_timestamp_start); |
|
78 | 78 | |
79 | 79 | $this->archive_name = $new_name; |
80 | 80 | |
81 | 81 | } |
82 | 82 | |
83 | - if(isset($part) and $part) |
|
83 | + if (isset($part) and $part) |
|
84 | 84 | { |
85 | - $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
|
86 | - if(!stristr($new_name, "-part")) |
|
87 | - $new_name = $this->archive_name . "-part".$part; |
|
85 | + $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
|
86 | + if (!stristr($new_name, "-part")) |
|
87 | + $new_name = $this->archive_name."-part".$part; |
|
88 | 88 | |
89 | 89 | $this->archive_name = $new_name; |
90 | 90 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function get_archive_name_multipart() |
111 | 111 | { |
112 | - $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
112 | + $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
113 | 113 | return $new_name."-multipart".$this->xcloner_settings->get_backup_extension_name(".csv"); |
114 | 114 | } |
115 | 115 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
132 | 132 | { |
133 | 133 | |
134 | - $body = $error_message; |
|
134 | + $body = $error_message; |
|
135 | 135 | |
136 | 136 | $this->logger->info(sprintf("Sending backup error notification to %s", $to)); |
137 | 137 | |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | |
140 | 140 | $headers = array('Content-Type: text/html; charset=UTF-8'); |
141 | 141 | |
142 | - if($admin_email and $from ) |
|
142 | + if ($admin_email and $from) |
|
143 | 143 | $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
144 | 144 | |
145 | - $return = wp_mail( $to, $subject, $body, $headers ); |
|
145 | + $return = wp_mail($to, $subject, $body, $headers); |
|
146 | 146 | |
147 | 147 | return $return; |
148 | 148 | } |
@@ -152,29 +152,29 @@ discard block |
||
152 | 152 | * Send backup archive notfication by E-Mail |
153 | 153 | * |
154 | 154 | */ |
155 | - public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="", $additional = array()) |
|
155 | + public function send_notification($to, $from, $subject, $backup_name, $params, $error_message = "", $additional = array()) |
|
156 | 156 | { |
157 | - if(!$from) |
|
157 | + if (!$from) |
|
158 | 158 | { |
159 | 159 | $from = "XCloner Backup"; |
160 | 160 | } |
161 | 161 | |
162 | - if(($error_message)) |
|
162 | + if (($error_message)) |
|
163 | 163 | { |
164 | 164 | return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message); |
165 | 165 | } |
166 | 166 | |
167 | 167 | $params = (array)$params; |
168 | 168 | |
169 | - if(!$subject) |
|
169 | + if (!$subject) |
|
170 | 170 | { |
171 | - $subject = sprintf(__("New backup generated %s") ,$backup_name); |
|
171 | + $subject = sprintf(__("New backup generated %s"), $backup_name); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
175 | 175 | $body .= "<br /><br />"; |
176 | 176 | |
177 | - if(isset($additional['lines_total'])) |
|
177 | + if (isset($additional['lines_total'])) |
|
178 | 178 | { |
179 | 179 | $body .= sprintf(__("Total files added: %s"), $additional['lines_total']); |
180 | 180 | $body .= "<br /><br />"; |
@@ -182,27 +182,27 @@ discard block |
||
182 | 182 | |
183 | 183 | $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
184 | 184 | |
185 | - if(!$backups_counter = sizeof($backup_parts)) |
|
185 | + if (!$backups_counter = sizeof($backup_parts)) |
|
186 | 186 | $backups_counter = 1; |
187 | 187 | |
188 | 188 | $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
189 | 189 | $body .= "<br />"; |
190 | 190 | |
191 | - if(sizeof($backup_parts)) |
|
191 | + if (sizeof($backup_parts)) |
|
192 | 192 | { |
193 | - $body .= implode("<br />",$backup_parts); |
|
193 | + $body .= implode("<br />", $backup_parts); |
|
194 | 194 | $body .= "<br />"; |
195 | 195 | } |
196 | 196 | |
197 | - $body.= "<br />"; |
|
197 | + $body .= "<br />"; |
|
198 | 198 | |
199 | - if(isset($params['backup_params']->backup_comments)) |
|
199 | + if (isset($params['backup_params']->backup_comments)) |
|
200 | 200 | { |
201 | 201 | $body .= __("Backup Comments: ").$params['backup_params']->backup_comments; |
202 | 202 | $body .= "<br /><br />"; |
203 | 203 | } |
204 | 204 | |
205 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
205 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
206 | 206 | $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
207 | 207 | |
208 | 208 | $attachments = $this->filesystem->get_backup_attachments(); |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $tar = new Tar(); |
213 | 213 | $tar->create($attachments_archive); |
214 | 214 | |
215 | - foreach($attachments as $key => $file) |
|
215 | + foreach ($attachments as $key => $file) |
|
216 | 216 | { |
217 | 217 | $tar->addFile($file, basename($file)); |
218 | 218 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | |
225 | 225 | $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>'); |
226 | 226 | |
227 | - $return = wp_mail( $to, $subject, $body, $headers, array($attachments_archive) ); |
|
227 | + $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive)); |
|
228 | 228 | |
229 | 229 | return $return; |
230 | 230 | } |
@@ -238,17 +238,17 @@ discard block |
||
238 | 238 | { |
239 | 239 | $return = array(); |
240 | 240 | |
241 | - if(!isset($extra_params['backup_part'])) |
|
241 | + if (!isset($extra_params['backup_part'])) |
|
242 | 242 | $extra_params['backup_part'] = 0; |
243 | 243 | |
244 | 244 | $return['extra']['backup_part'] = $extra_params['backup_part']; |
245 | 245 | |
246 | - if(isset( $extra_params['backup_archive_name'])) |
|
246 | + if (isset($extra_params['backup_archive_name'])) |
|
247 | 247 | $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
248 | 248 | else |
249 | 249 | $this->set_archive_name($backup_params['backup_name']); |
250 | 250 | |
251 | - if(!$this->get_archive_name()) |
|
251 | + if (!$this->get_archive_name()) |
|
252 | 252 | $this->set_archive_name(); |
253 | 253 | |
254 | 254 | $this->backup_archive = new Tar(); |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | |
257 | 257 | $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
258 | 258 | |
259 | - if($init) |
|
259 | + if ($init) |
|
260 | 260 | { |
261 | 261 | $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name())); |
262 | 262 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | |
265 | 265 | $return['extra']['backup_init'] = 1; |
266 | 266 | |
267 | - }else{ |
|
267 | + } else { |
|
268 | 268 | $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
269 | 269 | |
270 | 270 | $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
@@ -276,13 +276,13 @@ discard block |
||
276 | 276 | $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
277 | 277 | $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
278 | 278 | |
279 | - if(!isset($extra_params['start_at_line'])) |
|
279 | + if (!isset($extra_params['start_at_line'])) |
|
280 | 280 | $extra_params['start_at_line'] = 0; |
281 | 281 | |
282 | - if(!isset($extra_params['start_at_byte'])) |
|
282 | + if (!isset($extra_params['start_at_byte'])) |
|
283 | 283 | $extra_params['start_at_byte'] = 0; |
284 | 284 | |
285 | - if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
|
285 | + if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
|
286 | 286 | { |
287 | 287 | $this->logger->error(sprintf("Missing the includes file handler %s, aborting...", $this->filesystem->get_included_files_handler())); |
288 | 288 | |
@@ -296,14 +296,14 @@ discard block |
||
296 | 296 | |
297 | 297 | $file->seek(PHP_INT_MAX); |
298 | 298 | |
299 | - $return['extra']['lines_total'] = ($file->key()-1); |
|
299 | + $return['extra']['lines_total'] = ($file->key() - 1); |
|
300 | 300 | |
301 | 301 | //we skip the first CSV line with headers |
302 | - if(!$extra_params['start_at_line']) |
|
302 | + if (!$extra_params['start_at_line']) |
|
303 | 303 | { |
304 | 304 | $file->seek(1); |
305 | - }else{ |
|
306 | - $file->seek($extra_params['start_at_line']+1); |
|
305 | + } else { |
|
306 | + $file->seek($extra_params['start_at_line'] + 1); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | $this->processed_size_bytes = 0; |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | |
315 | 315 | $byte_limit = 0; |
316 | 316 | |
317 | - while(!$file->eof() and $counter<=$this->files_to_process_per_request) |
|
317 | + while (!$file->eof() and $counter <= $this->files_to_process_per_request) |
|
318 | 318 | { |
319 | 319 | $current_line_str = $file->current(); |
320 | 320 | |
@@ -324,15 +324,15 @@ discard block |
||
324 | 324 | |
325 | 325 | $start_filesystem = "start_filesystem"; |
326 | 326 | |
327 | - if(isset($line[4])){ |
|
327 | + if (isset($line[4])) { |
|
328 | 328 | $start_filesystem = $line[4]; |
329 | 329 | } |
330 | 330 | |
331 | 331 | //$adapter = $this->filesystem->get_adapter($start_filesystem); |
332 | 332 | |
333 | - if(!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) |
|
333 | + if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) |
|
334 | 334 | { |
335 | - if($relative_path != "") |
|
335 | + if ($relative_path != "") |
|
336 | 336 | { |
337 | 337 | $this->logger->error(sprintf("Could not add file %b to backup archive, file not found", $relative_path)); |
338 | 338 | } |
@@ -344,37 +344,37 @@ discard block |
||
344 | 344 | |
345 | 345 | $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
346 | 346 | |
347 | - if(!isset($file_info['size'])) |
|
347 | + if (!isset($file_info['size'])) |
|
348 | 348 | $file_info['size'] = 0; |
349 | 349 | |
350 | - if($start_filesystem == "tmp_filesystem") |
|
350 | + if ($start_filesystem == "tmp_filesystem") |
|
351 | 351 | { |
352 | 352 | $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
353 | 353 | } |
354 | 354 | |
355 | - $byte_limit = (int)$this->file_size_per_request_limit/512; |
|
355 | + $byte_limit = (int)$this->file_size_per_request_limit / 512; |
|
356 | 356 | |
357 | 357 | $append = 0; |
358 | 358 | |
359 | - if($file_info['size'] > $byte_limit*512 or $start_byte) |
|
359 | + if ($file_info['size'] > $byte_limit * 512 or $start_byte) |
|
360 | 360 | $append = 1; |
361 | 361 | |
362 | - if(!isset($return['extra']['backup_size'])) |
|
363 | - $return['extra']['backup_size'] =0; |
|
362 | + if (!isset($return['extra']['backup_size'])) |
|
363 | + $return['extra']['backup_size'] = 0; |
|
364 | 364 | |
365 | 365 | $return['extra']['backup_size'] = $archive_info->getSize(); |
366 | 366 | |
367 | 367 | $estimated_new_size = $return['extra']['backup_size'] + $file_info['size']; |
368 | 368 | |
369 | 369 | //we create a new backup part if we reach the Split Achive Limit |
370 | - if($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) |
|
370 | + if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) |
|
371 | 371 | { |
372 | - $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ",$this->xcloner_split_backup_limit, $estimated_new_size)); |
|
372 | + $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ", $this->xcloner_split_backup_limit, $estimated_new_size)); |
|
373 | 373 | list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']); |
374 | 374 | |
375 | - if($file_info['size'] > $this->xcloner_split_backup_limit) |
|
375 | + if ($file_info['size'] > $this->xcloner_split_backup_limit) |
|
376 | 376 | { |
377 | - $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file",$file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
377 | + $this->logger->info(sprintf("Excluding %s file as it's size(%s) is bigger than the backup split limit of %s and it won't fit a single backup file", $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
378 | 378 | $extra_params['start_at_line']++; |
379 | 379 | } |
380 | 380 | |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | return $return; |
387 | 387 | } |
388 | 388 | |
389 | - list($bytes_wrote, $last_position) = $this->add_file_to_archive( $file_info, $start_byte, $byte_limit, $append, $start_filesystem); |
|
389 | + list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, $append, $start_filesystem); |
|
390 | 390 | $this->processed_size_bytes += $bytes_wrote; |
391 | 391 | |
392 | 392 | //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n"; |
@@ -394,17 +394,17 @@ discard block |
||
394 | 394 | $return['extra']['processed_file_size'] = $file_info['size']; |
395 | 395 | $return['extra']['backup_size'] = $archive_info->getSize(); |
396 | 396 | |
397 | - if($last_position>0){ |
|
397 | + if ($last_position > 0) { |
|
398 | 398 | $start_byte = $last_position; |
399 | 399 | } |
400 | - else{ |
|
400 | + else { |
|
401 | 401 | $extra_params['start_at_line']++; |
402 | 402 | $file->next(); |
403 | 403 | $start_byte = 0; |
404 | 404 | $counter++; |
405 | 405 | } |
406 | 406 | |
407 | - if($this->processed_size_bytes >= $this->file_size_per_request_limit) |
|
407 | + if ($this->processed_size_bytes >= $this->file_size_per_request_limit) |
|
408 | 408 | { |
409 | 409 | clearstatcache(); |
410 | 410 | $return['extra']['backup_size'] = $archive_info->getSize(); |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | } |
418 | 418 | } |
419 | 419 | |
420 | - if(!$file->eof()) |
|
420 | + if (!$file->eof()) |
|
421 | 421 | { |
422 | 422 | clearstatcache(); |
423 | 423 | $return['extra']['backup_size'] = $archive_info->getSize(); |
@@ -434,12 +434,12 @@ discard block |
||
434 | 434 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
435 | 435 | $this->backup_archive->close(); |
436 | 436 | |
437 | - if($return['extra']['backup_part']) |
|
437 | + if ($return['extra']['backup_part']) |
|
438 | 438 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
439 | 439 | |
440 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']-1; |
|
440 | + $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1; |
|
441 | 441 | |
442 | - if(isset($file_info)) |
|
442 | + if (isset($file_info)) |
|
443 | 443 | { |
444 | 444 | $return['extra']['processed_file'] = $file_info['path']; |
445 | 445 | $return['extra']['processed_file_size'] = $file_info['size']; |
@@ -481,20 +481,20 @@ discard block |
||
481 | 481 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
482 | 482 | $this->backup_archive->close(); |
483 | 483 | |
484 | - if(!$part) |
|
484 | + if (!$part) |
|
485 | 485 | { |
486 | 486 | $old_name = $this->get_archive_name_with_extension(); |
487 | 487 | $this->set_archive_name($this->get_archive_name(), ++$part); |
488 | 488 | $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
489 | 489 | |
490 | - if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
490 | + if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
491 | 491 | $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
492 | 492 | |
493 | 493 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
494 | 494 | |
495 | - }else |
|
495 | + } else |
|
496 | 496 | { |
497 | - $this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension())); |
|
497 | + $this->logger->info(sprintf("Creating new multipart info file %s", $this->get_archive_name_with_extension())); |
|
498 | 498 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
499 | 499 | } |
500 | 500 | |
@@ -522,10 +522,10 @@ discard block |
||
522 | 522 | $start_adapter = $this->filesystem->get_adapter($filesystem); |
523 | 523 | $start_filesystem = $this->filesystem->get_adapter($filesystem); |
524 | 524 | |
525 | - if(!$file_info['path']) |
|
525 | + if (!$file_info['path']) |
|
526 | 526 | return; |
527 | 527 | |
528 | - if(isset($file_info['archive_prefix_path'])) |
|
528 | + if (isset($file_info['archive_prefix_path'])) |
|
529 | 529 | $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
530 | 530 | else |
531 | 531 | $file_info['target_path'] = $file_info['path']; |
@@ -534,36 +534,36 @@ discard block |
||
534 | 534 | |
535 | 535 | //$start_adapter = $this->filesystem->get_start_adapter(); |
536 | 536 | |
537 | - if(!$append){ |
|
537 | + if (!$append) { |
|
538 | 538 | $bytes_wrote = $file_info['size']; |
539 | 539 | $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, $file_info['target_path'], $this->get_archive_name_with_extension())); |
540 | 540 | $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']); |
541 | 541 | } |
542 | - else{ |
|
542 | + else { |
|
543 | 543 | $tmp_file = md5($file_info['path']); |
544 | 544 | |
545 | 545 | //we isolate file to tmp if we are at byte 0, the starting point of file reading |
546 | - if(!$start_at_byte) |
|
546 | + if (!$start_at_byte) |
|
547 | 547 | { |
548 | 548 | $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file)); |
549 | 549 | $file_stream = $start_filesystem->readStream($file_info['path']); |
550 | 550 | |
551 | - if(is_resource($file_stream['stream'])) |
|
551 | + if (is_resource($file_stream['stream'])) |
|
552 | 552 | $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
553 | 553 | } |
554 | 554 | |
555 | - if($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
|
555 | + if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
|
556 | 556 | { |
557 | 557 | $is_tmp = 1; |
558 | 558 | $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_file), $file_info['target_path'], $start_at_byte, $byte_limit); |
559 | 559 | } |
560 | - else{ |
|
560 | + else { |
|
561 | 561 | $is_tmp = 0; |
562 | 562 | $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit); |
563 | 563 | } |
564 | 564 | |
565 | 565 | |
566 | - if($last_position == -1) |
|
566 | + if ($last_position == -1) |
|
567 | 567 | { |
568 | 568 | $bytes_wrote = $file_info['size'] - $start_at_byte; |
569 | 569 | } |
@@ -573,18 +573,18 @@ discard block |
||
573 | 573 | } |
574 | 574 | |
575 | 575 | |
576 | - if($is_tmp) |
|
576 | + if ($is_tmp) |
|
577 | 577 | { |
578 | 578 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name())); |
579 | 579 | } |
580 | - else{ |
|
580 | + else { |
|
581 | 581 | $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name())); |
582 | 582 | } |
583 | 583 | |
584 | 584 | //we delete here the isolated tmp file |
585 | - if($last_position == -1) |
|
585 | + if ($last_position == -1) |
|
586 | 586 | { |
587 | - if($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) |
|
587 | + if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) |
|
588 | 588 | { |
589 | 589 | $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file)); |
590 | 590 | $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file); |
@@ -4,14 +4,14 @@ discard block |
||
4 | 4 | { |
5 | 5 | private $logger_file = "xcloner_main_%s.log"; |
6 | 6 | private $logger_file_hash = "xcloner%s.log"; |
7 | - private $hash ; |
|
7 | + private $hash; |
|
8 | 8 | private $xcloner_sanitization; |
9 | 9 | private $xcloner_container; |
10 | 10 | |
11 | 11 | public function __construct(Xcloner $xcloner_container, $hash = "") |
12 | 12 | { |
13 | 13 | $this->xcloner_container = $xcloner_container; |
14 | - if(isset($hash)) |
|
14 | + if (isset($hash)) |
|
15 | 15 | $this->set_hash($hash); |
16 | 16 | } |
17 | 17 | |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | public function get_logger_filename($include_hash = 0) |
24 | 24 | { |
25 | - if($include_hash) |
|
25 | + if ($include_hash) |
|
26 | 26 | $filename = sprintf($this->logger_file_hash, $this->get_hash()); |
27 | 27 | else |
28 | 28 | $filename = sprintf($this->logger_file, $this->get_server_unique_hash(5)); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | public function get_xcloner_start_path() |
34 | 34 | { |
35 | - if(!get_option('xcloner_start_path') or !is_dir(get_option('xcloner_start_path'))) |
|
35 | + if (!get_option('xcloner_start_path') or !is_dir(get_option('xcloner_start_path'))) |
|
36 | 36 | $path = realpath(ABSPATH); |
37 | 37 | else |
38 | 38 | $path = get_option('xcloner_start_path'); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | public function get_xcloner_store_path() |
51 | 51 | { |
52 | - if(!get_option('xcloner_store_path') or !is_dir(get_option('xcloner_store_path'))) |
|
52 | + if (!get_option('xcloner_store_path') or !is_dir(get_option('xcloner_store_path'))) |
|
53 | 53 | $path = realpath(XCLONER_STORAGE_PATH); |
54 | 54 | else |
55 | 55 | $path = get_option('xcloner_store_path'); |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | public function get_xcloner_tmp_path($suffix = true) |
67 | 67 | { |
68 | 68 | $path = sys_get_temp_dir(); |
69 | - if(!is_dir($path)) |
|
69 | + if (!is_dir($path)) |
|
70 | 70 | { |
71 | 71 | @mkdir($path); |
72 | 72 | @chmod($path, 0777); |
73 | 73 | } |
74 | 74 | |
75 | - if(!is_dir($path) or !is_writeable($path) or get_option('xcloner_force_tmp_path_site_root')) |
|
75 | + if (!is_dir($path) or !is_writeable($path) or get_option('xcloner_force_tmp_path_site_root')) |
|
76 | 76 | { |
77 | 77 | $path = $this->get_xcloner_store_path(); |
78 | 78 | } |
79 | 79 | |
80 | - if($suffix) |
|
80 | + if ($suffix) |
|
81 | 81 | { |
82 | 82 | $path = $path.DS.".".$this->get_xcloner_tmp_path_suffix(); |
83 | 83 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | public function get_enable_mysql_backup() |
89 | 89 | { |
90 | - if(get_option('xcloner_enable_mysql_backup')) |
|
90 | + if (get_option('xcloner_enable_mysql_backup')) |
|
91 | 91 | return true; |
92 | 92 | |
93 | 93 | return false; |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | |
96 | 96 | public function get_backup_extension_name($ext = "") |
97 | 97 | { |
98 | - if(!$ext) |
|
98 | + if (!$ext) |
|
99 | 99 | { |
100 | - if(get_option('xcloner_backup_compression_level')) |
|
100 | + if (get_option('xcloner_backup_compression_level')) |
|
101 | 101 | $ext = ".tgz"; |
102 | 102 | else |
103 | 103 | $ext = ".tar"; |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | public function get_hash() |
109 | 109 | { |
110 | - if(!$this->hash){ |
|
110 | + if (!$this->hash) { |
|
111 | 111 | $this->set_hash("-".$this->get_server_unique_hash(5)); |
112 | 112 | } |
113 | 113 | |
@@ -119,17 +119,17 @@ discard block |
||
119 | 119 | { |
120 | 120 | $hash = "-".md5(rand()); |
121 | 121 | |
122 | - $this->set_hash(substr( $hash, 0, 6)); |
|
122 | + $this->set_hash(substr($hash, 0, 6)); |
|
123 | 123 | |
124 | 124 | return $hash; |
125 | 125 | } |
126 | 126 | |
127 | 127 | public function set_hash($hash = "") |
128 | 128 | { |
129 | - if(substr($hash, 0, 1) != "-" and strlen($hash)) |
|
129 | + if (substr($hash, 0, 1) != "-" and strlen($hash)) |
|
130 | 130 | $hash = "-".$hash; |
131 | 131 | |
132 | - $this->hash = substr( $hash, 0, 6); |
|
132 | + $this->hash = substr($hash, 0, 6); |
|
133 | 133 | |
134 | 134 | return $this; |
135 | 135 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | { |
139 | 139 | $data = parse_url(get_site_url()); |
140 | 140 | |
141 | - $backup_name = "backup_[domain]".(isset($data['port'])?"_".$data['port']:"")."-[time]-".($this->get_enable_mysql_backup()?"sql":"nosql"); |
|
141 | + $backup_name = "backup_[domain]".(isset($data['port']) ? "_".$data['port'] : "")."-[time]-".($this->get_enable_mysql_backup() ? "sql" : "nosql"); |
|
142 | 142 | |
143 | 143 | return $backup_name; |
144 | 144 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | { |
148 | 148 | global $wpdb; |
149 | 149 | |
150 | - if(!$data = get_option('xcloner_mysql_hostname')) |
|
150 | + if (!$data = get_option('xcloner_mysql_hostname')) |
|
151 | 151 | $data = $wpdb->dbhost; |
152 | 152 | |
153 | 153 | return $data; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | { |
158 | 158 | global $wpdb; |
159 | 159 | |
160 | - if(!$data = get_option('xcloner_mysql_username')) |
|
160 | + if (!$data = get_option('xcloner_mysql_username')) |
|
161 | 161 | $data = $wpdb->dbuser; |
162 | 162 | |
163 | 163 | return $data; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | { |
168 | 168 | global $wpdb; |
169 | 169 | |
170 | - if(!$data = get_option('xcloner_mysql_password')) |
|
170 | + if (!$data = get_option('xcloner_mysql_password')) |
|
171 | 171 | $data = $wpdb->dbpassword; |
172 | 172 | |
173 | 173 | return $data; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | { |
178 | 178 | global $wpdb; |
179 | 179 | |
180 | - if(!$data = get_option('xcloner_mysql_database')) |
|
180 | + if (!$data = get_option('xcloner_mysql_database')) |
|
181 | 181 | $data = $wpdb->dbname; |
182 | 182 | |
183 | 183 | return $data; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | { |
202 | 202 | $hash = md5(get_home_url().__DIR__); |
203 | 203 | |
204 | - if($strlen) |
|
204 | + if ($strlen) |
|
205 | 205 | $hash = substr($hash, 0, $strlen); |
206 | 206 | |
207 | 207 | return $hash; |
@@ -213,20 +213,20 @@ discard block |
||
213 | 213 | $this->xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization(); |
214 | 214 | |
215 | 215 | //ADDING MISSING OPTIONS |
216 | - if( false == get_option( 'xcloner_mysql_settings_page' ) ) { |
|
217 | - add_option( 'xcloner_mysql_settings_page' ); |
|
216 | + if (false == get_option('xcloner_mysql_settings_page')) { |
|
217 | + add_option('xcloner_mysql_settings_page'); |
|
218 | 218 | } // end if |
219 | 219 | |
220 | - if( false == get_option( 'xcloner_cron_settings_page' ) ) { |
|
221 | - add_option( 'xcloner_cron_settings_page' ); |
|
220 | + if (false == get_option('xcloner_cron_settings_page')) { |
|
221 | + add_option('xcloner_cron_settings_page'); |
|
222 | 222 | } // end if |
223 | 223 | |
224 | - if( false == get_option( 'xcloner_system_settings_page' ) ) { |
|
225 | - add_option( 'xcloner_system_settings_page' ); |
|
224 | + if (false == get_option('xcloner_system_settings_page')) { |
|
225 | + add_option('xcloner_system_settings_page'); |
|
226 | 226 | } // end if |
227 | 227 | |
228 | - if( false == get_option( 'xcloner_cleanup_settings_page' ) ) { |
|
229 | - add_option( 'xcloner_cleanup_settings_page' ); |
|
228 | + if (false == get_option('xcloner_cleanup_settings_page')) { |
|
229 | + add_option('xcloner_cleanup_settings_page'); |
|
230 | 230 | } // end if |
231 | 231 | |
232 | 232 | |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | //SYSTEM section |
250 | 250 | add_settings_section( |
251 | 251 | 'xcloner_system_settings_group', |
252 | - __('These are advanced options recommended for developers!','xcloner-backup-and-restore'), |
|
252 | + __('These are advanced options recommended for developers!', 'xcloner-backup-and-restore'), |
|
253 | 253 | array($this, 'xcloner_settings_section_cb'), |
254 | 254 | 'xcloner_system_settings_page' |
255 | 255 | ); |
@@ -277,12 +277,12 @@ discard block |
||
277 | 277 | register_setting('xcloner_general_settings_group', 'xcloner_backup_compression_level', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
278 | 278 | add_settings_field( |
279 | 279 | 'xcloner_backup_compression_level', |
280 | - __('Backup Compression Level','xcloner-backup-and-restore'), |
|
280 | + __('Backup Compression Level', 'xcloner-backup-and-restore'), |
|
281 | 281 | array($this, 'do_form_range_field'), |
282 | 282 | 'xcloner_settings_page', |
283 | 283 | 'xcloner_general_settings_group', |
284 | 284 | array('xcloner_backup_compression_level', |
285 | - __('Options between [0-9]. Value 0 means no compression, while 9 is maximum compression affecting cpu load','xcloner-backup-and-restore'), |
|
285 | + __('Options between [0-9]. Value 0 means no compression, while 9 is maximum compression affecting cpu load', 'xcloner-backup-and-restore'), |
|
286 | 286 | 0, |
287 | 287 | 9 |
288 | 288 | ) |
@@ -291,12 +291,12 @@ discard block |
||
291 | 291 | register_setting('xcloner_general_settings_group', 'xcloner_start_path', array($this->xcloner_sanitization, "sanitize_input_as_absolute_path")); |
292 | 292 | add_settings_field( |
293 | 293 | 'xcloner_start_path', |
294 | - __('Backup Start Location','xcloner-backup-and-restore'), |
|
294 | + __('Backup Start Location', 'xcloner-backup-and-restore'), |
|
295 | 295 | array($this, 'do_form_text_field'), |
296 | 296 | 'xcloner_settings_page', |
297 | 297 | 'xcloner_general_settings_group', |
298 | 298 | array('xcloner_start_path', |
299 | - __('Base path location from where XCloner can start the Backup.','xcloner-backup-and-restore'), |
|
299 | + __('Base path location from where XCloner can start the Backup.', 'xcloner-backup-and-restore'), |
|
300 | 300 | $this->get_xcloner_start_path(), |
301 | 301 | //'disabled' |
302 | 302 | ) |
@@ -305,12 +305,12 @@ discard block |
||
305 | 305 | register_setting('xcloner_general_settings_group', 'xcloner_store_path', array($this->xcloner_sanitization, "sanitize_input_as_absolute_path")); |
306 | 306 | add_settings_field( |
307 | 307 | 'xcloner_store_path', |
308 | - __('Backup Storage Location','xcloner-backup-and-restore'), |
|
308 | + __('Backup Storage Location', 'xcloner-backup-and-restore'), |
|
309 | 309 | array($this, 'do_form_text_field'), |
310 | 310 | 'xcloner_settings_page', |
311 | 311 | 'xcloner_general_settings_group', |
312 | 312 | array('xcloner_store_path', |
313 | - __('Location where XCloner will store the Backup archives.','xcloner-backup-and-restore'), |
|
313 | + __('Location where XCloner will store the Backup archives.', 'xcloner-backup-and-restore'), |
|
314 | 314 | $this->get_xcloner_store_path(), |
315 | 315 | //'disabled' |
316 | 316 | ) |
@@ -319,24 +319,24 @@ discard block |
||
319 | 319 | register_setting('xcloner_general_settings_group', 'xcloner_enable_log', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
320 | 320 | add_settings_field( |
321 | 321 | 'xcloner_enable_log', |
322 | - __('Enable XCloner Backup Log','xcloner-backup-and-restore'), |
|
322 | + __('Enable XCloner Backup Log', 'xcloner-backup-and-restore'), |
|
323 | 323 | array($this, 'do_form_switch_field'), |
324 | 324 | 'xcloner_settings_page', |
325 | 325 | 'xcloner_general_settings_group', |
326 | 326 | array('xcloner_enable_log', |
327 | - sprintf(__('Enable the XCloner Backup log. You will find it stored unde the Backup Storage Location, file %s','xcloner-backup-and-restore'), $this->get_logger_filename()) |
|
327 | + sprintf(__('Enable the XCloner Backup log. You will find it stored unde the Backup Storage Location, file %s', 'xcloner-backup-and-restore'), $this->get_logger_filename()) |
|
328 | 328 | ) |
329 | 329 | ); |
330 | 330 | |
331 | 331 | register_setting('xcloner_general_settings_group', 'xcloner_regex_exclude', array($this->xcloner_sanitization, "sanitize_input_as_raw")); |
332 | 332 | add_settings_field( |
333 | 333 | 'xcloner_regex_exclude', |
334 | - __('Regex Exclude Files','xcloner-backup-and-restore'), |
|
334 | + __('Regex Exclude Files', 'xcloner-backup-and-restore'), |
|
335 | 335 | array($this, 'do_form_textarea_field'), |
336 | 336 | 'xcloner_settings_page', |
337 | 337 | 'xcloner_general_settings_group', |
338 | 338 | array('xcloner_regex_exclude', |
339 | - __('Regular expression match to exclude files and folders, example patterns provided below, one pattern per line','xcloner-backup-and-restore'), |
|
339 | + __('Regular expression match to exclude files and folders, example patterns provided below, one pattern per line', 'xcloner-backup-and-restore'), |
|
340 | 340 | //$this->get_xcloner_store_path(), |
341 | 341 | //'disabled' |
342 | 342 | ) |
@@ -346,36 +346,36 @@ discard block |
||
346 | 346 | register_setting('xcloner_mysql_settings_group', 'xcloner_enable_mysql_backup', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
347 | 347 | add_settings_field( |
348 | 348 | 'xcloner_enable_mysql_backup', |
349 | - __('Enable Mysql Backup','xcloner-backup-and-restore'), |
|
349 | + __('Enable Mysql Backup', 'xcloner-backup-and-restore'), |
|
350 | 350 | array($this, 'do_form_switch_field'), |
351 | 351 | 'xcloner_mysql_settings_page', |
352 | 352 | 'xcloner_mysql_settings_group', |
353 | 353 | array('xcloner_enable_mysql_backup', |
354 | - __('Enable Mysql Backup Option. If you don\'t want to backup the database, you can disable this.','xcloner-backup-and-restore') |
|
354 | + __('Enable Mysql Backup Option. If you don\'t want to backup the database, you can disable this.', 'xcloner-backup-and-restore') |
|
355 | 355 | ) |
356 | 356 | ); |
357 | 357 | |
358 | 358 | register_setting('xcloner_mysql_settings_group', 'xcloner_backup_only_wp_tables'); |
359 | 359 | add_settings_field( |
360 | 360 | 'xcloner_backup_only_wp_tables', |
361 | - __('Backup only WP tables','xcloner-backup-and-restore'), |
|
361 | + __('Backup only WP tables', 'xcloner-backup-and-restore'), |
|
362 | 362 | array($this, 'do_form_switch_field'), |
363 | 363 | 'xcloner_mysql_settings_page', |
364 | 364 | 'xcloner_mysql_settings_group', |
365 | 365 | array('xcloner_backup_only_wp_tables', |
366 | - sprintf(__('Enable this if you only want to Backup only tables starting with \'%s\' prefix','xcloner-backup-and-restore'), $this->get_table_prefix()) |
|
366 | + sprintf(__('Enable this if you only want to Backup only tables starting with \'%s\' prefix', 'xcloner-backup-and-restore'), $this->get_table_prefix()) |
|
367 | 367 | ) |
368 | 368 | ); |
369 | 369 | |
370 | 370 | register_setting('xcloner_mysql_settings_group', 'xcloner_mysql_hostname', array($this->xcloner_sanitization, "sanitize_input_as_raw")); |
371 | 371 | add_settings_field( |
372 | 372 | 'xcloner_mysql_hostname', |
373 | - __('Mysql Hostname','xcloner-backup-and-restore'), |
|
373 | + __('Mysql Hostname', 'xcloner-backup-and-restore'), |
|
374 | 374 | array($this, 'do_form_text_field'), |
375 | 375 | 'xcloner_mysql_settings_page', |
376 | 376 | 'xcloner_mysql_settings_group', |
377 | 377 | array('xcloner_mysql_hostname', |
378 | - __('Wordpress mysql hostname','xcloner-backup-and-restore'), |
|
378 | + __('Wordpress mysql hostname', 'xcloner-backup-and-restore'), |
|
379 | 379 | $this->get_db_hostname(), |
380 | 380 | 'disabled' |
381 | 381 | ) |
@@ -384,12 +384,12 @@ discard block |
||
384 | 384 | register_setting('xcloner_mysql_settings_group', 'xcloner_mysql_username', array($this->xcloner_sanitization, "sanitize_input_as_raw")); |
385 | 385 | add_settings_field( |
386 | 386 | 'xcloner_mysql_username', |
387 | - __('Mysql Username','xcloner-backup-and-restore'), |
|
387 | + __('Mysql Username', 'xcloner-backup-and-restore'), |
|
388 | 388 | array($this, 'do_form_text_field'), |
389 | 389 | 'xcloner_mysql_settings_page', |
390 | 390 | 'xcloner_mysql_settings_group', |
391 | 391 | array('xcloner_mysql_username', |
392 | - __('Wordpress mysql username','xcloner-backup-and-restore'), |
|
392 | + __('Wordpress mysql username', 'xcloner-backup-and-restore'), |
|
393 | 393 | $this->get_db_username(), |
394 | 394 | 'disabled' |
395 | 395 | ) |
@@ -398,12 +398,12 @@ discard block |
||
398 | 398 | register_setting('xcloner_mysql_settings_group', 'xcloner_mysql_database', array($this->xcloner_sanitization, "sanitize_input_as_raw")); |
399 | 399 | add_settings_field( |
400 | 400 | 'xcloner_mysql_database', |
401 | - __('Mysql Database','xcloner-backup-and-restore'), |
|
401 | + __('Mysql Database', 'xcloner-backup-and-restore'), |
|
402 | 402 | array($this, 'do_form_text_field'), |
403 | 403 | 'xcloner_mysql_settings_page', |
404 | 404 | 'xcloner_mysql_settings_group', |
405 | 405 | array('xcloner_mysql_database', |
406 | - __('Wordpress mysql database','xcloner-backup-and-restore'), |
|
406 | + __('Wordpress mysql database', 'xcloner-backup-and-restore'), |
|
407 | 407 | $this->get_db_database(), |
408 | 408 | 'disabled' |
409 | 409 | ) |
@@ -413,12 +413,12 @@ discard block |
||
413 | 413 | register_setting('xcloner_system_settings_group', 'xcloner_size_limit_per_request', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
414 | 414 | add_settings_field( |
415 | 415 | 'xcloner_size_limit_per_request', |
416 | - __('Data Size Limit Per Request','xcloner-backup-and-restore'), |
|
416 | + __('Data Size Limit Per Request', 'xcloner-backup-and-restore'), |
|
417 | 417 | array($this, 'do_form_range_field'), |
418 | 418 | 'xcloner_system_settings_page', |
419 | 419 | 'xcloner_system_settings_group', |
420 | 420 | array('xcloner_size_limit_per_request', |
421 | - __('Use this option to set how much file data can XCloner backup in one AJAX request. Range 0-1024 MB','xcloner-backup-and-restore'), |
|
421 | + __('Use this option to set how much file data can XCloner backup in one AJAX request. Range 0-1024 MB', 'xcloner-backup-and-restore'), |
|
422 | 422 | 0, |
423 | 423 | 1024 |
424 | 424 | ) |
@@ -427,12 +427,12 @@ discard block |
||
427 | 427 | register_setting('xcloner_system_settings_group', 'xcloner_files_to_process_per_request', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
428 | 428 | add_settings_field( |
429 | 429 | 'xcloner_files_to_process_per_request', |
430 | - __('Files To Process Per Request','xcloner-backup-and-restore'), |
|
430 | + __('Files To Process Per Request', 'xcloner-backup-and-restore'), |
|
431 | 431 | array($this, 'do_form_range_field'), |
432 | 432 | 'xcloner_system_settings_page', |
433 | 433 | 'xcloner_system_settings_group', |
434 | 434 | array('xcloner_files_to_process_per_request', |
435 | - __('Use this option to set how many files XCloner should process at one time before doing another AJAX call','xcloner-backup-and-restore'), |
|
435 | + __('Use this option to set how many files XCloner should process at one time before doing another AJAX call', 'xcloner-backup-and-restore'), |
|
436 | 436 | 0, |
437 | 437 | 1000 |
438 | 438 | ) |
@@ -441,12 +441,12 @@ discard block |
||
441 | 441 | register_setting('xcloner_system_settings_group', 'xcloner_directories_to_scan_per_request', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
442 | 442 | add_settings_field( |
443 | 443 | 'xcloner_directories_to_scan_per_request', |
444 | - __('Directories To Scan Per Request','xcloner-backup-and-restore'), |
|
444 | + __('Directories To Scan Per Request', 'xcloner-backup-and-restore'), |
|
445 | 445 | array($this, 'do_form_range_field'), |
446 | 446 | 'xcloner_system_settings_page', |
447 | 447 | 'xcloner_system_settings_group', |
448 | 448 | array('xcloner_directories_to_scan_per_request', |
449 | - __('Use this option to set how many directories XCloner should scan at one time before doing another AJAX call','xcloner-backup-and-restore'), |
|
449 | + __('Use this option to set how many directories XCloner should scan at one time before doing another AJAX call', 'xcloner-backup-and-restore'), |
|
450 | 450 | 0, |
451 | 451 | 1000 |
452 | 452 | ) |
@@ -455,12 +455,12 @@ discard block |
||
455 | 455 | register_setting('xcloner_system_settings_group', 'xcloner_database_records_per_request', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
456 | 456 | add_settings_field( |
457 | 457 | 'xcloner_database_records_per_request', |
458 | - __('Database Records Per Request','xcloner-backup-and-restore'), |
|
458 | + __('Database Records Per Request', 'xcloner-backup-and-restore'), |
|
459 | 459 | array($this, 'do_form_range_field'), |
460 | 460 | 'xcloner_system_settings_page', |
461 | 461 | 'xcloner_system_settings_group', |
462 | 462 | array('xcloner_database_records_per_request', |
463 | - __('Use this option to set how many database table records should be fetched per AJAX request, or set to 0 to fetch all. Range 0-100000 records','xcloner-backup-and-restore'), |
|
463 | + __('Use this option to set how many database table records should be fetched per AJAX request, or set to 0 to fetch all. Range 0-100000 records', 'xcloner-backup-and-restore'), |
|
464 | 464 | 0, |
465 | 465 | 100000 |
466 | 466 | ) |
@@ -481,36 +481,36 @@ discard block |
||
481 | 481 | register_setting('xcloner_system_settings_group', 'xcloner_exclude_files_larger_than_mb', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
482 | 482 | add_settings_field( |
483 | 483 | 'xcloner_exclude_files_larger_than_mb', |
484 | - __('Exclude files larger than (MB)','xcloner-backup-and-restore'), |
|
484 | + __('Exclude files larger than (MB)', 'xcloner-backup-and-restore'), |
|
485 | 485 | array($this, 'do_form_number_field'), |
486 | 486 | 'xcloner_system_settings_page', |
487 | 487 | 'xcloner_system_settings_group', |
488 | 488 | array('xcloner_exclude_files_larger_than_mb', |
489 | - __('Use this option to automatically exclude files larger than a certain size in MB, or set to 0 to include all. Range 0-1000 MB','xcloner-backup-and-restore'), |
|
489 | + __('Use this option to automatically exclude files larger than a certain size in MB, or set to 0 to include all. Range 0-1000 MB', 'xcloner-backup-and-restore'), |
|
490 | 490 | ) |
491 | 491 | ); |
492 | 492 | |
493 | 493 | register_setting('xcloner_system_settings_group', 'xcloner_split_backup_limit', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
494 | 494 | add_settings_field( |
495 | 495 | 'xcloner_split_backup_limit', |
496 | - __('Split Backup Archive Limit (MB)','xcloner-backup-and-restore'), |
|
496 | + __('Split Backup Archive Limit (MB)', 'xcloner-backup-and-restore'), |
|
497 | 497 | array($this, 'do_form_number_field'), |
498 | 498 | 'xcloner_system_settings_page', |
499 | 499 | 'xcloner_system_settings_group', |
500 | 500 | array('xcloner_split_backup_limit', |
501 | - __('Use this option to automatically split the backup archive into smaller parts. Range 0-10000 MB','xcloner-backup-and-restore'), |
|
501 | + __('Use this option to automatically split the backup archive into smaller parts. Range 0-10000 MB', 'xcloner-backup-and-restore'), |
|
502 | 502 | ) |
503 | 503 | ); |
504 | 504 | |
505 | 505 | register_setting('xcloner_system_settings_group', 'xcloner_force_tmp_path_site_root'); |
506 | 506 | add_settings_field( |
507 | 507 | 'xcloner_force_tmp_path_site_root', |
508 | - __('Force Temporary Path Within XCloner Storage','xcloner-backup-and-restore'), |
|
508 | + __('Force Temporary Path Within XCloner Storage', 'xcloner-backup-and-restore'), |
|
509 | 509 | array($this, 'do_form_switch_field'), |
510 | 510 | 'xcloner_system_settings_page', |
511 | 511 | 'xcloner_system_settings_group', |
512 | 512 | array('xcloner_force_tmp_path_site_root', |
513 | - sprintf(__('Enable this option if you want the XCloner Temporary Path to be within your XCloner Storage Location','xcloner-backup-and-restore'), $this->get_table_prefix()) |
|
513 | + sprintf(__('Enable this option if you want the XCloner Temporary Path to be within your XCloner Storage Location', 'xcloner-backup-and-restore'), $this->get_table_prefix()) |
|
514 | 514 | ) |
515 | 515 | ); |
516 | 516 | |
@@ -518,36 +518,36 @@ discard block |
||
518 | 518 | register_setting('xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_days', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
519 | 519 | add_settings_field( |
520 | 520 | 'xcloner_cleanup_retention_limit_days', |
521 | - __('Cleanup by Date(days)','xcloner-backup-and-restore'), |
|
521 | + __('Cleanup by Date(days)', 'xcloner-backup-and-restore'), |
|
522 | 522 | array($this, 'do_form_number_field'), |
523 | 523 | 'xcloner_cleanup_settings_page', |
524 | 524 | 'xcloner_cleanup_settings_group', |
525 | 525 | array('xcloner_cleanup_retention_limit_days', |
526 | - __('Specify the maximum number of days a backup archive can be kept on the server. 0 disables this option','xcloner-backup-and-restore') |
|
526 | + __('Specify the maximum number of days a backup archive can be kept on the server. 0 disables this option', 'xcloner-backup-and-restore') |
|
527 | 527 | ) |
528 | 528 | ); |
529 | 529 | |
530 | 530 | register_setting('xcloner_cleanup_settings_group', 'xcloner_cleanup_retention_limit_archives', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
531 | 531 | add_settings_field( |
532 | 532 | 'xcloner_cleanup_retention_limit_archives', |
533 | - __('Cleanup by Quantity','xcloner-backup-and-restore'), |
|
533 | + __('Cleanup by Quantity', 'xcloner-backup-and-restore'), |
|
534 | 534 | array($this, 'do_form_number_field'), |
535 | 535 | 'xcloner_cleanup_settings_page', |
536 | 536 | 'xcloner_cleanup_settings_group', |
537 | 537 | array('xcloner_cleanup_retention_limit_archives', |
538 | - __('Specify the maximum number of backup archives to keep on the server. 0 disables this option','xcloner-backup-and-restore') |
|
538 | + __('Specify the maximum number of backup archives to keep on the server. 0 disables this option', 'xcloner-backup-and-restore') |
|
539 | 539 | ) |
540 | 540 | ); |
541 | 541 | |
542 | 542 | register_setting('xcloner_cleanup_settings_group', 'xcloner_cleanup_capacity_limit', array($this->xcloner_sanitization, "sanitize_input_as_int")); |
543 | 543 | add_settings_field( |
544 | 544 | 'xcloner_cleanup_capacity_limit', |
545 | - __('Cleanup by Capacity(MB)','xcloner-backup-and-restore'), |
|
545 | + __('Cleanup by Capacity(MB)', 'xcloner-backup-and-restore'), |
|
546 | 546 | array($this, 'do_form_number_field'), |
547 | 547 | 'xcloner_cleanup_settings_page', |
548 | 548 | 'xcloner_cleanup_settings_group', |
549 | 549 | array('xcloner_cleanup_capacity_limit', |
550 | - __('Remove oldest backups if all created backups exceed the configured limit in Megabytes. 0 disables this option','xcloner-backup-and-restore') |
|
550 | + __('Remove oldest backups if all created backups exceed the configured limit in Megabytes. 0 disables this option', 'xcloner-backup-and-restore') |
|
551 | 551 | ) |
552 | 552 | ); |
553 | 553 | |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | register_setting('xcloner_cron_settings_group', 'xcloner_cron_frequency'); |
556 | 556 | add_settings_field( |
557 | 557 | 'xcloner_cron_frequency', |
558 | - __('Cron frequency','xcloner-backup-and-restore'), |
|
558 | + __('Cron frequency', 'xcloner-backup-and-restore'), |
|
559 | 559 | array($this, 'do_form_text_field'), |
560 | 560 | 'xcloner_cron_settings_page', |
561 | 561 | 'xcloner_cron_settings_group', |
@@ -581,20 +581,20 @@ discard block |
||
581 | 581 | // text field content cb |
582 | 582 | public function do_form_text_field($params) |
583 | 583 | { |
584 | - if(!isset($params['3'])) |
|
584 | + if (!isset($params['3'])) |
|
585 | 585 | $params[3] = 0; |
586 | - if(!isset($params['2'])) |
|
586 | + if (!isset($params['2'])) |
|
587 | 587 | $params[2] = 0; |
588 | 588 | |
589 | 589 | list($fieldname, $label, $value, $disabled) = $params; |
590 | 590 | |
591 | - if(!$value) |
|
591 | + if (!$value) |
|
592 | 592 | $value = get_option($fieldname); |
593 | 593 | // output the field |
594 | 594 | ?> |
595 | 595 | <div class="row"> |
596 | 596 | <div class="input-field col s10 m10 l8"> |
597 | - <input class="validate" <?php echo ($disabled)?"disabled":""?> name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" type="text" class="validate" value="<?php echo isset($value) ? esc_attr($value) : ''; ?>"> |
|
597 | + <input class="validate" <?php echo ($disabled) ? "disabled" : ""?> name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" type="text" class="validate" value="<?php echo isset($value) ? esc_attr($value) : ''; ?>"> |
|
598 | 598 | </div> |
599 | 599 | <div class="col s2 m2 "> |
600 | 600 | <a class="btn-floating tooltipped btn-small" data-position="left" data-delay="50" data-tooltip="<?php echo $label?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
@@ -608,20 +608,20 @@ discard block |
||
608 | 608 | // textarea field content cb |
609 | 609 | public function do_form_textarea_field($params) |
610 | 610 | { |
611 | - if(!isset($params['3'])) |
|
611 | + if (!isset($params['3'])) |
|
612 | 612 | $params[3] = 0; |
613 | - if(!isset($params['2'])) |
|
613 | + if (!isset($params['2'])) |
|
614 | 614 | $params[2] = 0; |
615 | 615 | |
616 | 616 | list($fieldname, $label, $value, $disabled) = $params; |
617 | 617 | |
618 | - if(!$value) |
|
618 | + if (!$value) |
|
619 | 619 | $value = get_option($fieldname); |
620 | 620 | // output the field |
621 | 621 | ?> |
622 | 622 | <div class="row"> |
623 | 623 | <div class="input-field col s10 m10 l8"> |
624 | - <textarea class="validate" <?php echo ($disabled)?"disabled":""?> name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" type="text" class="validate" value=""><?php echo isset($value) ? esc_attr($value) : ''; ?></textarea> |
|
624 | + <textarea class="validate" <?php echo ($disabled) ? "disabled" : ""?> name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" type="text" class="validate" value=""><?php echo isset($value) ? esc_attr($value) : ''; ?></textarea> |
|
625 | 625 | </div> |
626 | 626 | <div class="col s2 m2 "> |
627 | 627 | <a class="btn-floating tooltipped btn-small" data-position="center" data-html="true" data-delay="50" data-tooltip="<?php echo $label?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
@@ -652,20 +652,20 @@ discard block |
||
652 | 652 | // number field content cb |
653 | 653 | public function do_form_number_field($params) |
654 | 654 | { |
655 | - if(!isset($params['3'])) |
|
655 | + if (!isset($params['3'])) |
|
656 | 656 | $params[3] = 0; |
657 | - if(!isset($params['2'])) |
|
657 | + if (!isset($params['2'])) |
|
658 | 658 | $params[2] = 0; |
659 | 659 | |
660 | 660 | list($fieldname, $label, $value, $disabled) = $params; |
661 | 661 | |
662 | - if(!$value) |
|
662 | + if (!$value) |
|
663 | 663 | $value = get_option($fieldname); |
664 | 664 | // output the field |
665 | 665 | ?> |
666 | 666 | <div class="row"> |
667 | 667 | <div class="input-field col s10 m5 l3"> |
668 | - <input class="validate" <?php echo ($disabled)?"disabled":""?> name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" type="number" class="validate" value="<?php echo isset($value) ? esc_attr($value) : ''; ?>"> |
|
668 | + <input class="validate" <?php echo ($disabled) ? "disabled" : ""?> name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" type="number" class="validate" value="<?php echo isset($value) ? esc_attr($value) : ''; ?>"> |
|
669 | 669 | </div> |
670 | 670 | <div class="col s2 m2 "> |
671 | 671 | <a class="btn-floating tooltipped btn-small" data-html="true" data-position="center" data-delay="50" data-tooltip="<?php echo $label?>" data-tooltip-id=""><i class="material-icons">help_outline</i></a> |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | |
679 | 679 | public function do_form_range_field($params) |
680 | 680 | { |
681 | - if(!isset($params['4'])) |
|
681 | + if (!isset($params['4'])) |
|
682 | 682 | $params[4] = 0; |
683 | 683 | |
684 | 684 | list($fieldname, $label, $range_start, $range_end, $disabled) = $params; |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | <div class="row"> |
688 | 688 | <div class="input-field col s10 m10 l8"> |
689 | 689 | <p class="range-field"> |
690 | - <input <?php echo ($disabled)?"disabled":""?> type="range" name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" min="<?php echo $range_start?>" max="<?php echo $range_end?>" value="<?php echo isset($value) ? esc_attr($value) : ''; ?>" /> |
|
690 | + <input <?php echo ($disabled) ? "disabled" : ""?> type="range" name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" min="<?php echo $range_start?>" max="<?php echo $range_end?>" value="<?php echo isset($value) ? esc_attr($value) : ''; ?>" /> |
|
691 | 691 | </p> |
692 | 692 | </div> |
693 | 693 | <div class="col s2 m2 "> |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | |
701 | 701 | public function do_form_switch_field($params) |
702 | 702 | { |
703 | - if(!isset($params['2'])) |
|
703 | + if (!isset($params['2'])) |
|
704 | 704 | $params[2] = 0; |
705 | 705 | list($fieldname, $label, $disabled) = $params; |
706 | 706 | $value = get_option($fieldname); |
@@ -710,7 +710,7 @@ discard block |
||
710 | 710 | <div class="switch"> |
711 | 711 | <label> |
712 | 712 | Off |
713 | - <input <?php echo ($disabled)?"disabled":""?> type="checkbox" name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" value="1" <?php echo ($value) ? 'checked="checked"' : ''; ?>"> |
|
713 | + <input <?php echo ($disabled) ? "disabled" : ""?> type="checkbox" name="<?php echo $fieldname?>" id="<?php echo $fieldname?>" value="1" <?php echo ($value) ? 'checked="checked"' : ''; ?>"> |
|
714 | 714 | <span class="lever"></span> |
715 | 715 | On |
716 | 716 | </label> |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | use splitbrain\PHPArchive\FileInfo; |
12 | 12 | |
13 | 13 | |
14 | -class Xcloner_Api{ |
|
14 | +class Xcloner_Api { |
|
15 | 15 | |
16 | 16 | private $xcloner_database; |
17 | 17 | private $xcloner_settings; |
@@ -27,30 +27,30 @@ discard block |
||
27 | 27 | { |
28 | 28 | global $wpdb; |
29 | 29 | |
30 | - if(WP_DEBUG) |
|
30 | + if (WP_DEBUG) |
|
31 | 31 | { |
32 | 32 | error_reporting(0); |
33 | 33 | } |
34 | 34 | |
35 | - if( ob_get_length() ) |
|
35 | + if (ob_get_length()) |
|
36 | 36 | ob_end_clean(); |
37 | 37 | ob_start(); |
38 | 38 | |
39 | - $wpdb->show_errors = false; |
|
39 | + $wpdb->show_errors = false; |
|
40 | 40 | |
41 | 41 | $this->xcloner_container = $xcloner_container; |
42 | 42 | |
43 | 43 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
44 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api"); |
|
44 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_api"); |
|
45 | 45 | $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
46 | 46 | $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
47 | 47 | $this->xcloner_requirements = $xcloner_container->get_xcloner_requirements(); |
48 | - $this->archive_system = $xcloner_container->get_archive_system(); |
|
49 | - $this->xcloner_database = $xcloner_container->get_xcloner_database(); |
|
50 | - $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler(); |
|
48 | + $this->archive_system = $xcloner_container->get_archive_system(); |
|
49 | + $this->xcloner_database = $xcloner_container->get_xcloner_database(); |
|
50 | + $this->xcloner_scheduler = $xcloner_container->get_xcloner_scheduler(); |
|
51 | 51 | |
52 | - if(isset($_POST['API_ID'])){ |
|
53 | - $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0 , 15)); |
|
52 | + if (isset($_POST['API_ID'])) { |
|
53 | + $this->logger->info("Processing ajax request ID ".substr($this->xcloner_sanitization->sanitize_input_as_string($_POST['API_ID']), 0, 15)); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | } |
@@ -78,15 +78,15 @@ discard block |
||
78 | 78 | $data['dbDatabase'] = $this->xcloner_settings->get_db_database(); |
79 | 79 | |
80 | 80 | |
81 | - $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
82 | - $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database"; |
|
83 | - $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql"; |
|
81 | + $data['recordsPerSession'] = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
82 | + $data['TEMP_DBPROCESS_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS.".database"; |
|
83 | + $data['TEMP_DUMP_FILE'] = $this->xcloner_settings->get_xcloner_tmp_path().DS."database-sql.sql"; |
|
84 | 84 | |
85 | 85 | try |
86 | 86 | { |
87 | 87 | $this->xcloner_database->init($data); |
88 | 88 | |
89 | - }catch(Exception $e){ |
|
89 | + }catch (Exception $e) { |
|
90 | 90 | |
91 | 91 | $this->send_response($e->getMessage()); |
92 | 92 | $this->logger->error($e->getMessage()); |
@@ -113,19 +113,19 @@ discard block |
||
113 | 113 | $schedule = array(); |
114 | 114 | $response = array(); |
115 | 115 | |
116 | - if(isset($_POST['data'])) |
|
116 | + if (isset($_POST['data'])) |
|
117 | 117 | $params = json_decode(stripslashes($_POST['data'])); |
118 | 118 | |
119 | 119 | $this->process_params($params); |
120 | 120 | |
121 | - if(isset($_POST['id'])) |
|
121 | + if (isset($_POST['id'])) |
|
122 | 122 | { |
123 | 123 | |
124 | 124 | $this->form_params['backup_params']['backup_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['backup_name']); |
125 | 125 | $this->form_params['backup_params']['email_notification'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['email_notification']); |
126 | - if($_POST['diff_start_date']){ |
|
126 | + if ($_POST['diff_start_date']) { |
|
127 | 127 | $this->form_params['backup_params']['diff_start_date'] = strtotime($this->xcloner_sanitization->sanitize_input_as_string($_POST['diff_start_date'])); |
128 | - }else{ |
|
128 | + } else { |
|
129 | 129 | $this->form_params['backup_params']['diff_start_date'] = ""; |
130 | 130 | } |
131 | 131 | $this->form_params['backup_params']['schedule_name'] = $this->xcloner_sanitization->sanitize_input_as_string($_POST['schedule_name']); |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | $tables = explode(PHP_EOL, $this->form_params['database']); |
141 | 141 | $return = array(); |
142 | 142 | |
143 | - foreach($tables as $table) |
|
143 | + foreach ($tables as $table) |
|
144 | 144 | { |
145 | - $table = str_replace("\r","", $table); |
|
145 | + $table = str_replace("\r", "", $table); |
|
146 | 146 | $data = explode(".", $table); |
147 | - if(isset($data[1])) |
|
147 | + if (isset($data[1])) |
|
148 | 148 | $return[$data[0]][] = $data[1]; |
149 | 149 | } |
150 | 150 | |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | $excluded_files = explode(PHP_EOL, $this->form_params['excluded_files']); |
154 | 154 | $return = array(); |
155 | 155 | |
156 | - foreach($excluded_files as $file) |
|
156 | + foreach ($excluded_files as $file) |
|
157 | 157 | { |
158 | - $file = str_replace("\r","", $file); |
|
159 | - if($file) |
|
158 | + $file = str_replace("\r", "", $file); |
|
159 | + if ($file) |
|
160 | 160 | $return[] = $file; |
161 | 161 | } |
162 | 162 | |
@@ -164,27 +164,27 @@ discard block |
||
164 | 164 | |
165 | 165 | $schedule['start_at'] = $this->form_params['backup_params']['start_at']; |
166 | 166 | |
167 | - if(!isset($_POST['status'])) |
|
167 | + if (!isset($_POST['status'])) |
|
168 | 168 | $schedule['status'] = 0; |
169 | 169 | else |
170 | 170 | $schedule['status'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['status']); |
171 | - }else{ |
|
171 | + } else { |
|
172 | 172 | |
173 | 173 | $schedule['status'] = 1; |
174 | - $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date'] . |
|
174 | + $schedule['start_at'] = strtotime($this->form_params['backup_params']['schedule_start_date']. |
|
175 | 175 | " ".$this->form_params['backup_params']['schedule_start_time']); |
176 | 176 | |
177 | - if($schedule['start_at'] <= time()) |
|
177 | + if ($schedule['start_at'] <= time()) |
|
178 | 178 | { |
179 | 179 | $schedule['start_at'] = ""; |
180 | 180 | } |
181 | 181 | } |
182 | 182 | |
183 | - if(!$schedule['start_at']) |
|
183 | + if (!$schedule['start_at']) |
|
184 | 184 | { |
185 | 185 | $schedule['start_at'] = date('Y-m-d H:i:s', time()); |
186 | - }else{ |
|
187 | - $schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at'] - (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS) ); |
|
186 | + } else { |
|
187 | + $schedule['start_at'] = date('Y-m-d H:i:s', $schedule['start_at'] - (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | $schedule['name'] = $this->form_params['backup_params']['schedule_name']; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | //$schedule['backup_type'] = $this->form_params['backup_params']['backup_type']; |
194 | 194 | $schedule['params'] = json_encode($this->form_params); |
195 | 195 | |
196 | - if(!isset($_POST['id'])) |
|
196 | + if (!isset($_POST['id'])) |
|
197 | 197 | { |
198 | 198 | $wpdb->insert( |
199 | 199 | $wpdb->prefix.'xcloner_scheduler', |
@@ -203,23 +203,23 @@ discard block |
||
203 | 203 | '%s' |
204 | 204 | ) |
205 | 205 | ); |
206 | - }else { |
|
206 | + } else { |
|
207 | 207 | $wpdb->update( |
208 | 208 | $wpdb->prefix.'xcloner_scheduler', |
209 | 209 | $schedule, |
210 | - array( 'id' => $_POST['id'] ), |
|
210 | + array('id' => $_POST['id']), |
|
211 | 211 | array( |
212 | 212 | '%s', |
213 | 213 | '%s' |
214 | 214 | ) |
215 | 215 | ); |
216 | 216 | } |
217 | - if(isset($_POST['id'])) |
|
217 | + if (isset($_POST['id'])) |
|
218 | 218 | { |
219 | 219 | $scheduler->update_cron_hook($_POST['id']); |
220 | 220 | } |
221 | 221 | |
222 | - if( $wpdb->last_error ) { |
|
222 | + if ($wpdb->last_error) { |
|
223 | 223 | $response['error'] = 1; |
224 | 224 | $response['error_message'] = $wpdb->last_error/*."--".$wpdb->last_query*/; |
225 | 225 | |
@@ -242,19 +242,19 @@ discard block |
||
242 | 242 | |
243 | 243 | $params = json_decode(stripslashes($_POST['data'])); |
244 | 244 | |
245 | - $init = (int)$_POST['init']; |
|
245 | + $init = (int)$_POST['init']; |
|
246 | 246 | |
247 | - if($params === NULL) |
|
248 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
247 | + if ($params === NULL) |
|
248 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
249 | 249 | |
250 | 250 | $this->process_params($params); |
251 | 251 | |
252 | 252 | $return['finished'] = 1; |
253 | 253 | |
254 | 254 | //$return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
255 | - try{ |
|
255 | + try { |
|
256 | 256 | $return = $this->archive_system->start_incremental_backup($this->form_params['backup_params'], $this->form_params['extra'], $init); |
257 | - }catch(Exception $e) |
|
257 | + }catch (Exception $e) |
|
258 | 258 | { |
259 | 259 | $return = array(); |
260 | 260 | $return['error'] = true; |
@@ -263,26 +263,26 @@ discard block |
||
263 | 263 | return $this->send_response($return, $hash = 1); |
264 | 264 | } |
265 | 265 | |
266 | - if($return['finished']) |
|
266 | + if ($return['finished']) |
|
267 | 267 | { |
268 | 268 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
269 | - if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
269 | + if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
270 | 270 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
271 | 271 | } |
272 | 272 | |
273 | 273 | $data = $return; |
274 | 274 | |
275 | 275 | //check if backup is finished |
276 | - if($return['finished'] ) |
|
276 | + if ($return['finished']) |
|
277 | 277 | { |
278 | - if(isset($this->form_params['backup_params']['email_notification']) and $to=$this->form_params['backup_params']['email_notification']) |
|
278 | + if (isset($this->form_params['backup_params']['email_notification']) and $to = $this->form_params['backup_params']['email_notification']) |
|
279 | 279 | { |
280 | - try{ |
|
280 | + try { |
|
281 | 281 | $from = ""; |
282 | 282 | $subject = ""; |
283 | 283 | $additional['lines_total'] = $return['extra']['lines_total']; |
284 | - $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params,"", $additional); |
|
285 | - }catch(Exception $e) |
|
284 | + $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $this->form_params, "", $additional); |
|
285 | + }catch (Exception $e) |
|
286 | 286 | { |
287 | 287 | $this->logger->error($e->getMessage()); |
288 | 288 | } |
@@ -304,17 +304,17 @@ discard block |
||
304 | 304 | |
305 | 305 | $params = json_decode(stripslashes($_POST['data'])); |
306 | 306 | |
307 | - $init = (int)$_POST['init']; |
|
307 | + $init = (int)$_POST['init']; |
|
308 | 308 | |
309 | - if($params === NULL) |
|
310 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
309 | + if ($params === NULL) |
|
310 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
311 | 311 | |
312 | 312 | $this->process_params($params); |
313 | 313 | |
314 | 314 | //$xcloner_database = $this->init_db(); |
315 | 315 | $return = $this->xcloner_database->start_database_recursion($this->form_params['database'], $this->form_params['extra'], $init); |
316 | 316 | |
317 | - if(isset($return['error']) and $return['error']) |
|
317 | + if (isset($return['error']) and $return['error']) |
|
318 | 318 | $data['finished'] = 1; |
319 | 319 | else |
320 | 320 | $data['finished'] = $return['finished']; |
@@ -334,10 +334,10 @@ discard block |
||
334 | 334 | $this->check_access(); |
335 | 335 | |
336 | 336 | $params = json_decode(stripslashes($_POST['data'])); |
337 | - $init = (int)$_POST['init']; |
|
337 | + $init = (int)$_POST['init']; |
|
338 | 338 | |
339 | - if($params === NULL) |
|
340 | - die( '{"status":false,"msg":"The post_data parameter must be valid JSON"}' ); |
|
339 | + if ($params === NULL) |
|
340 | + die('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
341 | 341 | |
342 | 342 | $hash = $this->process_params($params); |
343 | 343 | |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | $data["finished"] = !$return; |
349 | 349 | $data["total_files_num"] = $this->xcloner_file_system->get_scanned_files_num(); |
350 | 350 | $data["last_logged_file"] = $this->xcloner_file_system->last_logged_file(); |
351 | - $data["total_files_size"] = sprintf("%.2f",$this->xcloner_file_system->get_scanned_files_total_size()/(1024*1024)); |
|
351 | + $data["total_files_size"] = sprintf("%.2f", $this->xcloner_file_system->get_scanned_files_total_size() / (1024 * 1024)); |
|
352 | 352 | |
353 | 353 | return $this->send_response($data, $hash = 1); |
354 | 354 | } |
@@ -360,7 +360,7 @@ discard block |
||
360 | 360 | */ |
361 | 361 | private function process_params($params) |
362 | 362 | { |
363 | - if(isset($params->hash)) |
|
363 | + if (isset($params->hash)) |
|
364 | 364 | $this->xcloner_settings->set_hash($params->hash); |
365 | 365 | |
366 | 366 | $this->form_params['extra'] = array(); |
@@ -368,9 +368,9 @@ discard block |
||
368 | 368 | |
369 | 369 | $this->form_params['database'] = array(); |
370 | 370 | |
371 | - if(isset($params->backup_params)) |
|
371 | + if (isset($params->backup_params)) |
|
372 | 372 | { |
373 | - foreach($params->backup_params as $param) |
|
373 | + foreach ($params->backup_params as $param) |
|
374 | 374 | { |
375 | 375 | $this->form_params['backup_params'][$param->name] = $this->xcloner_sanitization->sanitize_input_as_string($param->value); |
376 | 376 | $this->logger->debug("Adding form parameter ".$param->name.".".$param->value."\n", array('POST', 'fields filter')); |
@@ -379,28 +379,28 @@ discard block |
||
379 | 379 | |
380 | 380 | $this->form_params['database'] = array(); |
381 | 381 | |
382 | - if(isset($params->table_params)) |
|
382 | + if (isset($params->table_params)) |
|
383 | 383 | { |
384 | - foreach($params->table_params as $param) |
|
384 | + foreach ($params->table_params as $param) |
|
385 | 385 | { |
386 | 386 | $this->form_params['database'][$param->parent][] = $this->xcloner_sanitization->sanitize_input_as_raw($param->id); |
387 | 387 | $this->logger->debug("Adding database filter ".$param->parent.".".$param->id."\n", array('POST', 'database filter')); |
388 | 388 | } |
389 | 389 | } |
390 | 390 | |
391 | - $this->form_params['excluded_files'] = array(); |
|
392 | - if(isset($params->files_params)) |
|
391 | + $this->form_params['excluded_files'] = array(); |
|
392 | + if (isset($params->files_params)) |
|
393 | 393 | { |
394 | - foreach($params->files_params as $param) |
|
394 | + foreach ($params->files_params as $param) |
|
395 | 395 | { |
396 | 396 | $this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
397 | 397 | } |
398 | 398 | |
399 | 399 | $unique_exclude_files = array(); |
400 | 400 | |
401 | - foreach($params->files_params as $key=>$param) |
|
401 | + foreach ($params->files_params as $key=>$param) |
|
402 | 402 | { |
403 | - if(!in_array($param->parent, $this->form_params['excluded_files'])){ |
|
403 | + if (!in_array($param->parent, $this->form_params['excluded_files'])) { |
|
404 | 404 | //$this->form_params['excluded_files'][] = $this->xcloner_sanitization->sanitize_input_as_relative_path($param->id); |
405 | 405 | $unique_exclude_files[] = $param->id; |
406 | 406 | $this->logger->debug("Adding file filter ".$param->id."\n", array('POST', 'exclude files filter')); |
@@ -412,13 +412,13 @@ discard block |
||
412 | 412 | |
413 | 413 | //$this->form_params['excluded_files'] = array_merge($this->form_params['excluded_files'], $this->exclude_files_by_default); |
414 | 414 | |
415 | - if(isset($params->extra)) |
|
415 | + if (isset($params->extra)) |
|
416 | 416 | { |
417 | - foreach($params->extra as $key=>$value) |
|
417 | + foreach ($params->extra as $key=>$value) |
|
418 | 418 | $this->form_params['extra'][$key] = $this->xcloner_sanitization->sanitize_input_as_raw($value); |
419 | 419 | } |
420 | 420 | |
421 | - if(isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) |
|
421 | + if (isset($this->form_params['backup_params']['diff_start_date']) and $this->form_params['backup_params']['diff_start_date']) |
|
422 | 422 | { |
423 | 423 | $this->form_params['backup_params']['diff_start_date'] = strtotime($this->form_params['backup_params']['diff_start_date']); |
424 | 424 | $this->xcloner_file_system->set_diff_timestamp_start($this->form_params['backup_params']['diff_start_date']); |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | |
441 | 441 | $data = array(); |
442 | 442 | |
443 | - if($folder == "#"){ |
|
443 | + if ($folder == "#") { |
|
444 | 444 | |
445 | 445 | $folder = "/"; |
446 | 446 | $data[] = array( |
@@ -453,9 +453,9 @@ discard block |
||
453 | 453 | ); |
454 | 454 | } |
455 | 455 | |
456 | - try{ |
|
456 | + try { |
|
457 | 457 | $files = $this->xcloner_file_system->list_directory($folder); |
458 | - }catch(Exception $e){ |
|
458 | + }catch (Exception $e) { |
|
459 | 459 | |
460 | 460 | print $e->getMessage(); |
461 | 461 | $this->logger->error($e->getMessage()); |
@@ -470,17 +470,17 @@ discard block |
||
470 | 470 | } |
471 | 471 | array_multisort($type, SORT_ASC, $files); |
472 | 472 | |
473 | - foreach($files as $file) |
|
473 | + foreach ($files as $file) |
|
474 | 474 | { |
475 | 475 | $children = false; |
476 | 476 | $text = $file['basename']; |
477 | 477 | |
478 | - if($file['type'] == "dir") |
|
478 | + if ($file['type'] == "dir") |
|
479 | 479 | $children = true; |
480 | 480 | else |
481 | - $text .= " (". $this->xcloner_requirements->file_format_size($file['size']).")"; |
|
481 | + $text .= " (".$this->xcloner_requirements->file_format_size($file['size']).")"; |
|
482 | 482 | |
483 | - if($this->xcloner_file_system->is_excluded($file)) |
|
483 | + if ($this->xcloner_file_system->is_excluded($file)) |
|
484 | 484 | $selected = true; |
485 | 485 | else |
486 | 486 | $selected = false; |
@@ -515,25 +515,25 @@ discard block |
||
515 | 515 | |
516 | 516 | $xcloner_backup_only_wp_tables = $this->xcloner_settings->get_xcloner_option('xcloner_backup_only_wp_tables'); |
517 | 517 | |
518 | - if($database == "#") |
|
518 | + if ($database == "#") |
|
519 | 519 | { |
520 | - try{ |
|
520 | + try { |
|
521 | 521 | $return = $this->xcloner_database->get_all_databases(); |
522 | - }catch(Exception $e){ |
|
522 | + }catch (Exception $e) { |
|
523 | 523 | $this->logger->error($e->getMessage()); |
524 | 524 | } |
525 | 525 | |
526 | - foreach($return as $database) |
|
526 | + foreach ($return as $database) |
|
527 | 527 | { |
528 | - if($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) |
|
528 | + if ($xcloner_backup_only_wp_tables and $database['name'] != $this->xcloner_settings->get_db_database()) |
|
529 | 529 | continue; |
530 | 530 | |
531 | 531 | $state = array(); |
532 | 532 | |
533 | - if($database['name'] == $this->xcloner_settings->get_db_database()) |
|
533 | + if ($database['name'] == $this->xcloner_settings->get_db_database()) |
|
534 | 534 | { |
535 | 535 | $state['selected'] = true; |
536 | - if($database['num_tables'] < 25) |
|
536 | + if ($database['num_tables'] < 25) |
|
537 | 537 | $state['opened'] = false; |
538 | 538 | } |
539 | 539 | |
@@ -549,22 +549,22 @@ discard block |
||
549 | 549 | |
550 | 550 | } |
551 | 551 | |
552 | - else{ |
|
552 | + else { |
|
553 | 553 | |
554 | - try{ |
|
554 | + try { |
|
555 | 555 | $return = $this->xcloner_database->list_tables($database, "", 1); |
556 | - }catch(Exception $e){ |
|
556 | + }catch (Exception $e) { |
|
557 | 557 | $this->logger->error($e->getMessage()); |
558 | 558 | } |
559 | 559 | |
560 | - foreach($return as $table) |
|
560 | + foreach ($return as $table) |
|
561 | 561 | { |
562 | 562 | $state = array(); |
563 | 563 | |
564 | - if($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) |
|
564 | + if ($xcloner_backup_only_wp_tables and !stristr($table['name'], $this->xcloner_settings->get_table_prefix())) |
|
565 | 565 | continue; |
566 | 566 | |
567 | - if(isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) |
|
567 | + if (isset($database['name']) and $database['name'] == $this->xcloner_settings->get_db_database()) |
|
568 | 568 | $state = array('selected' => true); |
569 | 569 | |
570 | 570 | $data[] = array( |
@@ -592,12 +592,12 @@ discard block |
||
592 | 592 | |
593 | 593 | $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
594 | 594 | $scheduler = $this->xcloner_scheduler; |
595 | - $data = $scheduler->get_schedule_by_id($schedule_id); |
|
595 | + $data = $scheduler->get_schedule_by_id($schedule_id); |
|
596 | 596 | |
597 | - $data['start_at'] = date("Y-m-d H:i", strtotime($data['start_at']) + (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS)); |
|
598 | - if(isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") |
|
597 | + $data['start_at'] = date("Y-m-d H:i", strtotime($data['start_at']) + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
598 | + if (isset($data['backup_params']->diff_start_date) && $data['backup_params']->diff_start_date != "") |
|
599 | 599 | { |
600 | - $data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date) ); |
|
600 | + $data['backup_params']->diff_start_date = date("Y-m-d", ($data['backup_params']->diff_start_date)); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | return $this->send_response($data); |
@@ -613,14 +613,14 @@ discard block |
||
613 | 613 | $this->check_access(); |
614 | 614 | |
615 | 615 | $scheduler = $this->xcloner_scheduler; |
616 | - $data = $scheduler->get_scheduler_list(); |
|
616 | + $data = $scheduler->get_scheduler_list(); |
|
617 | 617 | $return['data'] = array(); |
618 | 618 | |
619 | - foreach($data as $res) |
|
619 | + foreach ($data as $res) |
|
620 | 620 | { |
621 | 621 | $action = "<a href=\"#".$res->id."\" class=\"edit\" title='Edit'> <i class=\"material-icons \">edit</i></a> |
622 | 622 | <a href=\"#".$res->id."\" class=\"delete\" title='Delete'><i class=\"material-icons \">delete</i></a>"; |
623 | - if($res->status) |
|
623 | + if ($res->status) |
|
624 | 624 | $status = '<i class="material-icons active status">timer</i>'; |
625 | 625 | else |
626 | 626 | $status = '<i class="material-icons status inactive">timer_off</i>'; |
@@ -631,14 +631,14 @@ discard block |
||
631 | 631 | |
632 | 632 | $remote_storage = $res->remote_storage; |
633 | 633 | |
634 | - if(!$next_run_time >= time()) |
|
634 | + if (!$next_run_time >= time()) |
|
635 | 635 | $next_run = " "; |
636 | 636 | |
637 | - if(trim($next_run)) |
|
637 | + if (trim($next_run)) |
|
638 | 638 | { |
639 | - $date_text = date(get_option('date_format')." ".get_option('time_format'), $next_run_time + (get_option( 'gmt_offset' ) * HOUR_IN_SECONDS)); |
|
639 | + $date_text = date(get_option('date_format')." ".get_option('time_format'), $next_run_time + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
640 | 640 | |
641 | - if($next_run_time >= time()) |
|
641 | + if ($next_run_time >= time()) |
|
642 | 642 | $next_run = "in ".human_time_diff($next_run_time, time()); |
643 | 643 | else |
644 | 644 | $next_run = __("executed", 'xcloner-backup-and-restore'); |
@@ -651,13 +651,13 @@ discard block |
||
651 | 651 | $backup_size = ""; |
652 | 652 | $backup_time = ""; |
653 | 653 | |
654 | - if($res->last_backup) |
|
654 | + if ($res->last_backup) |
|
655 | 655 | { |
656 | - if( $this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) |
|
656 | + if ($this->xcloner_file_system->get_storage_filesystem()->has($res->last_backup)) |
|
657 | 657 | { |
658 | 658 | $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($res->last_backup); |
659 | 659 | $backup_size = size_format($this->xcloner_file_system->get_backup_size($res->last_backup)); |
660 | - $backup_time = date(get_option('date_format')." ".get_option('time_format'), $metadata['timestamp']+(get_option( 'gmt_offset' ) * HOUR_IN_SECONDS)); |
|
660 | + $backup_time = date(get_option('date_format')." ".get_option('time_format'), $metadata['timestamp'] + (get_option('gmt_offset') * HOUR_IN_SECONDS)); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | $backup_text = "<span title='".$backup_time."' class='shorten_string'>".$res->last_backup." (".$backup_size.")</span>"; |
@@ -665,12 +665,12 @@ discard block |
||
665 | 665 | |
666 | 666 | $schedules = wp_get_schedules(); |
667 | 667 | |
668 | - if(isset($schedules[$res->recurrence])) |
|
668 | + if (isset($schedules[$res->recurrence])) |
|
669 | 669 | { |
670 | 670 | $res->recurrence = $schedules[$res->recurrence]['display']; |
671 | 671 | } |
672 | 672 | |
673 | - $return['data'][] = array($res->id, $res->name, $res->recurrence,/*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action); |
|
673 | + $return['data'][] = array($res->id, $res->name, $res->recurrence, /*$res->start_at,*/ $next_run, $remote_storage, $backup_text, $status, $action); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | return $this->send_response($return, 0); |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | |
688 | 688 | $schedule_id = $this->xcloner_sanitization->sanitize_input_as_int($_GET['id']); |
689 | 689 | $scheduler = $this->xcloner_scheduler; |
690 | - $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id); |
|
690 | + $data['finished'] = $scheduler->delete_schedule_by_id($schedule_id); |
|
691 | 691 | |
692 | 692 | return $this->send_response($data); |
693 | 693 | } |
@@ -721,32 +721,32 @@ discard block |
||
721 | 721 | |
722 | 722 | $backup_file = $source_backup_file; |
723 | 723 | |
724 | - if($this->xcloner_file_system->is_multipart($backup_file)) |
|
724 | + if ($this->xcloner_file_system->is_multipart($backup_file)) |
|
725 | 725 | { |
726 | 726 | $backup_parts = $this->xcloner_file_system->get_multipart_files($backup_file); |
727 | 727 | $backup_file = $backup_parts[$return['part']]; |
728 | 728 | } |
729 | 729 | |
730 | - try{ |
|
730 | + try { |
|
731 | 731 | $tar = new Tar(); |
732 | 732 | $tar->open($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file, $start); |
733 | 733 | |
734 | 734 | $data = $tar->contents(get_option('xcloner_files_to_process_per_request')); |
735 | - }catch(Exception $e) |
|
735 | + }catch (Exception $e) |
|
736 | 736 | { |
737 | 737 | $return['error'] = true; |
738 | 738 | $return['message'] = $e->getMessage(); |
739 | 739 | $this->send_response($return, 0); |
740 | 740 | } |
741 | 741 | |
742 | - $return['files'] = array(); |
|
743 | - $return['finished'] = 1; |
|
744 | - $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
742 | + $return['files'] = array(); |
|
743 | + $return['finished'] = 1; |
|
744 | + $return['total_size'] = filesize($this->xcloner_settings->get_xcloner_store_path().DS.$backup_file); |
|
745 | 745 | $i = 0; |
746 | 746 | |
747 | - if(isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
747 | + if (isset($data['extracted_files']) and is_array($data['extracted_files'])) |
|
748 | 748 | { |
749 | - foreach($data['extracted_files'] as $file) |
|
749 | + foreach ($data['extracted_files'] as $file) |
|
750 | 750 | { |
751 | 751 | $return['files'][$i]['path'] = $file->getPath(); |
752 | 752 | $return['files'][$i]['size'] = $file->getSize(); |
@@ -756,18 +756,18 @@ discard block |
||
756 | 756 | } |
757 | 757 | } |
758 | 758 | |
759 | - if(isset($data['start'])) |
|
759 | + if (isset($data['start'])) |
|
760 | 760 | { |
761 | 761 | $return['start'] = $data['start']; |
762 | 762 | $return['finished'] = 0; |
763 | - }else{ |
|
764 | - if($this->xcloner_file_system->is_multipart($source_backup_file)) |
|
763 | + } else { |
|
764 | + if ($this->xcloner_file_system->is_multipart($source_backup_file)) |
|
765 | 765 | { |
766 | 766 | $return['start'] = 0; |
767 | 767 | |
768 | 768 | ++$return['part']; |
769 | 769 | |
770 | - if($return['part'] < sizeof($backup_parts)) |
|
770 | + if ($return['part'] < sizeof($backup_parts)) |
|
771 | 771 | $return['finished'] = 0; |
772 | 772 | |
773 | 773 | } |
@@ -790,17 +790,17 @@ discard block |
||
790 | 790 | |
791 | 791 | try |
792 | 792 | { |
793 | - if(method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) |
|
793 | + if (method_exists($xcloner_remote_storage, "copy_backup_remote_to_local")) |
|
794 | 794 | { |
795 | 795 | $return = call_user_func_array(array($xcloner_remote_storage, "copy_backup_remote_to_local"), array($backup_file, $storage_type)); |
796 | 796 | } |
797 | - }catch(Exception $e){ |
|
797 | + }catch (Exception $e) { |
|
798 | 798 | |
799 | 799 | $return['error'] = 1; |
800 | 800 | $return['message'] = $e->getMessage(); |
801 | 801 | } |
802 | 802 | |
803 | - if(!$return) |
|
803 | + if (!$return) |
|
804 | 804 | { |
805 | 805 | $return['error'] = 1; |
806 | 806 | $return['message'] = "Upload failed, please check the error log for more information!"; |
@@ -829,17 +829,17 @@ discard block |
||
829 | 829 | |
830 | 830 | try |
831 | 831 | { |
832 | - if(method_exists($xcloner_remote_storage, "upload_backup_to_storage")) |
|
832 | + if (method_exists($xcloner_remote_storage, "upload_backup_to_storage")) |
|
833 | 833 | { |
834 | 834 | $return = call_user_func_array(array($xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $storage_type)); |
835 | 835 | } |
836 | - }catch(Exception $e){ |
|
836 | + }catch (Exception $e) { |
|
837 | 837 | |
838 | 838 | $return['error'] = 1; |
839 | 839 | $return['message'] = $e->getMessage(); |
840 | 840 | } |
841 | 841 | |
842 | - if(!$return) |
|
842 | + if (!$return) |
|
843 | 843 | { |
844 | 844 | $return['error'] = 1; |
845 | 845 | $return['message'] = "Upload failed, please check the error log for more information!"; |
@@ -873,7 +873,7 @@ discard block |
||
873 | 873 | |
874 | 874 | @ob_end_clean(); |
875 | 875 | |
876 | - $adapter = new Local(dirname(__DIR__) ,LOCK_EX, 'SKIP_LINKS'); |
|
876 | + $adapter = new Local(dirname(__DIR__), LOCK_EX, 'SKIP_LINKS'); |
|
877 | 877 | $xcloner_plugin_filesystem = new Filesystem($adapter, new Config([ |
878 | 878 | 'disable_asserts' => true, |
879 | 879 | ])); |
@@ -903,7 +903,7 @@ discard block |
||
903 | 903 | //$tar->addFile(dirname(__DIR__)."/restore/vendor.tgz", "vendor.tgz"); |
904 | 904 | |
905 | 905 | $files = $xcloner_plugin_filesystem->listContents("vendor/", true); |
906 | - foreach($files as $file) |
|
906 | + foreach ($files as $file) |
|
907 | 907 | { |
908 | 908 | $tar->addFile(dirname(__DIR__).DS.$file['path'], $file['path']); |
909 | 909 | } |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | header('Expires: 0'); |
923 | 923 | header('Cache-Control: must-revalidate'); |
924 | 924 | header('Pragma: public'); |
925 | - header('Content-Length: ' . filesize($tmp_file)); |
|
925 | + header('Content-Length: '.filesize($tmp_file)); |
|
926 | 926 | readfile($tmp_file); |
927 | 927 | |
928 | 928 | } |
@@ -945,8 +945,8 @@ discard block |
||
945 | 945 | $backup_name = $this->xcloner_sanitization->sanitize_input_as_string($_GET['name']); |
946 | 946 | |
947 | 947 | |
948 | - $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name); |
|
949 | - $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name); |
|
948 | + $metadata = $this->xcloner_file_system->get_storage_filesystem()->getMetadata($backup_name); |
|
949 | + $read_stream = $this->xcloner_file_system->get_storage_filesystem()->readStream($backup_name); |
|
950 | 950 | |
951 | 951 | |
952 | 952 | header('Pragma: public'); |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | header('Content-Transfer-Encoding: binary'); |
957 | 957 | header('Content-Disposition: attachment; filename="'.$metadata['path'].'";'); |
958 | 958 | header('Content-Type: application/octet-stream'); |
959 | - header('Content-Length: ' . $metadata['size']); |
|
959 | + header('Content-Length: '.$metadata['size']); |
|
960 | 960 | |
961 | 961 | @ob_end_clean(); |
962 | 962 | |
@@ -984,10 +984,10 @@ discard block |
||
984 | 984 | $file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
985 | 985 | $hash = $this->xcloner_sanitization->sanitize_input_as_string($_POST['hash']); |
986 | 986 | |
987 | - if(isset($_POST['part'])) |
|
987 | + if (isset($_POST['part'])) |
|
988 | 988 | $return['part'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['part']); |
989 | 989 | |
990 | - if(isset($_POST['uploaded_size'])) |
|
990 | + if (isset($_POST['uploaded_size'])) |
|
991 | 991 | $return['uploaded_size'] = $this->xcloner_sanitization->sanitize_input_as_int($_POST['uploaded_size']); |
992 | 992 | |
993 | 993 | $start = $this->xcloner_sanitization->sanitize_input_as_string($_POST['start']); |
@@ -995,46 +995,46 @@ discard block |
||
995 | 995 | |
996 | 996 | $return['total_size'] = $this->xcloner_file_system->get_backup_size($file); |
997 | 997 | |
998 | - if($this->xcloner_file_system->is_multipart($file)) |
|
998 | + if ($this->xcloner_file_system->is_multipart($file)) |
|
999 | 999 | { |
1000 | 1000 | $backup_parts = $this->xcloner_file_system->get_multipart_files($file); |
1001 | 1001 | |
1002 | - $return['total_parts'] = sizeof($backup_parts)+1; |
|
1002 | + $return['total_parts'] = sizeof($backup_parts) + 1; |
|
1003 | 1003 | |
1004 | - if($return['part'] and isset($backup_parts[$return['part']-1])) |
|
1004 | + if ($return['part'] and isset($backup_parts[$return['part'] - 1])) |
|
1005 | 1005 | { |
1006 | - $file = $backup_parts[$return['part']-1]; |
|
1006 | + $file = $backup_parts[$return['part'] - 1]; |
|
1007 | 1007 | } |
1008 | 1008 | |
1009 | 1009 | $is_multipart = 1; |
1010 | 1010 | } |
1011 | 1011 | |
1012 | - try{ |
|
1012 | + try { |
|
1013 | 1013 | |
1014 | 1014 | $xcloner_file_transfer = $this->get_xcloner_container()->get_xcloner_file_transfer(); |
1015 | 1015 | $xcloner_file_transfer->set_target($target_url); |
1016 | 1016 | $return['start'] = $xcloner_file_transfer->transfer_file($file, $start, $hash); |
1017 | 1017 | |
1018 | - }catch(Exception $e){ |
|
1018 | + }catch (Exception $e) { |
|
1019 | 1019 | |
1020 | 1020 | $return = array(); |
1021 | 1021 | $return['error'] = true; |
1022 | 1022 | $return['status'] = 500; |
1023 | 1023 | $return['message'] = "CURL communication error with the restore host. ".$e->getMessage(); |
1024 | - $this->send_response( $return, 0); |
|
1024 | + $this->send_response($return, 0); |
|
1025 | 1025 | |
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | $return['status'] = 200; |
1029 | 1029 | |
1030 | 1030 | //we have finished the upload |
1031 | - if(!$return['start'] and $is_multipart) |
|
1031 | + if (!$return['start'] and $is_multipart) |
|
1032 | 1032 | { |
1033 | 1033 | $return['part']++; |
1034 | 1034 | $return['uploaded_size'] += $this->xcloner_file_system->get_storage_filesystem()->getSize($file); |
1035 | 1035 | } |
1036 | 1036 | |
1037 | - $this->send_response( $return, 0); |
|
1037 | + $this->send_response($return, 0); |
|
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | public function restore_backup() |
@@ -1042,7 +1042,7 @@ discard block |
||
1042 | 1042 | $this->check_access(); |
1043 | 1043 | |
1044 | 1044 | define("XCLONER_PLUGIN_ACCESS", 1); |
1045 | - include_once(dirname(__DIR__) .DS."restore".DS."xcloner_restore.php"); |
|
1045 | + include_once(dirname(__DIR__).DS."restore".DS."xcloner_restore.php"); |
|
1046 | 1046 | return; |
1047 | 1047 | } |
1048 | 1048 | |
@@ -1054,12 +1054,12 @@ discard block |
||
1054 | 1054 | private function send_response($data, $attach_hash = 1) |
1055 | 1055 | { |
1056 | 1056 | |
1057 | - if($attach_hash and null !== $this->xcloner_settings->get_hash()) |
|
1057 | + if ($attach_hash and null !== $this->xcloner_settings->get_hash()) |
|
1058 | 1058 | { |
1059 | 1059 | $data['hash'] = $this->xcloner_settings->get_hash(); |
1060 | 1060 | } |
1061 | 1061 | |
1062 | - if( ob_get_length() ) |
|
1062 | + if (ob_get_length()) |
|
1063 | 1063 | ob_clean(); |
1064 | 1064 | wp_send_json($data); |
1065 | 1065 |
@@ -35,22 +35,22 @@ discard block |
||
35 | 35 | |
36 | 36 | global $wpdb; |
37 | 37 | |
38 | - if(version_compare(phpversion(), Xcloner_Activator::xcloner_minimum_version, '<')) |
|
38 | + if (version_compare(phpversion(), Xcloner_Activator::xcloner_minimum_version, '<')) |
|
39 | 39 | { |
40 | - wp_die('<p>'.sprintf(__("XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s"),Xcloner_Activator::xcloner_minimum_version, phpversion()).'</p>', __("XCloner Activation Error"), array( 'response'=>500, 'back_link'=>TRUE ) ); |
|
40 | + wp_die('<p>'.sprintf(__("XCloner requires minimum PHP version %s in order to run correctly. We have detected your version as %s"), Xcloner_Activator::xcloner_minimum_version, phpversion()).'</p>', __("XCloner Activation Error"), array('response'=>500, 'back_link'=>TRUE)); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | $charset_collate = $wpdb->get_charset_collate(); |
44 | 44 | |
45 | - $installed_ver = get_option( "xcloner_db_version" ); |
|
45 | + $installed_ver = get_option("xcloner_db_version"); |
|
46 | 46 | |
47 | 47 | $xcloner_db_version = Xcloner_Activator::xcloner_db_version; |
48 | 48 | |
49 | - $xcloner_scheduler_table = $wpdb->prefix . "xcloner_scheduler"; |
|
49 | + $xcloner_scheduler_table = $wpdb->prefix."xcloner_scheduler"; |
|
50 | 50 | |
51 | - if($installed_ver != $xcloner_db_version) |
|
51 | + if ($installed_ver != $xcloner_db_version) |
|
52 | 52 | { |
53 | - $xcloner_schedule_sql="CREATE TABLE `".$xcloner_scheduler_table."` ( |
|
53 | + $xcloner_schedule_sql = "CREATE TABLE `".$xcloner_scheduler_table."` ( |
|
54 | 54 | `id` int(11) NOT NULL AUTO_INCREMENT, |
55 | 55 | `name` varchar(255) NOT NULL, |
56 | 56 | `recurrence` varchar(25) NOT NULL, |
@@ -64,53 +64,53 @@ discard block |
||
64 | 64 | ) ".$charset_collate."; |
65 | 65 | "; |
66 | 66 | |
67 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
68 | - dbDelta( $xcloner_schedule_sql ); |
|
67 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
68 | + dbDelta($xcloner_schedule_sql); |
|
69 | 69 | |
70 | - update_option( "xcloner_db_version", $xcloner_db_version ); |
|
70 | + update_option("xcloner_db_version", $xcloner_db_version); |
|
71 | 71 | } |
72 | 72 | |
73 | - if(get_option('xcloner_backup_compression_level') === false) |
|
73 | + if (get_option('xcloner_backup_compression_level') === false) |
|
74 | 74 | update_option('xcloner_backup_compression_level', 0); |
75 | 75 | |
76 | - if(get_option('xcloner_enable_log') === false) |
|
76 | + if (get_option('xcloner_enable_log') === false) |
|
77 | 77 | update_option('xcloner_enable_log', 1); |
78 | 78 | |
79 | - if(get_option('xcloner_enable_mysql_backup') === false) |
|
79 | + if (get_option('xcloner_enable_mysql_backup') === false) |
|
80 | 80 | update_option('xcloner_enable_mysql_backup', 1); |
81 | 81 | |
82 | - if(get_option('xcloner_system_settings_page') === false) |
|
82 | + if (get_option('xcloner_system_settings_page') === false) |
|
83 | 83 | update_option('xcloner_system_settings_page', 100); |
84 | 84 | |
85 | - if(get_option('xcloner_files_to_process_per_request') === false) |
|
85 | + if (get_option('xcloner_files_to_process_per_request') === false) |
|
86 | 86 | update_option('xcloner_files_to_process_per_request', 250); |
87 | 87 | |
88 | - if(get_option('xcloner_database_records_per_request') === false) |
|
88 | + if (get_option('xcloner_database_records_per_request') === false) |
|
89 | 89 | update_option('xcloner_database_records_per_request', 10000); |
90 | 90 | |
91 | - if(get_option('xcloner_exclude_files_larger_than_mb') === false) |
|
91 | + if (get_option('xcloner_exclude_files_larger_than_mb') === false) |
|
92 | 92 | update_option('xcloner_exclude_files_larger_than_mb', 0); |
93 | 93 | |
94 | - if(get_option('xcloner_split_backup_limit') === false) |
|
94 | + if (get_option('xcloner_split_backup_limit') === false) |
|
95 | 95 | update_option('xcloner_split_backup_limit', 2048); |
96 | 96 | |
97 | - if(get_option('xcloner_size_limit_per_request') === false) |
|
97 | + if (get_option('xcloner_size_limit_per_request') === false) |
|
98 | 98 | update_option('xcloner_size_limit_per_request', 50); |
99 | 99 | |
100 | - if(get_option('xcloner_cleanup_retention_limit_days') === false) |
|
100 | + if (get_option('xcloner_cleanup_retention_limit_days') === false) |
|
101 | 101 | update_option('xcloner_cleanup_retention_limit_days', 60); |
102 | 102 | |
103 | - if(get_option('xcloner_cleanup_retention_limit_archives') === false) |
|
103 | + if (get_option('xcloner_cleanup_retention_limit_archives') === false) |
|
104 | 104 | update_option('xcloner_cleanup_retention_limit_archives', 100); |
105 | 105 | |
106 | - if(get_option('xcloner_directories_to_scan_per_request') === false) |
|
106 | + if (get_option('xcloner_directories_to_scan_per_request') === false) |
|
107 | 107 | update_option('xcloner_directories_to_scan_per_request', 25); |
108 | 108 | |
109 | 109 | /*if(!get_option('xcloner_diff_backup_recreate_period')) |
110 | 110 | update_option('xcloner_diff_backup_recreate_period', 10); |
111 | 111 | * */ |
112 | 112 | |
113 | - if(!get_option('xcloner_regex_exclude')) |
|
113 | + if (!get_option('xcloner_regex_exclude')) |
|
114 | 114 | update_option('xcloner_regex_exclude', "(wp-content\/updraft|wp-content\/uploads\/wp_all_backup)(.*)$".PHP_EOL."(.*)\.(svn|git)(.*)$".PHP_EOL."wp-content\/cache(.*)$".PHP_EOL."(.*)error_log$"); |
115 | 115 | |
116 | 116 | } |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | |
24 | -class Xcloner_Database extends wpdb{ |
|
24 | +class Xcloner_Database extends wpdb { |
|
25 | 25 | |
26 | 26 | |
27 | - public $debug = 0; |
|
28 | - public $recordsPerSession = 10000; |
|
29 | - public $dbCompatibility = ""; |
|
27 | + public $debug = 0; |
|
28 | + public $recordsPerSession = 10000; |
|
29 | + public $dbCompatibility = ""; |
|
30 | 30 | public $dbDropSyntax = 1; |
31 | 31 | public $countRecords = 0; |
32 | 32 | |
@@ -38,24 +38,24 @@ discard block |
||
38 | 38 | private $TEMP_DBPROCESS_FILE = ".database"; |
39 | 39 | private $TEMP_DUMP_FILE = "database-backup.sql"; |
40 | 40 | |
41 | - public function __construct(Xcloner $xcloner_container, $wp_user="", $wp_pass="", $wp_db="", $wp_host="") |
|
41 | + public function __construct(Xcloner $xcloner_container, $wp_user = "", $wp_pass = "", $wp_db = "", $wp_host = "") |
|
42 | 42 | { |
43 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_database"); |
|
44 | - $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
45 | - $this->fs = $xcloner_container->get_xcloner_filesystem(); |
|
43 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_database"); |
|
44 | + $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
|
45 | + $this->fs = $xcloner_container->get_xcloner_filesystem(); |
|
46 | 46 | |
47 | - if($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) |
|
48 | - $this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
47 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request')) |
|
48 | + $this->recordsPerSession = $this->xcloner_settings->get_xcloner_option('xcloner_database_records_per_request'); |
|
49 | 49 | |
50 | - if(!$this->recordsPerSession) |
|
50 | + if (!$this->recordsPerSession) |
|
51 | 51 | $this->recordsPerSession = 100; |
52 | 52 | |
53 | - if(!$wp_user && !$wp_pass && !$wp_host && !$wp_db ) |
|
53 | + if (!$wp_user && !$wp_pass && !$wp_host && !$wp_db) |
|
54 | 54 | { |
55 | 55 | $wp_host = $this->xcloner_settings->get_db_hostname(); |
56 | 56 | $wp_user = $this->xcloner_settings->get_db_username(); |
57 | 57 | $wp_pass = $this->xcloner_settings->get_db_password(); |
58 | - $wp_db = $this->xcloner_settings->get_db_database(); |
|
58 | + $wp_db = $this->xcloner_settings->get_db_database(); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | parent::__construct($wp_user, $wp_pass, $wp_db, $wp_host); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function init($data, $start = 0) |
73 | 73 | { |
74 | - if($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)){ |
|
74 | + if ($start and $this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) { |
|
75 | 75 | $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
76 | 76 | } |
77 | 77 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | "database_count"=>0, |
91 | 91 | ); |
92 | 92 | |
93 | - if(!$this->xcloner_settings->get_enable_mysql_backup()) |
|
93 | + if (!$this->xcloner_settings->get_enable_mysql_backup()) |
|
94 | 94 | { |
95 | 95 | $return['finished'] = 1; |
96 | 96 | return $return; |
@@ -100,44 +100,44 @@ discard block |
||
100 | 100 | |
101 | 101 | $this->init($params, $init); |
102 | 102 | |
103 | - if($init) |
|
103 | + if ($init) |
|
104 | 104 | { |
105 | 105 | $db_count = 0; |
106 | 106 | |
107 | - if(isset($params['#'])) |
|
107 | + if (isset($params['#'])) |
|
108 | 108 | { |
109 | - foreach($params['#'] as $database) |
|
109 | + foreach ($params['#'] as $database) |
|
110 | 110 | { |
111 | - if(!isset($params[$database]) or !is_array($params[$database])) |
|
111 | + if (!isset($params[$database]) or !is_array($params[$database])) |
|
112 | 112 | $params[$database] = array(); |
113 | 113 | } |
114 | 114 | $db_count = -1; |
115 | 115 | } |
116 | 116 | |
117 | - if(isset($params) and is_array($params)) |
|
118 | - foreach($params as $database=>$tables) |
|
117 | + if (isset($params) and is_array($params)) |
|
118 | + foreach ($params as $database=>$tables) |
|
119 | 119 | { |
120 | - if($database != "#") |
|
120 | + if ($database != "#") |
|
121 | 121 | { |
122 | 122 | $stats = $this->write_backup_process_list($database, $tables); |
123 | - $return['stats']['tables_count'] += $stats['tables_count']; |
|
124 | - $return['stats']['total_records'] += $stats['total_records']; |
|
123 | + $return['stats']['tables_count'] += $stats['tables_count']; |
|
124 | + $return['stats']['total_records'] += $stats['total_records']; |
|
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | - if(sizeof($params)) |
|
129 | - $return['stats']['database_count'] = sizeof($params)+$db_count; |
|
128 | + if (sizeof($params)) |
|
129 | + $return['stats']['database_count'] = sizeof($params) + $db_count; |
|
130 | 130 | else |
131 | 131 | $return['stats']['database_count'] = 0; |
132 | 132 | |
133 | 133 | return $return; |
134 | 134 | } |
135 | 135 | |
136 | - if(!isset($extra_params['startAtLine'])) |
|
136 | + if (!isset($extra_params['startAtLine'])) |
|
137 | 137 | $extra_params['startAtLine'] = 0; |
138 | - if(!isset($extra_params['startAtRecord'])) |
|
138 | + if (!isset($extra_params['startAtRecord'])) |
|
139 | 139 | $extra_params['startAtRecord'] = 0; |
140 | - if(!isset($extra_params['dumpfile'])) |
|
140 | + if (!isset($extra_params['dumpfile'])) |
|
141 | 141 | $extra_params['dumpfile'] = ""; |
142 | 142 | |
143 | 143 | $return = $this->process_incremental($extra_params['startAtLine'], $extra_params['startAtRecord'], $extra_params['dumpfile']); |
@@ -148,13 +148,13 @@ discard block |
||
148 | 148 | public function log($message = "") |
149 | 149 | { |
150 | 150 | |
151 | - if($message){ |
|
152 | - $this->logger->info( $message, array("")); |
|
153 | - }else{ |
|
154 | - if($this->last_query) |
|
155 | - $this->logger->debug( $this->last_query, array("")); |
|
156 | - if($this->last_error) |
|
157 | - $this->logger->error( $this->last_error, array("")); |
|
151 | + if ($message) { |
|
152 | + $this->logger->info($message, array("")); |
|
153 | + } else { |
|
154 | + if ($this->last_query) |
|
155 | + $this->logger->debug($this->last_query, array("")); |
|
156 | + if ($this->last_error) |
|
157 | + $this->logger->error($this->last_error, array("")); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return; |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | */ |
170 | 170 | public function error($message) |
171 | 171 | { |
172 | - $this->logger->error( $message, array("")); |
|
172 | + $this->logger->error($message, array("")); |
|
173 | 173 | |
174 | 174 | return; |
175 | 175 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | |
203 | 203 | $query = "show tables in `".$database."`"; |
204 | 204 | |
205 | - $res = $this->get_results($query); |
|
205 | + $res = $this->get_results($query); |
|
206 | 206 | $this->log(); |
207 | 207 | |
208 | 208 | return count($res); |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($this->dbname); |
226 | 226 | $i++; |
227 | 227 | |
228 | - if(is_array($databases)) |
|
229 | - foreach( $databases as $db){ |
|
230 | - if($db->Database != $this->dbname) |
|
228 | + if (is_array($databases)) |
|
229 | + foreach ($databases as $db) { |
|
230 | + if ($db->Database != $this->dbname) |
|
231 | 231 | { |
232 | 232 | $databases_list[$i]['name'] = $db->Database; |
233 | 233 | $databases_list[$i]['num_tables'] = $this->get_database_num_tables($db->Database); |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $tablesList[0] = array( ); |
253 | 253 | $inc = 0; |
254 | 254 | |
255 | - if(!$database) |
|
255 | + if (!$database) |
|
256 | 256 | $database = $this->dbname; |
257 | 257 | |
258 | 258 | $this->logger->debug(sprintf(("Listing tables in %s database"), $database)); |
@@ -260,14 +260,14 @@ discard block |
||
260 | 260 | $tables = $this->get_results("SHOW TABLES in `".$database."`"); |
261 | 261 | $this->log(); |
262 | 262 | |
263 | - foreach ($tables as $table){ |
|
263 | + foreach ($tables as $table) { |
|
264 | 264 | |
265 | 265 | $table = array_values((array)$table)[0]; |
266 | 266 | |
267 | 267 | $tablesList[$inc]['name'] = $table; |
268 | 268 | $tablesList[$inc]['database'] = $database; |
269 | 269 | |
270 | - if($get_num_records) |
|
270 | + if ($get_num_records) |
|
271 | 271 | { |
272 | 272 | $records_num_result = $this->get_var("SELECT count(*) FROM `".$database."`.`".$table."`"); |
273 | 273 | $this->log(); |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | |
278 | 278 | $tablesList[$inc]['excluded'] = 0; |
279 | 279 | |
280 | - if(sizeof($included) and is_array($included)) |
|
281 | - if(!in_array($table, $included) ) |
|
280 | + if (sizeof($included) and is_array($included)) |
|
281 | + if (!in_array($table, $included)) |
|
282 | 282 | { |
283 | 283 | $tablesList[$inc]['excluded'] = 1; |
284 | 284 | $this->log(sprintf(__("Excluding table %s.%s from backup"), $table, $database)); |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | |
300 | 300 | $tables = $this->list_tables($dbname, $incl_tables, 1); |
301 | 301 | |
302 | - if($this->dbname != $dbname) |
|
302 | + if ($this->dbname != $dbname) |
|
303 | 303 | $dumpfile = $dbname."-backup.sql"; |
304 | 304 | else |
305 | 305 | $dumpfile = $this->TEMP_DUMP_FILE; |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
309 | 309 | |
310 | 310 | // write this to the class and write to $TEMP_DBPROCESS_FILE file as database.table records |
311 | - foreach($tables as $key=>$table) |
|
312 | - if($table!= "" and !$tables[$key]['excluded']){ |
|
311 | + foreach ($tables as $key=>$table) |
|
312 | + if ($table != "" and !$tables[$key]['excluded']) { |
|
313 | 313 | |
314 | 314 | $line = sprintf("`%s`.`%s`\t%s\t%s\n", $dbname, $tables[$key]['name'], $tables[$key]['records'], $tables[$key]['excluded']); |
315 | 315 | $this->fs->get_tmp_filesystem_append()->write($this->TEMP_DBPROCESS_FILE, $line); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | |
338 | 338 | $result = $this->get_var("SELECT count(*) FROM $table;"); |
339 | 339 | |
340 | - return intval($result) ;// not max limit on 32 bit systems 2147483647; on 64 bit 999999999999 |
|
340 | + return intval($result); // not max limit on 32 bit systems 2147483647; on 64 bit 999999999999 |
|
341 | 341 | |
342 | 342 | } |
343 | 343 | |
@@ -353,25 +353,25 @@ discard block |
||
353 | 353 | * int $dbDropSyntax - check if the DROP TABLE syntax should be added |
354 | 354 | * @return array $return |
355 | 355 | */ |
356 | - public function process_incremental($startAtLine= 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility= ""){ |
|
356 | + public function process_incremental($startAtLine = 0, $startAtRecord = 0, $dumpfile = "", $dbCompatibility = "") { |
|
357 | 357 | |
358 | 358 | $count = 0; |
359 | 359 | $return['finished'] = 0; |
360 | 360 | $lines = array(); |
361 | 361 | |
362 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
363 | - $lines = array_filter(explode("\n",$this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
362 | + if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
363 | + $lines = array_filter(explode("\n", $this->fs->get_tmp_filesystem()->read($this->TEMP_DBPROCESS_FILE))); |
|
364 | 364 | |
365 | - foreach ($lines as $buffer){ |
|
365 | + foreach ($lines as $buffer) { |
|
366 | 366 | |
367 | - if($count == $startAtLine) |
|
367 | + if ($count == $startAtLine) |
|
368 | 368 | { |
369 | 369 | |
370 | - $tableInfo =explode("\t", $buffer); |
|
370 | + $tableInfo = explode("\t", $buffer); |
|
371 | 371 | |
372 | - if($tableInfo[0] == "###newdump###"){ |
|
372 | + if ($tableInfo[0] == "###newdump###") { |
|
373 | 373 | // we create a new mysql dump file |
374 | - if($dumpfile != ""){ |
|
374 | + if ($dumpfile != "") { |
|
375 | 375 | // we finished a previous one and write the footers |
376 | 376 | $return['dumpsize'] = $this->data_footers($dumpfile); |
377 | 377 | } |
@@ -385,13 +385,13 @@ discard block |
||
385 | 385 | $startAtLine++; |
386 | 386 | $return['new_dump'] = 1; |
387 | 387 | //break; |
388 | - }else{ |
|
388 | + } else { |
|
389 | 389 | //we export the table |
390 | - if($tableInfo[0] == "###enddump###") |
|
390 | + if ($tableInfo[0] == "###enddump###") |
|
391 | 391 | $return['endDump'] = 1; |
392 | 392 | |
393 | 393 | //table is excluded |
394 | - if($tableInfo[2]) |
|
394 | + if ($tableInfo[2]) |
|
395 | 395 | continue; |
396 | 396 | |
397 | 397 | $next = $startAtRecord + $this->recordsPerSession; |
@@ -403,28 +403,28 @@ discard block |
||
403 | 403 | |
404 | 404 | //return something to the browser |
405 | 405 | $return['databaseName'] = $databaseName; |
406 | - $return['tableName'] = $tableName; |
|
406 | + $return['tableName'] = $tableName; |
|
407 | 407 | $return['totalRecords'] = $tableInfo[1]; |
408 | 408 | |
409 | 409 | $processed_records = 0; |
410 | 410 | |
411 | - if(trim($tableName) !="" and !$tableInfo[2]) |
|
411 | + if (trim($tableName) != "" and !$tableInfo[2]) |
|
412 | 412 | $processed_records = $this->export_table($databaseName, $tableName, $startAtRecord, $this->recordsPerSession, $dumpfile); |
413 | 413 | |
414 | - $return['processedRecords'] = $startAtRecord+$processed_records; |
|
414 | + $return['processedRecords'] = $startAtRecord + $processed_records; |
|
415 | 415 | |
416 | - if($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
416 | + if ($next >= $tableInfo[1]) //we finished loading the records for next sessions, will go to the new record |
|
417 | 417 | { |
418 | - $startAtLine ++; |
|
418 | + $startAtLine++; |
|
419 | 419 | $startAtRecord = 0; |
420 | - }else{ |
|
420 | + } else { |
|
421 | 421 | $startAtRecord = $startAtRecord + $this->recordsPerSession; |
422 | 422 | } |
423 | 423 | |
424 | 424 | //$return['dbCompatibility'] = self::$dbCompatibility; |
425 | 425 | |
426 | - $return['startAtLine'] = $startAtLine; |
|
427 | - $return['startAtRecord'] = $startAtRecord; |
|
426 | + $return['startAtLine'] = $startAtLine; |
|
427 | + $return['startAtRecord'] = $startAtRecord; |
|
428 | 428 | $return['dumpfile'] = $dumpfile; |
429 | 429 | $return['dumpsize'] = $this->fs->get_tmp_filesystem_append()->getSize($dumpfile); |
430 | 430 | |
@@ -442,15 +442,15 @@ discard block |
||
442 | 442 | } |
443 | 443 | |
444 | 444 | //while is finished, lets go home... |
445 | - if($dumpfile != ""){ |
|
445 | + if ($dumpfile != "") { |
|
446 | 446 | // we finished a previous one and write the footers |
447 | 447 | $return['dumpsize'] = $this->data_footers($dumpfile); |
448 | 448 | $return['dumpfile'] = ($dumpfile); |
449 | 449 | } |
450 | 450 | $return['finished'] = 1; |
451 | - $return['startAtLine'] = $startAtLine; |
|
451 | + $return['startAtLine'] = $startAtLine; |
|
452 | 452 | |
453 | - if($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
453 | + if ($this->fs->get_tmp_filesystem()->has($this->TEMP_DBPROCESS_FILE)) |
|
454 | 454 | $this->fs->get_tmp_filesystem()->delete($this->TEMP_DBPROCESS_FILE); |
455 | 455 | |
456 | 456 | $this->logger->debug(sprintf(("Database backup finished!"))); |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | |
480 | 480 | $records = 0; |
481 | 481 | |
482 | - if($start == 0) |
|
482 | + if ($start == 0) |
|
483 | 483 | $this->dump_structure($databaseName, $tableName, $dumpfile); |
484 | 484 | |
485 | 485 | $start = intval($start); |
@@ -487,20 +487,20 @@ discard block |
||
487 | 487 | //exporting the table content now |
488 | 488 | |
489 | 489 | $query = "SELECT * from `$databaseName`.`$tableName` Limit $start, $limit ;"; |
490 | - if($this->use_mysqli) |
|
490 | + if ($this->use_mysqli) |
|
491 | 491 | { |
492 | 492 | $result = mysqli_query($this->dbh, $query); |
493 | 493 | $mysql_fetch_function = "mysqli_fetch_array"; |
494 | 494 | |
495 | - }else{ |
|
495 | + } else { |
|
496 | 496 | $result = mysql_query($query, $this->dbh); |
497 | 497 | $mysql_fetch_function = "mysql_fetch_array"; |
498 | 498 | } |
499 | 499 | //$result = $this->get_results($query, ARRAY_N); |
500 | 500 | //print_r($result); exit; |
501 | 501 | |
502 | - if($result){ |
|
503 | - while($row = $mysql_fetch_function($result, MYSQLI_ASSOC)){ |
|
502 | + if ($result) { |
|
503 | + while ($row = $mysql_fetch_function($result, MYSQLI_ASSOC)) { |
|
504 | 504 | |
505 | 505 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, "INSERT INTO `$tableName` VALUES ("); |
506 | 506 | $arr = $row; |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | $value = $this->_real_escape($value); |
512 | 512 | $buffer .= "'".$value."', "; |
513 | 513 | } |
514 | - $buffer = rtrim($buffer, ', ') . ");\n"; |
|
514 | + $buffer = rtrim($buffer, ', ').");\n"; |
|
515 | 515 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $buffer); |
516 | 516 | unset($buffer); |
517 | 517 | |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | |
527 | 527 | } |
528 | 528 | |
529 | - public function dump_structure($databaseName, $tableName ,$dumpfile) |
|
529 | + public function dump_structure($databaseName, $tableName, $dumpfile) |
|
530 | 530 | { |
531 | 531 | $this->log(sprintf(__("Dumping the structure for %s.%s table"), $databaseName, $tableName)); |
532 | 532 | |
@@ -541,14 +541,14 @@ discard block |
||
541 | 541 | |
542 | 542 | //$result = mysqli_query($this->dbh,"SHOW CREATE table `$databaseName`.`$tableName`;"); |
543 | 543 | $result = $this->get_row("SHOW CREATE table `$databaseName`.`$tableName`;", ARRAY_N); |
544 | - if($result){ |
|
544 | + if ($result) { |
|
545 | 545 | //$row = mysqli_fetch_row( $result); |
546 | 546 | $line = ($result[1].";\n"); |
547 | 547 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
548 | 548 | } |
549 | 549 | |
550 | - $line = ( "\n#\n# End Structure for table `$tableName`\n#\n\n"); |
|
551 | - $line .=("#\n# Dumping data for table `$tableName`\n#\n\n"); |
|
550 | + $line = ("\n#\n# End Structure for table `$tableName`\n#\n\n"); |
|
551 | + $line .= ("#\n# Dumping data for table `$tableName`\n#\n\n"); |
|
552 | 552 | $this->fs->get_tmp_filesystem_append()->write($dumpfile, $line); |
553 | 553 | |
554 | 554 | return; |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | |
572 | 572 | } |
573 | 573 | |
574 | - public function resetcountRecords(){ |
|
574 | + public function resetcountRecords() { |
|
575 | 575 | |
576 | 576 | $this->countRecords = 0; |
577 | 577 | |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | |
580 | 580 | } |
581 | 581 | |
582 | - public function getcountRecords(){ |
|
582 | + public function getcountRecords() { |
|
583 | 583 | |
584 | 584 | return $this->countRecords; |
585 | 585 | |
@@ -596,14 +596,14 @@ discard block |
||
596 | 596 | $return .= "# Powered by XCloner Site Backup\n"; |
597 | 597 | $return .= "# http://www.xcloner.com\n"; |
598 | 598 | $return .= "#\n"; |
599 | - $return .= "# Host: " . get_site_url() . "\n"; |
|
600 | - $return .= "# Generation Time: " . date("M j, Y \a\\t H:i") . "\n"; |
|
601 | - $return .= "# PHP Version: " . phpversion() . "\n"; |
|
602 | - $return .= "# Database Charset: ". $this->charset . "\n"; |
|
599 | + $return .= "# Host: ".get_site_url()."\n"; |
|
600 | + $return .= "# Generation Time: ".date("M j, Y \a\\t H:i")."\n"; |
|
601 | + $return .= "# PHP Version: ".phpversion()."\n"; |
|
602 | + $return .= "# Database Charset: ".$this->charset."\n"; |
|
603 | 603 | |
604 | 604 | $results = $this->get_results("SHOW VARIABLES LIKE \"%version%\";", ARRAY_N); |
605 | - if(isset($results)){ |
|
606 | - foreach($results as $result){ |
|
605 | + if (isset($results)) { |
|
606 | + foreach ($results as $result) { |
|
607 | 607 | |
608 | 608 | $return .= "# MYSQL ".$result[0].": ".$result[1]."\n"; |
609 | 609 | |
@@ -613,13 +613,13 @@ discard block |
||
613 | 613 | $results = $this->get_results("SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME |
614 | 614 | FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".$database."';"); |
615 | 615 | |
616 | - if(isset($results[0])){ |
|
616 | + if (isset($results[0])) { |
|
617 | 617 | |
618 | 618 | $return .= "# MYSQL DEFAULT_CHARACTER_SET_NAME: ".$results[0]->DEFAULT_CHARACTER_SET_NAME."\n"; |
619 | 619 | $return .= "# MYSQL SCHEMA_NAME: ".$results[0]->DEFAULT_COLLATION_NAME."\n"; |
620 | 620 | } |
621 | 621 | |
622 | - $return .= "#\n# Database : `" . $database . "`\n# --------------------------------------------------------\n\n"; |
|
622 | + $return .= "#\n# Database : `".$database."`\n# --------------------------------------------------------\n\n"; |
|
623 | 623 | |
624 | 624 | $this->log(sprintf(__("Writing %s database dump headers"), $database)); |
625 | 625 |
@@ -4,18 +4,18 @@ discard block |
||
4 | 4 | use League\Flysystem\Util; |
5 | 5 | use League\Flysystem\Adapter\Local; |
6 | 6 | |
7 | -class Xcloner_File_System{ |
|
7 | +class Xcloner_File_System { |
|
8 | 8 | |
9 | - private $excluded_files = ""; |
|
10 | - private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
11 | - private $included_files_handler = "backup_files.csv"; |
|
12 | - private $temp_dir_handler = ".dir"; |
|
9 | + private $excluded_files = ""; |
|
10 | + private $excluded_files_by_default = array("administrator/backups", "wp-content/backups"); |
|
11 | + private $included_files_handler = "backup_files.csv"; |
|
12 | + private $temp_dir_handler = ".dir"; |
|
13 | 13 | public $filesystem; |
14 | 14 | public $tmp_filesystem; |
15 | 15 | public $storage_filesystem; |
16 | 16 | private $xcloner_settings_append; |
17 | 17 | private $xcloner_container; |
18 | - private $diff_timestamp_start = ""; |
|
18 | + private $diff_timestamp_start = ""; |
|
19 | 19 | |
20 | 20 | private $logger; |
21 | 21 | private $start_adapter; |
@@ -38,47 +38,47 @@ discard block |
||
38 | 38 | { |
39 | 39 | $this->xcloner_container = $xcloner_container; |
40 | 40 | |
41 | - $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system"); |
|
41 | + $this->logger = $xcloner_container->get_xcloner_logger()->withName("xcloner_file_system"); |
|
42 | 42 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
43 | 43 | |
44 | - try{ |
|
44 | + try { |
|
45 | 45 | |
46 | - $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(),LOCK_EX, 'SKIP_LINKS'); |
|
46 | + $this->start_adapter = new Local($this->xcloner_settings->get_xcloner_start_path(), LOCK_EX, 'SKIP_LINKS'); |
|
47 | 47 | $this->start_filesystem = new Filesystem($this->start_adapter, new Config([ |
48 | 48 | 'disable_asserts' => true, |
49 | 49 | ])); |
50 | 50 | |
51 | - $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX, 'SKIP_LINKS'); |
|
51 | + $this->tmp_adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX, 'SKIP_LINKS'); |
|
52 | 52 | $this->tmp_filesystem = new Filesystem($this->tmp_adapter, new Config([ |
53 | 53 | 'disable_asserts' => true, |
54 | 54 | ])); |
55 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(),LOCK_EX|FILE_APPEND, 'SKIP_LINKS'); |
|
55 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
56 | 56 | $this->tmp_filesystem_append = new Filesystem($adapter, new Config([ |
57 | 57 | 'disable_asserts' => true, |
58 | 58 | ])); |
59 | 59 | |
60 | - $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),LOCK_EX, 'SKIP_LINKS'); |
|
60 | + $adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), LOCK_EX, 'SKIP_LINKS'); |
|
61 | 61 | $this->storage_filesystem = new Filesystem($adapter, new Config([ |
62 | 62 | 'disable_asserts' => true, |
63 | 63 | ])); |
64 | 64 | |
65 | - $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(),FILE_APPEND, 'SKIP_LINKS'); |
|
65 | + $this->storage_adapter = new Local($this->xcloner_settings->get_xcloner_store_path(), FILE_APPEND, 'SKIP_LINKS'); |
|
66 | 66 | $this->storage_filesystem_append = new Filesystem($this->storage_adapter, new Config([ |
67 | 67 | 'disable_asserts' => true, |
68 | 68 | ])); |
69 | - }catch(Exception $e){ |
|
69 | + }catch (Exception $e) { |
|
70 | 70 | $this->logger->error("Filesystem Initialization Error: ".$e->getMessage()); |
71 | 71 | } |
72 | 72 | |
73 | 73 | |
74 | - if($value = get_option('xcloner_directories_to_scan_per_request')) |
|
74 | + if ($value = get_option('xcloner_directories_to_scan_per_request')) |
|
75 | 75 | $this->folders_to_process_per_session = $value; |
76 | 76 | |
77 | 77 | } |
78 | 78 | |
79 | 79 | public function set_diff_timestamp_start($timestamp = "") |
80 | 80 | { |
81 | - if($timestamp) |
|
81 | + if ($timestamp) |
|
82 | 82 | { |
83 | 83 | $this->logger->info(sprintf("Setting Differential Timestamp To %s", date("Y-m-d", $timestamp)), array("FILESYSTEM", "DIFF")); |
84 | 84 | $this->diff_timestamp_start = $timestamp; |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | |
114 | 114 | public function get_storage_filesystem($remote_storage_selection = "") |
115 | 115 | { |
116 | - if($remote_storage_selection != "") |
|
116 | + if ($remote_storage_selection != "") |
|
117 | 117 | { |
118 | 118 | $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
119 | 119 | $method = "get_".$remote_storage_selection."_filesystem"; |
120 | 120 | |
121 | - if(!method_exists($remote_storage, $method)) |
|
121 | + if (!method_exists($remote_storage, $method)) |
|
122 | 122 | return false; |
123 | 123 | |
124 | 124 | list($adapter, $filesystem) = $remote_storage->$method(); |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | public function get_start_path_file_info($file) |
158 | 158 | { |
159 | - $info= $this->getMetadataFull('start_adapter', $file); |
|
159 | + $info = $this->getMetadataFull('start_adapter', $file); |
|
160 | 160 | return $this->start_filesystem->normalizeFileInfo($info); |
161 | 161 | } |
162 | 162 | |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | return $this->getMetadataFull('storage_adapter', $file); |
166 | 166 | } |
167 | 167 | |
168 | - public function get_included_files_handler($metadata = 0) |
|
168 | + public function get_included_files_handler($metadata = 0) |
|
169 | 169 | { |
170 | 170 | $path = $this->included_files_handler; |
171 | - if(!$metadata) |
|
171 | + if (!$metadata) |
|
172 | 172 | return $path; |
173 | 173 | |
174 | 174 | $spl_info = $this->getMetadataFull('tmp_adapter', $path); |
@@ -185,16 +185,16 @@ discard block |
||
185 | 185 | { |
186 | 186 | $files = $this->get_backup_archives_list(); |
187 | 187 | |
188 | - if(is_array($files)) |
|
189 | - $this->sort_by($files, "timestamp","desc"); |
|
188 | + if (is_array($files)) |
|
189 | + $this->sort_by($files, "timestamp", "desc"); |
|
190 | 190 | |
191 | 191 | $new_list = array(); |
192 | 192 | |
193 | - foreach($files as $key=>$file) |
|
194 | - if(!isset($file['parent'])) |
|
193 | + foreach ($files as $key=>$file) |
|
194 | + if (!isset($file['parent'])) |
|
195 | 195 | $new_list[] = ($files[$key]); |
196 | 196 | |
197 | - if(isset($new_list[0])) |
|
197 | + if (isset($new_list[0])) |
|
198 | 198 | return $new_list[0]; |
199 | 199 | } |
200 | 200 | |
@@ -202,13 +202,13 @@ discard block |
||
202 | 202 | { |
203 | 203 | $files = $this->get_backup_archives_list(); |
204 | 204 | |
205 | - if(is_array($files)) |
|
206 | - $this->sort_by($files, "timestamp","desc"); |
|
205 | + if (is_array($files)) |
|
206 | + $this->sort_by($files, "timestamp", "desc"); |
|
207 | 207 | |
208 | 208 | $new_list = array(); |
209 | 209 | |
210 | - foreach($files as $key=>$file) |
|
211 | - if(!isset($file['parent'])) |
|
210 | + foreach ($files as $key=>$file) |
|
211 | + if (!isset($file['parent'])) |
|
212 | 212 | $new_list[] = ($files[$key]); |
213 | 213 | |
214 | 214 | return $new_list; |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | $files = $this->get_backup_archives_list(); |
220 | 220 | $total = 0; |
221 | 221 | |
222 | - if(is_array($files)) |
|
223 | - foreach($files as $file) |
|
222 | + if (is_array($files)) |
|
223 | + foreach ($files as $file) |
|
224 | 224 | $total += $file['size']; |
225 | 225 | |
226 | 226 | return $total; |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | |
229 | 229 | public function is_part($backup_name) |
230 | 230 | { |
231 | - if(stristr($backup_name, "-part")) |
|
231 | + if (stristr($backup_name, "-part")) |
|
232 | 232 | return true; |
233 | 233 | |
234 | 234 | return false; |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | |
237 | 237 | public function is_multipart($backup_name) |
238 | 238 | { |
239 | - if(stristr($backup_name, "-multipart")) |
|
239 | + if (stristr($backup_name, "-multipart")) |
|
240 | 240 | return true; |
241 | 241 | |
242 | 242 | return false; |
@@ -245,10 +245,10 @@ discard block |
||
245 | 245 | public function get_backup_size($backup_name) |
246 | 246 | { |
247 | 247 | $backup_size = $this->get_storage_filesystem()->getSize($backup_name); |
248 | - if($this->is_multipart($backup_name)) |
|
248 | + if ($this->is_multipart($backup_name)) |
|
249 | 249 | { |
250 | 250 | $backup_parts = $this->get_multipart_files($backup_name); |
251 | - foreach($backup_parts as $part_file) |
|
251 | + foreach ($backup_parts as $part_file) |
|
252 | 252 | $backup_size += $this->get_storage_filesystem()->getSize($part_file); |
253 | 253 | } |
254 | 254 | |
@@ -259,12 +259,12 @@ discard block |
||
259 | 259 | { |
260 | 260 | $files = array(); |
261 | 261 | |
262 | - if($this->is_multipart($backup_name)) |
|
262 | + if ($this->is_multipart($backup_name)) |
|
263 | 263 | { |
264 | 264 | $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
265 | - foreach($lines as $line) |
|
265 | + foreach ($lines as $line) |
|
266 | 266 | { |
267 | - if($line) |
|
267 | + if ($line) |
|
268 | 268 | { |
269 | 269 | $data = str_getcsv($line); |
270 | 270 | $files[] = $data[0]; |
@@ -277,12 +277,12 @@ discard block |
||
277 | 277 | |
278 | 278 | public function delete_backup_by_name($backup_name, $storage_selection = "") |
279 | 279 | { |
280 | - if($this->is_multipart($backup_name)) |
|
280 | + if ($this->is_multipart($backup_name)) |
|
281 | 281 | { |
282 | 282 | $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($backup_name)); |
283 | - foreach($lines as $line) |
|
283 | + foreach ($lines as $line) |
|
284 | 284 | { |
285 | - if($line) |
|
285 | + if ($line) |
|
286 | 286 | { |
287 | 287 | $data = str_getcsv($line); |
288 | 288 | $this->get_storage_filesystem($storage_selection)->delete($data[0]); |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | - if($this->get_storage_filesystem($storage_selection)->delete($backup_name)) |
|
293 | + if ($this->get_storage_filesystem($storage_selection)->delete($backup_name)) |
|
294 | 294 | $return = true; |
295 | 295 | else |
296 | 296 | $return = false; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | return $return; |
299 | 299 | } |
300 | 300 | |
301 | - public function getMetadataFull($adapter = "storage_adapter" , $path) |
|
301 | + public function getMetadataFull($adapter = "storage_adapter", $path) |
|
302 | 302 | { |
303 | 303 | $location = $this->$adapter->applyPathPrefix($path); |
304 | 304 | $spl_info = new SplFileInfo($location); |
@@ -312,25 +312,25 @@ discard block |
||
312 | 312 | $list = array(); |
313 | 313 | |
314 | 314 | |
315 | - if(method_exists($this->get_storage_filesystem($storage_selection), "listContents")) |
|
315 | + if (method_exists($this->get_storage_filesystem($storage_selection), "listContents")) |
|
316 | 316 | $list = $this->get_storage_filesystem($storage_selection)->listContents(); |
317 | 317 | |
318 | 318 | |
319 | 319 | $backup_files = array(); |
320 | 320 | $parents = array(); |
321 | 321 | |
322 | - foreach($list as $file_info) |
|
322 | + foreach ($list as $file_info) |
|
323 | 323 | { |
324 | - if(isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
324 | + if (isset($file_info['extension']) and $file_info['extension'] == "csv") |
|
325 | 325 | { |
326 | 326 | $data = array(); |
327 | 327 | |
328 | 328 | $lines = explode(PHP_EOL, $this->get_storage_filesystem($storage_selection)->read($file_info['path'])); |
329 | - foreach($lines as $line) |
|
330 | - if($line) |
|
329 | + foreach ($lines as $line) |
|
330 | + if ($line) |
|
331 | 331 | { |
332 | 332 | $data = str_getcsv($line); |
333 | - if(is_array($data)){ |
|
333 | + if (is_array($data)) { |
|
334 | 334 | $parents[$data[0]] = $file_info['basename']; |
335 | 335 | $file_info['childs'][] = $data; |
336 | 336 | $file_info['size'] += $data[2]; |
@@ -339,18 +339,18 @@ discard block |
||
339 | 339 | |
340 | 340 | } |
341 | 341 | |
342 | - if($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
342 | + if ($file_info['type'] == 'file' and isset($file_info['extension']) and in_array($file_info['extension'], $this->backup_archive_extensions)) |
|
343 | 343 | $backup_files[$file_info['path']] = $file_info; |
344 | 344 | } |
345 | 345 | |
346 | - foreach($backup_files as $key=>$file_info) |
|
346 | + foreach ($backup_files as $key=>$file_info) |
|
347 | 347 | { |
348 | - if(!isset($backup_files[$key]['timestamp'])) |
|
348 | + if (!isset($backup_files[$key]['timestamp'])) |
|
349 | 349 | { |
350 | 350 | //$backup_files[$key]['timestamp'] = $this->get_storage_filesystem($storage_selection)->getTimestamp($file_info['path']); |
351 | 351 | } |
352 | 352 | |
353 | - if(isset($parents[$file_info['basename']])) |
|
353 | + if (isset($parents[$file_info['basename']])) |
|
354 | 354 | $backup_files[$key]['parent'] = $parents[$file_info['basename']]; |
355 | 355 | } |
356 | 356 | |
@@ -359,40 +359,40 @@ discard block |
||
359 | 359 | |
360 | 360 | public function start_file_recursion($init = 0) |
361 | 361 | { |
362 | - if($init) |
|
362 | + if ($init) |
|
363 | 363 | { |
364 | 364 | $this->logger->info(sprintf(__("Starting the filesystem scanner on root folder %s"), $this->xcloner_settings->get_xcloner_start_path())); |
365 | 365 | $this->do_system_init(); |
366 | 366 | } |
367 | 367 | |
368 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())){ |
|
368 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) { |
|
369 | 369 | //.dir exists, we presume we have files to iterate |
370 | 370 | $content = $this->tmp_filesystem->read($this->get_temp_dir_handler()); |
371 | 371 | $files = array_filter(explode("\n", $content)); |
372 | 372 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
373 | 373 | |
374 | 374 | $counter = 0; |
375 | - foreach($files as $file) |
|
375 | + foreach ($files as $file) |
|
376 | 376 | { |
377 | - if($counter < $this->folders_to_process_per_session){ |
|
377 | + if ($counter < $this->folders_to_process_per_session) { |
|
378 | 378 | $this->build_files_list($file); |
379 | 379 | $counter++; |
380 | - }else{ |
|
380 | + } else { |
|
381 | 381 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file."\n"); |
382 | 382 | } |
383 | 383 | } |
384 | - }else{ |
|
384 | + } else { |
|
385 | 385 | $this->build_files_list(); |
386 | 386 | } |
387 | 387 | |
388 | - if($this->scan_finished()) |
|
388 | + if ($this->scan_finished()) |
|
389 | 389 | { |
390 | 390 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata("index.html"); |
391 | 391 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
392 | 392 | $this->files_counter++; |
393 | 393 | |
394 | 394 | //adding included dump file to the included files list |
395 | - if($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
395 | + if ($this->get_tmp_filesystem()->has($this->get_included_files_handler())) |
|
396 | 396 | { |
397 | 397 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->get_included_files_handler()); |
398 | 398 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -400,13 +400,13 @@ discard block |
||
400 | 400 | } |
401 | 401 | |
402 | 402 | //adding a default index.html to the temp xcloner folder |
403 | - if(!$this->get_tmp_filesystem()->has("index.html")) |
|
403 | + if (!$this->get_tmp_filesystem()->has("index.html")) |
|
404 | 404 | { |
405 | - $this->get_tmp_filesystem()->write("index.html",""); |
|
405 | + $this->get_tmp_filesystem()->write("index.html", ""); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | //adding the default log file |
409 | - if($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
409 | + if ($this->get_tmp_filesystem()->has($this->xcloner_settings->get_logger_filename(1))) |
|
410 | 410 | { |
411 | 411 | $metadata_dumpfile = $this->get_tmp_filesystem()->getMetadata($this->xcloner_settings->get_logger_filename(1)); |
412 | 412 | $this->store_file($metadata_dumpfile, 'tmp_filesystem'); |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | { |
424 | 424 | $return = array(); |
425 | 425 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->get_included_files_handler(); |
426 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
426 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
427 | 427 | $return[] = $this->xcloner_settings->get_xcloner_tmp_path().DS.$this->xcloner_settings->get_logger_filename(1); |
428 | 428 | |
429 | 429 | return $return; |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | |
437 | 437 | $contents = $this->get_tmp_filesystem()->listContents(); |
438 | 438 | |
439 | - if(is_array($contents)) |
|
440 | - foreach($contents as $file_info) |
|
439 | + if (is_array($contents)) |
|
440 | + foreach ($contents as $file_info) |
|
441 | 441 | $this->get_tmp_filesystem()->delete($file_info['path']); |
442 | 442 | |
443 | 443 | @rmdir($this->xcloner_settings->get_xcloner_tmp_path()); |
@@ -447,16 +447,16 @@ discard block |
||
447 | 447 | |
448 | 448 | public function cleanup_tmp_directories() |
449 | 449 | { |
450 | - $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false),LOCK_EX|FILE_APPEND, 'SKIP_LINKS'); |
|
450 | + $adapter = new Local($this->xcloner_settings->get_xcloner_tmp_path(false), LOCK_EX | FILE_APPEND, 'SKIP_LINKS'); |
|
451 | 451 | $tmp_filesystem = new Filesystem($adapter, new Config([ |
452 | 452 | 'disable_asserts' => true, |
453 | 453 | ])); |
454 | 454 | |
455 | 455 | $contents = $tmp_filesystem->listContents(); |
456 | 456 | |
457 | - foreach($contents as $file) |
|
457 | + foreach ($contents as $file) |
|
458 | 458 | { |
459 | - if(preg_match("/.xcloner-(.*)/",$file['path'])) |
|
459 | + if (preg_match("/.xcloner-(.*)/", $file['path'])) |
|
460 | 460 | { |
461 | 461 | $tmp_filesystem->deleteDir($file['path']); |
462 | 462 | $this->logger->info(sprintf("Delete temporary directory %s", $file['path'])); |
@@ -470,16 +470,16 @@ discard block |
||
470 | 470 | { |
471 | 471 | $this->files_counter = 0; |
472 | 472 | |
473 | - if(!$this->storage_filesystem->has("index.html")) |
|
474 | - $this->storage_filesystem->write("index.html",""); |
|
473 | + if (!$this->storage_filesystem->has("index.html")) |
|
474 | + $this->storage_filesystem->write("index.html", ""); |
|
475 | 475 | |
476 | - if(!$this->tmp_filesystem->has("index.html")) |
|
477 | - $this->tmp_filesystem->write("index.html",""); |
|
476 | + if (!$this->tmp_filesystem->has("index.html")) |
|
477 | + $this->tmp_filesystem->write("index.html", ""); |
|
478 | 478 | |
479 | - if($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
479 | + if ($this->tmp_filesystem->has($this->get_included_files_handler())) |
|
480 | 480 | $this->tmp_filesystem->delete($this->get_included_files_handler()); |
481 | 481 | |
482 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
482 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
483 | 483 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
484 | 484 | } |
485 | 485 | |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | |
501 | 501 | public function set_excluded_files($excluded_files = array()) |
502 | 502 | { |
503 | - if(!is_array($excluded_files)) |
|
503 | + if (!is_array($excluded_files)) |
|
504 | 504 | $excluded_files = array(); |
505 | 505 | |
506 | 506 | $this->excluded_files = array_merge($excluded_files, $this->excluded_files_by_default); |
@@ -523,35 +523,35 @@ discard block |
||
523 | 523 | $this->logger->debug(sprintf(("Building the files system list"))); |
524 | 524 | |
525 | 525 | //if we start with the root folder(empty value), we initializa the file system |
526 | - if(!$folder){ |
|
526 | + if (!$folder) { |
|
527 | 527 | |
528 | 528 | } |
529 | 529 | |
530 | - try{ |
|
530 | + try { |
|
531 | 531 | |
532 | 532 | $files = $this->start_filesystem->listContents($folder); |
533 | - foreach($files as $file) |
|
533 | + foreach ($files as $file) |
|
534 | 534 | { |
535 | - if(!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
535 | + if (!is_readable($this->xcloner_settings->get_xcloner_start_path().DS.$file['path'])) |
|
536 | 536 | { |
537 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN","NOT READABLE")); |
|
537 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, file not readable"), $file['path']), array("FILESYSTEM SCAN", "NOT READABLE")); |
|
538 | 538 | } |
539 | - elseif(!$matching_pattern = $this->is_excluded($file) ){ |
|
540 | - $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN","INCLUDE")); |
|
539 | + elseif (!$matching_pattern = $this->is_excluded($file)) { |
|
540 | + $this->logger->info(sprintf(__("Adding %s to the filesystem list"), $file['path']), array("FILESYSTEM SCAN", "INCLUDE")); |
|
541 | 541 | $file['visibility'] = $this->start_filesystem->getVisibility($file['path']); |
542 | - if($this->store_file($file)) |
|
542 | + if ($this->store_file($file)) |
|
543 | 543 | { |
544 | 544 | $this->files_counter++; |
545 | 545 | } |
546 | - if(isset($file['size'])) |
|
546 | + if (isset($file['size'])) |
|
547 | 547 | $this->files_size += $file['size']; |
548 | 548 | |
549 | - }else{ |
|
550 | - $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN","EXCLUDE")); |
|
549 | + } else { |
|
550 | + $this->logger->info(sprintf(__("Excluding %s from the filesystem list, matching pattern %s"), $file['path'], $matching_pattern), array("FILESYSTEM SCAN", "EXCLUDE")); |
|
551 | 551 | } |
552 | 552 | } |
553 | 553 | |
554 | - }catch(Exception $e){ |
|
554 | + }catch (Exception $e) { |
|
555 | 555 | |
556 | 556 | $this->logger->error($e->getMessage()); |
557 | 557 | |
@@ -565,9 +565,9 @@ discard block |
||
565 | 565 | |
566 | 566 | $start_time = microtime(); |
567 | 567 | |
568 | - $data = str_repeat(rand(0,9), 1024*1024); //write 1MB data |
|
568 | + $data = str_repeat(rand(0, 9), 1024 * 1024); //write 1MB data |
|
569 | 569 | |
570 | - try{ |
|
570 | + try { |
|
571 | 571 | $this->tmp_filesystem->write($tmp_file, $data); |
572 | 572 | |
573 | 573 | $end_time = microtime() - $start_time; |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | |
579 | 579 | $this->tmp_filesystem->delete($tmp_file); |
580 | 580 | |
581 | - }catch(Exception $e){ |
|
581 | + }catch (Exception $e) { |
|
582 | 582 | |
583 | 583 | $this->logger->error($e->getMessage()); |
584 | 584 | |
@@ -599,10 +599,10 @@ discard block |
||
599 | 599 | |
600 | 600 | $files = $this->storage_filesystem->listContents(); |
601 | 601 | |
602 | - if(is_array($files)) |
|
603 | - foreach($files as $file) |
|
602 | + if (is_array($files)) |
|
603 | + foreach ($files as $file) |
|
604 | 604 | { |
605 | - if(isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
605 | + if (isset($file['extension']) and in_array($file['extension'], $this->backup_archive_extensions)) |
|
606 | 606 | { |
607 | 607 | $_storage_size += $file['size']; //bytes |
608 | 608 | $_backup_files_list[] = $file; |
@@ -610,15 +610,15 @@ discard block |
||
610 | 610 | } |
611 | 611 | |
612 | 612 | |
613 | - $this->sort_by($_backup_files_list, "timestamp","asc"); |
|
613 | + $this->sort_by($_backup_files_list, "timestamp", "asc"); |
|
614 | 614 | |
615 | 615 | $_backups_counter = sizeof($_backup_files_list); |
616 | 616 | |
617 | - foreach($_backup_files_list as $file) |
|
617 | + foreach ($_backup_files_list as $file) |
|
618 | 618 | { |
619 | 619 | //processing rule folder capacity |
620 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
621 | - $_storage_size >= ($set_storage_limit = 1024*1024*$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
620 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit') && |
|
621 | + $_storage_size >= ($set_storage_limit = 1024 * 1024 * $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_capacity_limit'))) //bytes |
|
622 | 622 | { |
623 | 623 | $this->storage_filesystem->delete($file['path']); |
624 | 624 | $_storage_size -= $file['size']; |
@@ -626,14 +626,14 @@ discard block |
||
626 | 626 | } |
627 | 627 | |
628 | 628 | //processing rule days limit |
629 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
629 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days') && $current_timestamp >= $file['timestamp']) |
|
630 | 630 | { |
631 | 631 | $this->storage_filesystem->delete($file['path']); |
632 | 632 | $this->logger->info("Deleting backup ".$file['path']." matching rule", array("RETENTION LIMIT TIMESTAMP", $file['timestamp']." =< ".$this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_days'))); |
633 | 633 | } |
634 | 634 | |
635 | 635 | //processing backup countert limit |
636 | - if($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) |
|
636 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives') && $_backups_counter >= $this->xcloner_settings->get_xcloner_option('xcloner_cleanup_retention_limit_archives')) |
|
637 | 637 | { |
638 | 638 | $this->storage_filesystem->delete($file['path']); |
639 | 639 | $_backups_counter--; |
@@ -659,33 +659,33 @@ discard block |
||
659 | 659 | |
660 | 660 | } |
661 | 661 | |
662 | - public function process_backup_name($name = "", $max_length=100) |
|
662 | + public function process_backup_name($name = "", $max_length = 100) |
|
663 | 663 | { |
664 | - if(!$name) |
|
664 | + if (!$name) |
|
665 | 665 | $name = $this->xcloner_settings->get_default_backup_name(); |
666 | 666 | |
667 | - foreach($this->backup_name_tags as $tag) |
|
667 | + foreach ($this->backup_name_tags as $tag) |
|
668 | 668 | { |
669 | - if($tag == '[time]') |
|
670 | - $name = str_replace($tag, date("Y-m-d_H-i"),$name); |
|
671 | - elseif($tag == '[hostname]') |
|
672 | - $name = str_replace($tag, gethostname() ,$name); |
|
673 | - elseif($tag == '[domain]') |
|
669 | + if ($tag == '[time]') |
|
670 | + $name = str_replace($tag, date("Y-m-d_H-i"), $name); |
|
671 | + elseif ($tag == '[hostname]') |
|
672 | + $name = str_replace($tag, gethostname(), $name); |
|
673 | + elseif ($tag == '[domain]') |
|
674 | 674 | { |
675 | 675 | $domain = parse_url(admin_url(), PHP_URL_HOST); |
676 | - $name = str_replace($tag, $domain ,$name); |
|
676 | + $name = str_replace($tag, $domain, $name); |
|
677 | 677 | } |
678 | 678 | } |
679 | 679 | |
680 | - if($max_length) |
|
680 | + if ($max_length) |
|
681 | 681 | $name = substr($name, 0, $max_length); |
682 | 682 | |
683 | 683 | return $name; |
684 | 684 | } |
685 | 685 | |
686 | - public function sort_by( &$array, $field, $direction = 'asc') |
|
686 | + public function sort_by(&$array, $field, $direction = 'asc') |
|
687 | 687 | { |
688 | - if(strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
688 | + if (strtolower($direction) == "desc" || $direction == SORT_DESC) |
|
689 | 689 | $direction = SORT_DESC; |
690 | 690 | else |
691 | 691 | $direction = SORT_ASC; |
@@ -705,7 +705,7 @@ discard block |
||
705 | 705 | $tmp = array(); |
706 | 706 | foreach ($data as $key => $row) |
707 | 707 | { |
708 | - if(is_array($row)) |
|
708 | + if (is_array($row)) |
|
709 | 709 | $tmp[$key] = $row[$field]; |
710 | 710 | else |
711 | 711 | $tmp[$key] = $row->$field; |
@@ -722,18 +722,18 @@ discard block |
||
722 | 722 | |
723 | 723 | private function check_file_diff_time($file) |
724 | 724 | { |
725 | - if($this->get_diff_timestamp_start() != "") |
|
725 | + if ($this->get_diff_timestamp_start() != "") |
|
726 | 726 | { |
727 | 727 | $fileMeta = $this->getMetadataFull("start_adapter", $file['path']); |
728 | 728 | $timestamp = $fileMeta->getMTime(); |
729 | - if($timestamp < $fileMeta->getCTime()) |
|
729 | + if ($timestamp < $fileMeta->getCTime()) |
|
730 | 730 | { |
731 | 731 | $timestamp = $fileMeta->getCTime(); |
732 | 732 | } |
733 | 733 | |
734 | - if($timestamp <= $this->get_diff_timestamp_start()) |
|
734 | + if ($timestamp <= $this->get_diff_timestamp_start()) |
|
735 | 735 | { |
736 | - return " file DIFF timestamp ".$timestamp." < ". $this->diff_timestamp_start; |
|
736 | + return " file DIFF timestamp ".$timestamp." < ".$this->diff_timestamp_start; |
|
737 | 737 | } |
738 | 738 | } |
739 | 739 | |
@@ -744,35 +744,35 @@ discard block |
||
744 | 744 | { |
745 | 745 | $this->logger->debug(sprintf(("Checking if %s is excluded"), $file['path'])); |
746 | 746 | |
747 | - if($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
747 | + if ($xcloner_exclude_files_larger_than_mb = $this->xcloner_settings->get_xcloner_option('xcloner_exclude_files_larger_than_mb')) |
|
748 | 748 | { |
749 | - if(isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
749 | + if (isset($file['size']) && $file['size'] > $this->calc_to_bytes($xcloner_exclude_files_larger_than_mb)) |
|
750 | 750 | return "> ".$xcloner_exclude_files_larger_than_mb."MB"; |
751 | 751 | } |
752 | 752 | |
753 | - if(!sizeof($this->excluded_files)) |
|
753 | + if (!sizeof($this->excluded_files)) |
|
754 | 754 | $this->set_excluded_files(); |
755 | 755 | |
756 | - if(is_array($this->excluded_files)) |
|
757 | - foreach($this->excluded_files as $excluded_file_pattern) |
|
756 | + if (is_array($this->excluded_files)) |
|
757 | + foreach ($this->excluded_files as $excluded_file_pattern) |
|
758 | 758 | { |
759 | - if($excluded_file_pattern == "/") |
|
759 | + if ($excluded_file_pattern == "/") |
|
760 | 760 | $needle = "$"; |
761 | 761 | else |
762 | 762 | $needle = "$".$excluded_file_pattern; |
763 | 763 | |
764 | - if(strstr("$".$file['path'], $needle)){ |
|
764 | + if (strstr("$".$file['path'], $needle)) { |
|
765 | 765 | return $excluded_file_pattern; |
766 | 766 | } |
767 | 767 | } |
768 | 768 | |
769 | - if( $regex = $this->is_excluded_regex($file)) |
|
769 | + if ($regex = $this->is_excluded_regex($file)) |
|
770 | 770 | return $regex; |
771 | 771 | |
772 | - if($file['type'] == "file") |
|
772 | + if ($file['type'] == "file") |
|
773 | 773 | { |
774 | 774 | $check_file_diff_timestamp = $this->check_file_diff_time($file); |
775 | - if($check_file_diff_timestamp) |
|
775 | + if ($check_file_diff_timestamp) |
|
776 | 776 | { |
777 | 777 | return $check_file_diff_timestamp; |
778 | 778 | } |
@@ -821,25 +821,25 @@ discard block |
||
821 | 821 | |
822 | 822 | //print_r($regex_patterns);exit; |
823 | 823 | |
824 | - if(is_array($regex_patterns)) |
|
824 | + if (is_array($regex_patterns)) |
|
825 | 825 | { |
826 | 826 | //$this->excluded_files = array(); |
827 | 827 | //$this->excluded_files[] ="(.*)\.(git)(.*)$"; |
828 | 828 | //$this->excluded_files[] ="wp-content\/backups(.*)$"; |
829 | 829 | |
830 | - foreach($regex_patterns as $excluded_file_pattern) |
|
830 | + foreach ($regex_patterns as $excluded_file_pattern) |
|
831 | 831 | { |
832 | 832 | |
833 | - if( substr($excluded_file_pattern, strlen($excluded_file_pattern)-1, strlen($excluded_file_pattern)) == "\r") |
|
834 | - $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern)-1); |
|
833 | + if (substr($excluded_file_pattern, strlen($excluded_file_pattern) - 1, strlen($excluded_file_pattern)) == "\r") |
|
834 | + $excluded_file_pattern = substr($excluded_file_pattern, 0, strlen($excluded_file_pattern) - 1); |
|
835 | 835 | |
836 | - if($file['path'] == "/") |
|
836 | + if ($file['path'] == "/") |
|
837 | 837 | $needle = "/"; |
838 | 838 | else |
839 | 839 | $needle = "/".$file['path']; |
840 | 840 | //echo $needle."---".$excluded_file_pattern."---\n"; |
841 | 841 | |
842 | - if(@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)){ |
|
842 | + if (@preg_match("/(^|^\/)".$excluded_file_pattern."/i", $needle)) { |
|
843 | 843 | return $excluded_file_pattern; |
844 | 844 | } |
845 | 845 | } |
@@ -852,36 +852,36 @@ discard block |
||
852 | 852 | { |
853 | 853 | $this->logger->debug(sprintf("Storing %s in the backup list", $file['path'])); |
854 | 854 | |
855 | - if(!isset($file['size'])) |
|
855 | + if (!isset($file['size'])) |
|
856 | 856 | $file['size'] = 0; |
857 | - if(!isset($file['visibility'])) |
|
857 | + if (!isset($file['visibility'])) |
|
858 | 858 | $file['visibility'] = "private"; |
859 | 859 | |
860 | - $csv_filename = str_replace('"','""', $file['path']); |
|
860 | + $csv_filename = str_replace('"', '""', $file['path']); |
|
861 | 861 | |
862 | 862 | $line = '"'.($csv_filename).'","'.$file['timestamp'].'","'.$file['size'].'","'.$file['visibility'].'","'.$storage.'"'.PHP_EOL; |
863 | 863 | |
864 | 864 | $this->last_logged_file = $file['path']; |
865 | 865 | |
866 | - if($file['type'] == "dir"){ |
|
867 | - try{ |
|
866 | + if ($file['type'] == "dir") { |
|
867 | + try { |
|
868 | 868 | $this->tmp_filesystem_append->write($this->get_temp_dir_handler(), $file['path']."\n"); |
869 | - }catch(Exception $e){ |
|
869 | + }catch (Exception $e) { |
|
870 | 870 | $this->logger->error($e->getMessage()); |
871 | 871 | } |
872 | 872 | } |
873 | 873 | |
874 | - if($this->get_diff_timestamp_start()) |
|
874 | + if ($this->get_diff_timestamp_start()) |
|
875 | 875 | { |
876 | - if($file['type'] != "file" && $response = $this->check_file_diff_time($file)) |
|
876 | + if ($file['type'] != "file" && $response = $this->check_file_diff_time($file)) |
|
877 | 877 | { |
878 | - $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], $response), array("FILESYSTEM SCAN","DIR DIFF")); |
|
878 | + $this->logger->info(sprintf("Directory %s archiving skipped on differential backup %s", $file['path'], $response), array("FILESYSTEM SCAN", "DIR DIFF")); |
|
879 | 879 | return false; |
880 | 880 | } |
881 | 881 | } |
882 | 882 | |
883 | - try{ |
|
884 | - if(!$this->tmp_filesystem_append->has($this->get_included_files_handler())) |
|
883 | + try { |
|
884 | + if (!$this->tmp_filesystem_append->has($this->get_included_files_handler())) |
|
885 | 885 | { |
886 | 886 | //adding fix for UTF-8 CSV preview |
887 | 887 | $start_line = "\xEF\xBB\xBF".'"Filename","Timestamp","Size","Visibility","Storage"'.PHP_EOL; |
@@ -890,7 +890,7 @@ discard block |
||
890 | 890 | |
891 | 891 | $this->tmp_filesystem_append->write($this->get_included_files_handler(), $line); |
892 | 892 | |
893 | - }catch(Exception $e){ |
|
893 | + }catch (Exception $e) { |
|
894 | 894 | |
895 | 895 | $this->logger->error($e->getMessage()); |
896 | 896 | } |
@@ -905,13 +905,13 @@ discard block |
||
905 | 905 | |
906 | 906 | public function get_filesystem($system = "") |
907 | 907 | { |
908 | - if($system == "storage_filesystem_append") |
|
908 | + if ($system == "storage_filesystem_append") |
|
909 | 909 | return $this->storage_filesystem_append; |
910 | - elseif($system == "tmp_filesystem_append") |
|
910 | + elseif ($system == "tmp_filesystem_append") |
|
911 | 911 | return $this->tmp_filesystem_append; |
912 | - elseif($system == "tmp_filesystem") |
|
912 | + elseif ($system == "tmp_filesystem") |
|
913 | 913 | return $this->tmp_filesystem; |
914 | - elseif($system == "storage_filesystem") |
|
914 | + elseif ($system == "storage_filesystem") |
|
915 | 915 | return $this->storage_filesystem; |
916 | 916 | else |
917 | 917 | return $this->start_filesystem; |
@@ -919,9 +919,9 @@ discard block |
||
919 | 919 | |
920 | 920 | public function get_adapter($system) |
921 | 921 | { |
922 | - if($system == "tmp_filesystem") |
|
922 | + if ($system == "tmp_filesystem") |
|
923 | 923 | return $this->tmp_adapter; |
924 | - elseif($system == "storage_filesystem") |
|
924 | + elseif ($system == "storage_filesystem") |
|
925 | 925 | return $this->storage_adapter; |
926 | 926 | else |
927 | 927 | return $this->start_adapter; |
@@ -929,10 +929,10 @@ discard block |
||
929 | 929 | |
930 | 930 | private function scan_finished() |
931 | 931 | { |
932 | - if($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
932 | + if ($this->tmp_filesystem_append->has($this->get_temp_dir_handler()) && $this->tmp_filesystem_append->getSize($this->get_temp_dir_handler())) |
|
933 | 933 | return false; |
934 | 934 | |
935 | - if($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
935 | + if ($this->tmp_filesystem->has($this->get_temp_dir_handler())) |
|
936 | 936 | $this->tmp_filesystem->delete($this->get_temp_dir_handler()); |
937 | 937 | |
938 | 938 | $this->logger->debug(sprintf(("File scan finished"))); |
@@ -942,7 +942,7 @@ discard block |
||
942 | 942 | |
943 | 943 | private function calc_to_bytes($mb_size) |
944 | 944 | { |
945 | - return $mb_size*(1024*1024); |
|
945 | + return $mb_size * (1024 * 1024); |
|
946 | 946 | } |
947 | 947 | |
948 | 948 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class Xcloner_Scheduler{ |
|
3 | +class Xcloner_Scheduler { |
|
4 | 4 | |
5 | 5 | private $db; |
6 | 6 | private $scheduler_table = "xcloner_scheduler"; |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | { |
22 | 22 | global $wpdb; |
23 | 23 | |
24 | - $this->db = $wpdb; |
|
25 | - $wpdb->show_errors = false; |
|
24 | + $this->db = $wpdb; |
|
25 | + $wpdb->show_errors = false; |
|
26 | 26 | |
27 | 27 | $this->xcloner_container = $xcloner_container; |
28 | 28 | $this->xcloner_settings = $xcloner_container->get_xcloner_settings(); |
@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | $this->xcloner_container = $container; |
41 | 41 | } |
42 | 42 | |
43 | - public function get_scheduler_list($return_only_enabled = 0 ) |
|
43 | + public function get_scheduler_list($return_only_enabled = 0) |
|
44 | 44 | { |
45 | 45 | $list = $this->db->get_results("SELECT * FROM ".$this->scheduler_table); |
46 | 46 | |
47 | - if($return_only_enabled) |
|
47 | + if ($return_only_enabled) |
|
48 | 48 | { |
49 | - $new_list= array(); |
|
49 | + $new_list = array(); |
|
50 | 50 | |
51 | - foreach($list as $res) |
|
52 | - if($res->status) |
|
51 | + foreach ($list as $res) |
|
52 | + if ($res->status) |
|
53 | 53 | { |
54 | - $res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id))+(get_option( 'gmt_offset' ) * HOUR_IN_SECONDS); |
|
54 | + $res->next_run_time = wp_next_scheduled('xcloner_scheduler_'.$res->id, array($res->id)) + (get_option('gmt_offset') * HOUR_IN_SECONDS); |
|
55 | 55 | $new_list[] = $res; |
56 | 56 | } |
57 | 57 | $list = $new_list; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | { |
78 | 78 | $data = $this->db->get_row("SELECT * FROM ".$this->scheduler_table." WHERE id=".$id, ARRAY_A); |
79 | 79 | |
80 | - if(!$data) |
|
80 | + if (!$data) |
|
81 | 81 | return false; |
82 | 82 | |
83 | 83 | $params = json_decode($data['params']); |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | |
95 | 95 | public function delete_schedule_by_id($id) |
96 | 96 | { |
97 | - $hook = 'xcloner_scheduler_'.$id; |
|
98 | - wp_clear_scheduled_hook( $hook, array($id) ); |
|
97 | + $hook = 'xcloner_scheduler_'.$id; |
|
98 | + wp_clear_scheduled_hook($hook, array($id)); |
|
99 | 99 | |
100 | - $data = $this->db->delete( $this->scheduler_table , array( 'id' => $id ) ); |
|
100 | + $data = $this->db->delete($this->scheduler_table, array('id' => $id)); |
|
101 | 101 | |
102 | 102 | return $data; |
103 | 103 | } |
@@ -106,12 +106,12 @@ discard block |
||
106 | 106 | { |
107 | 107 | $list = $this->get_scheduler_list(); |
108 | 108 | |
109 | - foreach($list as $schedule) |
|
109 | + foreach ($list as $schedule) |
|
110 | 110 | { |
111 | - $hook = 'xcloner_scheduler_'.$schedule->id; |
|
111 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
112 | 112 | |
113 | - $timestamp = wp_next_scheduled( $hook , array($schedule->id) ); |
|
114 | - wp_unschedule_event( $timestamp, $hook, array($schedule->id) ); |
|
113 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
114 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | |
@@ -119,26 +119,26 @@ discard block |
||
119 | 119 | { |
120 | 120 | $list = $this->get_scheduler_list(); |
121 | 121 | |
122 | - foreach($list as $schedule) |
|
122 | + foreach ($list as $schedule) |
|
123 | 123 | { |
124 | - $hook = 'xcloner_scheduler_'.$schedule->id; |
|
124 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
125 | 125 | |
126 | 126 | //adding the xcloner_scheduler hook with xcloner_scheduler_callback callback |
127 | - add_action( $hook, array($this, 'xcloner_scheduler_callback'), 10, 1 ); |
|
127 | + add_action($hook, array($this, 'xcloner_scheduler_callback'), 10, 1); |
|
128 | 128 | |
129 | - if ( ! wp_next_scheduled( $hook, array($schedule->id) ) and $schedule->status) { |
|
129 | + if (!wp_next_scheduled($hook, array($schedule->id)) and $schedule->status) { |
|
130 | 130 | |
131 | - if($schedule->recurrence == "single") |
|
131 | + if ($schedule->recurrence == "single") |
|
132 | 132 | { |
133 | - wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
134 | - }else{ |
|
135 | - wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) ); |
|
133 | + wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
134 | + } else { |
|
135 | + wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id)); |
|
136 | 136 | } |
137 | 137 | |
138 | - }elseif(!$schedule->status) |
|
138 | + }elseif (!$schedule->status) |
|
139 | 139 | { |
140 | - $timestamp = wp_next_scheduled( $hook , array($schedule->id) ); |
|
141 | - wp_unschedule_event( $timestamp, $hook, array($schedule->id) ); |
|
140 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
141 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
@@ -147,18 +147,18 @@ discard block |
||
147 | 147 | public function update_cron_hook($id) |
148 | 148 | { |
149 | 149 | $schedule = $this->get_schedule_by_id_object($id); |
150 | - $hook = 'xcloner_scheduler_'.$schedule->id; |
|
150 | + $hook = 'xcloner_scheduler_'.$schedule->id; |
|
151 | 151 | |
152 | - $timestamp = wp_next_scheduled( $hook , array($schedule->id) ); |
|
153 | - wp_unschedule_event( $timestamp, $hook, array($schedule->id) ); |
|
152 | + $timestamp = wp_next_scheduled($hook, array($schedule->id)); |
|
153 | + wp_unschedule_event($timestamp, $hook, array($schedule->id)); |
|
154 | 154 | |
155 | 155 | if ($schedule->status) { |
156 | 156 | |
157 | - if($schedule->recurrence == "single") |
|
157 | + if ($schedule->recurrence == "single") |
|
158 | 158 | { |
159 | - wp_schedule_single_event( strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
160 | - }else{ |
|
161 | - wp_schedule_event( strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id) ); |
|
159 | + wp_schedule_single_event(strtotime($schedule->start_at), $hook, array($schedule->id)); |
|
160 | + } else { |
|
161 | + wp_schedule_event(strtotime($schedule->start_at), $schedule->recurrence, $hook, array($schedule->id)); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | } |
@@ -166,16 +166,16 @@ discard block |
||
166 | 166 | |
167 | 167 | public function disable_single_cron($schedule_id) |
168 | 168 | { |
169 | - $hook = 'xcloner_scheduler_'.$schedule_id; |
|
170 | - $timestamp = wp_next_scheduled( $hook , array($schedule_id) ); |
|
171 | - wp_unschedule_event( $timestamp, $hook, array($schedule_id) ); |
|
169 | + $hook = 'xcloner_scheduler_'.$schedule_id; |
|
170 | + $timestamp = wp_next_scheduled($hook, array($schedule_id)); |
|
171 | + wp_unschedule_event($timestamp, $hook, array($schedule_id)); |
|
172 | 172 | |
173 | 173 | $schedule['status'] = 0; |
174 | 174 | |
175 | 175 | $update = $this->db->update( |
176 | 176 | $this->scheduler_table, |
177 | 177 | $schedule, |
178 | - array( 'id' => $schedule_id ), |
|
178 | + array('id' => $schedule_id), |
|
179 | 179 | array( |
180 | 180 | '%s', |
181 | 181 | '%s' |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | $update = $this->db->update( |
192 | 192 | $this->scheduler_table, |
193 | 193 | $schedule, |
194 | - array( 'id' => $schedule_id ), |
|
194 | + array('id' => $schedule_id), |
|
195 | 195 | array( |
196 | 196 | '%s', |
197 | 197 | '%s' |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | $update = $this->db->update( |
208 | 208 | $this->scheduler_table, |
209 | 209 | $schedule, |
210 | - array( 'id' => $schedule_id ), |
|
210 | + array('id' => $schedule_id), |
|
211 | 211 | array( |
212 | 212 | '%s', |
213 | 213 | '%s' |
@@ -224,25 +224,25 @@ discard block |
||
224 | 224 | $xcloner->init(); |
225 | 225 | $this->set_xcloner_container($xcloner); |
226 | 226 | |
227 | - $this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem(); |
|
228 | - $this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database(); |
|
229 | - $this->archive_system = $this->get_xcloner_container()->get_archive_system(); |
|
230 | - $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler"); |
|
231 | - $this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
227 | + $this->xcloner_file_system = $this->get_xcloner_container()->get_xcloner_filesystem(); |
|
228 | + $this->xcloner_database = $this->get_xcloner_container()->get_xcloner_database(); |
|
229 | + $this->archive_system = $this->get_xcloner_container()->get_archive_system(); |
|
230 | + $this->logger = $this->get_xcloner_container()->get_xcloner_logger()->withName("xcloner_scheduler"); |
|
231 | + $this->xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
|
232 | 232 | |
233 | 233 | $this->logger->info(sprintf("New schedule hash is %s", $this->xcloner_settings->get_hash())); |
234 | 234 | |
235 | - if($schedule['backup_params']->diff_start_date) |
|
235 | + if ($schedule['backup_params']->diff_start_date) |
|
236 | 236 | { |
237 | 237 | $this->xcloner_file_system->set_diff_timestamp_start($schedule['backup_params']->diff_start_date); |
238 | 238 | } |
239 | 239 | |
240 | - if($schedule['recurrence'] == "single") |
|
240 | + if ($schedule['recurrence'] == "single") |
|
241 | 241 | { |
242 | 242 | $this->disable_single_cron($schedule['id']); |
243 | 243 | } |
244 | 244 | |
245 | - if(!$schedule) |
|
245 | + if (!$schedule) |
|
246 | 246 | { |
247 | 247 | $this->logger->info(sprintf("Could not load schedule with id'%s'", $id), array("CRON")); |
248 | 248 | return; |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | $init = 1; |
258 | 258 | $continue = 1; |
259 | 259 | |
260 | - while($continue) |
|
260 | + while ($continue) |
|
261 | 261 | { |
262 | 262 | $continue = $this->xcloner_file_system->start_file_recursion($init); |
263 | 263 | |
@@ -271,9 +271,9 @@ discard block |
||
271 | 271 | $init = 1; |
272 | 272 | $return['finished'] = 0; |
273 | 273 | |
274 | - while(!$return['finished']) |
|
274 | + while (!$return['finished']) |
|
275 | 275 | { |
276 | - $return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init); |
|
276 | + $return = $this->xcloner_database->start_database_recursion((array)json_decode($schedule['table_params']), $return, $init); |
|
277 | 277 | $init = 0; |
278 | 278 | } |
279 | 279 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | $return['finished'] = 0; |
286 | 286 | $return['extra'] = array(); |
287 | 287 | |
288 | - while(!$return['finished']) |
|
288 | + while (!$return['finished']) |
|
289 | 289 | { |
290 | 290 | $return = $this->archive_system->start_incremental_backup((array)$schedule['backup_params'], $return['extra'], $init); |
291 | 291 | $init = 0; |
@@ -294,31 +294,31 @@ discard block |
||
294 | 294 | |
295 | 295 | //getting the last backup archive file |
296 | 296 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_with_extension(); |
297 | - if($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
297 | + if ($this->xcloner_file_system->is_part($this->archive_system->get_archive_name_with_extension())) |
|
298 | 298 | $return['extra']['backup_parent'] = $this->archive_system->get_archive_name_multipart(); |
299 | 299 | |
300 | 300 | $this->update_last_backup($schedule['id'], $return['extra']['backup_parent']); |
301 | 301 | |
302 | - if($schedule['remote_storage'] and array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) |
|
302 | + if ($schedule['remote_storage'] and array_key_exists($schedule['remote_storage'], $this->xcloner_remote_storage->get_available_storages())) |
|
303 | 303 | { |
304 | 304 | $backup_file = $return['extra']['backup_parent']; |
305 | 305 | |
306 | 306 | $this->logger->info(sprintf("Transferring backup to remote storage %s", strtoupper($schedule['remote_storage'])), array("CRON")); |
307 | 307 | |
308 | - if(method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) |
|
308 | + if (method_exists($this->xcloner_remote_storage, "upload_backup_to_storage")) |
|
309 | 309 | call_user_func_array(array($this->xcloner_remote_storage, "upload_backup_to_storage"), array($backup_file, $schedule['remote_storage'])); |
310 | 310 | } |
311 | 311 | |
312 | 312 | |
313 | - if(isset($schedule['backup_params']->email_notification) and $to=$schedule['backup_params']->email_notification) |
|
313 | + if (isset($schedule['backup_params']->email_notification) and $to = $schedule['backup_params']->email_notification) |
|
314 | 314 | { |
315 | - try{ |
|
315 | + try { |
|
316 | 316 | $from = "XCloner Scheduler"; |
317 | 317 | $additional['lines_total'] = $return['extra']['lines_total']; |
318 | - $subject = sprintf(__("%s - new backup generated %s") , $schedule['name'], $return['extra']['backup_parent']); |
|
318 | + $subject = sprintf(__("%s - new backup generated %s"), $schedule['name'], $return['extra']['backup_parent']); |
|
319 | 319 | |
320 | 320 | $this->archive_system->send_notification($to, $from, $subject, $return['extra']['backup_parent'], $schedule, "", $additional); |
321 | - }catch(Exception $e) |
|
321 | + }catch (Exception $e) |
|
322 | 322 | { |
323 | 323 | $this->logger->error($e->getMessage()); |
324 | 324 | } |
@@ -333,22 +333,22 @@ discard block |
||
333 | 333 | { |
334 | 334 | $schedule = $this->get_schedule_by_id($id); |
335 | 335 | |
336 | - try{ |
|
336 | + try { |
|
337 | 337 | |
338 | 338 | $this->__xcloner_scheduler_callback($id, $schedule); |
339 | 339 | |
340 | - }catch(Exception $e){ |
|
340 | + }catch (Exception $e) { |
|
341 | 341 | |
342 | 342 | //send email to site admin if email notification is not set in the scheduler |
343 | - if(!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) |
|
343 | + if (!isset($schedule['backup_params']->email_notification) || !$schedule['backup_params']->email_notification) |
|
344 | 344 | { |
345 | 345 | $schedule['backup_params']->email_notification = get_option('admin_email'); |
346 | 346 | } |
347 | 347 | |
348 | - if(isset($schedule['backup_params']->email_notification) && $to=$schedule['backup_params']->email_notification) |
|
348 | + if (isset($schedule['backup_params']->email_notification) && $to = $schedule['backup_params']->email_notification) |
|
349 | 349 | { |
350 | 350 | $from = "XCloner Scheduler"; |
351 | - $this->archive_system->send_notification($to, $from, $schedule['name']." - backup error","", "", $e->getMessage()); |
|
351 | + $this->archive_system->send_notification($to, $from, $schedule['name']." - backup error", "", "", $e->getMessage()); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | } |
@@ -361,10 +361,10 @@ discard block |
||
361 | 361 | $new_schedules = array(); |
362 | 362 | |
363 | 363 | foreach ($schedules as $key => $row) { |
364 | - if(in_array($key, $this->allowed_schedules)) |
|
364 | + if (in_array($key, $this->allowed_schedules)) |
|
365 | 365 | { |
366 | 366 | $new_schedules[$key] = $row; |
367 | - $intervals[$key] = $row['interval']; |
|
367 | + $intervals[$key] = $row['interval']; |
|
368 | 368 | } |
369 | 369 | } |
370 | 370 |
@@ -148,15 +148,15 @@ discard block |
||
148 | 148 | return $this->xcloner_file_transfer; |
149 | 149 | } |
150 | 150 | |
151 | - public function check_dependencies(){ |
|
151 | + public function check_dependencies() { |
|
152 | 152 | |
153 | 153 | $backup_storage_path = realpath(__DIR__.DS."..".DS."..".DS."..").DS."backups".DS; |
154 | 154 | |
155 | 155 | define("XCLONER_STORAGE_PATH", realpath($backup_storage_path)); |
156 | 156 | |
157 | - if(!is_dir($backup_storage_path)) |
|
157 | + if (!is_dir($backup_storage_path)) |
|
158 | 158 | { |
159 | - if(!@mkdir($backup_storage_path)) |
|
159 | + if (!@mkdir($backup_storage_path)) |
|
160 | 160 | { |
161 | 161 | $status = "error"; |
162 | 162 | $message = sprintf(__("Unable to create the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | return; |
165 | 165 | } |
166 | 166 | } |
167 | - if(!is_writable($backup_storage_path)) |
|
167 | + if (!is_writable($backup_storage_path)) |
|
168 | 168 | { |
169 | 169 | $status = "error"; |
170 | 170 | $message = sprintf(__("Unable to write to the Backup Storage Location Folder %s . Please fix this before starting the backup process."), $backup_storage_path); |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | public function trigger_message($message, $status = "error", $message_param1 = "", $message_param2 = "", $message_param3 = "") |
179 | 179 | { |
180 | 180 | $message = sprintf(__($message), $message_param1, $message_param2, $message_param3); |
181 | - add_action( 'xcloner_admin_notices', array($this,"trigger_message_notice"), 10, 2); |
|
182 | - do_action( 'xcloner_admin_notices', $message, $status); |
|
181 | + add_action('xcloner_admin_notices', array($this, "trigger_message_notice"), 10, 2); |
|
182 | + do_action('xcloner_admin_notices', $message, $status); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | public function trigger_message_notice($message, $status = "success") |
186 | 186 | { |
187 | 187 | ?> |
188 | 188 | <div class="notice notice-<?php echo $status?> is-dismissible"> |
189 | - <p><?php _e( $message, 'xcloner-backup-and-restore' ); ?></p> |
|
189 | + <p><?php _e($message, 'xcloner-backup-and-restore'); ?></p> |
|
190 | 190 | </div> |
191 | 191 | <?php |
192 | 192 | } |
@@ -213,79 +213,79 @@ discard block |
||
213 | 213 | * The class responsible for orchestrating the actions and filters of the |
214 | 214 | * core plugin. |
215 | 215 | */ |
216 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-loader.php'; |
|
216 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-loader.php'; |
|
217 | 217 | |
218 | 218 | /** |
219 | 219 | * The class responsible for defining internationalization functionality |
220 | 220 | * of the plugin. |
221 | 221 | */ |
222 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-i18n.php'; |
|
222 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-i18n.php'; |
|
223 | 223 | |
224 | 224 | /** |
225 | 225 | * The class responsible for defining all actions that occur in the admin area. |
226 | 226 | */ |
227 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-xcloner-admin.php'; |
|
227 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-xcloner-admin.php'; |
|
228 | 228 | |
229 | 229 | /** |
230 | 230 | * The class responsible for debugging XCloner. |
231 | 231 | */ |
232 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-logger.php'; |
|
232 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-logger.php'; |
|
233 | 233 | |
234 | 234 | /** |
235 | 235 | * The class responsible for defining the admin settings area. |
236 | 236 | */ |
237 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-settings.php'; |
|
237 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-settings.php'; |
|
238 | 238 | |
239 | 239 | /** |
240 | 240 | * The class responsible for defining the Remote Storage settings area. |
241 | 241 | */ |
242 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-remote-storage.php'; |
|
242 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-remote-storage.php'; |
|
243 | 243 | |
244 | 244 | /** |
245 | 245 | * The class responsible for implementing the database backup methods. |
246 | 246 | */ |
247 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-database.php'; |
|
247 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-database.php'; |
|
248 | 248 | |
249 | 249 | /** |
250 | 250 | * The class responsible for sanitization of users input. |
251 | 251 | */ |
252 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-sanitization.php'; |
|
252 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-sanitization.php'; |
|
253 | 253 | |
254 | 254 | /** |
255 | 255 | * The class responsible for XCloner system requirements validation. |
256 | 256 | */ |
257 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-requirements.php'; |
|
257 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-requirements.php'; |
|
258 | 258 | |
259 | 259 | /** |
260 | 260 | * The class responsible for XCloner backup archive creation. |
261 | 261 | */ |
262 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-archive.php'; |
|
262 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-archive.php'; |
|
263 | 263 | |
264 | 264 | /** |
265 | 265 | * The class responsible for XCloner API requests. |
266 | 266 | */ |
267 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-api.php'; |
|
267 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-api.php'; |
|
268 | 268 | |
269 | 269 | /** |
270 | 270 | * The class responsible for the XCloner File System methods. |
271 | 271 | */ |
272 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-system.php'; |
|
272 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-system.php'; |
|
273 | 273 | |
274 | 274 | /** |
275 | 275 | * The class responsible for the XCloner File Transfer methods. |
276 | 276 | */ |
277 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-file-transfer.php'; |
|
277 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-file-transfer.php'; |
|
278 | 278 | |
279 | 279 | /** |
280 | 280 | * The class responsible for the XCloner Scheduler methods. |
281 | 281 | */ |
282 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-xcloner-scheduler.php'; |
|
282 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-xcloner-scheduler.php'; |
|
283 | 283 | |
284 | 284 | /** |
285 | 285 | * The class responsible for defining all actions that occur in the public-facing |
286 | 286 | * side of the site. |
287 | 287 | */ |
288 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-xcloner-public.php'; |
|
288 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-xcloner-public.php'; |
|
289 | 289 | |
290 | 290 | $this->loader = new Xcloner_Loader($this); |
291 | 291 | |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | |
305 | 305 | $plugin_i18n = new Xcloner_i18n(); |
306 | 306 | |
307 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
307 | + $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
|
308 | 308 | |
309 | 309 | //wp_localize_script( 'ajax-script', 'my_ajax_object', |
310 | 310 | // array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); |
@@ -320,11 +320,11 @@ discard block |
||
320 | 320 | */ |
321 | 321 | private function define_admin_hooks() { |
322 | 322 | |
323 | - $plugin_admin = new Xcloner_Admin( $this ); |
|
323 | + $plugin_admin = new Xcloner_Admin($this); |
|
324 | 324 | $this->plugin_admin = $plugin_admin; |
325 | 325 | |
326 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
327 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
326 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
|
327 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
|
328 | 328 | |
329 | 329 | } |
330 | 330 | |
@@ -333,24 +333,24 @@ discard block |
||
333 | 333 | * |
334 | 334 | * @access private |
335 | 335 | */ |
336 | - private function define_admin_menu(){ |
|
336 | + private function define_admin_menu() { |
|
337 | 337 | |
338 | 338 | add_action('admin_menu', array($this->loader, 'xcloner_backup_add_admin_menu')); |
339 | 339 | |
340 | 340 | } |
341 | 341 | |
342 | - private function define_plugin_settings(){ |
|
342 | + private function define_plugin_settings() { |
|
343 | 343 | /** |
344 | 344 | * register wporg_settings_init to the admin_init action hook |
345 | 345 | */ |
346 | 346 | |
347 | 347 | $this->xcloner_settings = new XCloner_Settings($this); |
348 | 348 | |
349 | - if(defined('DOING_CRON') || isset($_POST['hash'])){ |
|
349 | + if (defined('DOING_CRON') || isset($_POST['hash'])) { |
|
350 | 350 | |
351 | - if(defined('DOING_CRON') || $_POST['hash'] == "generate_hash"){ |
|
351 | + if (defined('DOING_CRON') || $_POST['hash'] == "generate_hash") { |
|
352 | 352 | $this->xcloner_settings->generate_new_hash(); |
353 | - }else{ |
|
353 | + } else { |
|
354 | 354 | $this->xcloner_settings->set_hash($_POST['hash']); |
355 | 355 | } |
356 | 356 | } |
@@ -373,10 +373,10 @@ discard block |
||
373 | 373 | */ |
374 | 374 | private function define_public_hooks() { |
375 | 375 | |
376 | - $plugin_public = new Xcloner_Public( $this ); |
|
376 | + $plugin_public = new Xcloner_Public($this); |
|
377 | 377 | |
378 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
379 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
378 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); |
|
379 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); |
|
380 | 380 | |
381 | 381 | } |
382 | 382 | |
@@ -385,20 +385,20 @@ discard block |
||
385 | 385 | $logger = new XCloner_Logger($this, "php_system"); |
386 | 386 | $error = error_get_last(); |
387 | 387 | |
388 | - if($error['type'] and $logger) |
|
388 | + if ($error['type'] and $logger) |
|
389 | 389 | { |
390 | - $logger->info($this->friendly_error_type ($error['type']).": ".var_export($error, true)); |
|
390 | + $logger->info($this->friendly_error_type($error['type']).": ".var_export($error, true)); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | } |
394 | 394 | |
395 | 395 | function friendly_error_type($type) { |
396 | - static $levels=null; |
|
397 | - if ($levels===null) { |
|
398 | - $levels=[]; |
|
396 | + static $levels = null; |
|
397 | + if ($levels === null) { |
|
398 | + $levels = []; |
|
399 | 399 | foreach (get_defined_constants() as $key=>$value) { |
400 | - if (strpos($key,'E_')!==0) {continue;} |
|
401 | - $levels[$value]= $key; //substr($key,2); |
|
400 | + if (strpos($key, 'E_') !== 0) {continue; } |
|
401 | + $levels[$value] = $key; //substr($key,2); |
|
402 | 402 | } |
403 | 403 | } |
404 | 404 | return (isset($levels[$type]) ? $levels[$type] : "Error #{$type}"); |
@@ -406,47 +406,47 @@ discard block |
||
406 | 406 | |
407 | 407 | private function define_ajax_hooks() |
408 | 408 | { |
409 | - if(is_admin() || defined('DOING_CRON')) |
|
409 | + if (is_admin() || defined('DOING_CRON')) |
|
410 | 410 | { |
411 | - $this->xcloner_logger = new XCloner_Logger($this, "xcloner_api"); |
|
412 | - $this->xcloner_filesystem = new Xcloner_File_System($this); |
|
411 | + $this->xcloner_logger = new XCloner_Logger($this, "xcloner_api"); |
|
412 | + $this->xcloner_filesystem = new Xcloner_File_System($this); |
|
413 | 413 | |
414 | 414 | //$this->xcloner_filesystem->set_diff_timestamp_start (strtotime("-15 days")); |
415 | 415 | |
416 | - $this->archive_system = new Xcloner_Archive($this); |
|
417 | - $this->xcloner_database = new Xcloner_Database($this); |
|
418 | - $this->xcloner_scheduler = new Xcloner_Scheduler($this); |
|
419 | - $this->xcloner_remote_storage = new Xcloner_Remote_Storage($this); |
|
420 | - $this->xcloner_file_transfer = new Xcloner_File_Transfer($this); |
|
416 | + $this->archive_system = new Xcloner_Archive($this); |
|
417 | + $this->xcloner_database = new Xcloner_Database($this); |
|
418 | + $this->xcloner_scheduler = new Xcloner_Scheduler($this); |
|
419 | + $this->xcloner_remote_storage = new Xcloner_Remote_Storage($this); |
|
420 | + $this->xcloner_file_transfer = new Xcloner_File_Transfer($this); |
|
421 | 421 | |
422 | - $xcloner_api = new Xcloner_Api($this); |
|
422 | + $xcloner_api = new Xcloner_Api($this); |
|
423 | 423 | |
424 | - add_action( 'wp_ajax_get_database_tables_action', array($xcloner_api,'get_database_tables_action') ); |
|
425 | - add_action( 'wp_ajax_get_file_system_action', array($xcloner_api,'get_file_system_action') ); |
|
426 | - add_action( 'wp_ajax_scan_filesystem', array($xcloner_api,'scan_filesystem') ); |
|
427 | - add_action( 'wp_ajax_backup_database', array($xcloner_api,'backup_database') ); |
|
428 | - add_action( 'wp_ajax_backup_files' , array($xcloner_api,'backup_files') ); |
|
429 | - add_action( 'wp_ajax_save_schedule' , array($xcloner_api,'save_schedule') ); |
|
430 | - add_action( 'wp_ajax_get_schedule_by_id', array($xcloner_api,'get_schedule_by_id') ); |
|
431 | - add_action( 'wp_ajax_get_scheduler_list', array($xcloner_api,'get_scheduler_list') ); |
|
432 | - add_action( 'wp_ajax_delete_schedule_by_id' , array($xcloner_api,'delete_schedule_by_id') ); |
|
433 | - add_action( 'wp_ajax_delete_backup_by_name' , array($xcloner_api,'delete_backup_by_name') ); |
|
434 | - add_action( 'wp_ajax_download_backup_by_name', array($xcloner_api,'download_backup_by_name') ); |
|
435 | - add_action( 'wp_ajax_remote_storage_save_status', array($xcloner_api,'remote_storage_save_status') ); |
|
436 | - add_action( 'wp_ajax_upload_backup_to_remote', array($xcloner_api,'upload_backup_to_remote') ); |
|
437 | - add_action( 'wp_ajax_list_backup_files' , array($xcloner_api,'list_backup_files') ); |
|
438 | - add_action( 'wp_ajax_restore_upload_backup' , array($xcloner_api,'restore_upload_backup') ); |
|
439 | - add_action( 'wp_ajax_download_restore_script', array($xcloner_api,'download_restore_script') ); |
|
440 | - add_action( 'wp_ajax_copy_backup_remote_to_local', array($xcloner_api,'copy_backup_remote_to_local') ); |
|
441 | - add_action( 'wp_ajax_restore_backup', array($xcloner_api,'restore_backup') ); |
|
442 | - add_action( 'admin_notices', array($this, 'xcloner_error_admin_notices' )); |
|
424 | + add_action('wp_ajax_get_database_tables_action', array($xcloner_api, 'get_database_tables_action')); |
|
425 | + add_action('wp_ajax_get_file_system_action', array($xcloner_api, 'get_file_system_action')); |
|
426 | + add_action('wp_ajax_scan_filesystem', array($xcloner_api, 'scan_filesystem')); |
|
427 | + add_action('wp_ajax_backup_database', array($xcloner_api, 'backup_database')); |
|
428 | + add_action('wp_ajax_backup_files', array($xcloner_api, 'backup_files')); |
|
429 | + add_action('wp_ajax_save_schedule', array($xcloner_api, 'save_schedule')); |
|
430 | + add_action('wp_ajax_get_schedule_by_id', array($xcloner_api, 'get_schedule_by_id')); |
|
431 | + add_action('wp_ajax_get_scheduler_list', array($xcloner_api, 'get_scheduler_list')); |
|
432 | + add_action('wp_ajax_delete_schedule_by_id', array($xcloner_api, 'delete_schedule_by_id')); |
|
433 | + add_action('wp_ajax_delete_backup_by_name', array($xcloner_api, 'delete_backup_by_name')); |
|
434 | + add_action('wp_ajax_download_backup_by_name', array($xcloner_api, 'download_backup_by_name')); |
|
435 | + add_action('wp_ajax_remote_storage_save_status', array($xcloner_api, 'remote_storage_save_status')); |
|
436 | + add_action('wp_ajax_upload_backup_to_remote', array($xcloner_api, 'upload_backup_to_remote')); |
|
437 | + add_action('wp_ajax_list_backup_files', array($xcloner_api, 'list_backup_files')); |
|
438 | + add_action('wp_ajax_restore_upload_backup', array($xcloner_api, 'restore_upload_backup')); |
|
439 | + add_action('wp_ajax_download_restore_script', array($xcloner_api, 'download_restore_script')); |
|
440 | + add_action('wp_ajax_copy_backup_remote_to_local', array($xcloner_api, 'copy_backup_remote_to_local')); |
|
441 | + add_action('wp_ajax_restore_backup', array($xcloner_api, 'restore_backup')); |
|
442 | + add_action('admin_notices', array($this, 'xcloner_error_admin_notices')); |
|
443 | 443 | |
444 | 444 | } |
445 | 445 | |
446 | 446 | } |
447 | 447 | |
448 | 448 | function add_plugin_action_links($links, $file) { |
449 | - if ($file == plugin_basename(dirname(dirname(__FILE__)) . '/xcloner.php')) |
|
449 | + if ($file == plugin_basename(dirname(dirname(__FILE__)).'/xcloner.php')) |
|
450 | 450 | { |
451 | 451 | $links[] = '<a href="admin.php?page=xcloner_settings_page">'.__('Settings', 'xcloner-backup-and-restore').'</a>'; |
452 | 452 | $links[] = '<a href="admin.php?page=xcloner_generate_backups_page">'.__('Generate Backup', 'xcloner-backup-and-restore').'</a>'; |
@@ -456,13 +456,13 @@ discard block |
||
456 | 456 | } |
457 | 457 | |
458 | 458 | public function xcloner_error_admin_notices() { |
459 | - settings_errors( 'xcloner_error_message' ); |
|
459 | + settings_errors('xcloner_error_message'); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | public function define_cron_hooks() |
463 | 463 | { |
464 | 464 | //registering new schedule intervals |
465 | - add_filter( 'cron_schedules', array($this, 'add_new_intervals')); |
|
465 | + add_filter('cron_schedules', array($this, 'add_new_intervals')); |
|
466 | 466 | |
467 | 467 | |
468 | 468 | $xcloner_scheduler = $this->get_xcloner_scheduler(); |
@@ -543,7 +543,7 @@ discard block |
||
543 | 543 | |
544 | 544 | $page = sanitize_key($_GET['page']); |
545 | 545 | |
546 | - if($page) |
|
546 | + if ($page) |
|
547 | 547 | { |
548 | 548 | $this->display($page); |
549 | 549 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class Xcloner_File_Transfer extends Xcloner_File_System{ |
|
3 | +class Xcloner_File_Transfer extends Xcloner_File_System { |
|
4 | 4 | |
5 | 5 | private $target_url; |
6 | 6 | private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | public function set_target($target_url) |
10 | 10 | { |
11 | - return $this->target_url= $target_url; |
|
11 | + return $this->target_url = $target_url; |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | public function get_target() |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | |
20 | 20 | public function transfer_file($file, $start = 0, $hash = "") |
21 | 21 | { |
22 | - if(!$this->target_url) |
|
22 | + if (!$this->target_url) |
|
23 | 23 | throw new Exception("Please setup a target url for upload"); |
24 | 24 | |
25 | 25 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | fseek($fp, $start, SEEK_SET); |
29 | 29 | |
30 | - $binary_data = fread($fp, $this->transfer_limit); |
|
30 | + $binary_data = fread($fp, $this->transfer_limit); |
|
31 | 31 | |
32 | 32 | $tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5); |
33 | 33 | |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | $send_array = array(); |
39 | 39 | |
40 | 40 | $send_array['file'] = $file; |
41 | - $send_array['start'] = $start; |
|
42 | - $send_array['xcloner_action'] = "write_file"; |
|
41 | + $send_array['start'] = $start; |
|
42 | + $send_array['xcloner_action'] = "write_file"; |
|
43 | 43 | $send_array['hash'] = $hash; |
44 | 44 | #$send_array['blob'] = $binary_data; |
45 | - $send_array['blob'] = $this->curl_file_create($tmp_file_path,'application/x-binary',$tmp_filename); |
|
45 | + $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename); |
|
46 | 46 | |
47 | 47 | //$data = http_build_query($send_array); |
48 | 48 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | |
52 | 52 | $ch = curl_init(); |
53 | - curl_setopt($ch, CURLOPT_URL,$this->target_url); |
|
53 | + curl_setopt($ch, CURLOPT_URL, $this->target_url); |
|
54 | 54 | |
55 | 55 | curl_setopt($ch, CURLOPT_POST, 1); |
56 | 56 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
@@ -59,24 +59,24 @@ discard block |
||
59 | 59 | curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
60 | 60 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
61 | 61 | |
62 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array ); |
|
62 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array); |
|
63 | 63 | curl_setopt($ch, CURLOPT_VERBOSE, true); |
64 | 64 | |
65 | - $original_result = curl_exec ($ch); |
|
65 | + $original_result = curl_exec($ch); |
|
66 | 66 | |
67 | 67 | $this->get_tmp_filesystem()->delete($tmp_filename); |
68 | 68 | |
69 | 69 | $result = json_decode($original_result); |
70 | 70 | |
71 | - if(!$result) |
|
72 | - throw new Exception("We have received no valid response from the remote host, original message: ". $original_result); |
|
71 | + if (!$result) |
|
72 | + throw new Exception("We have received no valid response from the remote host, original message: ".$original_result); |
|
73 | 73 | |
74 | - if($result->status != 200) |
|
74 | + if ($result->status != 200) |
|
75 | 75 | { |
76 | 76 | throw new Exception($result->response); |
77 | 77 | } |
78 | 78 | |
79 | - if(ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) |
|
79 | + if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) |
|
80 | 80 | { |
81 | 81 | $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes", $file, $this->target_url, ftell($fp))); |
82 | 82 | $this->remove_tmp_filesystem(); |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | . ($postname ?: basename($filename)) |
94 | 94 | . ($mimetype ? ";type=$mimetype" : ''); |
95 | 95 | |
96 | - }else{ |
|
96 | + } else { |
|
97 | 97 | |
98 | 98 | return curl_file_create($filename, $mimetype, $postname); |
99 | 99 |