@@ -45,6 +45,11 @@ discard block |
||
| 45 | 45 | * Rename backup archive |
| 46 | 46 | * |
| 47 | 47 | */ |
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @param string $old_name |
|
| 51 | + * @param string $new_name |
|
| 52 | + */ |
|
| 48 | 53 | public function rename_archive($old_name, $new_name) |
| 49 | 54 | { |
| 50 | 55 | $this->logger->info(sprintf("Renaming backup archive %s to %s", $old_name, $new_name)); |
@@ -109,6 +114,10 @@ discard block |
||
| 109 | 114 | * Send notification error by E-Mail |
| 110 | 115 | * |
| 111 | 116 | */ |
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param string $error_message |
|
| 120 | + */ |
|
| 112 | 121 | public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
| 113 | 122 | { |
| 114 | 123 | |
@@ -133,6 +142,11 @@ discard block |
||
| 133 | 142 | * Send backup archive notfication by E-Mail |
| 134 | 143 | * |
| 135 | 144 | */ |
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param string $from |
|
| 148 | + * @param string $subject |
|
| 149 | + */ |
|
| 136 | 150 | public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="") |
| 137 | 151 | { |
| 138 | 152 | if(!$from) |
@@ -205,6 +219,10 @@ discard block |
||
| 205 | 219 | * Incremental Backup method |
| 206 | 220 | * |
| 207 | 221 | */ |
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @param integer $init |
|
| 225 | + */ |
|
| 208 | 226 | public function start_incremental_backup($backup_params, $extra_params, $init) |
| 209 | 227 | { |
| 210 | 228 | $return = array(); |
@@ -413,6 +431,10 @@ discard block |
||
| 413 | 431 | * Write multipart file components |
| 414 | 432 | * |
| 415 | 433 | */ |
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * @param string $path |
|
| 437 | + */ |
|
| 416 | 438 | private function write_multipart_file($path) |
| 417 | 439 | { |
| 418 | 440 | $path = $this->get_archive_name_with_extension(); |
@@ -472,6 +494,10 @@ discard block |
||
| 472 | 494 | * Add file to archive |
| 473 | 495 | * |
| 474 | 496 | */ |
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * @param integer $append |
|
| 500 | + */ |
|
| 475 | 501 | public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem) |
| 476 | 502 | { |
| 477 | 503 | |
@@ -8,9 +8,9 @@ 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 | 15 | |
| 16 | 16 | private $archive_name; |
@@ -18,25 +18,25 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function __construct($hash = "", $archive_name = "") |
| 20 | 20 | { |
| 21 | - $this->filesystem = new Xcloner_File_System($hash); |
|
| 22 | - $this->logger = new XCloner_Logger('xcloner_archive', $hash); |
|
| 21 | + $this->filesystem = new Xcloner_File_System($hash); |
|
| 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; //MB |
|
| 27 | 27 | |
| 28 | - if($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
| 28 | + if ($value = $this->xcloner_settings->get_xcloner_option('xcloner_files_to_process_per_request')) |
|
| 29 | 29 | $this->files_to_process_per_request = $value; |
| 30 | 30 | |
| 31 | - if($value = get_option('xcloner_backup_compression_level')) |
|
| 31 | + if ($value = get_option('xcloner_backup_compression_level')) |
|
| 32 | 32 | $this->compression_level = $value; |
| 33 | 33 | |
| 34 | - if($value = get_option('xcloner_split_backup_limit')) |
|
| 34 | + if ($value = get_option('xcloner_split_backup_limit')) |
|
| 35 | 35 | $this->xcloner_split_backup_limit = $value; |
| 36 | 36 | |
| 37 | - $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024*1024; //transform to bytes |
|
| 37 | + $this->xcloner_split_backup_limit = $this->xcloner_split_backup_limit * 1024 * 1024; //transform to bytes |
|
| 38 | 38 | |
| 39 | - if(isset($archive_name)) |
|
| 39 | + if (isset($archive_name)) |
|
| 40 | 40 | $this->set_archive_name($archive_name); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -61,11 +61,11 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $this->archive_name = $this->filesystem->process_backup_name($name); |
| 63 | 63 | |
| 64 | - if(isset($part) and $part) |
|
| 64 | + if (isset($part) and $part) |
|
| 65 | 65 | { |
| 66 | - $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; |
|
| 66 | + $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; |
|
| 69 | 69 | |
| 70 | 70 | $this->archive_name = $new_name; |
| 71 | 71 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function get_archive_name_multipart() |
| 92 | 92 | { |
| 93 | - $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
| 93 | + $new_name = preg_replace('/-part(\d*)/', "", $this->archive_name); |
|
| 94 | 94 | return $new_name."-multipart".$this->xcloner_settings->get_backup_extension_name(".csv"); |
| 95 | 95 | } |
| 96 | 96 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
| 113 | 113 | { |
| 114 | 114 | |
| 115 | - $body = $error_message; |
|
| 115 | + $body = $error_message; |
|
| 116 | 116 | |
| 117 | 117 | $this->logger->info(sprintf("Sending backup error notification to %s", $to)); |
| 118 | 118 | |
@@ -120,10 +120,10 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $headers = array('Content-Type: text/html; charset=UTF-8'); |
| 122 | 122 | |
| 123 | - if($admin_email and $from ) |
|
| 123 | + if ($admin_email and $from) |
|
| 124 | 124 | $headers[] = 'From: '.$from.' <'.$admin_email.'>'; |
| 125 | 125 | |
| 126 | - $return = wp_mail( $to, $subject, $body, $headers ); |
|
| 126 | + $return = wp_mail($to, $subject, $body, $headers); |
|
| 127 | 127 | |
| 128 | 128 | return $return; |
| 129 | 129 | } |
@@ -133,47 +133,47 @@ discard block |
||
| 133 | 133 | * Send backup archive notfication by E-Mail |
| 134 | 134 | * |
| 135 | 135 | */ |
| 136 | - public function send_notification($to, $from, $subject, $backup_name, $params, $error_message="") |
|
| 136 | + public function send_notification($to, $from, $subject, $backup_name, $params, $error_message = "") |
|
| 137 | 137 | { |
| 138 | - if(!$from) |
|
| 138 | + if (!$from) |
|
| 139 | 139 | $from = "XCloner Backup"; |
| 140 | 140 | |
| 141 | - if(($error_message)) |
|
| 141 | + if (($error_message)) |
|
| 142 | 142 | { |
| 143 | 143 | return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | $params = (array)$params; |
| 147 | 147 | |
| 148 | - if(!$subject) |
|
| 149 | - $subject = sprintf(__("New backup generated %s") ,$backup_name); |
|
| 148 | + if (!$subject) |
|
| 149 | + $subject = sprintf(__("New backup generated %s"), $backup_name); |
|
| 150 | 150 | |
| 151 | 151 | $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
| 152 | 152 | $body .= "<br /><br />"; |
| 153 | 153 | |
| 154 | 154 | $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
| 155 | 155 | |
| 156 | - if(!$backups_counter = sizeof($backup_parts)) |
|
| 156 | + if (!$backups_counter = sizeof($backup_parts)) |
|
| 157 | 157 | $backups_counter = 1; |
| 158 | 158 | |
| 159 | 159 | $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
| 160 | 160 | $body .= "<br />"; |
| 161 | 161 | |
| 162 | - if(sizeof($backup_parts)) |
|
| 162 | + if (sizeof($backup_parts)) |
|
| 163 | 163 | { |
| 164 | - $body .= implode("<br />",$backup_parts); |
|
| 164 | + $body .= implode("<br />", $backup_parts); |
|
| 165 | 165 | $body .= "<br />"; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $body.= "<br />"; |
|
| 168 | + $body .= "<br />"; |
|
| 169 | 169 | |
| 170 | - if(isset($params['backup_params']->backup_comments)) |
|
| 170 | + if (isset($params['backup_params']->backup_comments)) |
|
| 171 | 171 | { |
| 172 | 172 | $body .= __("Backup Comments: ").$params['backup_params']->backup_comments; |
| 173 | 173 | $body .= "<br /><br />"; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 176 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 177 | 177 | $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", $this->logger->getLastDebugLines(50)); |
| 178 | 178 | |
| 179 | 179 | $attachments = $this->filesystem->get_backup_attachments(); |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | $tar = new Tar(); |
| 184 | 184 | $tar->create($attachments_archive); |
| 185 | 185 | |
| 186 | - foreach($attachments as $key => $file) |
|
| 186 | + foreach ($attachments as $key => $file) |
|
| 187 | 187 | { |
| 188 | 188 | $tar->addFile($file, basename($file)); |
| 189 | 189 | } |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | |
| 196 | 196 | $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>'); |
| 197 | 197 | |
| 198 | - $return = wp_mail( $to, $subject, $body, $headers, array($attachments_archive) ); |
|
| 198 | + $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive)); |
|
| 199 | 199 | |
| 200 | 200 | return $return; |
| 201 | 201 | } |
@@ -209,17 +209,17 @@ discard block |
||
| 209 | 209 | { |
| 210 | 210 | $return = array(); |
| 211 | 211 | |
| 212 | - if(!isset($extra_params['backup_part'])) |
|
| 212 | + if (!isset($extra_params['backup_part'])) |
|
| 213 | 213 | $extra_params['backup_part'] = 0; |
| 214 | 214 | |
| 215 | 215 | $return['extra']['backup_part'] = $extra_params['backup_part']; |
| 216 | 216 | |
| 217 | - if(isset( $extra_params['backup_archive_name'])) |
|
| 217 | + if (isset($extra_params['backup_archive_name'])) |
|
| 218 | 218 | $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
| 219 | 219 | else |
| 220 | 220 | $this->set_archive_name($backup_params['backup_name']); |
| 221 | 221 | |
| 222 | - if(!$this->get_archive_name()) |
|
| 222 | + if (!$this->get_archive_name()) |
|
| 223 | 223 | $this->set_archive_name(); |
| 224 | 224 | |
| 225 | 225 | $this->backup_archive = new Tar(); |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | |
| 228 | 228 | $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
| 229 | 229 | |
| 230 | - if($init) |
|
| 230 | + if ($init) |
|
| 231 | 231 | { |
| 232 | 232 | $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name())); |
| 233 | 233 | |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | $return['extra']['backup_init'] = 1; |
| 237 | 237 | |
| 238 | - }else{ |
|
| 238 | + } else { |
|
| 239 | 239 | $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
| 240 | 240 | |
| 241 | 241 | $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
| 248 | 248 | $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
| 249 | 249 | |
| 250 | - if(!isset($extra_params['start_at_line'])) |
|
| 250 | + if (!isset($extra_params['start_at_line'])) |
|
| 251 | 251 | $extra_params['start_at_line'] = 0; |
| 252 | 252 | |
| 253 | - if(!isset($extra_params['start_at_byte'])) |
|
| 253 | + if (!isset($extra_params['start_at_byte'])) |
|
| 254 | 254 | $extra_params['start_at_byte'] = 0; |
| 255 | 255 | |
| 256 | - if(!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
|
| 256 | + if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) |
|
| 257 | 257 | { |
| 258 | 258 | $this->logger->error(sprintf("Missing the includes file handler %s, aborting...", $this->filesystem->get_included_files_handler())); |
| 259 | 259 | |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | $byte_limit = 0; |
| 281 | 281 | |
| 282 | - while(!$file->eof() and $counter<=$this->files_to_process_per_request) |
|
| 282 | + while (!$file->eof() and $counter <= $this->files_to_process_per_request) |
|
| 283 | 283 | { |
| 284 | 284 | $line = str_getcsv($file->current()); |
| 285 | 285 | |
@@ -287,13 +287,13 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | $start_filesystem = "start_filesystem"; |
| 289 | 289 | |
| 290 | - if(isset($line[4])){ |
|
| 290 | + if (isset($line[4])) { |
|
| 291 | 291 | $start_filesystem = $line[4]; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | //$adapter = $this->filesystem->get_adapter($start_filesystem); |
| 295 | 295 | |
| 296 | - if(!$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) |
|
| 296 | + if (!$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) |
|
| 297 | 297 | { |
| 298 | 298 | $extra_params['start_at_line']++; |
| 299 | 299 | $file->next(); |
@@ -302,35 +302,35 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
| 304 | 304 | |
| 305 | - if(!isset($file_info['size'])) |
|
| 305 | + if (!isset($file_info['size'])) |
|
| 306 | 306 | $file_info['size'] = 0; |
| 307 | 307 | |
| 308 | - if($start_filesystem == "tmp_filesystem") |
|
| 308 | + if ($start_filesystem == "tmp_filesystem") |
|
| 309 | 309 | $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
| 310 | 310 | |
| 311 | - $byte_limit = (int)$this->file_size_per_request_limit/512; |
|
| 311 | + $byte_limit = (int)$this->file_size_per_request_limit / 512; |
|
| 312 | 312 | |
| 313 | 313 | $append = 0; |
| 314 | 314 | |
| 315 | - if($file_info['size'] > $byte_limit*512 or $start_byte) |
|
| 315 | + if ($file_info['size'] > $byte_limit * 512 or $start_byte) |
|
| 316 | 316 | $append = 1; |
| 317 | 317 | |
| 318 | - if(!isset($return['extra']['backup_size'])) |
|
| 319 | - $return['extra']['backup_size'] =0; |
|
| 318 | + if (!isset($return['extra']['backup_size'])) |
|
| 319 | + $return['extra']['backup_size'] = 0; |
|
| 320 | 320 | |
| 321 | 321 | $return['extra']['backup_size'] = $archive_info->getSize(); |
| 322 | 322 | |
| 323 | 323 | $estimated_new_size = $return['extra']['backup_size'] + $file_info['size']; |
| 324 | 324 | |
| 325 | 325 | //we create a new backup part if we reach the Split Achive Limit |
| 326 | - if($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) |
|
| 326 | + if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) |
|
| 327 | 327 | { |
| 328 | - $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)); |
|
| 328 | + $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)); |
|
| 329 | 329 | list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']); |
| 330 | 330 | |
| 331 | - if($file_info['size'] > $this->xcloner_split_backup_limit) |
|
| 331 | + if ($file_info['size'] > $this->xcloner_split_backup_limit) |
|
| 332 | 332 | { |
| 333 | - $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)); |
|
| 333 | + $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)); |
|
| 334 | 334 | $extra_params['start_at_line']++; |
| 335 | 335 | } |
| 336 | 336 | |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | return $return; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | - list($bytes_wrote, $last_position) = $this->add_file_to_archive( $file_info, $start_byte, $byte_limit, $append, $start_filesystem); |
|
| 345 | + list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, $append, $start_filesystem); |
|
| 346 | 346 | $this->processed_size_bytes += $bytes_wrote; |
| 347 | 347 | |
| 348 | 348 | //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n"; |
@@ -350,17 +350,17 @@ discard block |
||
| 350 | 350 | $return['extra']['processed_file_size'] = $file_info['size']; |
| 351 | 351 | $return['extra']['backup_size'] = $archive_info->getSize(); |
| 352 | 352 | |
| 353 | - if($last_position>0){ |
|
| 353 | + if ($last_position > 0) { |
|
| 354 | 354 | $start_byte = $last_position; |
| 355 | 355 | } |
| 356 | - else{ |
|
| 356 | + else { |
|
| 357 | 357 | $extra_params['start_at_line']++; |
| 358 | 358 | $file->next(); |
| 359 | 359 | $start_byte = 0; |
| 360 | 360 | $counter++; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if($this->processed_size_bytes >= $this->file_size_per_request_limit) |
|
| 363 | + if ($this->processed_size_bytes >= $this->file_size_per_request_limit) |
|
| 364 | 364 | { |
| 365 | 365 | clearstatcache(); |
| 366 | 366 | $return['extra']['backup_size'] = $archive_info->getSize(); |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - if(!$file->eof()) |
|
| 376 | + if (!$file->eof()) |
|
| 377 | 377 | { |
| 378 | 378 | clearstatcache(); |
| 379 | 379 | $return['extra']['backup_size'] = $archive_info->getSize(); |
@@ -390,12 +390,12 @@ discard block |
||
| 390 | 390 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
| 391 | 391 | $this->backup_archive->close(); |
| 392 | 392 | |
| 393 | - if($return['extra']['backup_part']) |
|
| 393 | + if ($return['extra']['backup_part']) |
|
| 394 | 394 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
| 395 | 395 | |
| 396 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']-1; |
|
| 396 | + $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1; |
|
| 397 | 397 | |
| 398 | - if(isset($file_info)) |
|
| 398 | + if (isset($file_info)) |
|
| 399 | 399 | { |
| 400 | 400 | $return['extra']['processed_file'] = $file_info['path']; |
| 401 | 401 | $return['extra']['processed_file_size'] = $file_info['size']; |
@@ -437,20 +437,20 @@ discard block |
||
| 437 | 437 | $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", $this->get_archive_name_with_extension())); |
| 438 | 438 | $this->backup_archive->close(); |
| 439 | 439 | |
| 440 | - if(!$part) |
|
| 440 | + if (!$part) |
|
| 441 | 441 | { |
| 442 | 442 | $old_name = $this->get_archive_name_with_extension(); |
| 443 | 443 | $this->set_archive_name($this->get_archive_name(), ++$part); |
| 444 | 444 | $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
| 445 | 445 | |
| 446 | - if($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
| 446 | + if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) |
|
| 447 | 447 | $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
| 448 | 448 | |
| 449 | 449 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
| 450 | 450 | |
| 451 | - }else |
|
| 451 | + } else |
|
| 452 | 452 | { |
| 453 | - $this->logger->info(sprintf("Creating new multipart info file %s",$this->get_archive_name_with_extension())); |
|
| 453 | + $this->logger->info(sprintf("Creating new multipart info file %s", $this->get_archive_name_with_extension())); |
|
| 454 | 454 | $this->write_multipart_file($this->get_archive_name_with_extension()); |
| 455 | 455 | } |
| 456 | 456 | |
@@ -478,10 +478,10 @@ discard block |
||
| 478 | 478 | $start_adapter = $this->filesystem->get_adapter($filesystem); |
| 479 | 479 | $start_filesystem = $this->filesystem->get_adapter($filesystem); |
| 480 | 480 | |
| 481 | - if(!$file_info['path']) |
|
| 481 | + if (!$file_info['path']) |
|
| 482 | 482 | return; |
| 483 | 483 | |
| 484 | - if(isset($file_info['archive_prefix_path'])) |
|
| 484 | + if (isset($file_info['archive_prefix_path'])) |
|
| 485 | 485 | $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
| 486 | 486 | else |
| 487 | 487 | $file_info['target_path'] = $file_info['path']; |
@@ -490,36 +490,36 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | //$start_adapter = $this->filesystem->get_start_adapter(); |
| 492 | 492 | |
| 493 | - if(!$append){ |
|
| 493 | + if (!$append) { |
|
| 494 | 494 | $bytes_wrote = $file_info['size']; |
| 495 | 495 | $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 | 496 | $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path']); |
| 497 | 497 | } |
| 498 | - else{ |
|
| 498 | + else { |
|
| 499 | 499 | $tmp_file = md5($file_info['path']); |
| 500 | 500 | |
| 501 | 501 | //we isolate file to tmp if we are at byte 0, the starting point of file reading |
| 502 | - if(!$start_at_byte) |
|
| 502 | + if (!$start_at_byte) |
|
| 503 | 503 | { |
| 504 | 504 | $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", $file_info['path'], $tmp_file)); |
| 505 | 505 | $file_stream = $start_filesystem->readStream($file_info['path']); |
| 506 | 506 | |
| 507 | - if(is_resource($file_stream['stream'])) |
|
| 507 | + if (is_resource($file_stream['stream'])) |
|
| 508 | 508 | $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | - if($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
|
| 511 | + if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) |
|
| 512 | 512 | { |
| 513 | 513 | $is_tmp = 1; |
| 514 | 514 | $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 | 515 | } |
| 516 | - else{ |
|
| 516 | + else { |
|
| 517 | 517 | $is_tmp = 0; |
| 518 | 518 | $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), $file_info['target_path'], $start_at_byte, $byte_limit); |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | |
| 522 | - if($last_position == -1) |
|
| 522 | + if ($last_position == -1) |
|
| 523 | 523 | { |
| 524 | 524 | $bytes_wrote = $file_info['size'] - $start_at_byte; |
| 525 | 525 | } |
@@ -529,18 +529,18 @@ discard block |
||
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | |
| 532 | - if($is_tmp) |
|
| 532 | + if ($is_tmp) |
|
| 533 | 533 | { |
| 534 | 534 | $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 | 535 | } |
| 536 | - else{ |
|
| 536 | + else { |
|
| 537 | 537 | $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 | 538 | } |
| 539 | 539 | |
| 540 | 540 | //we delete here the isolated tmp file |
| 541 | - if($last_position == -1) |
|
| 541 | + if ($last_position == -1) |
|
| 542 | 542 | { |
| 543 | - if($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) |
|
| 543 | + if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) |
|
| 544 | 544 | { |
| 545 | 545 | $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file)); |
| 546 | 546 | $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file); |
@@ -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 | |
@@ -4,32 +4,32 @@ discard block |
||
| 4 | 4 | use Monolog\Handler\StreamHandler; |
| 5 | 5 | use Monolog\Handler\RotatingFileHandler; |
| 6 | 6 | |
| 7 | -class Xcloner_Logger extends Logger{ |
|
| 7 | +class Xcloner_Logger extends Logger { |
|
| 8 | 8 | |
| 9 | - private $logger_path ; |
|
| 9 | + private $logger_path; |
|
| 10 | 10 | private $max_logger_files = 15; |
| 11 | 11 | private $main_logger_url; |
| 12 | 12 | |
| 13 | - public function __construct($logger_name = "xcloner_logger", $hash="") |
|
| 13 | + public function __construct($logger_name = "xcloner_logger", $hash = "") |
|
| 14 | 14 | { |
| 15 | - $xcloner_settings = new Xcloner_Settings($hash); |
|
| 16 | - $logger_path = $xcloner_settings->get_xcloner_store_path().DS.$xcloner_settings->get_logger_filename(); |
|
| 15 | + $xcloner_settings = new Xcloner_Settings($hash); |
|
| 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) |
|
| 19 | + if ($hash) |
|
| 20 | 20 | $logger_path_tmp = $xcloner_settings->get_xcloner_tmp_path().DS.$xcloner_settings->get_logger_filename(1); |
| 21 | 21 | |
| 22 | 22 | |
| 23 | 23 | $this->logger_path = $logger_path; |
| 24 | 24 | //$this->logger_path_tmp = $logger_path_tmp; |
| 25 | 25 | |
| 26 | - if(!is_dir($xcloner_settings->get_xcloner_store_path()) or !is_writable($xcloner_settings->get_xcloner_store_path())) |
|
| 26 | + if (!is_dir($xcloner_settings->get_xcloner_store_path()) or !is_writable($xcloner_settings->get_xcloner_store_path())) |
|
| 27 | 27 | { |
| 28 | 28 | $logger_path = "php://stderr"; |
| 29 | 29 | $logger_path_tmp = ""; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if(!$xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 32 | + if (!$xcloner_settings->get_xcloner_option('xcloner_enable_log')) |
|
| 33 | 33 | { |
| 34 | 34 | $logger_path = "php://stderr"; |
| 35 | 35 | $logger_path_tmp = ""; |
@@ -40,19 +40,19 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | $debug_level = Logger::INFO; |
| 42 | 42 | |
| 43 | - if(WP_DEBUG) |
|
| 43 | + if (WP_DEBUG) |
|
| 44 | 44 | $debug_level = Logger::DEBUG; |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - if($logger_path) |
|
| 47 | + if ($logger_path) |
|
| 48 | 48 | { |
| 49 | 49 | $stream = new RotatingFileHandler($logger_path, $this->max_logger_files, $debug_level); |
| 50 | 50 | $this->pushHandler($stream); |
| 51 | 51 | |
| 52 | - $this->main_logger_url = $stream->getUrl(); |
|
| 52 | + $this->main_logger_url = $stream->getUrl(); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if($hash and $logger_path_tmp) |
|
| 55 | + if ($hash and $logger_path_tmp) |
|
| 56 | 56 | $this->pushHandler(new StreamHandler($logger_path_tmp, $debug_level)); |
| 57 | 57 | |
| 58 | 58 | return $this; |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $lines = array(); |
| 69 | 69 | |
| 70 | 70 | //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)) |
|
| 71 | + if (!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url)) |
|
| 72 | 72 | return false; |
| 73 | 73 | |
| 74 | 74 | //$fp = fopen($this->logger_path, 'r'); |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | $lastLine = ""; |
| 79 | 79 | |
| 80 | 80 | // Loop backword until we have our lines or we reach the start |
| 81 | - while($pos > 0 && count($lines) < $totalLines) { |
|
| 81 | + while ($pos > 0 && count($lines) < $totalLines) { |
|
| 82 | 82 | |
| 83 | 83 | $C = fgetc($fp); |
| 84 | - if($C == "\n") { |
|
| 84 | + if ($C == "\n") { |
|
| 85 | 85 | // skip empty lines |
| 86 | - if(trim($lastLine) != "") { |
|
| 86 | + if (trim($lastLine) != "") { |
|
| 87 | 87 | $lines[] = $lastLine; |
| 88 | 88 | } |
| 89 | 89 | $lastLine = ''; |
@@ -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'); |