@@ -214,9 +214,9 @@ discard block |
||
214 | 214 | * @return bool |
215 | 215 | */ |
216 | 216 | |
217 | - /** |
|
218 | - * @param string $error_message |
|
219 | - */ |
|
217 | + /** |
|
218 | + * @param string $error_message |
|
219 | + */ |
|
220 | 220 | public function send_notification_error($to, $from, $subject, $backup_name, $params, $error_message) |
221 | 221 | { |
222 | 222 | |
@@ -255,486 +255,486 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @return bool |
257 | 257 | */ |
258 | - public function send_notification( |
|
259 | - $to, |
|
260 | - $from, |
|
261 | - $subject, |
|
262 | - $backup_name, |
|
263 | - $params, |
|
264 | - $error_message = "", |
|
265 | - $additional = array() |
|
266 | - ) { |
|
267 | - if (!$from) { |
|
268 | - $from = "XCloner Backup"; |
|
269 | - } |
|
258 | + public function send_notification( |
|
259 | + $to, |
|
260 | + $from, |
|
261 | + $subject, |
|
262 | + $backup_name, |
|
263 | + $params, |
|
264 | + $error_message = "", |
|
265 | + $additional = array() |
|
266 | + ) { |
|
267 | + if (!$from) { |
|
268 | + $from = "XCloner Backup"; |
|
269 | + } |
|
270 | 270 | |
271 | - if (($error_message)) { |
|
272 | - return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message); |
|
273 | - } |
|
271 | + if (($error_message)) { |
|
272 | + return $this->send_notification_error($to, $from, $subject, $backup_name, $params, $error_message); |
|
273 | + } |
|
274 | 274 | |
275 | - $params = (array)$params; |
|
275 | + $params = (array)$params; |
|
276 | 276 | |
277 | - if (!$subject) { |
|
278 | - $subject = sprintf(__("New backup generated %s"), $backup_name); |
|
279 | - } |
|
277 | + if (!$subject) { |
|
278 | + $subject = sprintf(__("New backup generated %s"), $backup_name); |
|
279 | + } |
|
280 | 280 | |
281 | - $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
|
282 | - $body .= "<br /><br />"; |
|
281 | + $body = sprintf(__("Generated Backup Size: %s"), size_format($this->filesystem->get_backup_size($backup_name))); |
|
282 | + $body .= "<br /><br />"; |
|
283 | 283 | |
284 | - if (isset($additional['lines_total'])) { |
|
285 | - $body .= sprintf(__("Total files added: %s"), $additional['lines_total']); |
|
286 | - $body .= "<br /><br />"; |
|
287 | - } |
|
284 | + if (isset($additional['lines_total'])) { |
|
285 | + $body .= sprintf(__("Total files added: %s"), $additional['lines_total']); |
|
286 | + $body .= "<br /><br />"; |
|
287 | + } |
|
288 | 288 | |
289 | - $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
|
289 | + $backup_parts = $this->filesystem->get_multipart_files($backup_name); |
|
290 | 290 | |
291 | - if (!$backups_counter = sizeof($backup_parts)) { |
|
292 | - $backups_counter = 1; |
|
293 | - } |
|
291 | + if (!$backups_counter = sizeof($backup_parts)) { |
|
292 | + $backups_counter = 1; |
|
293 | + } |
|
294 | 294 | |
295 | - $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
|
296 | - $body .= "<br />"; |
|
295 | + $body .= sprintf(__("Backup Parts: %s"), $backups_counter); |
|
296 | + $body .= "<br />"; |
|
297 | 297 | |
298 | - if (sizeof($backup_parts)) { |
|
299 | - $body .= implode("<br />", $backup_parts); |
|
300 | - $body .= "<br />"; |
|
301 | - } |
|
298 | + if (sizeof($backup_parts)) { |
|
299 | + $body .= implode("<br />", $backup_parts); |
|
300 | + $body .= "<br />"; |
|
301 | + } |
|
302 | 302 | |
303 | - $body .= "<br />"; |
|
303 | + $body .= "<br />"; |
|
304 | 304 | |
305 | - $body .= sprintf(__("Backup Site Url: %s"), get_site_url()); |
|
306 | - $body .= "<br />"; |
|
305 | + $body .= sprintf(__("Backup Site Url: %s"), get_site_url()); |
|
306 | + $body .= "<br />"; |
|
307 | 307 | |
308 | - if (isset($params['backup_params']->backup_comments)) { |
|
309 | - $body .= __("Backup Comments: ").$params['backup_params']->backup_comments; |
|
310 | - $body .= "<br /><br />"; |
|
311 | - } |
|
308 | + if (isset($params['backup_params']->backup_comments)) { |
|
309 | + $body .= __("Backup Comments: ").$params['backup_params']->backup_comments; |
|
310 | + $body .= "<br /><br />"; |
|
311 | + } |
|
312 | 312 | |
313 | - if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
314 | - $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", |
|
315 | - $this->logger->getLastDebugLines(50)); |
|
316 | - } |
|
313 | + if ($this->xcloner_settings->get_xcloner_option('xcloner_enable_log')) { |
|
314 | + $body .= __("Latest 50 Log Lines: ")."<br />".implode("<br />\n", |
|
315 | + $this->logger->getLastDebugLines(50)); |
|
316 | + } |
|
317 | 317 | |
318 | - $attachments = $this->filesystem->get_backup_attachments(); |
|
318 | + $attachments = $this->filesystem->get_backup_attachments(); |
|
319 | 319 | |
320 | - $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path().DS."info.tgz"; |
|
320 | + $attachments_archive = $this->xcloner_settings->get_xcloner_tmp_path().DS."info.tgz"; |
|
321 | 321 | |
322 | - $tar = new Tar(); |
|
323 | - $tar->create($attachments_archive); |
|
322 | + $tar = new Tar(); |
|
323 | + $tar->create($attachments_archive); |
|
324 | 324 | |
325 | - foreach ($attachments as $key => $file) { |
|
326 | - $tar->addFile($file, basename($file)); |
|
327 | - } |
|
328 | - $tar->close(); |
|
325 | + foreach ($attachments as $key => $file) { |
|
326 | + $tar->addFile($file, basename($file)); |
|
327 | + } |
|
328 | + $tar->close(); |
|
329 | 329 | |
330 | - $this->logger->info(sprintf("Sending backup notification to %s", $to)); |
|
330 | + $this->logger->info(sprintf("Sending backup notification to %s", $to)); |
|
331 | 331 | |
332 | - $admin_email = get_option("admin_email"); |
|
332 | + $admin_email = get_option("admin_email"); |
|
333 | 333 | |
334 | - $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>'); |
|
334 | + $headers = array('Content-Type: text/html; charset=UTF-8', 'From: '.$from.' <'.$admin_email.'>'); |
|
335 | 335 | |
336 | - $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive)); |
|
336 | + $return = wp_mail($to, $subject, $body, $headers, array($attachments_archive)); |
|
337 | 337 | |
338 | - return $return; |
|
339 | - } |
|
338 | + return $return; |
|
339 | + } |
|
340 | 340 | |
341 | - /* |
|
341 | + /* |
|
342 | 342 | * |
343 | 343 | * Incremental Backup method |
344 | 344 | * |
345 | 345 | */ |
346 | - public function start_incremental_backup($backup_params, $extra_params, $init) |
|
347 | - { |
|
348 | - $return = array(); |
|
349 | - |
|
350 | - if (!isset($extra_params['backup_part'])) { |
|
351 | - $extra_params['backup_part'] = 0; |
|
352 | - } |
|
353 | - |
|
354 | - $return['extra']['backup_part'] = $extra_params['backup_part']; |
|
346 | + public function start_incremental_backup($backup_params, $extra_params, $init) |
|
347 | + { |
|
348 | + $return = array(); |
|
355 | 349 | |
356 | - if (isset($extra_params['backup_archive_name'])) { |
|
357 | - $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
358 | - } else { |
|
359 | - $this->set_archive_name($backup_params['backup_name']); |
|
360 | - } |
|
350 | + if (!isset($extra_params['backup_part'])) { |
|
351 | + $extra_params['backup_part'] = 0; |
|
352 | + } |
|
361 | 353 | |
362 | - if (!$this->get_archive_name()) { |
|
363 | - $this->set_archive_name(); |
|
364 | - } |
|
354 | + $return['extra']['backup_part'] = $extra_params['backup_part']; |
|
365 | 355 | |
366 | - $this->backup_archive = new Tar(); |
|
367 | - $this->backup_archive->setCompression($this->compression_level); |
|
356 | + if (isset($extra_params['backup_archive_name'])) { |
|
357 | + $this->set_archive_name($extra_params['backup_archive_name'], $return['extra']['backup_part']); |
|
358 | + } else { |
|
359 | + $this->set_archive_name($backup_params['backup_name']); |
|
360 | + } |
|
368 | 361 | |
369 | - $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
362 | + if (!$this->get_archive_name()) { |
|
363 | + $this->set_archive_name(); |
|
364 | + } |
|
370 | 365 | |
371 | - if ($init) { |
|
372 | - $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name())); |
|
366 | + $this->backup_archive = new Tar(); |
|
367 | + $this->backup_archive->setCompression($this->compression_level); |
|
373 | 368 | |
374 | - $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename()); |
|
369 | + $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
375 | 370 | |
376 | - $return['extra']['backup_init'] = 1; |
|
371 | + if ($init) { |
|
372 | + $this->logger->info(sprintf(__("Initializing the backup archive %s"), $this->get_archive_name())); |
|
377 | 373 | |
378 | - } else { |
|
379 | - $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
|
374 | + $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename()); |
|
380 | 375 | |
381 | - $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
|
376 | + $return['extra']['backup_init'] = 1; |
|
382 | 377 | |
383 | - $return['extra']['backup_init'] = 0; |
|
378 | + } else { |
|
379 | + $this->logger->info(sprintf(__("Opening for append the backup archive %s"), $this->get_archive_name())); |
|
384 | 380 | |
385 | - } |
|
381 | + $this->backup_archive->openForAppend($archive_info->getPath().DS.$archive_info->getFilename()); |
|
386 | 382 | |
387 | - $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
|
388 | - $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
|
383 | + $return['extra']['backup_init'] = 0; |
|
389 | 384 | |
390 | - if (!isset($extra_params['start_at_line'])) { |
|
391 | - $extra_params['start_at_line'] = 0; |
|
392 | - } |
|
385 | + } |
|
393 | 386 | |
394 | - if (!isset($extra_params['start_at_byte'])) { |
|
395 | - $extra_params['start_at_byte'] = 0; |
|
396 | - } |
|
387 | + $return['extra']['backup_archive_name'] = $this->get_archive_name(); |
|
388 | + $return['extra']['backup_archive_name_full'] = $this->get_archive_name_with_extension(); |
|
397 | 389 | |
398 | - if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) { |
|
399 | - $this->logger->error(sprintf("Missing the includes file handler %s, aborting...", |
|
400 | - $this->filesystem->get_included_files_handler())); |
|
390 | + if (!isset($extra_params['start_at_line'])) { |
|
391 | + $extra_params['start_at_line'] = 0; |
|
392 | + } |
|
401 | 393 | |
402 | - $return['finished'] = 1; |
|
403 | - return $return; |
|
404 | - } |
|
394 | + if (!isset($extra_params['start_at_byte'])) { |
|
395 | + $extra_params['start_at_byte'] = 0; |
|
396 | + } |
|
405 | 397 | |
406 | - $included_files_handler = $this->filesystem->get_included_files_handler(1); |
|
398 | + if (!$this->filesystem->get_tmp_filesystem()->has($this->filesystem->get_included_files_handler())) { |
|
399 | + $this->logger->error(sprintf("Missing the includes file handler %s, aborting...", |
|
400 | + $this->filesystem->get_included_files_handler())); |
|
407 | 401 | |
408 | - $file = new SplFileObject($included_files_handler); |
|
402 | + $return['finished'] = 1; |
|
403 | + return $return; |
|
404 | + } |
|
409 | 405 | |
410 | - $file->seek(PHP_INT_MAX); |
|
406 | + $included_files_handler = $this->filesystem->get_included_files_handler(1); |
|
411 | 407 | |
412 | - $return['extra']['lines_total'] = ($file->key() - 1); |
|
408 | + $file = new SplFileObject($included_files_handler); |
|
413 | 409 | |
414 | - //we skip the first CSV line with headers |
|
415 | - if (!$extra_params['start_at_line']) { |
|
416 | - $file->seek(1); |
|
417 | - } else { |
|
418 | - $file->seek($extra_params['start_at_line'] + 1); |
|
419 | - } |
|
410 | + $file->seek(PHP_INT_MAX); |
|
420 | 411 | |
421 | - $this->processed_size_bytes = 0; |
|
412 | + $return['extra']['lines_total'] = ($file->key() - 1); |
|
422 | 413 | |
423 | - $counter = 0; |
|
414 | + //we skip the first CSV line with headers |
|
415 | + if (!$extra_params['start_at_line']) { |
|
416 | + $file->seek(1); |
|
417 | + } else { |
|
418 | + $file->seek($extra_params['start_at_line'] + 1); |
|
419 | + } |
|
424 | 420 | |
425 | - $start_byte = $extra_params['start_at_byte']; |
|
421 | + $this->processed_size_bytes = 0; |
|
426 | 422 | |
427 | - $byte_limit = 0; |
|
423 | + $counter = 0; |
|
428 | 424 | |
429 | - while (!$file->eof() and $counter <= $this->files_to_process_per_request) { |
|
430 | - $current_line_str = $file->current(); |
|
425 | + $start_byte = $extra_params['start_at_byte']; |
|
431 | 426 | |
432 | - $line = str_getcsv($current_line_str); |
|
427 | + $byte_limit = 0; |
|
433 | 428 | |
434 | - $relative_path = stripslashes($line[0]); |
|
429 | + while (!$file->eof() and $counter <= $this->files_to_process_per_request) { |
|
430 | + $current_line_str = $file->current(); |
|
435 | 431 | |
436 | - $start_filesystem = "start_filesystem"; |
|
432 | + $line = str_getcsv($current_line_str); |
|
437 | 433 | |
438 | - if (isset($line[4])) { |
|
439 | - $start_filesystem = $line[4]; |
|
440 | - } |
|
434 | + $relative_path = stripslashes($line[0]); |
|
441 | 435 | |
442 | - //$adapter = $this->filesystem->get_adapter($start_filesystem); |
|
436 | + $start_filesystem = "start_filesystem"; |
|
443 | 437 | |
444 | - if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) { |
|
445 | - if ($relative_path != "") { |
|
446 | - $this->logger->error(sprintf("Could not add file %b to backup archive, file not found", |
|
447 | - $relative_path)); |
|
448 | - } |
|
438 | + if (isset($line[4])) { |
|
439 | + $start_filesystem = $line[4]; |
|
440 | + } |
|
449 | 441 | |
450 | - $extra_params['start_at_line']++; |
|
451 | - $file->next(); |
|
452 | - continue; |
|
453 | - } |
|
442 | + //$adapter = $this->filesystem->get_adapter($start_filesystem); |
|
454 | 443 | |
455 | - $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
|
444 | + if (!$relative_path || !$this->filesystem->get_filesystem($start_filesystem)->has($relative_path)) { |
|
445 | + if ($relative_path != "") { |
|
446 | + $this->logger->error(sprintf("Could not add file %b to backup archive, file not found", |
|
447 | + $relative_path)); |
|
448 | + } |
|
456 | 449 | |
457 | - if (!isset($file_info['size'])) { |
|
458 | - $file_info['size'] = 0; |
|
459 | - } |
|
450 | + $extra_params['start_at_line']++; |
|
451 | + $file->next(); |
|
452 | + continue; |
|
453 | + } |
|
460 | 454 | |
461 | - if ($start_filesystem == "tmp_filesystem") { |
|
462 | - $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
|
463 | - } |
|
455 | + $file_info = $this->filesystem->get_filesystem($start_filesystem)->getMetadata($relative_path); |
|
464 | 456 | |
465 | - $byte_limit = (int)$this->file_size_per_request_limit / 512; |
|
457 | + if (!isset($file_info['size'])) { |
|
458 | + $file_info['size'] = 0; |
|
459 | + } |
|
466 | 460 | |
467 | - $append = 0; |
|
461 | + if ($start_filesystem == "tmp_filesystem") { |
|
462 | + $file_info['archive_prefix_path'] = $this->xcloner_settings->get_xcloner_tmp_path_suffix(); |
|
463 | + } |
|
468 | 464 | |
469 | - if ($file_info['size'] > $byte_limit * 512 or $start_byte) { |
|
470 | - $append = 1; |
|
471 | - } |
|
465 | + $byte_limit = (int)$this->file_size_per_request_limit / 512; |
|
472 | 466 | |
473 | - if (!isset($return['extra']['backup_size'])) { |
|
474 | - $return['extra']['backup_size'] = 0; |
|
475 | - } |
|
467 | + $append = 0; |
|
476 | 468 | |
477 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
469 | + if ($file_info['size'] > $byte_limit * 512 or $start_byte) { |
|
470 | + $append = 1; |
|
471 | + } |
|
478 | 472 | |
479 | - $estimated_new_size = $return['extra']['backup_size'] + $file_info['size']; |
|
473 | + if (!isset($return['extra']['backup_size'])) { |
|
474 | + $return['extra']['backup_size'] = 0; |
|
475 | + } |
|
480 | 476 | |
481 | - //we create a new backup part if we reach the Split Achive Limit |
|
482 | - if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) { |
|
483 | - $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ", |
|
484 | - $this->xcloner_split_backup_limit, $estimated_new_size)); |
|
485 | - list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']); |
|
477 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
486 | 478 | |
487 | - if ($file_info['size'] > $this->xcloner_split_backup_limit) { |
|
488 | - $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", |
|
489 | - $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
490 | - $extra_params['start_at_line']++; |
|
491 | - } |
|
479 | + $estimated_new_size = $return['extra']['backup_size'] + $file_info['size']; |
|
492 | 480 | |
493 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
494 | - $return['extra']['start_at_byte'] = 0; |
|
481 | + //we create a new backup part if we reach the Split Achive Limit |
|
482 | + if ($this->xcloner_split_backup_limit and ($estimated_new_size > $this->xcloner_split_backup_limit) and (!$start_byte)) { |
|
483 | + $this->logger->info(sprintf("Backup size limit %s bytes reached, file add estimate %s, attempt to create a new archive ", |
|
484 | + $this->xcloner_split_backup_limit, $estimated_new_size)); |
|
485 | + list($archive_info, $return['extra']['backup_part']) = $this->create_new_backup_part($return['extra']['backup_part']); |
|
495 | 486 | |
496 | - $return['finished'] = 0; |
|
487 | + if ($file_info['size'] > $this->xcloner_split_backup_limit) { |
|
488 | + $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", |
|
489 | + $file_info['path'], $file_info['size'], $this->xcloner_split_backup_limit)); |
|
490 | + $extra_params['start_at_line']++; |
|
491 | + } |
|
497 | 492 | |
498 | - return $return; |
|
499 | - } |
|
493 | + $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
494 | + $return['extra']['start_at_byte'] = 0; |
|
500 | 495 | |
501 | - list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, |
|
502 | - $append, $start_filesystem); |
|
503 | - $this->processed_size_bytes += $bytes_wrote; |
|
496 | + $return['finished'] = 0; |
|
504 | 497 | |
505 | - //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n"; |
|
506 | - $return['extra']['processed_file'] = $file_info['path']; |
|
507 | - $return['extra']['processed_file_size'] = $file_info['size']; |
|
508 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
498 | + return $return; |
|
499 | + } |
|
509 | 500 | |
510 | - if ($last_position > 0) { |
|
511 | - $start_byte = $last_position; |
|
512 | - } else { |
|
513 | - $extra_params['start_at_line']++; |
|
514 | - $file->next(); |
|
515 | - $start_byte = 0; |
|
516 | - $counter++; |
|
517 | - } |
|
501 | + list($bytes_wrote, $last_position) = $this->add_file_to_archive($file_info, $start_byte, $byte_limit, |
|
502 | + $append, $start_filesystem); |
|
503 | + $this->processed_size_bytes += $bytes_wrote; |
|
504 | + |
|
505 | + //echo" - processed ".$this->processed_size_bytes." bytes ".$this->file_size_per_request_limit." last_position:".$last_position." \n"; |
|
506 | + $return['extra']['processed_file'] = $file_info['path']; |
|
507 | + $return['extra']['processed_file_size'] = $file_info['size']; |
|
508 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
509 | + |
|
510 | + if ($last_position > 0) { |
|
511 | + $start_byte = $last_position; |
|
512 | + } else { |
|
513 | + $extra_params['start_at_line']++; |
|
514 | + $file->next(); |
|
515 | + $start_byte = 0; |
|
516 | + $counter++; |
|
517 | + } |
|
518 | 518 | |
519 | - if ($this->processed_size_bytes >= $this->file_size_per_request_limit) { |
|
520 | - clearstatcache(); |
|
521 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
519 | + if ($this->processed_size_bytes >= $this->file_size_per_request_limit) { |
|
520 | + clearstatcache(); |
|
521 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
522 | 522 | |
523 | - $return['finished'] = 0; |
|
524 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
525 | - $return['extra']['start_at_byte'] = $last_position; |
|
526 | - $this->logger->info(sprintf("Reached the maximum %s request data limit, returning response", |
|
527 | - $this->file_size_per_request_limit)); |
|
528 | - return $return; |
|
529 | - } |
|
530 | - } |
|
523 | + $return['finished'] = 0; |
|
524 | + $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
525 | + $return['extra']['start_at_byte'] = $last_position; |
|
526 | + $this->logger->info(sprintf("Reached the maximum %s request data limit, returning response", |
|
527 | + $this->file_size_per_request_limit)); |
|
528 | + return $return; |
|
529 | + } |
|
530 | + } |
|
531 | 531 | |
532 | - if (!$file->eof()) { |
|
533 | - clearstatcache(); |
|
534 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
532 | + if (!$file->eof()) { |
|
533 | + clearstatcache(); |
|
534 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
535 | 535 | |
536 | - $return['finished'] = 0; |
|
537 | - $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
538 | - $return['extra']['start_at_byte'] = $last_position; |
|
539 | - $this->logger->info(sprintf("We have reached the maximum files to process per request limit of %s, returning response", |
|
540 | - $this->files_to_process_per_request)); |
|
536 | + $return['finished'] = 0; |
|
537 | + $return['extra']['start_at_line'] = $extra_params['start_at_line']; |
|
538 | + $return['extra']['start_at_byte'] = $last_position; |
|
539 | + $this->logger->info(sprintf("We have reached the maximum files to process per request limit of %s, returning response", |
|
540 | + $this->files_to_process_per_request)); |
|
541 | 541 | |
542 | - return $return; |
|
543 | - } |
|
542 | + return $return; |
|
543 | + } |
|
544 | 544 | |
545 | - //close the backup archive by adding 2*512 blocks of zero bytes |
|
546 | - $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", |
|
547 | - $this->get_archive_name_with_extension())); |
|
548 | - $this->backup_archive->close(); |
|
545 | + //close the backup archive by adding 2*512 blocks of zero bytes |
|
546 | + $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", |
|
547 | + $this->get_archive_name_with_extension())); |
|
548 | + $this->backup_archive->close(); |
|
549 | 549 | |
550 | - /** |
|
551 | - * XCloner HOOK backup_archive_finished. |
|
552 | - * |
|
553 | - * This will get triggered when a backup archive is finished writing. |
|
554 | - */ |
|
555 | - //do_action('backup_archive_finished', $this->backup_archive, $this); |
|
550 | + /** |
|
551 | + * XCloner HOOK backup_archive_finished. |
|
552 | + * |
|
553 | + * This will get triggered when a backup archive is finished writing. |
|
554 | + */ |
|
555 | + //do_action('backup_archive_finished', $this->backup_archive, $this); |
|
556 | 556 | |
557 | - //updating archive_info |
|
558 | - $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
557 | + //updating archive_info |
|
558 | + $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
559 | 559 | |
560 | - if ($return['extra']['backup_part']) { |
|
561 | - $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
562 | - } |
|
560 | + if ($return['extra']['backup_part']) { |
|
561 | + $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
562 | + } |
|
563 | 563 | |
564 | - $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1; |
|
564 | + $return['extra']['start_at_line'] = $extra_params['start_at_line'] - 1; |
|
565 | 565 | |
566 | - if (isset($file_info)) { |
|
567 | - $return['extra']['processed_file'] = $file_info['path']; |
|
568 | - $return['extra']['processed_file_size'] = $file_info['size']; |
|
569 | - } |
|
566 | + if (isset($file_info)) { |
|
567 | + $return['extra']['processed_file'] = $file_info['path']; |
|
568 | + $return['extra']['processed_file_size'] = $file_info['size']; |
|
569 | + } |
|
570 | 570 | |
571 | - clearstatcache(); |
|
572 | - $return['extra']['backup_size'] = $archive_info->getSize(); |
|
571 | + clearstatcache(); |
|
572 | + $return['extra']['backup_size'] = $archive_info->getSize(); |
|
573 | 573 | |
574 | - $return['finished'] = 1; |
|
575 | - return $return; |
|
576 | - } |
|
574 | + $return['finished'] = 1; |
|
575 | + return $return; |
|
576 | + } |
|
577 | 577 | |
578 | - /* |
|
578 | + /* |
|
579 | 579 | * |
580 | 580 | * Write multipart file components |
581 | 581 | * |
582 | 582 | */ |
583 | - private function write_multipart_file($path = "") |
|
584 | - { |
|
585 | - if (!$path) { |
|
586 | - $path = $this->get_archive_name_with_extension(); |
|
587 | - } |
|
583 | + private function write_multipart_file($path = "") |
|
584 | + { |
|
585 | + if (!$path) { |
|
586 | + $path = $this->get_archive_name_with_extension(); |
|
587 | + } |
|
588 | 588 | |
589 | - $file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path); |
|
590 | - //print_r($file_info); |
|
591 | - $line = '"'.$file['path'].'","'.$file['timestamp'].'","'.$file['size'].'"'.PHP_EOL; |
|
589 | + $file = $this->filesystem->get_filesystem("storage_filesystem_append")->getMetadata($path); |
|
590 | + //print_r($file_info); |
|
591 | + $line = '"'.$file['path'].'","'.$file['timestamp'].'","'.$file['size'].'"'.PHP_EOL; |
|
592 | 592 | |
593 | 593 | |
594 | - $this->filesystem->get_filesystem("storage_filesystem_append") |
|
595 | - ->write($this->get_archive_name_multipart(), $line); |
|
596 | - } |
|
594 | + $this->filesystem->get_filesystem("storage_filesystem_append") |
|
595 | + ->write($this->get_archive_name_multipart(), $line); |
|
596 | + } |
|
597 | 597 | |
598 | - /* |
|
598 | + /* |
|
599 | 599 | * |
600 | 600 | * Create a new backup part |
601 | 601 | * |
602 | 602 | */ |
603 | - private function create_new_backup_part($part = 0) |
|
604 | - { |
|
605 | - //close the backup archive by adding 2*512 blocks of zero bytes |
|
606 | - $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", |
|
607 | - $this->get_archive_name_with_extension())); |
|
608 | - $this->backup_archive->close(); |
|
609 | - |
|
610 | - if (!$part) { |
|
611 | - $old_name = $this->get_archive_name_with_extension(); |
|
612 | - $this->set_archive_name($this->get_archive_name(), ++$part); |
|
613 | - $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
|
614 | - |
|
615 | - if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) { |
|
616 | - $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
617 | - } |
|
603 | + private function create_new_backup_part($part = 0) |
|
604 | + { |
|
605 | + //close the backup archive by adding 2*512 blocks of zero bytes |
|
606 | + $this->logger->info(sprintf("Closing the backup archive %s with 2*512 zero bytes blocks.", |
|
607 | + $this->get_archive_name_with_extension())); |
|
608 | + $this->backup_archive->close(); |
|
609 | + |
|
610 | + if (!$part) { |
|
611 | + $old_name = $this->get_archive_name_with_extension(); |
|
612 | + $this->set_archive_name($this->get_archive_name(), ++$part); |
|
613 | + $this->rename_archive($old_name, $this->get_archive_name_with_extension()); |
|
614 | + |
|
615 | + if ($this->filesystem->get_storage_filesystem()->has($this->get_archive_name_multipart())) { |
|
616 | + $this->filesystem->get_storage_filesystem()->delete($this->get_archive_name_multipart()); |
|
617 | + } |
|
618 | 618 | |
619 | - $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
619 | + $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
620 | 620 | |
621 | - } else { |
|
622 | - $this->logger->info(sprintf("Creating new multipart info file %s", |
|
623 | - $this->get_archive_name_with_extension())); |
|
624 | - $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
625 | - } |
|
621 | + } else { |
|
622 | + $this->logger->info(sprintf("Creating new multipart info file %s", |
|
623 | + $this->get_archive_name_with_extension())); |
|
624 | + $this->write_multipart_file($this->get_archive_name_with_extension()); |
|
625 | + } |
|
626 | 626 | |
627 | - $this->set_archive_name($this->get_archive_name(), ++$part); |
|
627 | + $this->set_archive_name($this->get_archive_name(), ++$part); |
|
628 | 628 | |
629 | - $this->logger->info(sprintf("Creating new backup archive part %s", $this->get_archive_name_with_extension())); |
|
629 | + $this->logger->info(sprintf("Creating new backup archive part %s", $this->get_archive_name_with_extension())); |
|
630 | 630 | |
631 | - $this->backup_archive = new Tar(); |
|
632 | - $this->backup_archive->setCompression($this->compression_level); |
|
633 | - $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
634 | - $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename()); |
|
631 | + $this->backup_archive = new Tar(); |
|
632 | + $this->backup_archive->setCompression($this->compression_level); |
|
633 | + $archive_info = $this->filesystem->get_storage_path_file_info($this->get_archive_name_with_extension()); |
|
634 | + $this->backup_archive->create($archive_info->getPath().DS.$archive_info->getFilename()); |
|
635 | 635 | |
636 | - return array($archive_info, $part); |
|
636 | + return array($archive_info, $part); |
|
637 | 637 | |
638 | - } |
|
638 | + } |
|
639 | 639 | |
640 | - /* |
|
640 | + /* |
|
641 | 641 | * |
642 | 642 | * Add file to archive |
643 | 643 | * |
644 | 644 | */ |
645 | 645 | |
646 | - /** |
|
647 | - * @param integer $append |
|
648 | - */ |
|
649 | - public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem) |
|
650 | - { |
|
646 | + /** |
|
647 | + * @param integer $append |
|
648 | + */ |
|
649 | + public function add_file_to_archive($file_info, $start_at_byte, $byte_limit = 0, $append, $filesystem) |
|
650 | + { |
|
651 | 651 | |
652 | - $start_adapter = $this->filesystem->get_adapter($filesystem); |
|
653 | - $start_filesystem = $this->filesystem->get_adapter($filesystem); |
|
652 | + $start_adapter = $this->filesystem->get_adapter($filesystem); |
|
653 | + $start_filesystem = $this->filesystem->get_adapter($filesystem); |
|
654 | 654 | |
655 | - if (!$file_info['path']) { |
|
656 | - return; |
|
657 | - } |
|
655 | + if (!$file_info['path']) { |
|
656 | + return; |
|
657 | + } |
|
658 | 658 | |
659 | - if (isset($file_info['archive_prefix_path'])) { |
|
660 | - $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
|
661 | - } else { |
|
662 | - $file_info['target_path'] = $file_info['path']; |
|
663 | - } |
|
659 | + if (isset($file_info['archive_prefix_path'])) { |
|
660 | + $file_info['target_path'] = $file_info['archive_prefix_path']."/".$file_info['path']; |
|
661 | + } else { |
|
662 | + $file_info['target_path'] = $file_info['path']; |
|
663 | + } |
|
664 | 664 | |
665 | - $last_position = $start_at_byte; |
|
665 | + $last_position = $start_at_byte; |
|
666 | 666 | |
667 | - //$start_adapter = $this->filesystem->get_start_adapter(); |
|
667 | + //$start_adapter = $this->filesystem->get_start_adapter(); |
|
668 | 668 | |
669 | - if (!$append) { |
|
670 | - $bytes_wrote = $file_info['size']; |
|
671 | - $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, |
|
672 | - $file_info['target_path'], $this->get_archive_name_with_extension())); |
|
673 | - $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), |
|
674 | - $file_info['target_path']); |
|
675 | - } else { |
|
676 | - $tmp_file = md5($file_info['path']); |
|
669 | + if (!$append) { |
|
670 | + $bytes_wrote = $file_info['size']; |
|
671 | + $this->logger->info(sprintf("Adding %s bytes of file %s to archive %s ", $bytes_wrote, |
|
672 | + $file_info['target_path'], $this->get_archive_name_with_extension())); |
|
673 | + $this->backup_archive->addFile($start_adapter->applyPathPrefix($file_info['path']), |
|
674 | + $file_info['target_path']); |
|
675 | + } else { |
|
676 | + $tmp_file = md5($file_info['path']); |
|
677 | 677 | |
678 | - //we isolate file to tmp if we are at byte 0, the starting point of file reading |
|
679 | - if (!$start_at_byte) { |
|
680 | - $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", |
|
681 | - $file_info['path'], $tmp_file)); |
|
682 | - $file_stream = $start_filesystem->readStream($file_info['path']); |
|
678 | + //we isolate file to tmp if we are at byte 0, the starting point of file reading |
|
679 | + if (!$start_at_byte) { |
|
680 | + $this->logger->info(sprintf("Copying %s file to tmp filesystem file %s to prevent reading changes", |
|
681 | + $file_info['path'], $tmp_file)); |
|
682 | + $file_stream = $start_filesystem->readStream($file_info['path']); |
|
683 | 683 | |
684 | - if (is_resource($file_stream['stream'])) { |
|
685 | - $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
686 | - } |
|
687 | - } |
|
684 | + if (is_resource($file_stream['stream'])) { |
|
685 | + $this->filesystem->get_tmp_filesystem()->writeStream($tmp_file, $file_stream['stream']); |
|
686 | + } |
|
687 | + } |
|
688 | 688 | |
689 | - if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) { |
|
690 | - $is_tmp = 1; |
|
691 | - $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter() |
|
692 | - ->applyPathPrefix($tmp_file), |
|
693 | - $file_info['target_path'], $start_at_byte, $byte_limit); |
|
694 | - } else { |
|
695 | - $is_tmp = 0; |
|
696 | - $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), |
|
697 | - $file_info['target_path'], $start_at_byte, $byte_limit); |
|
698 | - } |
|
689 | + if ($this->filesystem->get_tmp_filesystem()->has($tmp_file)) { |
|
690 | + $is_tmp = 1; |
|
691 | + $last_position = $this->backup_archive->appendFileData($this->filesystem->get_tmp_filesystem_adapter() |
|
692 | + ->applyPathPrefix($tmp_file), |
|
693 | + $file_info['target_path'], $start_at_byte, $byte_limit); |
|
694 | + } else { |
|
695 | + $is_tmp = 0; |
|
696 | + $last_position = $this->backup_archive->appendFileData($start_adapter->applyPathPrefix($file_info['path']), |
|
697 | + $file_info['target_path'], $start_at_byte, $byte_limit); |
|
698 | + } |
|
699 | 699 | |
700 | 700 | |
701 | - if ($last_position == -1) { |
|
702 | - $bytes_wrote = $file_info['size'] - $start_at_byte; |
|
703 | - } else { |
|
704 | - $bytes_wrote = $last_position - $start_at_byte; |
|
705 | - } |
|
701 | + if ($last_position == -1) { |
|
702 | + $bytes_wrote = $file_info['size'] - $start_at_byte; |
|
703 | + } else { |
|
704 | + $bytes_wrote = $last_position - $start_at_byte; |
|
705 | + } |
|
706 | 706 | |
707 | 707 | |
708 | - if ($is_tmp) { |
|
709 | - $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", |
|
710 | - $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name())); |
|
711 | - } else { |
|
712 | - $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", |
|
713 | - $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name())); |
|
714 | - } |
|
708 | + if ($is_tmp) { |
|
709 | + $this->logger->info(sprintf("Appended %s bytes, starting position %s, of tmp file %s (%s) to archive %s ", |
|
710 | + $bytes_wrote, $start_at_byte, $tmp_file, $file_info['target_path'], $this->get_archive_name())); |
|
711 | + } else { |
|
712 | + $this->logger->info(sprintf("Appended %s bytes, starting position %s, of original file %s to archive %s ", |
|
713 | + $bytes_wrote, $start_at_byte, $file_info['target_path'], $tmp_file, $this->get_archive_name())); |
|
714 | + } |
|
715 | 715 | |
716 | - //we delete here the isolated tmp file |
|
717 | - if ($last_position == -1) { |
|
718 | - if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) { |
|
719 | - $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file)); |
|
720 | - $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file); |
|
721 | - } |
|
722 | - } |
|
716 | + //we delete here the isolated tmp file |
|
717 | + if ($last_position == -1) { |
|
718 | + if ($this->filesystem->get_tmp_filesystem_adapter()->has($tmp_file)) { |
|
719 | + $this->logger->info(sprintf("Deleting %s from the tmp filesystem", $tmp_file)); |
|
720 | + $this->filesystem->get_tmp_filesystem_adapter()->delete($tmp_file); |
|
721 | + } |
|
722 | + } |
|
723 | 723 | |
724 | - } |
|
724 | + } |
|
725 | 725 | |
726 | - return array($bytes_wrote, $last_position); |
|
727 | - } |
|
726 | + return array($bytes_wrote, $last_position); |
|
727 | + } |
|
728 | 728 | |
729 | - /** |
|
730 | - * Open a TAR archive and put the file cursor at the end for data appending |
|
731 | - * |
|
732 | - * If $file is empty, the tar file will be created in memory |
|
733 | - * |
|
734 | - * @param string $file |
|
735 | - * @throws ArchiveIOException |
|
736 | - */ |
|
737 | - /* |
|
729 | + /** |
|
730 | + * Open a TAR archive and put the file cursor at the end for data appending |
|
731 | + * |
|
732 | + * If $file is empty, the tar file will be created in memory |
|
733 | + * |
|
734 | + * @param string $file |
|
735 | + * @throws ArchiveIOException |
|
736 | + */ |
|
737 | + /* |
|
738 | 738 | public function openForAppend($file = '') |
739 | 739 | { |
740 | 740 | $this->file = $file; |
@@ -29,137 +29,137 @@ |
||
29 | 29 | class Xcloner_File_Transfer extends Xcloner_File_System |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Target url web address of the restore script |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - private $target_url; |
|
37 | - /** |
|
38 | - * Transfer data limit in bytes |
|
39 | - * @var int |
|
40 | - */ |
|
41 | - private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400 |
|
32 | + /** |
|
33 | + * Target url web address of the restore script |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + private $target_url; |
|
37 | + /** |
|
38 | + * Transfer data limit in bytes |
|
39 | + * @var int |
|
40 | + */ |
|
41 | + private $transfer_limit = 1048576; //bytes 1MB= 1048576 300KB = 358400 |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param $target_url |
|
46 | - * |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public function set_target($target_url) |
|
50 | - { |
|
51 | - return $this->target_url = $target_url; |
|
52 | - } |
|
44 | + /** |
|
45 | + * @param $target_url |
|
46 | + * |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public function set_target($target_url) |
|
50 | + { |
|
51 | + return $this->target_url = $target_url; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function get_target() |
|
58 | - { |
|
59 | - return $this->target_url; |
|
60 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function get_target() |
|
58 | + { |
|
59 | + return $this->target_url; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | |
63 | - /** |
|
64 | - * @param $file |
|
65 | - * @param int $start |
|
66 | - * @param string $hash |
|
67 | - * |
|
68 | - * @return bool|int |
|
69 | - * @throws Exception |
|
70 | - */ |
|
71 | - public function transfer_file($file, $start = 0, $hash = "") |
|
72 | - { |
|
73 | - if (!$this->target_url) { |
|
74 | - throw new Exception("Please setup a target url for upload"); |
|
75 | - } |
|
63 | + /** |
|
64 | + * @param $file |
|
65 | + * @param int $start |
|
66 | + * @param string $hash |
|
67 | + * |
|
68 | + * @return bool|int |
|
69 | + * @throws Exception |
|
70 | + */ |
|
71 | + public function transfer_file($file, $start = 0, $hash = "") |
|
72 | + { |
|
73 | + if (!$this->target_url) { |
|
74 | + throw new Exception("Please setup a target url for upload"); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - $fp = $this->get_storage_filesystem()->readStream($file); |
|
78 | + $fp = $this->get_storage_filesystem()->readStream($file); |
|
79 | 79 | |
80 | - fseek($fp, $start, SEEK_SET); |
|
80 | + fseek($fp, $start, SEEK_SET); |
|
81 | 81 | |
82 | - $binary_data = fread($fp, $this->transfer_limit); |
|
82 | + $binary_data = fread($fp, $this->transfer_limit); |
|
83 | 83 | |
84 | - $tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5); |
|
84 | + $tmp_filename = "xcloner_upload_".substr(md5(time()), 0, 5); |
|
85 | 85 | |
86 | - $this->get_tmp_filesystem()->write($tmp_filename, $binary_data); |
|
86 | + $this->get_tmp_filesystem()->write($tmp_filename, $binary_data); |
|
87 | 87 | |
88 | - $tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename); |
|
88 | + $tmp_file_path = $this->get_tmp_filesystem_adapter()->applyPathPrefix($tmp_filename); |
|
89 | 89 | |
90 | - $send_array = array(); |
|
90 | + $send_array = array(); |
|
91 | 91 | |
92 | - $send_array['file'] = $file; |
|
93 | - $send_array['start'] = $start; |
|
94 | - $send_array['xcloner_action'] = "write_file"; |
|
95 | - $send_array['hash'] = $hash; |
|
96 | - #$send_array['blob'] = $binary_data; |
|
97 | - $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename); |
|
92 | + $send_array['file'] = $file; |
|
93 | + $send_array['start'] = $start; |
|
94 | + $send_array['xcloner_action'] = "write_file"; |
|
95 | + $send_array['hash'] = $hash; |
|
96 | + #$send_array['blob'] = $binary_data; |
|
97 | + $send_array['blob'] = $this->curl_file_create($tmp_file_path, 'application/x-binary', $tmp_filename); |
|
98 | 98 | |
99 | - //$data = http_build_query($send_array); |
|
99 | + //$data = http_build_query($send_array); |
|
100 | 100 | |
101 | - $this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s", |
|
102 | - $this->target_url, $this->transfer_limit, $file, $start, $tmp_filename)); |
|
101 | + $this->get_logger()->info(sprintf("Sending curl request to %s with %s data of file %s starting position %s using temporary file %s", |
|
102 | + $this->target_url, $this->transfer_limit, $file, $start, $tmp_filename)); |
|
103 | 103 | |
104 | 104 | |
105 | - $ch = curl_init(); |
|
106 | - curl_setopt($ch, CURLOPT_URL, $this->target_url); |
|
105 | + $ch = curl_init(); |
|
106 | + curl_setopt($ch, CURLOPT_URL, $this->target_url); |
|
107 | 107 | |
108 | - curl_setopt($ch, CURLOPT_POST, 1); |
|
109 | - //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); |
|
110 | - //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); |
|
111 | - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); |
|
112 | - curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
|
113 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
108 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
109 | + //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); |
|
110 | + //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); |
|
111 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); |
|
112 | + curl_setopt($ch, CURLOPT_TIMEOUT, 1200); |
|
113 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
|
114 | 114 | |
115 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array); |
|
116 | - curl_setopt($ch, CURLOPT_VERBOSE, true); |
|
115 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $send_array); |
|
116 | + curl_setopt($ch, CURLOPT_VERBOSE, true); |
|
117 | 117 | |
118 | - $original_result = curl_exec($ch); |
|
118 | + $original_result = curl_exec($ch); |
|
119 | 119 | |
120 | 120 | |
121 | - $this->get_tmp_filesystem()->delete($tmp_filename); |
|
121 | + $this->get_tmp_filesystem()->delete($tmp_filename); |
|
122 | 122 | |
123 | - $result = json_decode($original_result); |
|
123 | + $result = json_decode($original_result); |
|
124 | 124 | |
125 | - if (!$result) { |
|
126 | - throw new Exception("We have received no valid response from the remote host, original message: ".$original_result); |
|
127 | - } |
|
125 | + if (!$result) { |
|
126 | + throw new Exception("We have received no valid response from the remote host, original message: ".$original_result); |
|
127 | + } |
|
128 | 128 | |
129 | - if ($result->status != 200) { |
|
130 | - throw new Exception($result->response); |
|
131 | - } |
|
129 | + if ($result->status != 200) { |
|
130 | + throw new Exception($result->response); |
|
131 | + } |
|
132 | 132 | |
133 | - if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) { |
|
134 | - $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes", |
|
135 | - $file, $this->target_url, ftell($fp))); |
|
136 | - $this->remove_tmp_filesystem(); |
|
133 | + if (ftell($fp) >= $this->get_storage_filesystem()->getSize($file)) { |
|
134 | + $this->get_logger()->info(sprintf("Upload done for file %s to target url %s, transferred a total of %s bytes", |
|
135 | + $file, $this->target_url, ftell($fp))); |
|
136 | + $this->remove_tmp_filesystem(); |
|
137 | 137 | |
138 | - return false; |
|
139 | - } |
|
138 | + return false; |
|
139 | + } |
|
140 | 140 | |
141 | - return ftell($fp); |
|
142 | - } |
|
141 | + return ftell($fp); |
|
142 | + } |
|
143 | 143 | |
144 | - /** |
|
145 | - * @param string $filename |
|
146 | - * @param string $mimetype |
|
147 | - * @param string $postname |
|
148 | - * |
|
149 | - * @return CURLFile|string |
|
150 | - */ |
|
151 | - private function curl_file_create($filename, $mimetype = '', $postname = '') |
|
152 | - { |
|
153 | - if (!function_exists('curl_file_create')) { |
|
144 | + /** |
|
145 | + * @param string $filename |
|
146 | + * @param string $mimetype |
|
147 | + * @param string $postname |
|
148 | + * |
|
149 | + * @return CURLFile|string |
|
150 | + */ |
|
151 | + private function curl_file_create($filename, $mimetype = '', $postname = '') |
|
152 | + { |
|
153 | + if (!function_exists('curl_file_create')) { |
|
154 | 154 | |
155 | - return "@$filename;filename=" |
|
156 | - . ($postname ?: basename($filename)) |
|
157 | - . ($mimetype ? ";type=$mimetype" : ''); |
|
155 | + return "@$filename;filename=" |
|
156 | + . ($postname ?: basename($filename)) |
|
157 | + . ($mimetype ? ";type=$mimetype" : ''); |
|
158 | 158 | |
159 | - } else { |
|
159 | + } else { |
|
160 | 160 | |
161 | - return curl_file_create($filename, $mimetype, $postname); |
|
161 | + return curl_file_create($filename, $mimetype, $postname); |
|
162 | 162 | |
163 | - } |
|
164 | - } |
|
163 | + } |
|
164 | + } |
|
165 | 165 | } |
@@ -10,13 +10,13 @@ discard block |
||
10 | 10 | private $max_logger_files = 7; |
11 | 11 | private $main_logger_url; |
12 | 12 | |
13 | - /** |
|
14 | - * Xcloner_Logger constructor. |
|
15 | - * @param Xcloner $xcloner_container |
|
16 | - * @param string $logger_name |
|
17 | - * @throws Exception |
|
18 | - */ |
|
19 | - public function __construct(Xcloner $xcloner_container, $logger_name = "xcloner_logger") { |
|
13 | + /** |
|
14 | + * Xcloner_Logger constructor. |
|
15 | + * @param Xcloner $xcloner_container |
|
16 | + * @param string $logger_name |
|
17 | + * @throws Exception |
|
18 | + */ |
|
19 | + public function __construct(Xcloner $xcloner_container, $logger_name = "xcloner_logger") { |
|
20 | 20 | if (!$xcloner_container->get_xcloner_settings()) { |
21 | 21 | $xcloner_settings = new Xcloner_Settings($xcloner_container); |
22 | 22 | } else { |
@@ -76,18 +76,18 @@ discard block |
||
76 | 76 | //return $this; |
77 | 77 | } |
78 | 78 | |
79 | - /** |
|
80 | - * @return string|null |
|
81 | - */ |
|
82 | - function get_main_logger_url() { |
|
79 | + /** |
|
80 | + * @return string|null |
|
81 | + */ |
|
82 | + function get_main_logger_url() { |
|
83 | 83 | return $this->main_logger_url; |
84 | 84 | } |
85 | 85 | |
86 | - /** |
|
87 | - * @param int $totalLines |
|
88 | - * @return array|bool |
|
89 | - */ |
|
90 | - function getLastDebugLines($totalLines = 200) { |
|
86 | + /** |
|
87 | + * @param int $totalLines |
|
88 | + * @return array|bool |
|
89 | + */ |
|
90 | + function getLastDebugLines($totalLines = 200) { |
|
91 | 91 | $lines = array(); |
92 | 92 | |
93 | 93 | if (!file_exists($this->main_logger_url) or !is_readable($this->main_logger_url)) { |
@@ -40,28 +40,28 @@ discard block |
||
40 | 40 | */ |
41 | 41 | private $version; |
42 | 42 | |
43 | - /** |
|
44 | - * @var Xcloner |
|
45 | - */ |
|
46 | - private $xcloner_container; |
|
47 | - |
|
48 | - /** |
|
49 | - * Initialize the class and set its properties. |
|
50 | - * |
|
51 | - * Xcloner_Admin constructor. |
|
52 | - * @param Xcloner $xcloner_container |
|
53 | - */ |
|
54 | - public function __construct(Xcloner $xcloner_container) { |
|
43 | + /** |
|
44 | + * @var Xcloner |
|
45 | + */ |
|
46 | + private $xcloner_container; |
|
47 | + |
|
48 | + /** |
|
49 | + * Initialize the class and set its properties. |
|
50 | + * |
|
51 | + * Xcloner_Admin constructor. |
|
52 | + * @param Xcloner $xcloner_container |
|
53 | + */ |
|
54 | + public function __construct(Xcloner $xcloner_container) { |
|
55 | 55 | |
56 | 56 | $this->plugin_name = $xcloner_container->get_plugin_name(); |
57 | 57 | $this->version = $xcloner_container->get_version(); |
58 | 58 | $this->xcloner_container = $xcloner_container; |
59 | 59 | } |
60 | 60 | |
61 | - /** |
|
62 | - * @return Xcloner |
|
63 | - */ |
|
64 | - public function get_xcloner_container() { |
|
61 | + /** |
|
62 | + * @return Xcloner |
|
63 | + */ |
|
64 | + public function get_xcloner_container() { |
|
65 | 65 | return $this->xcloner_container; |
66 | 66 | } |
67 | 67 | |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | |
145 | 145 | } |
146 | 146 | |
147 | - /** |
|
148 | - * Returns the XCloner Storage Page |
|
149 | - */ |
|
150 | - public function xcloner_remote_storage_page() { |
|
147 | + /** |
|
148 | + * Returns the XCloner Storage Page |
|
149 | + */ |
|
150 | + public function xcloner_remote_storage_page() { |
|
151 | 151 | $xcloner_sanitization = $this->get_xcloner_container()->get_xcloner_sanitization(); |
152 | 152 | $remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
153 | 153 |
@@ -106,13 +106,13 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Checks API access |
|
111 | - */ |
|
112 | - private function check_access() |
|
109 | + /** |
|
110 | + * Checks API access |
|
111 | + */ |
|
112 | + private function check_access() |
|
113 | 113 | { |
114 | 114 | if (function_exists('current_user_can') && !current_user_can('manage_options')) { |
115 | - $this->send_response(json_encode("Not allowed access here!")); |
|
115 | + $this->send_response(json_encode("Not allowed access here!")); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -291,8 +291,8 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function backup_files() |
293 | 293 | { |
294 | - $return = array(); |
|
295 | - $additional = array(); |
|
294 | + $return = array(); |
|
295 | + $additional = array(); |
|
296 | 296 | |
297 | 297 | $this->check_access(); |
298 | 298 | |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | */ |
357 | 357 | public function backup_database() |
358 | 358 | { |
359 | - $data = array(); |
|
359 | + $data = array(); |
|
360 | 360 | |
361 | 361 | $this->check_access(); |
362 | 362 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | */ |
393 | 393 | public function scan_filesystem() |
394 | 394 | { |
395 | - $data = array(); |
|
395 | + $data = array(); |
|
396 | 396 | |
397 | 397 | $this->check_access(); |
398 | 398 | |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | $init = (int)$_POST['init']; |
401 | 401 | |
402 | 402 | if ($params === null) { |
403 | - $this->send_response('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
403 | + $this->send_response('{"status":false,"msg":"The post_data parameter must be valid JSON"}'); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | $this->process_params($params); |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | */ |
678 | 678 | public function get_scheduler_list() |
679 | 679 | { |
680 | - $return = array(); |
|
680 | + $return = array(); |
|
681 | 681 | |
682 | 682 | $this->check_access(); |
683 | 683 | |
@@ -761,7 +761,7 @@ discard block |
||
761 | 761 | */ |
762 | 762 | public function delete_schedule_by_id() |
763 | 763 | { |
764 | - $data = array(); |
|
764 | + $data = array(); |
|
765 | 765 | |
766 | 766 | $this->check_access(); |
767 | 767 | |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | */ |
780 | 780 | public function delete_backup_by_name() |
781 | 781 | { |
782 | - $data = array(); |
|
782 | + $data = array(); |
|
783 | 783 | |
784 | 784 | $this->check_access(); |
785 | 785 | |
@@ -928,9 +928,9 @@ discard block |
||
928 | 928 | |
929 | 929 | public function get_manage_backups_list() { |
930 | 930 | |
931 | - $this->check_access(); |
|
931 | + $this->check_access(); |
|
932 | 932 | |
933 | - $return = array(); |
|
933 | + $return = array(); |
|
934 | 934 | $storage_selection = ""; |
935 | 935 | |
936 | 936 | if (isset($_GET['storage_selection']) and $_GET['storage_selection']) { |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | $this->check_access(); |
1114 | 1114 | |
1115 | 1115 | $backup_parts = array(); |
1116 | - $return = array(); |
|
1116 | + $return = array(); |
|
1117 | 1117 | |
1118 | 1118 | $source_backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
1119 | 1119 | $start = $this->xcloner_sanitization->sanitize_input_as_int($_POST['start']); |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | { |
1226 | 1226 | $this->check_access(); |
1227 | 1227 | |
1228 | - $return = array(); |
|
1228 | + $return = array(); |
|
1229 | 1229 | |
1230 | 1230 | $backup_file = $this->xcloner_sanitization->sanitize_input_as_string($_POST['file']); |
1231 | 1231 | $storage_type = $this->xcloner_sanitization->sanitize_input_as_string($_POST['storage_type']); |
@@ -1264,7 +1264,7 @@ discard block |
||
1264 | 1264 | { |
1265 | 1265 | $this->check_access(); |
1266 | 1266 | |
1267 | - $return = array(); |
|
1267 | + $return = array(); |
|
1268 | 1268 | |
1269 | 1269 | $xcloner_remote_storage = $this->get_xcloner_container()->get_xcloner_remote_storage(); |
1270 | 1270 | |
@@ -1334,10 +1334,10 @@ discard block |
||
1334 | 1334 | } |
1335 | 1335 | |
1336 | 1336 | try { |
1337 | - unlink($tmp_file); |
|
1338 | - }catch(Exception $e) { |
|
1339 | - //We are not interested in the error here |
|
1340 | - } |
|
1337 | + unlink($tmp_file); |
|
1338 | + }catch(Exception $e) { |
|
1339 | + //We are not interested in the error here |
|
1340 | + } |
|
1341 | 1341 | |
1342 | 1342 | die(); |
1343 | 1343 | } |
@@ -1378,7 +1378,7 @@ discard block |
||
1378 | 1378 | } |
1379 | 1379 | fclose($read_stream); |
1380 | 1380 | |
1381 | - wp_die(); |
|
1381 | + wp_die(); |
|
1382 | 1382 | |
1383 | 1383 | } |
1384 | 1384 | |
@@ -1389,7 +1389,7 @@ discard block |
||
1389 | 1389 | { |
1390 | 1390 | $this->check_access(); |
1391 | 1391 | |
1392 | - $return = array(); |
|
1392 | + $return = array(); |
|
1393 | 1393 | |
1394 | 1394 | $return['part'] = 0; |
1395 | 1395 | $return['total_parts'] = 0; |
@@ -162,11 +162,11 @@ |
||
162 | 162 | private $logger; |
163 | 163 | private $xcloner; |
164 | 164 | |
165 | - /** |
|
166 | - * Xcloner_Remote_Storage constructor. |
|
167 | - * @param Xcloner $xcloner_container |
|
168 | - */ |
|
169 | - public function __construct( Xcloner $xcloner_container ) { |
|
165 | + /** |
|
166 | + * Xcloner_Remote_Storage constructor. |
|
167 | + * @param Xcloner $xcloner_container |
|
168 | + */ |
|
169 | + public function __construct( Xcloner $xcloner_container ) { |
|
170 | 170 | $this->xcloner_sanitization = $xcloner_container->get_xcloner_sanitization(); |
171 | 171 | $this->xcloner_file_system = $xcloner_container->get_xcloner_filesystem(); |
172 | 172 | $this->logger = $xcloner_container->get_xcloner_logger()->withName( "xcloner_remote_storage" ); |
@@ -59,24 +59,24 @@ discard block |
||
59 | 59 | */ |
60 | 60 | protected $filters; |
61 | 61 | |
62 | - /** |
|
63 | - * @var Xcloner |
|
64 | - */ |
|
65 | - private $xcloner_plugin; |
|
66 | - |
|
67 | - /** |
|
68 | - * @var Xcloner |
|
69 | - */ |
|
70 | - private $xcloner_container; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Initialize the collections used to maintain the actions and filters. |
|
75 | - * |
|
76 | - * Xcloner_Loader constructor. |
|
77 | - * @param Xcloner $xcloner_container |
|
78 | - */ |
|
79 | - public function __construct(Xcloner $xcloner_container) |
|
62 | + /** |
|
63 | + * @var Xcloner |
|
64 | + */ |
|
65 | + private $xcloner_plugin; |
|
66 | + |
|
67 | + /** |
|
68 | + * @var Xcloner |
|
69 | + */ |
|
70 | + private $xcloner_container; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Initialize the collections used to maintain the actions and filters. |
|
75 | + * |
|
76 | + * Xcloner_Loader constructor. |
|
77 | + * @param Xcloner $xcloner_container |
|
78 | + */ |
|
79 | + public function __construct(Xcloner $xcloner_container) |
|
80 | 80 | { |
81 | 81 | |
82 | 82 | $this->actions = array(); |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | |
87 | 87 | } |
88 | 88 | |
89 | - /** |
|
90 | - * Add XCloner to Admin Menu |
|
91 | - */ |
|
92 | - public function xcloner_backup_add_admin_menu() |
|
89 | + /** |
|
90 | + * Add XCloner to Admin Menu |
|
91 | + */ |
|
92 | + public function xcloner_backup_add_admin_menu() |
|
93 | 93 | { |
94 | 94 | if (function_exists('add_menu_page')) { |
95 | 95 | add_menu_page(__('Site Backup', 'xcloner-backup-and-restore'), |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | private $xcloner_container; |
20 | 20 | private $verification = false; |
21 | 21 | |
22 | - /** |
|
23 | - * Xcloner_Encryption constructor. |
|
24 | - * @param Xcloner $xcloner_container |
|
25 | - */ |
|
26 | - public function __construct(Xcloner $xcloner_container) |
|
22 | + /** |
|
23 | + * Xcloner_Encryption constructor. |
|
24 | + * @param Xcloner $xcloner_container |
|
25 | + */ |
|
26 | + public function __construct(Xcloner $xcloner_container) |
|
27 | 27 | { |
28 | 28 | $this->xcloner_container = $xcloner_container; |
29 | 29 | if (method_exists($xcloner_container, 'get_xcloner_settings')) { |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | public function is_encrypted_file($filename) { |
64 | 64 | $fp = fopen($this->get_xcloner_path().$filename, 'r'); |
65 | 65 | if($fp) { |
66 | - $encryption_length = fread($fp, 16); |
|
67 | - fclose($fp); |
|
68 | - if (is_numeric($encryption_length)) { |
|
69 | - return true; |
|
70 | - } |
|
71 | - } |
|
66 | + $encryption_length = fread($fp, 16); |
|
67 | + fclose($fp); |
|
68 | + if (is_numeric($encryption_length)) { |
|
69 | + return true; |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | 73 | return false; |
74 | 74 | |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | if (isset($argv[1])) { |
373 | 373 | |
374 | 374 | class Xcloner { |
375 | - /** |
|
376 | - * Xcloner constructor. |
|
377 | - */ |
|
378 | - public function __construct() |
|
375 | + /** |
|
376 | + * Xcloner constructor. |
|
377 | + */ |
|
378 | + public function __construct() |
|
379 | 379 | { |
380 | 380 | } |
381 | 381 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | try { |
254 | 254 | unlink($_FILES['blob']['tmp_name']); |
255 | 255 | }catch (Exception $e) { |
256 | - //silent message |
|
256 | + //silent message |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | }elseif (isset($_POST['blob'])) { |
@@ -424,18 +424,18 @@ discard block |
||
424 | 424 | |
425 | 425 | } |
426 | 426 | |
427 | - $return['start'] = ftell($fp); |
|
427 | + $return['start'] = ftell($fp); |
|
428 | 428 | |
429 | - $this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start'] - $start))); |
|
429 | + $this->logger->info(sprintf("Executed %s queries of size %s bytes", $line_count, ($return['start'] - $start))); |
|
430 | 430 | |
431 | - if (!feof($fp)) |
|
432 | - { |
|
433 | - $return['finished'] = 0; |
|
434 | - } else { |
|
435 | - $this->logger->info(sprintf("Mysql Import Done.")); |
|
436 | - } |
|
431 | + if (!feof($fp)) |
|
432 | + { |
|
433 | + $return['finished'] = 0; |
|
434 | + } else { |
|
435 | + $this->logger->info(sprintf("Mysql Import Done.")); |
|
436 | + } |
|
437 | 437 | |
438 | - fclose($fp); |
|
438 | + fclose($fp); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | $this->send_response(200, $return); |