| @@ -31,34 +31,15 @@ | ||
| 31 | 31 | * Backup Child Site. |
| 32 | 32 | * |
| 33 | 33 | * @param mixed $siteid Child Site ID. |
| 34 | 34 | * @param mixed $pTask Task to perform. |
| 35 | - * @param mixed $subfolder Sub folder to place backup. | |
| 35 | + * @param mixed $subfolder Subfolder to place backup. | |
| 36 | 36 | * |
| 37 | 37 | * @gobal object $wp_filesystem WordPress filesystem instance. |
| 38 | 38 | * |
| 39 | + * @throws MainWP_Exception | |
| 40 | + * | |
| 39 | 41 | * @return mixed $backup_result |
| 40 | - * @throws MainWP_Exception Error message. | |
| 41 | - * | |
| 42 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 43 | - * @uses \MainWP\Dashboard\MainWP_Connect::download_to_file() | |
| 44 | - * @uses \MainWP\Dashboard\MainWP_Connect::get_get_data_authed() | |
| 45 | - * @uses \MainWP\Dashboard\MainWP_DB_Backup::get_backup_task_progress() | |
| 46 | - * @uses \MainWP\Dashboard\MainWP_DB_Backup::add_backup_task_progress() | |
| 47 | - * @uses \MainWP\Dashboard\MainWP_DB_Backup::update_backup_task_progress() | |
| 48 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 49 | - * @uses \MainWP\Dashboard\MainWP_Exception | |
| 50 | - * @uses \MainWP\Dashboard\MainWP_Logger::debug_for_website() | |
| 51 | - * @uses \MainWP\Dashboard\MainWP_Logger::warning_for_website() | |
| 52 | - * @uses \MainWP\Dashboard\MainWP_System::is_single_user() | |
| 53 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_wp_file_system() | |
| 54 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_specific_dir() | |
| 55 | - * @uses \MainWP\Dashboard\MainWP_Utility::sanitize() | |
| 56 | - * @uses \MainWP\Dashboard\MainWP_Utility::date() | |
| 57 | - * @uses \MainWP\Dashboard\MainWP_Utility::remove_preslash_spaces() | |
| 58 | - * @uses \MainWP\Dashboard\MainWP_Utility::normalize_filename() | |
| 59 | - * @uses \MainWP\Dashboard\MainWP_Utility::value_to_string() | |
| 60 | - * @uses \MainWP\Dashboard\self::get_real_extension() | |
| 61 | 42 | */ |
| 62 | 43 | public static function backup_site( $siteid, $pTask, $subfolder ) { |
| 63 | 44 | // phpcs: ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated. |
| 64 | 45 | if ( ! get_option( 'mainwp_enableLegacyBackupFeature' ) ) { |
| @@ -91,9 +72,9 @@ | ||
| 91 | 72 | $subfolder = str_replace( '%', '', $subfolder ); |
| 92 | 73 | $subfolder = MainWP_Utility::remove_preslash_spaces( $subfolder ); |
| 93 | 74 | $subfolder = MainWP_Utility::normalize_filename( $subfolder ); |
| 94 | 75 | |
| 95 | - if ( ! MainWP_System::instance()->is_single_user() && ( $userid !== $website->userid ) ) { | |
| 76 | + if ( ! MainWP_System::instance()->is_single_user() && ( $userid != $website->userid ) ) { | |
| 96 | 77 | throw new MainWP_Exception( 'Undefined error.' ); |
| 97 | 78 | } |
| 98 | 79 | |
| 99 | 80 | $websiteCleanUrl = $website->url; |
| @@ -135,12 +116,12 @@ | ||
| 135 | 116 | if ( ! empty( $file ) ) { |
| 136 | 117 | $file .= $ext; |
| 137 | 118 | } |
| 138 | 119 | |
| 139 | - if ( 'zip' === $pTask->archiveFormat ) { | |
| 140 | - $loadFilesBeforeZip = (int) $pTask->loadFilesBeforeZip; | |
| 141 | - } elseif ( '' === $pTask->archiveFormat || 'site' === $pTask->archiveFormat ) { | |
| 142 | - $loadFilesBeforeZip = (int) $website->loadFilesBeforeZip; | |
| 120 | + if ( 'zip' == $pTask->archiveFormat ) { | |
| 121 | + $loadFilesBeforeZip = $pTask->loadFilesBeforeZip; | |
| 122 | + } elseif ( '' == $pTask->archiveFormat || 'site' == $pTask->archiveFormat ) { | |
| 123 | + $loadFilesBeforeZip = $website->loadFilesBeforeZip; | |
| 143 | 124 | } else { |
| 144 | 125 | $loadFilesBeforeZip = 1; |
| 145 | 126 | } |
| 146 | 127 | |
| @@ -145,18 +126,18 @@ | ||
| 145 | 126 | } |
| 146 | 127 | |
| 147 | 128 | if ( 1 === $loadFilesBeforeZip ) { |
| 148 | 129 | $loadFilesBeforeZip = get_option( 'mainwp_options_loadFilesBeforeZip' ); |
| 149 | - $loadFilesBeforeZip = ( 1 === (int) $loadFilesBeforeZip || false === $loadFilesBeforeZip ); | |
| 130 | + $loadFilesBeforeZip = ( 1 === $loadFilesBeforeZip || false === $loadFilesBeforeZip ); | |
| 150 | 131 | } else { |
| 151 | 132 | $loadFilesBeforeZip = ( 2 === $loadFilesBeforeZip ); |
| 152 | 133 | } |
| 153 | 134 | |
| 154 | - if ( ( 'zip' === $pTask->archiveFormat ) && ( 1 === (int) $pTask->maximumFileDescriptorsOverride ) ) { | |
| 155 | - $maximumFileDescriptorsAuto = ( 1 === (int) $pTask->maximumFileDescriptorsAuto ); | |
| 135 | + if ( ( 'zip' == $pTask->archiveFormat ) && ( 1 == $pTask->maximumFileDescriptorsOverride ) ) { | |
| 136 | + $maximumFileDescriptorsAuto = ( 1 == $pTask->maximumFileDescriptorsAuto ); | |
| 156 | 137 | $maximumFileDescriptors = $pTask->maximumFileDescriptors; |
| 157 | - } elseif ( ( '' === $pTask->archiveFormat || 'site' === $pTask->archiveFormat ) && ( 1 === (int) $website->maximumFileDescriptorsOverride ) ) { | |
| 158 | - $maximumFileDescriptorsAuto = ( 1 === (int) $website->maximumFileDescriptorsAuto ); | |
| 138 | + } elseif ( ( '' == $pTask->archiveFormat || 'site' == $pTask->archiveFormat ) && ( 1 == $website->maximumFileDescriptorsOverride ) ) { | |
| 139 | + $maximumFileDescriptorsAuto = ( 1 == $website->maximumFileDescriptorsAuto ); | |
| 159 | 140 | $maximumFileDescriptors = $website->maximumFileDescriptors; |
| 160 | 141 | } else { |
| 161 | 142 | $maximumFileDescriptorsAuto = get_option( 'mainwp_maximumFileDescriptorsAuto' ); |
| 162 | 143 | $maximumFileDescriptors = get_option( 'mainwp_maximumFileDescriptors' ); |
| @@ -292,9 +273,9 @@ | ||
| 292 | 273 | |
| 293 | 274 | if ( ! is_array( $error ) ) { |
| 294 | 275 | throw new MainWP_Exception( 'Backup failed.' ); |
| 295 | 276 | } else { |
| 296 | - throw new MainWP_Exception( $error['message'], $error['extra'] ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 277 | + throw new MainWP_Exception( $error['message'], $error['extra'] ); | |
| 297 | 278 | } |
| 298 | 279 | } elseif ( 'busy' === $temp['status'] ) { |
| 299 | 280 | return false; |
| 300 | 281 | } elseif ( 'done' === $temp['status'] ) { |
| @@ -309,12 +290,14 @@ | ||
| 309 | 290 | $information['size'] = $temp['size']; |
| 310 | 291 | |
| 311 | 292 | $backupTaskProgress = MainWP_DB_Backup::instance()->update_backup_task_progress( $taskId, $website->id, array( 'fetchResult' => wp_json_encode( $information ) ) ); |
| 312 | 293 | } |
| 313 | - } elseif ( 5 > $backupTaskProgress->attempts ) { | |
| 294 | + } else { | |
| 295 | + if ( 5 > $backupTaskProgress->attempts ) { | |
| 314 | 296 | $backupTaskProgress = MainWP_DB_Backup::instance()->update_backup_task_progress( $taskId, $website->id, array( 'attempts' => $backupTaskProgress->attempts ++ ) ); |
| 315 | - } else { | |
| 316 | - throw new MainWP_Exception( 'Backup failed after 5 retries.' ); | |
| 297 | + } else { | |
| 298 | + throw new MainWP_Exception( 'Backup failed after 5 retries.' ); | |
| 299 | + } | |
| 317 | 300 | } |
| 318 | 301 | } |
| 319 | 302 | |
| 320 | 303 | if ( false === $information ) { |
| @@ -321,9 +304,9 @@ | ||
| 321 | 304 | $information = $backupTaskProgress->fetchResult; |
| 322 | 305 | } |
| 323 | 306 | |
| 324 | 307 | if ( isset( $information['error'] ) ) { |
| 325 | - throw new MainWP_Exception( esc_html( $information['error'] ) ); | |
| 308 | + throw new MainWP_Exception( $information['error'] ); | |
| 326 | 309 | } elseif ( 'db' === $type && ! $information['db'] ) { |
| 327 | 310 | throw new MainWP_Exception( 'Database backup failed.' ); |
| 328 | 311 | } elseif ( 'full' === $type && ! $information['full'] ) { |
| 329 | 312 | throw new MainWP_Exception( 'Full backup failed.' ); |
| @@ -338,9 +321,9 @@ | ||
| 338 | 321 | global $wp_filesystem; |
| 339 | 322 | |
| 340 | 323 | $dir = MainWP_System_Utility::get_mainwp_specific_dir( $website->id ); |
| 341 | 324 | |
| 342 | - $wp_filesystem->mkdir( $dir, 0777 ); | |
| 325 | + $wp_filesystem->mkdir( $dir, 0777, true ); | |
| 343 | 326 | |
| 344 | 327 | if ( ! $wp_filesystem->exists( $dir . 'index.php' ) ) { |
| 345 | 328 | $wp_filesystem->touch( $dir . 'index.php' ); |
| 346 | 329 | } |
| @@ -376,9 +359,9 @@ | ||
| 376 | 359 | krsort( $fullBackups ); |
| 377 | 360 | |
| 378 | 361 | $cnt = 0; |
| 379 | 362 | foreach ( $dbBackups as $key => $dbBackup ) { |
| 380 | - ++$cnt; | |
| 363 | + $cnt ++; | |
| 381 | 364 | if ( $cnt >= $maxBackups ) { |
| 382 | 365 | $wp_filesystem->delete( $dbBackup ); |
| 383 | 366 | } |
| 384 | 367 | } |
| @@ -384,9 +367,9 @@ | ||
| 384 | 367 | } |
| 385 | 368 | |
| 386 | 369 | $cnt = 0; |
| 387 | 370 | foreach ( $fullBackups as $key => $fullBackup ) { |
| 388 | - ++$cnt; | |
| 371 | + $cnt ++; | |
| 389 | 372 | if ( $cnt >= $maxBackups ) { |
| 390 | 373 | $wp_filesystem->delete( $fullBackup ); |
| 391 | 374 | } |
| 392 | 375 | } |
| @@ -403,12 +386,12 @@ | ||
| 403 | 386 | |
| 404 | 387 | if ( $information['db'] ) { |
| 405 | 388 | $what = 'db'; |
| 406 | 389 | $regexBackupFile = 'db-' . $websiteCleanUrl . '-(.*)-(.*).sql(\.zip|\.tar|\.tar\.gz|\.tar\.bz2)?'; |
| 407 | - if ( '' === $backupTaskProgress->downloadedDB ) { | |
| 390 | + if ( '' == $backupTaskProgress->downloadedDB ) { | |
| 408 | 391 | $localBackupFile = $dir . 'db-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time; |
| 409 | 392 | |
| 410 | - if ( null !== $pFilename ) { | |
| 393 | + if ( null != $pFilename ) { | |
| 411 | 394 | $filename = str_replace( |
| 412 | 395 | array( |
| 413 | 396 | '%sitename%', |
| 414 | 397 | '%url%', |
| @@ -427,9 +410,9 @@ | ||
| 427 | 410 | ); |
| 428 | 411 | $filename = str_replace( '%', '', $filename ); |
| 429 | 412 | $localBackupFile = $dir . $filename; |
| 430 | 413 | } |
| 431 | - $localBackupFile .= self::get_real_extension( $information['db'] ); | |
| 414 | + $localBackupFile .= MainWP_Utility::get_real_extension( $information['db'] ); | |
| 432 | 415 | |
| 433 | 416 | $localBackupFile = MainWP_Utility::normalize_filename( $localBackupFile ); |
| 434 | 417 | |
| 435 | 418 | $backupTaskProgress = MainWP_DB_Backup::instance()->update_backup_task_progress( $taskId, $website->id, array( 'downloadedDB' => $localBackupFile ) ); |
| @@ -436,9 +419,9 @@ | ||
| 436 | 419 | } else { |
| 437 | 420 | $localBackupFile = $backupTaskProgress->downloadedDB; |
| 438 | 421 | } |
| 439 | 422 | |
| 440 | - if ( 0 === (int) $backupTaskProgress->downloadedDBComplete ) { | |
| 423 | + if ( 0 == $backupTaskProgress->downloadedDBComplete ) { | |
| 441 | 424 | MainWP_Connect::download_to_file( MainWP_Connect::get_get_data_authed( $website, $information['db'], 'fdl' ), $localBackupFile, $information['size'], $website->http_user, $website->http_pass ); |
| 442 | 425 | $backupTaskProgress = MainWP_DB_Backup::instance()->update_backup_task_progress( $taskId, $website->id, array( 'downloadedDBComplete' => 1 ) ); |
| 443 | 426 | } |
| 444 | 427 | } |
| @@ -443,15 +426,15 @@ | ||
| 443 | 426 | } |
| 444 | 427 | } |
| 445 | 428 | |
| 446 | 429 | if ( $information['full'] ) { |
| 447 | - $realExt = self::get_real_extension( $information['full'] ); | |
| 430 | + $realExt = MainWP_Utility::get_real_extension( $information['full'] ); | |
| 448 | 431 | $what = 'full'; |
| 449 | 432 | $regexBackupFile = 'full-' . $websiteCleanUrl . '-(.*)-(.*).(zip|tar|tar.gz|tar.bz2)'; |
| 450 | - if ( '' === $backupTaskProgress->downloadedFULL ) { | |
| 433 | + if ( '' == $backupTaskProgress->downloadedFULL ) { | |
| 451 | 434 | $localBackupFile = $dir . 'full-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . $realExt; |
| 452 | 435 | |
| 453 | - if ( null !== $pFilename ) { | |
| 436 | + if ( null != $pFilename ) { | |
| 454 | 437 | $filename = str_replace( |
| 455 | 438 | array( |
| 456 | 439 | '%sitename%', |
| 457 | 440 | '%url%', |
| @@ -478,9 +461,9 @@ | ||
| 478 | 461 | } else { |
| 479 | 462 | $localBackupFile = $backupTaskProgress->downloadedFULL; |
| 480 | 463 | } |
| 481 | 464 | |
| 482 | - if ( 0 === (int) $backupTaskProgress->downloadedFULLComplete ) { | |
| 465 | + if ( 0 == $backupTaskProgress->downloadedFULLComplete ) { | |
| 483 | 466 | if ( file_exists( $localBackupFile ) ) { |
| 484 | 467 | $time = filemtime( $localBackupFile ); |
| 485 | 468 | |
| 486 | 469 | $minutes = gmdate( 'i', time() ); |
| @@ -528,19 +511,13 @@ | ||
| 528 | 511 | * |
| 529 | 512 | * Download backup file. |
| 530 | 513 | * |
| 531 | 514 | * @param mixed $pSiteId Child Site ID. |
| 532 | - * @param mixed $pType full|db Type of backup. | |
| 533 | - * @param mixed $pUrl Backup location. | |
| 534 | - * @param mixed $pFile Backup File. | |
| 515 | + * @param mixed $pType full|db Type of backup. | |
| 516 | + * @param mixed $pUrl Backup location. | |
| 517 | + * @param mixed $pFile Backup File. | |
| 535 | 518 | * |
| 536 | 519 | * @return bool true|false |
| 537 | - * @throws MainWP_Exception Error message. | |
| 538 | - * | |
| 539 | - * @uses \MainWP\Dashboard\MainWP_Connect::get_get_data_authed() | |
| 540 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 541 | - * @uses \MainWP\Dashboard\MainWP_Connect::download_to_file() | |
| 542 | - * @uses \MainWP\Dashboard\MainWP_Utility::end_session() | |
| 543 | 520 | */ |
| 544 | 521 | public static function backup_download_file( $pSiteId, $pType, $pUrl, $pFile ) { |
| 545 | 522 | $hasWPFileSystem = MainWP_System_Utility::get_wp_file_system(); |
| 546 | 523 | |
| @@ -551,9 +528,9 @@ | ||
| 551 | 528 | */ |
| 552 | 529 | global $wp_filesystem; |
| 553 | 530 | |
| 554 | 531 | $dir = dirname( $pFile ) . '/'; |
| 555 | - $wp_filesystem->mkdir( $dir, 0777 ); | |
| 532 | + $wp_filesystem->mkdir( $dir, 0777, true ); | |
| 556 | 533 | if ( ! $wp_filesystem->exists( $dir . 'index.php' ) ) { |
| 557 | 534 | $wp_filesystem->touch( $dir . 'index.php' ); |
| 558 | 535 | } |
| 559 | 536 | // Clean old backups from our system. |
| @@ -587,9 +564,9 @@ | ||
| 587 | 564 | krsort( $fullBackups ); |
| 588 | 565 | |
| 589 | 566 | $cnt = 0; |
| 590 | 567 | foreach ( $dbBackups as $key => $dbBackup ) { |
| 591 | - ++$cnt; | |
| 568 | + $cnt ++; | |
| 592 | 569 | if ( $cnt >= $maxBackups ) { |
| 593 | 570 | $wp_filesystem->delete( $dbBackup ); |
| 594 | 571 | } |
| 595 | 572 | } |
| @@ -595,9 +572,9 @@ | ||
| 595 | 572 | } |
| 596 | 573 | |
| 597 | 574 | $cnt = 0; |
| 598 | 575 | foreach ( $fullBackups as $key => $fullBackup ) { |
| 599 | - ++$cnt; | |
| 576 | + $cnt ++; | |
| 600 | 577 | if ( $cnt >= $maxBackups ) { |
| 601 | 578 | $wp_filesystem->delete( $fullBackup ); |
| 602 | 579 | } |
| 603 | 580 | } |
| @@ -617,19 +594,16 @@ | ||
| 617 | 594 | return true; |
| 618 | 595 | } |
| 619 | 596 | |
| 620 | 597 | /** |
| 621 | - * Method backup_delete_file(). | |
| 598 | + * Method backup_delete_file() | |
| 622 | 599 | * |
| 623 | 600 | * Delete backup file. |
| 624 | 601 | * |
| 625 | - * @param mixed $pSiteId Child Site ID. | |
| 602 | + * @param mixed $pSiteId Child Site ID | |
| 626 | 603 | * @param mixed $pFile File to delete. |
| 627 | 604 | * |
| 628 | 605 | * @return bool true |
| 629 | - * | |
| 630 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 631 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 632 | 606 | */ |
| 633 | 607 | public static function backup_delete_file( $pSiteId, $pFile ) { |
| 634 | 608 | $website = MainWP_DB::instance()->get_website_by_id( $pSiteId ); |
| 635 | 609 | MainWP_Connect::fetch_url_authed( $website, 'delete_backup', array( 'del' => $pFile ) ); |
| @@ -641,27 +615,15 @@ | ||
| 641 | 615 | * Method backup_check_pid() |
| 642 | 616 | * |
| 643 | 617 | * Check backup pid. |
| 644 | 618 | * |
| 645 | - * @param mixed $pSiteId Child Site id. | |
| 646 | - * @param mixed $pid Backup pid. | |
| 647 | - * @param mixed $type full|db Type of backup. | |
| 648 | - * @param mixed $subfolder Sub folder for backup. | |
| 649 | - * @param mixed $pFilename Backups filename. | |
| 619 | + * @param mixed $pSiteId Child Site id. | |
| 620 | + * @param mixed $pid Backup pid. | |
| 621 | + * @param mixed $type full|db Type of backup. | |
| 622 | + * @param mixed $subfolder Subfolder for backup. | |
| 623 | + * @param mixed $pFilename Backups filename | |
| 650 | 624 | * |
| 651 | 625 | * @return array $status, $result. |
| 652 | - * @throws \Exception Error message. | |
| 653 | - * | |
| 654 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_specific_dir() | |
| 655 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 656 | - * @uses \MainWP\Dashboard\MainWP_Utility::end_session() | |
| 657 | - * @uses \MainWP\Dashboard\MainWP_Utility::sanitize() | |
| 658 | - * @uses \MainWP\Dashboard\MainWP_Utility::get_nice_url() | |
| 659 | - * @uses \MainWP\Dashboard\MainWP_Utility::date() | |
| 660 | - * @uses \MainWP\Dashboard\MainWP_Utility::remove_preslash_spaces() | |
| 661 | - * @uses \MainWP\Dashboard\MainWP_Utility::normalize_filename() | |
| 662 | - * @uses \MainWP\Dashboard\MainWP_Utility::sanitize_file_name() | |
| 663 | - * @uses \MainWP\Dashboard\self::get_real_extension() | |
| 664 | 626 | */ |
| 665 | 627 | public static function backup_check_pid( $pSiteId, $pid, $type, $subfolder, $pFilename ) { |
| 666 | 628 | $website = MainWP_DB::instance()->get_website_by_id( $pSiteId ); |
| 667 | 629 | |
| @@ -705,16 +667,16 @@ | ||
| 705 | 667 | $fm_date = MainWP_Utility::sanitize_file_name( MainWP_Utility::date( get_option( 'date_format' ) ) ); |
| 706 | 668 | $fm_time = MainWP_Utility::sanitize_file_name( MainWP_Utility::date( get_option( 'time_format' ) ) ); |
| 707 | 669 | |
| 708 | 670 | if ( 'db' === $type ) { |
| 709 | - $localBackupFile = $dir . 'db-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . self::get_real_extension( $information['file'] ); | |
| 671 | + $localBackupFile = $dir . 'db-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . MainWP_Utility::get_real_extension( $information['file'] ); | |
| 710 | 672 | $localRegexFile = 'db-' . $websiteCleanUrl . '-(.*)-(.*).sql(\.zip|\.tar|\.tar\.gz|\.tar\.bz2)?'; |
| 711 | 673 | } else { |
| 712 | - $localBackupFile = $dir . 'full-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . self::get_real_extension( $information['file'] ); | |
| 674 | + $localBackupFile = $dir . 'full-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . MainWP_Utility::get_real_extension( $information['file'] ); | |
| 713 | 675 | $localRegexFile = 'full-' . $websiteCleanUrl . '-(.*)-(.*).(zip|tar|tar.gz|tar.bz2)'; |
| 714 | 676 | } |
| 715 | 677 | |
| 716 | - if ( null !== $pFilename ) { | |
| 678 | + if ( null != $pFilename ) { | |
| 717 | 679 | $filename = str_replace( |
| 718 | 680 | array( |
| 719 | 681 | '%sitename%', |
| 720 | 682 | '%url%', |
| @@ -735,11 +697,11 @@ | ||
| 735 | 697 | $localBackupFile = $dir . $filename; |
| 736 | 698 | $localBackupFile = MainWP_Utility::normalize_filename( $localBackupFile ); |
| 737 | 699 | |
| 738 | 700 | if ( 'db' === $type ) { |
| 739 | - $localBackupFile .= self::get_real_extension( $information['file'] ); | |
| 701 | + $localBackupFile .= MainWP_Utility::get_real_extension( $information['file'] ); | |
| 740 | 702 | } else { |
| 741 | - $localBackupFile .= self::get_real_extension( $information['file'] ); | |
| 703 | + $localBackupFile .= MainWP_Utility::get_real_extension( $information['file'] ); | |
| 742 | 704 | } |
| 743 | 705 | } |
| 744 | 706 | |
| 745 | 707 | $result['local'] = $localBackupFile; |
| @@ -756,43 +718,29 @@ | ||
| 756 | 718 | * Method backup() |
| 757 | 719 | * |
| 758 | 720 | * Backup Child Site. |
| 759 | 721 | * |
| 760 | - * @param mixed $pSiteId Child Site ID. | |
| 761 | - * @param mixed $pType full|db Typ of backup. | |
| 762 | - * @param mixed $pSubfolder Sub folder to store backup. | |
| 763 | - * @param mixed $pExclude Exclusion list. | |
| 764 | - * @param mixed $excludebackup Exclude backup files. | |
| 765 | - * @param mixed $excludecache Exclude cache files. | |
| 766 | - * @param mixed $excludenonwp Exclude no WP Files. | |
| 767 | - * @param mixed $excludezip Exclude Zip files. | |
| 768 | - * @param null $pFilename Name of backup file. | |
| 769 | - * @param string $pFileNameUID File name unique ID. | |
| 770 | - * @param bool $pArchiveFormat Archive format. | |
| 771 | - * @param bool $pMaximumFileDescriptorsOverride Override maximum file descriptors. | |
| 772 | - * @param bool $pMaximumFileDescriptorsAuto Auto maximum file descriptors. | |
| 773 | - * @param bool $pMaximumFileDescriptors Maximum file descriptors. | |
| 774 | - * @param bool $pLoadFilesBeforeZip Load files before zip. | |
| 775 | - * @param bool $pid Backup pid. | |
| 776 | - * @param bool $append Append to backup. | |
| 722 | + * @param mixed $pSiteId Child Site ID. | |
| 723 | + * @param mixed $pType full|db Typ of backup. | |
| 724 | + * @param mixed $pSubfolder Subfolder to store backup. | |
| 725 | + * @param mixed $pExclude Exclusion list. | |
| 726 | + * @param mixed $excludebackup Exclued backup files. | |
| 727 | + * @param mixed $excludecache Exclude cache files. | |
| 728 | + * @param mixed $excludenonwp Exclude no WP Files. | |
| 729 | + * @param mixed $excludezip Exclude Zip files | |
| 730 | + * @param null $pFilename Name of backup file. | |
| 731 | + * @param string $pFileNameUID File name unique ID. | |
| 732 | + * @param bool $pArchiveFormat Achive format. | |
| 733 | + * @param bool $pMaximumFileDescriptorsOverride Overide maximum file descriptors. | |
| 734 | + * @param bool $pMaximumFileDescriptorsAuto Auto maximum file descriptors. | |
| 735 | + * @param bool $pMaximumFileDescriptors Maximum file decriptors. | |
| 736 | + * @param bool $pLoadFilesBeforeZip Load files before zip. | |
| 737 | + * @param bool $pid Backup pid. | |
| 738 | + * @param bool $append Append to backup. | |
| 777 | 739 | * |
| 740 | + * @throw MainWP_Exception | |
| 741 | + * | |
| 778 | 742 | * @return mixed $backup_result |
| 779 | - * @throws MainWP_Exception Error message. | |
| 780 | - * | |
| 781 | - * @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed() | |
| 782 | - * @uses \MainWP\Dashboard\MainWP_Exception | |
| 783 | - * @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id() | |
| 784 | - * @uses \MainWP\Dashboard\MainWP_Logger::debug_for_website() | |
| 785 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website() | |
| 786 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_specific_dir() | |
| 787 | - * @uses \MainWP\Dashboard\MainWP_Utility::sanitize() | |
| 788 | - * @uses \MainWP\Dashboard\MainWP_Utility::date() | |
| 789 | - * @uses \MainWP\Dashboard\MainWP_Utility::remove_preslash_spaces() | |
| 790 | - * @uses \MainWP\Dashboard\MainWP_Utility::normalize_filename() | |
| 791 | - * @uses \MainWP\Dashboard\MainWP_Utility::sanitize_file_name() | |
| 792 | - * @uses \MainWP\Dashboard\MainWP_Utility::end_session() | |
| 793 | - * @uses \MainWP\Dashboard\MainWP_Utility::value_to_string() | |
| 794 | - * @uses \MainWP\Dashboard\self::get_real_extension() | |
| 795 | 743 | */ |
| 796 | 744 | public static function backup( |
| 797 | 745 | $pSiteId, |
| 798 | 746 | $pType, |
| @@ -809,16 +757,15 @@ | ||
| 809 | 757 | $pMaximumFileDescriptorsAuto = false, |
| 810 | 758 | $pMaximumFileDescriptors = false, |
| 811 | 759 | $pLoadFilesBeforeZip = false, |
| 812 | 760 | $pid = false, |
| 813 | - $append = false | |
| 814 | - ) { | |
| 761 | + $append = false ) { | |
| 815 | 762 | |
| 816 | 763 | if ( ! get_option( 'mainwp_enableLegacyBackupFeature' ) ) { |
| 817 | 764 | return false; |
| 818 | 765 | } |
| 819 | 766 | |
| 820 | - if ( '' === trim( $pFilename ) ) { | |
| 767 | + if ( '' == trim( $pFilename ) ) { | |
| 821 | 768 | $pFilename = null; |
| 822 | 769 | } |
| 823 | 770 | |
| 824 | 771 | $backup_result = array(); |
| @@ -832,12 +779,8 @@ | ||
| 832 | 779 | $subfolder = str_replace( '%', '', $subfolder ); |
| 833 | 780 | $subfolder = MainWP_Utility::remove_preslash_spaces( $subfolder ); |
| 834 | 781 | $subfolder = MainWP_Utility::normalize_filename( $subfolder ); |
| 835 | 782 | |
| 836 | - if ( MainWP_System_Utility::is_suspended_site( $website ) ) { | |
| 837 | - throw new MainWP_Exception( 'Suspended site.', '', 'SUSPENDED_SITE' ); | |
| 838 | - } | |
| 839 | - | |
| 840 | 783 | if ( ! MainWP_System_Utility::can_edit_website( $website ) ) { |
| 841 | 784 | throw new MainWP_Exception( 'You are not allowed to backup this site' ); |
| 842 | 785 | } |
| 843 | 786 | |
| @@ -851,10 +794,10 @@ | ||
| 851 | 794 | $websiteCleanUrl |
| 852 | 795 | ); |
| 853 | 796 | |
| 854 | 797 | if ( false === $pMaximumFileDescriptorsOverride ) { |
| 855 | - if ( 1 === (int) $website->maximumFileDescriptorsOverride ) { | |
| 856 | - $maximumFileDescriptorsAuto = ( 1 === (int) $website->maximumFileDescriptorsAuto ); | |
| 798 | + if ( 1 == $website->maximumFileDescriptorsOverride ) { | |
| 799 | + $maximumFileDescriptorsAuto = ( 1 == $website->maximumFileDescriptorsAuto ); | |
| 857 | 800 | $maximumFileDescriptors = $website->maximumFileDescriptors; |
| 858 | 801 | } else { |
| 859 | 802 | $maximumFileDescriptorsAuto = get_option( 'mainwp_maximumFileDescriptorsAuto' ); |
| 860 | 803 | $maximumFileDescriptors = get_option( 'mainwp_maximumFileDescriptors' ); |
| @@ -859,9 +802,9 @@ | ||
| 859 | 802 | $maximumFileDescriptorsAuto = get_option( 'mainwp_maximumFileDescriptorsAuto' ); |
| 860 | 803 | $maximumFileDescriptors = get_option( 'mainwp_maximumFileDescriptors' ); |
| 861 | 804 | $maximumFileDescriptors = ( false === $maximumFileDescriptors ? 150 : $maximumFileDescriptors ); |
| 862 | 805 | } |
| 863 | - } elseif ( ( 'global' !== $pArchiveFormat ) && ( 1 === (int) $pMaximumFileDescriptorsOverride ) ) { | |
| 806 | + } elseif ( ( 'global' !== $pArchiveFormat ) && ( 1 === $pMaximumFileDescriptorsOverride ) ) { | |
| 864 | 807 | $maximumFileDescriptorsAuto = ( 1 === $pMaximumFileDescriptorsAuto ); |
| 865 | 808 | $maximumFileDescriptors = $pMaximumFileDescriptors; |
| 866 | 809 | } else { |
| 867 | 810 | $maximumFileDescriptorsAuto = get_option( 'mainwp_maximumFileDescriptorsAuto' ); |
| @@ -897,9 +840,9 @@ | ||
| 897 | 840 | $loadFilesBeforeZip = ( 1 === $loadFilesBeforeZip || false === $loadFilesBeforeZip ); |
| 898 | 841 | } else { |
| 899 | 842 | $loadFilesBeforeZip = ( 2 === $loadFilesBeforeZip ); |
| 900 | 843 | } |
| 901 | - } elseif ( 'global' === $pArchiveFormat || 1 === $pLoadFilesBeforeZip ) { // Overridden flow: only fallback to global. | |
| 844 | + } elseif ( 'global' === $pArchiveFormat || 1 === $pLoadFilesBeforeZip ) { // Overriden flow: only fallback to global. | |
| 902 | 845 | $loadFilesBeforeZip = get_option( 'mainwp_options_loadFilesBeforeZip' ); |
| 903 | 846 | $loadFilesBeforeZip = ( 1 === $loadFilesBeforeZip || false === $loadFilesBeforeZip ); |
| 904 | 847 | } else { |
| 905 | 848 | $loadFilesBeforeZip = ( 2 === $pLoadFilesBeforeZip ); |
| @@ -904,9 +847,9 @@ | ||
| 904 | 847 | } else { |
| 905 | 848 | $loadFilesBeforeZip = ( 2 === $pLoadFilesBeforeZip ); |
| 906 | 849 | } |
| 907 | 850 | |
| 908 | - // Normal flow: check site settings & fallback to global. | |
| 851 | + // Nomral flow: check site settings & fallback to global. | |
| 909 | 852 | if ( false === $pArchiveFormat ) { |
| 910 | 853 | $archiveFormat = self::get_current_archive_extension( $website ); |
| 911 | 854 | } elseif ( 'global' === $pArchiveFormat ) { |
| 912 | 855 | $archiveFormat = self::get_current_archive_extension(); |
| @@ -938,9 +881,9 @@ | ||
| 938 | 881 | $information = MainWP_Connect::fetch_url_authed( $website, 'backup', $params, false, false, false ); |
| 939 | 882 | do_action( 'mainwp_managesite_backup', $website, array( 'type' => $pType ), $information ); |
| 940 | 883 | |
| 941 | 884 | if ( isset( $information['error'] ) ) { |
| 942 | - throw new MainWP_Exception( esc_html( $information['error'] ) ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 885 | + throw new MainWP_Exception( $information['error'] ); | |
| 943 | 886 | } elseif ( 'db' === $pType && ! $information['db'] ) { |
| 944 | 887 | throw new MainWP_Exception( 'Database backup failed.' ); |
| 945 | 888 | } elseif ( 'full' === $pType && ! $information['full'] ) { |
| 946 | 889 | throw new MainWP_Exception( 'Full backup failed.' ); |
| @@ -963,16 +906,16 @@ | ||
| 963 | 906 | $fm_date = MainWP_Utility::sanitize_file_name( MainWP_Utility::date( get_option( 'date_format' ) ) ); |
| 964 | 907 | $fm_time = MainWP_Utility::sanitize_file_name( MainWP_Utility::date( get_option( 'time_format' ) ) ); |
| 965 | 908 | |
| 966 | 909 | if ( 'db' === $pType ) { |
| 967 | - $localBackupFile = $dir . 'db-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . self::get_real_extension( $information['db'] ); | |
| 910 | + $localBackupFile = $dir . 'db-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . MainWP_Utility::get_real_extension( $information['db'] ); | |
| 968 | 911 | $localRegexFile = 'db-' . $websiteCleanUrl . '-(.*)-(.*).sql(\.zip|\.tar|\.tar\.gz|\.tar\.bz2)?'; |
| 969 | 912 | } else { |
| 970 | - $localBackupFile = $dir . 'full-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . self::get_real_extension( $information['full'] ); | |
| 913 | + $localBackupFile = $dir . 'full-' . $websiteCleanUrl . '-' . $fm_date . '-' . $fm_time . MainWP_Utility::get_real_extension( $information['full'] ); | |
| 971 | 914 | $localRegexFile = 'full-' . $websiteCleanUrl . '-(.*)-(.*).(zip|tar|tar.gz|tar.bz2)'; |
| 972 | 915 | } |
| 973 | 916 | |
| 974 | - if ( null !== $pFilename ) { | |
| 917 | + if ( null != $pFilename ) { | |
| 975 | 918 | $filename = str_replace( |
| 976 | 919 | array( |
| 977 | 920 | '%sitename%', |
| 978 | 921 | '%url%', |
| @@ -993,11 +936,11 @@ | ||
| 993 | 936 | $localBackupFile = $dir . $filename; |
| 994 | 937 | $localBackupFile = MainWP_Utility::normalize_filename( $localBackupFile ); |
| 995 | 938 | |
| 996 | 939 | if ( 'db' === $pType ) { |
| 997 | - $localBackupFile .= self::get_real_extension( $information['db'] ); | |
| 940 | + $localBackupFile .= MainWP_Utility::get_real_extension( $information['db'] ); | |
| 998 | 941 | } else { |
| 999 | - $localBackupFile .= self::get_real_extension( $information['full'] ); | |
| 942 | + $localBackupFile .= MainWP_Utility::get_real_extension( $information['full'] ); | |
| 1000 | 943 | } |
| 1001 | 944 | } |
| 1002 | 945 | |
| 1003 | 946 | $backup_result['local'] = $localBackupFile; |
| @@ -1054,22 +997,20 @@ | ||
| 1054 | 997 | * Method get_current_archive_extension() |
| 1055 | 998 | * |
| 1056 | 999 | * Get extension of current Archive. |
| 1057 | 1000 | * |
| 1058 | - * @param bool $website true|false. | |
| 1059 | - * @param bool|string $task true|false|global|site. | |
| 1001 | + * @param bool $website true|false | |
| 1002 | + * @param bool|string $task true|false|global|site | |
| 1060 | 1003 | * |
| 1061 | 1004 | * @return mixed $archiveFormat Format of Archive. |
| 1062 | - * | |
| 1063 | - * @uses \MainWP\Dashboard\MainWP_DB_Backup::get_website_backup_settings() | |
| 1064 | 1005 | */ |
| 1065 | 1006 | public static function get_current_archive_extension( $website = false, $task = false ) { |
| 1066 | 1007 | $useSite = true; |
| 1067 | - if ( false !== $task ) { | |
| 1008 | + if ( false != $task ) { | |
| 1068 | 1009 | if ( 'global' === $task->archiveFormat ) { |
| 1069 | 1010 | $useGlobal = true; |
| 1070 | 1011 | $useSite = false; |
| 1071 | - } elseif ( '' === $task->archiveFormat || 'site' === $task->archiveFormat ) { | |
| 1012 | + } elseif ( '' == $task->archiveFormat || 'site' == $task->archiveFormat ) { | |
| 1072 | 1013 | $useGlobal = false; |
| 1073 | 1014 | $useSite = true; |
| 1074 | 1015 | } else { |
| 1075 | 1016 | $archiveFormat = $task->archiveFormat; |
| @@ -1109,9 +1050,9 @@ | ||
| 1109 | 1050 | */ |
| 1110 | 1051 | public static function get_real_extension( $path ) { |
| 1111 | 1052 | $checks = array( '.sql.zip', '.sql.tar', '.sql.tar.gz', '.sql.tar.bz2', '.tar.gz', '.tar.bz2' ); |
| 1112 | 1053 | foreach ( $checks as $check ) { |
| 1113 | - if ( MainWP_Utility::ends_with( $path, $check ) ) { | |
| 1054 | + if ( self::ends_with( $path, $check ) ) { | |
| 1114 | 1055 | return $check; |
| 1115 | 1056 | } |
| 1116 | 1057 | } |
| 1117 | 1058 | |
| @@ -1124,11 +1065,8 @@ | ||
| 1124 | 1065 | * |
| 1125 | 1066 | * Update Child Site Settings. |
| 1126 | 1067 | * |
| 1127 | 1068 | * @return bool true|false |
| 1128 | - * | |
| 1129 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin() | |
| 1130 | - * @uses \MainWP\Dashboard\MainWP_Utility::update_option() | |
| 1131 | 1069 | */ |
| 1132 | 1070 | public static function handle_settings_post() { |
| 1133 | 1071 | if ( MainWP_System_Utility::is_admin() ) { |
| 1134 | 1072 | if ( isset( $_POST['submit'] ) && isset( $_POST['wp_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['wp_nonce'] ), 'Settings' ) ) { |
| @@ -1189,17 +1127,16 @@ | ||
| 1189 | 1127 | * |
| 1190 | 1128 | * @param mixed $pFile Backup file. |
| 1191 | 1129 | * |
| 1192 | 1130 | * @return false|int |
| 1193 | - * | |
| 1194 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_specific_dir() | |
| 1195 | 1131 | */ |
| 1196 | 1132 | public static function backup_get_file_size( $pFile ) { |
| 1197 | 1133 | $dir = MainWP_System_Utility::get_mainwp_specific_dir(); |
| 1198 | 1134 | |
| 1199 | 1135 | if ( stristr( $pFile, $dir ) && file_exists( $pFile ) ) { |
| 1200 | - return filesize( $pFile ); | |
| 1136 | + return @filesize( $pFile ); | |
| 1201 | 1137 | } |
| 1202 | 1138 | |
| 1203 | 1139 | return 0; |
| 1204 | 1140 | } |
| 1141 | + | |
| 1205 | 1142 | } |