@@ -16,8 +16,9 @@ discard block |
||
| 16 | 16 | $logger_path = $xcloner_settings->get_xcloner_store_path().DS.$xcloner_settings->get_logger_filename(); |
| 17 | 17 | $logger_path_tmp = ""; |
| 18 | 18 | |
| 19 | - if($hash) |
|
| 20 | - $logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path().DS.$xcloner_settings->get_logger_filename(1); |
|
| 19 | + if($hash) { |
|
| 20 | + $logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path().DS.$xcloner_settings->get_logger_filename(1); |
|
| 21 | + } |
|
| 21 | 22 | |
| 22 | 23 | |
| 23 | 24 | $this->logger_path = $logger_path; |
@@ -40,8 +41,9 @@ discard block |
||
| 40 | 41 | |
| 41 | 42 | $debug_level = Logger::INFO; |
| 42 | 43 | |
| 43 | - if(WP_DEBUG) |
|
| 44 | - $debug_level = Logger::DEBUG; |
|
| 44 | + if(WP_DEBUG) { |
|
| 45 | + $debug_level = Logger::DEBUG; |
|
| 46 | + } |
|
| 45 | 47 | |
| 46 | 48 | |
| 47 | 49 | if($logger_path) |
@@ -52,8 +54,9 @@ discard block |
||
| 52 | 54 | $this->main_logger_url = $stream->getUrl(); |
| 53 | 55 | } |
| 54 | 56 | |
| 55 | - if($hash and $logger_path_tmp) |
|
| 56 | - $this->pushHandler(new StreamHandler($logger_path_tmp, $debug_level)); |
|
| 57 | + if($hash and $logger_path_tmp) { |
|
| 58 | + $this->pushHandler(new StreamHandler($logger_path_tmp, $debug_level)); |
|
| 59 | + } |
|
| 57 | 60 | |
| 58 | 61 | return $this; |
| 59 | 62 | } |
@@ -68,8 +71,9 @@ discard block |
||
| 68 | 71 | $lines = array(); |
| 69 | 72 | |
| 70 | 73 | //if(!file_exists($this->logger_path) or !is_readable($this->logger_path)) |
| 71 | - if(!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url)) |
|
| 72 | - return false; |
|
| 74 | + if(!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url)) { |
|
| 75 | + return false; |
|
| 76 | + } |
|
| 73 | 77 | |
| 74 | 78 | //$fp = fopen($this->logger_path, 'r'); |
| 75 | 79 | $fp = fopen($this->main_logger_url, 'r'); |
@@ -22,22 +22,28 @@ discard block |
||
| 22 | 22 | $this->logger = new XCloner_Logger('xcloner_archive', $hash); |
| 23 | 23 | $this->xcloner_settings = new Xcloner_Settings($hash); |
| 24 | 24 | |
| 25 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) |
|
| 26 | - $this->file_size_per_request_limit = $value*1024*1024; //MB |
|
| 25 | + if($value = $this->xcloner_settings->get_xcloner_option('xcloner_size_limit_per_request')) { |
|
| 26 | + $this->file_size_per_request_limit = $value*1024*1024; |
|
| 27 | + } |
|
| 28 | + //MB |
|
| 27 | 29 | |
| 28 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
| 29 | - $this->files_to_process_per_request = $value; |
|
| 30 | + if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) { |
|
| 31 | + $this->files_to_process_per_request = $value; |
|
| 32 | + } |
|
| 30 | 33 | |
| 31 | - if($value = get_option('xcloner_backup_compression_level')) |
|
| 32 | - $this->compression_level = $value; |
|
| 34 | + if($value = get_option('xcloner_backup_compression_level')) { |
|
| 35 | + $this->compression_level = $value; |
|
| 36 | + } |
|
| 33 | 37 | |
| 34 | - if($value = get_option('xcloner_split_backup_limit')) |
|
| 35 | - $this->xcloner_split_backup_limit = $value; |
|
| 38 | + if($value = get_option('xcloner_split_backup_limit')) { |
|
| 39 | + $this->xcloner_split_backup_limit = $value; |
|
| 40 | + } |
|
| 36 | 41 | |
| 37 | 42 | $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes |
| 38 | 43 | |
| 39 | - if(isset($archive_name)) |
|
| 40 | - $this->set_archive_name($archive_name); |
|
| 44 | + if(isset($archive_name)) { |
|
| 45 | + $this->set_archive_name($archive_name); |
|
| 46 | + } |
|
| 41 | 47 | } |
| 42 | 48 | |
| 43 | 49 | /* |
@@ -64,8 +70,9 @@ discard block |
||
| 64 | 70 | if(isset($part) and $part) |
| 65 | 71 | { |
| 66 | 72 | $new_name = preg_replace('/-part(\d*)/', "-part".$part, $this->archive_name); |
| 67 | - if(!stristr($new_name, "-part")) |
|
| 68 | - $new_name = $this->archive_name . "-part".$part; |
|
| 73 | + if(!stristr($new_name, "-part")) { |
|
| 74 | + $new_name = $this->archive_name . "-part".$part; |
|
| 75 | + } |
|
| 69 | 76 | |
| 70 | 77 | $this->archive_name = $new_name; |
| 71 | 78 | } |
@@ -120,8 +127,9 @@ discard block |
||
| 120 | 127 | |
| 121 | 128 | $headers = array('Content-Type: text/html; charset=UTF-8'); |
| 122 | 129 | |
| 123 | - if($admin_email and $from ) |
|
| 124 | - $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
|
| 130 | + if($admin_email and $from ) { |
|
| 131 | + $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
|
| 132 | + } |
|
| 125 | 133 | |
| 126 | 134 | $return = wp_mail( $to, $subject, $body, $headers ); |
| 127 | 135 | |
@@ -135,8 +143,9 @@ discard block |
||
| 135 | 143 | */ |
| 136 | 144 | public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="") |
| 137 | 145 | { |
| 138 | - if(!$from) |
|
| 139 | - $from = "XCloner Backup"; |
|
| 146 | + if(!$from) { |
|
| 147 | + $from = "XCloner Backup"; |
|
| 148 | + } |
|
| 140 | 149 | |
| 141 | 150 | if(($error_message)) |
| 142 | 151 | { |
@@ -145,16 +154,18 @@ discard block |
||
| 145 | 154 | |
| 146 | 155 | $params = (array)$params; |
| 147 | 156 | |
| 148 | - if(!$subject) |
|
| 149 | - $subject = sprintf(__("New backup generated %s") ,$backup_name); |
|
| 157 | + if(!$subject) { |
|
| 158 | + $subject = sprintf(__("New backup generated %s") ,$backup_name); |
|
| 159 | + } |
|
| 150 | 160 | |
| 151 | 161 | $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
| 152 | 162 | $body .= "<br /><br />"; |
| 153 | 163 | |
| 154 | 164 | $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
| 155 | 165 | |
| 156 | - if(!$backups_counter = sizeof($backup_parts)) |
|
| 157 | - $backups_counter = 1; |
|
| 166 | + if(!$backups_counter = sizeof($backup_parts)) { |
|
| 167 | + $backups_counter = 1; |
|
| 168 | + } |
|
| 158 | 169 | |
| 159 | 170 | $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
| 160 | 171 | $body .= "<br />"; |
@@ -173,8 +184,9 @@ discard block |
||
| 173 | 184 | $body .= "<br /><br />"; |
| 174 | 185 | } |
| 175 | 186 | |
| 176 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 177 | - $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
|
| 187 | + if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
| 188 | + $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
|
| 189 | + } |
|
| 178 | 190 | |
| 179 | 191 | $attachments = $this->filesystem->get_backup_attachments(); |
| 180 | 192 | |
@@ -209,18 +221,21 @@ discard block |
||
| 209 | 221 | { |
| 210 | 222 | $return = array(); |
| 211 | 223 | |
| 212 | - if(!isset($extra_params['backup_part'])) |
|
| 213 | - $extra_params['backup_part'] = 0; |
|
| 224 | + if(!isset($extra_params['backup_part'])) { |
|
| 225 | + $extra_params['backup_part'] = 0; |
|
| 226 | + } |
|
| 214 | 227 | |
| 215 | 228 | $return['extra']['backup_part'] = $extra_params['backup_part']; |
| 216 | 229 | |
| 217 | - if(isset( $extra_params['backup_archive_name'])) |
|
| 218 | - $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
| 219 | - else |
|
| 220 | - $this->set_archive_name($backup_params['backup_name']); |
|
| 230 | + if(isset( $extra_params['backup_archive_name'])) { |
|
| 231 | + $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
| 232 | + } else { |
|
| 233 | + $this->set_archive_name($backup_params['backup_name']); |
|
| 234 | + } |
|
| 221 | 235 | |
| 222 | - if(!$this->get_archive_name()) |
|
| 223 | - $this->set_archive_name(); |
|
| 236 | + if(!$this->get_archive_name()) { |
|
| 237 | + $this->set_archive_name(); |
|
| 238 | + } |
|
| 224 | 239 | |
| 225 | 240 | $this->backup_archive = new Tar(); |
| 226 | 241 | $this->backup_archive->setCompression($this->compression_level); |
@@ -235,7 +250,7 @@ discard block |
||
| 235 | 250 | |
| 236 | 251 | $return['extra']['backup_init'] = 1; |
| 237 | 252 | |
| 238 | - }else{ |
|
| 253 | + } else{ |
|
| 239 | 254 | $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
| 240 | 255 | |
| 241 | 256 | $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
@@ -247,11 +262,13 @@ discard block |
||
| 247 | 262 | $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
| 248 | 263 | $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
| 249 | 264 | |
| 250 | - if(!isset($extra_params['start_at_line'])) |
|
| 251 | - $extra_params['start_at_line'] = 0; |
|
| 265 | + if(!isset($extra_params['start_at_line'])) { |
|
| 266 | + $extra_params['start_at_line'] = 0; |
|
| 267 | + } |
|
| 252 | 268 | |
| 253 | - if(!isset($extra_params['start_at_byte'])) |
|
| 254 | - $extra_params['start_at_byte'] = 0; |
|
| 269 | + if(!isset($extra_params['start_at_byte'])) { |
|
| 270 | + $extra_params['start_at_byte'] = 0; |
|
| 271 | + } |
|
| 255 | 272 | |
| 256 | 273 | if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
| 257 | 274 | { |
@@ -302,21 +319,25 @@ discard block |
||
| 302 | 319 | |
| 303 | 320 | $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
| 304 | 321 | |
| 305 | - if(!isset($file_info['size'])) |
|
| 306 | - $file_info['size'] = 0; |
|
| 322 | + if(!isset($file_info['size'])) { |
|
| 323 | + $file_info['size'] = 0; |
|
| 324 | + } |
|
| 307 | 325 | |
| 308 | - if($start_filesystem == "tmp_filesystem") |
|
| 309 | - $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
|
| 326 | + if($start_filesystem == "tmp_filesystem") { |
|
| 327 | + $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
|
| 328 | + } |
|
| 310 | 329 | |
| 311 | 330 | $byte_limit = (int)$this->file_size_per_request_limit/512; |
| 312 | 331 | |
| 313 | 332 | $append = 0; |
| 314 | 333 | |
| 315 | - if($file_info['size'] > $byte_limit*512 or $start_byte) |
|
| 316 | - $append = 1; |
|
| 334 | + if($file_info['size'] > $byte_limit*512 or $start_byte) { |
|
| 335 | + $append = 1; |
|
| 336 | + } |
|
| 317 | 337 | |
| 318 | - if(!isset($return['extra']['backup_size'])) |
|
| 319 | - $return['extra']['backup_size'] =0; |
|
| 338 | + if(!isset($return['extra']['backup_size'])) { |
|
| 339 | + $return['extra']['backup_size'] =0; |
|
| 340 | + } |
|
| 320 | 341 | |
| 321 | 342 | $return['extra']['backup_size'] = $archive_info->getSize(); |
| 322 | 343 | |
@@ -352,8 +373,7 @@ discard block |
||
| 352 | 373 | |
| 353 | 374 | if($last_position>0){ |
| 354 | 375 | $start_byte = $last_position; |
| 355 | - } |
|
| 356 | - else{ |
|
| 376 | + } else{ |
|
| 357 | 377 | $extra_params['start_at_line']++; |
| 358 | 378 | $file->next(); |
| 359 | 379 | $start_byte = 0; |
@@ -390,8 +410,9 @@ discard block |
||
| 390 | 410 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
| 391 | 411 | $this->backup_archive->close(); |
| 392 | 412 | |
| 393 | - if($return['extra']['backup_part']) |
|
| 394 | - $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
| 413 | + if($return['extra']['backup_part']) { |
|
| 414 | + $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
| 415 | + } |
|
| 395 | 416 | |
| 396 | 417 | $return['extra']['start_at_line'] = $extra_params['start_at_line']-1; |
| 397 | 418 | |
@@ -443,12 +464,13 @@ discard block |
||
| 443 | 464 | $this->set_archive_name($this->get_archive_name(), ++$part); |
| 444 | 465 | $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
| 445 | 466 | |
| 446 | - if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
| 447 | - $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
| 467 | + if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) { |
|
| 468 | + $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
| 469 | + } |
|
| 448 | 470 | |
| 449 | 471 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
| 450 | 472 | |
| 451 | - }else |
|
| 473 | + } else |
|
| 452 | 474 | { |
| 453 | 475 | $this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension())); |
| 454 | 476 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
@@ -478,13 +500,15 @@ discard block |
||
| 478 | 500 | $start_adapter = $this->filesystem->get_adapter($filesystem); |
| 479 | 501 | $start_filesystem = $this->filesystem->get_adapter($filesystem); |
| 480 | 502 | |
| 481 | - if(!$file_info['path']) |
|
| 482 | - return; |
|
| 503 | + if(!$file_info['path']) { |
|
| 504 | + return; |
|
| 505 | + } |
|
| 483 | 506 | |
| 484 | - if(isset($file_info['archive_prefix_path'])) |
|
| 485 | - $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
|
| 486 | - else |
|
| 487 | - $file_info['target_path'] = $file_info['path']; |
|
| 507 | + if(isset($file_info['archive_prefix_path'])) { |
|
| 508 | + $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
|
| 509 | + } else { |
|
| 510 | + $file_info['target_path'] = $file_info['path']; |
|
| 511 | + } |
|
| 488 | 512 | |
| 489 | 513 | $last_position = $start_at_byte; |
| 490 | 514 | |
@@ -494,8 +518,7 @@ discard block |
||
| 494 | 518 | $bytes_wrote = $file_info['size']; |
| 495 | 519 | $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())); |
| 496 | 520 | $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']); |
| 497 | - } |
|
| 498 | - else{ |
|
| 521 | + } else{ |
|
| 499 | 522 | $tmp_file = md5($file_info['path']); |
| 500 | 523 | |
| 501 | 524 | //we isolate file to tmp if we are at byte 0, the starting point of file reading |
@@ -504,16 +527,16 @@ discard block |
||
| 504 | 527 | $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file)); |
| 505 | 528 | $file_stream = $start_filesystem->readStream($file_info['path']); |
| 506 | 529 | |
| 507 | - if(is_resource($file_stream['stream'])) |
|
| 508 | - $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
| 530 | + if(is_resource($file_stream['stream'])) { |
|
| 531 | + $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
| 532 | + } |
|
| 509 | 533 | } |
| 510 | 534 | |
| 511 | 535 | if($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
| 512 | 536 | { |
| 513 | 537 | $is_tmp = 1; |
| 514 | 538 | $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_file), $file_info['target_path'], $start_at_byte, $byte_limit); |
| 515 | - } |
|
| 516 | - else{ |
|
| 539 | + } else{ |
|
| 517 | 540 | $is_tmp = 0; |
| 518 | 541 | $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit); |
| 519 | 542 | } |
@@ -522,8 +545,7 @@ discard block |
||
| 522 | 545 | if($last_position == -1) |
| 523 | 546 | { |
| 524 | 547 | $bytes_wrote = $file_info['size'] - $start_at_byte; |
| 525 | - } |
|
| 526 | - else |
|
| 548 | + } else |
|
| 527 | 549 | { |
| 528 | 550 | $bytes_wrote = $last_position - $start_at_byte; |
| 529 | 551 | } |
@@ -532,8 +554,7 @@ discard block |
||
| 532 | 554 | if($is_tmp) |
| 533 | 555 | { |
| 534 | 556 | $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())); |
| 535 | - } |
|
| 536 | - else{ |
|
| 557 | + } else{ |
|
| 537 | 558 | $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())); |
| 538 | 559 | } |
| 539 | 560 | |