Changeset 3374608
- Timestamp:
- 10/07/2025 05:50:15 PM (5 months ago)
- Location:
- 1-click-migration/trunk
- Files:
-
- 4 edited
-
inc/background/class-background-helper.php (modified) (1 diff)
-
inc/backup/class-ocm-backup.php (modified) (25 diffs)
-
one-click-migration.php (modified) (6 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
1-click-migration/trunk/inc/background/class-background-helper.php
r2414581 r3374608 17 17 } 18 18 19 $wpdb->get_results( $wpdb->prepare("DELETE FROM {$table} where {$column} LIKE 'wp_ocm_background_%_batch_%'", []));20 $wpdb->get_results( $wpdb->prepare("DELETE FROM {$table} where {$column} LIKE '_transient_%'", []));21 $wpdb->get_results( $wpdb->prepare("DELETE FROM {$table} where {$column} LIKE '_site_transient_%'", []));22 $wpdb->get_results( $wpdb->prepare("DELETE FROM {$table} where {$column} = 'backup_steps'", []));23 $wpdb->get_results( $wpdb->prepare("DELETE FROM {$table} where {$column} = 'restore_steps'", []));19 $wpdb->get_results("DELETE FROM {$table} where {$column} LIKE 'wp_ocm_background_%_batch_%'"); 20 $wpdb->get_results("DELETE FROM {$table} where {$column} LIKE '_transient_%'"); 21 $wpdb->get_results("DELETE FROM {$table} where {$column} LIKE '_site_transient_%'"); 22 $wpdb->get_results("DELETE FROM {$table} where {$column} = 'backup_steps'"); 23 $wpdb->get_results("DELETE FROM {$table} where {$column} = 'restore_steps'"); 24 24 } 25 25 -
1-click-migration/trunk/inc/backup/class-ocm-backup.php
r3372639 r3374608 72 72 ['Current IP Address', '1%'], 73 73 ['Creating temporary directory', '1%'], 74 75 76 ['URL generated: db', '5%'], 77 ['URL generated: uploads', '9%'], 78 ['URL generated: themes', '14%'], 79 ['URL generated: plugins', '18%'], 80 ['URL generated: log', '23%'], 81 ['URL generated: log_download', '27%'], 74 82 75 83 … … 235 243 ['Notice: file db.zip.crypt not found', '60%'], 236 244 237 ['Themes have been restored', ' 92%'],238 ['Uploads have been restored', ' 94%'],239 ['Plugins have been restored', ' 96%'],245 ['Themes have been restored', '64%'], 246 ['Uploads have been restored', '64%'], 247 ['Plugins have been restored', '64%'], 240 248 241 249 ['Restore plugins', '75%'], 242 250 ['Please make payment before the restore can complete', '77%'], 243 251 ['Notice: Database restore in progress. Please don\'t leave the plugin page.', '80%'], 244 ['Database has been restored', ' 98%'],245 ['Starting to update URLs in database', ' 99%'],246 ['Cleaning up.', '9 9%'],252 ['Database has been restored', '83%'], 253 ['Starting to update URLs in database', '84%'], 254 ['Cleaning up.', '92%'], 247 255 ['Restore completed.', '100%'], 248 256 ['Error:', '0%'], … … 329 337 $bucket_key = self::get_bucket_key($username, $password); 330 338 $excluded_folders = self::get_excluded_folders(); 339 340 // Try to create bucket and get presigned URLs with retry logic 331 341 $presigned_urls = OCM_S3::s3_create_bucket_ifnot_exists($bucket_key); 342 343 // If bucket was just created, the URLs might not be immediately available 344 // Retry up to 3 times with a 2-second delay between attempts 345 $retry_count = 0; 346 $max_retries = 3; 347 348 while (!$presigned_urls && $retry_count < $max_retries) { 349 $retry_count++; 350 One_Click_Migration::write_to_log("Bucket created, waiting for presigned URLs (attempt $retry_count/$max_retries)..."); 351 sleep(2); // Wait 2 seconds for bucket to be fully initialized 352 $presigned_urls = OCM_S3::s3_create_bucket_ifnot_exists($bucket_key); 353 } 354 332 355 $prev_bucket_key = get_option('ocm_bucket_key'); 333 356 … … 346 369 347 370 if (!$presigned_urls) { 348 One_Click_Migration::write_to_log('Error: Backup does not exist');371 One_Click_Migration::write_to_log('Error: Could not get presigned URLs after ' . ($retry_count + 1) . ' attempts'); 349 372 wp_safe_redirect(admin_url('tools.php?page=one-click-migration&message=endpoint_failure')); 350 373 exit; … … 472 495 update_option('ocm_is_stopped', false, true); 473 496 474 // Enable maintenance mode for the restore process 475 One_Click_Migration::enable_maintenance_mode(); 497 476 498 477 499 $content_dir = WP_CONTENT_DIR . '/ocm_restore'; … … 516 538 } 517 539 518 // Debug: Log all generated URLs to see the mapping519 One_Click_Migration::write_to_log("DEBUG: Generated URL for '$key': " . $generated_url);520 540 } 521 541 … … 536 556 } 537 557 538 // Try to get presigned URLs from restore steps first, fallback to option539 558 $presigned_urls = self::get_restore_step_value('init', self::STEP_RESTORE_CHILD_PRESIGNED_URLS); 540 541 // If restore steps method fails, try getting from option directly542 if (!$presigned_urls) {543 One_Click_Migration::write_to_log('DEBUG: Restore steps method failed, trying option method');544 $presigned_urls = get_option('ocm_presigned_urls');545 }546 547 // Convert stdClass object to array if needed (WordPress sometimes converts arrays to objects)548 if (is_object($presigned_urls)) {549 One_Click_Migration::write_to_log('DEBUG: Converting stdClass object to array');550 $presigned_urls = (array) $presigned_urls;551 }552 553 559 $excluded_folders = self::get_excluded_folders(); 554 555 // Debug: Log presigned URLs status556 One_Click_Migration::write_to_log('DEBUG: Retrieved presigned URLs: ' . (is_null($presigned_urls) ? 'NULL' : 'NOT NULL'));557 if (!is_null($presigned_urls)) {558 One_Click_Migration::write_to_log('DEBUG: Presigned URLs count: ' . (is_array($presigned_urls) ? count($presigned_urls) : 'NOT ARRAY'));559 }560 561 // Check if presigned URLs are available562 if (!$presigned_urls || !is_array($presigned_urls)) {563 One_Click_Migration::write_to_log('Error: No presigned URLs available for download');564 One_Click_Migration::write_to_log('DEBUG: Available restore steps: ' . print_r(self::get_current_restore_steps(), true));565 update_option('ocm_is_stopped', true, true);566 exit;567 }568 569 // Clear excluded files list before starting downloads (but after URLs are retrieved)570 delete_option('ocm_excluded_folders');571 delete_option('ocm_skipped_folders');572 delete_option('ocm_eexcluded_folders');573 One_Click_Migration::write_to_log('DEBUG: Cleared excluded files list for fresh restore attempt');574 560 575 561 // Download each of the zip files … … 629 615 630 616 631 632 // Debug: Log the download URL for database files633 if ($key === 'db') {634 One_Click_Migration::write_to_log("DEBUG: Attempting to download database from URL: " . $download_url);635 }636 637 617 $downloadTmpPathFile = download_url($download_url, One_Click_Migration::$process_restore_single->remaining_time()); 638 618 639 619 if(is_wp_error($downloadTmpPathFile)){ 640 620 $error_message = $downloadTmpPathFile->get_error_message(); 641 642 // Debug: Log detailed error for database files643 if ($key === 'db') {644 One_Click_Migration::write_to_log("DEBUG: Database download failed with error: " . $error_message);645 One_Click_Migration::write_to_log("DEBUG: Full WP_Error object: " . print_r($downloadTmpPathFile, true));646 }647 648 621 if($error_message === 'Not Found'){ 649 622 … … 656 629 657 630 continue; 658 } else {659 // Handle other download errors660 One_Click_Migration::write_to_log("Download failed for $key: $error_message");661 update_option('ocm_is_stopped', true, true);662 exit;663 631 } 664 632 } … … 872 840 // Fallback: Try copying files instead of moving 873 841 if (!self::copyDirectory($extract_path, $directory)) { 874 self::handle_restore_error(sprintf(842 One_Click_Migration::write_to_log(sprintf( 875 843 'Downloading restore files. Error: "%s" directory could not be moved or copied to "%s" directory. Please check the write permission for these directories.', 876 844 $extract_path, $directory 877 845 )); 846 847 update_option('ocm_is_stopped', true, true); 848 die(); 878 849 } 879 850 } … … 930 901 931 902 } 932 if( !in_array('db', $excluded_restore_files)){933 // Database is not excluded, so we need to restore it934 // This requires payment for database restore903 if(in_array('db', $excluded_restore_files)){ 904 self::complete_restore(); 905 }else{ 935 906 One_Click_Migration::write_to_log('Please make payment before the restore can complete'); 936 }else{937 // Database is excluded, so we can complete the restore without it938 self::complete_restore();939 907 } 940 908 … … 963 931 // Delete ocm_restore folder 964 932 if (file_exists($ocmRestoreDir) && !rmdir($ocmRestoreDir)) { 965 self::handle_restore_error(sprintf(933 One_Click_Migration::write_to_log(sprintf( 966 934 'Cleaning up "ocm_restore" directory. Error: "%s" directory could not be deleted. Please check the write permission for this directory or the parent directory.', 967 935 $ocmRestoreDir 968 936 )); 937 938 update_option('ocm_is_stopped', true, true); 939 exit; 969 940 } 970 941 } … … 972 943 self::print_folders_skipped(); 973 944 self::print_folders_not_found(); 974 975 // Disable maintenance mode before completion message976 One_Click_Migration::disable_maintenance_mode();977 945 978 946 One_Click_Migration::write_to_log('Restore completed.'); … … 1210 1178 public static function createZipFile($filepath, $password, $presigned_urls) 1211 1179 { 1180 // Suppress PHP 8+ compatibility warnings from vendor library 1181 $old_error_reporting = error_reporting(); 1182 error_reporting($old_error_reporting & ~E_DEPRECATED & ~E_NOTICE); 1183 1212 1184 $zip = new ZipFile(); 1213 1185 $filename = OCM_PLUGIN_WRITABLE_PATH . 'db.zip'; … … 1284 1256 return $return; 1285 1257 } 1286 1258 1259 // Restore original error reporting 1260 error_reporting($old_error_reporting); 1287 1261 } 1288 1262 1289 1263 public static function initiate_folder_backup($folder_name, $presigned_urls, $password) 1290 1264 { 1265 // Suppress PHP 8+ compatibility warnings from vendor library 1266 $old_error_reporting = error_reporting(); 1267 error_reporting($old_error_reporting & ~E_DEPRECATED & ~E_NOTICE); 1268 1291 1269 // Initialize archive object 1292 1270 $zip = new ZipFile(); … … 1539 1517 } 1540 1518 } 1519 1520 // Restore original error reporting 1521 error_reporting($old_error_reporting); 1541 1522 } 1542 1523 … … 1619 1600 1620 1601 return true; 1621 }1622 1623 /**1624 * Handle restore errors and disable maintenance mode1625 */1626 private static function handle_restore_error($message)1627 {1628 One_Click_Migration::write_to_log($message);1629 update_option('ocm_is_stopped', true, true);1630 One_Click_Migration::disable_maintenance_mode();1631 die();1632 1602 } 1633 1603 … … 1806 1776 $uploadFileData = get_option('ocm_upload_file'); 1807 1777 $isStopped = get_option('ocm_is_stopped'); 1808 $isMaintenanceMode = get_option('ocm_maintenance_mode', false);1809 1778 1810 1779 if ($isStopped) { // cancel all bg process … … 1817 1786 'text' => $lastLog, 1818 1787 'value' => self::get_previous_log_percentage(), 1819 'customNotice' => self::LOG_MESSAGE_BG_PROCESS_RESTARTING_LOG, 1820 'maintenanceMode' => $isMaintenanceMode 1788 'customNotice' => self::LOG_MESSAGE_BG_PROCESS_RESTARTING_LOG 1821 1789 ]; 1822 1790 } … … 1827 1795 'text' => $lastLog, 1828 1796 'value' => self::get_previous_log_percentage(), 1829 'maintenanceMode' => $isMaintenanceMode 1797 1830 1798 ]; 1831 1799 } … … 1836 1804 'text' => 'Process is Restarting', 1837 1805 'value' => self::get_previous_log_percentage(), 1838 'maintenanceMode' => $isMaintenanceMode 1806 1839 1807 ]; 1840 1808 } … … 1846 1814 'text' => $lastLog, 1847 1815 'value' => self::get_previous_log_percentage(), 1848 'maintenanceMode' => $isMaintenanceMode 1816 1849 1817 ]; 1850 1818 } … … 1853 1821 $default_text = array( 1854 1822 'text' => 'Start a backup or a restore to see current progress here.</br></br>Entire process runs in the background, independent of your browser activity.</br> </br>If you get logged out during restore, log back in using your backup old WordPress credentials and refresh this page for progress.', 1855 'value' => '0%', 1856 'maintenanceMode' => $isMaintenanceMode 1823 'value' => '0%' 1857 1824 ); 1858 1825 … … 1867 1834 'uploadFileData' => $uploadFileData, 1868 1835 'text' => $lastLog, 1869 'value' => $progress_item[1], 1870 'maintenanceMode' => $isMaintenanceMode 1836 'value' => $progress_item[1] 1871 1837 ); 1872 1838 } else { … … 1874 1840 'uploadFileData' => $uploadFileData, 1875 1841 'text' => $lastLog, 1876 'value' => $progress_item[1], 1877 'maintenanceMode' => $isMaintenanceMode 1842 'value' => $progress_item[1] 1878 1843 ); 1879 1844 } 1880 1845 1881 1846 if ($isStopped && $lastLog !== 'Restore completed.') { 1882 $progress_item_text = array(1847 $progress_item_text = array( 1883 1848 'isStopped' => true, 1884 1849 'text' => $lastLog, 1885 'value' => $progress_item[1], 1886 'maintenanceMode' => $isMaintenanceMode 1850 'value' => $progress_item[1] 1887 1851 ); 1888 1852 } -
1-click-migration/trunk/one-click-migration.php
r3372639 r3374608 5 5 * Plugin URI: https://wordpress.org/plugins/1-click-migration/ 6 6 * Description: Migrate, copy, or clone your entire site with 1 click. <strong>Any host, no size limitation, no premium versions.</strong> 7 * Version: 2.3 7 * Version: 2.3.1 8 8 * Author: 1ClickMigration 9 9 * Author URI: https://1clickmigration.com/ … … 348 348 { 349 349 self::delete_options(); 350 // Delete ocm_restore folder 351 if (is_dir(WP_CONTENT_DIR . '/ocm_restore/')) { 352 OCM_Backup::deleteDir(WP_CONTENT_DIR . '/ocm_restore/', 'Deleting ocm_restore', null); 353 } 354 355 // Clear tmp folder 356 if (is_dir(OCM_PLUGIN_WRITABLE_PATH)) { 357 OCM_Backup::deleteDir(OCM_PLUGIN_WRITABLE_PATH, 'Deleting TMP Folder', null); 350 351 // Delete ocm_restore folder (silently - don't log errors during deactivation) 352 try { 353 if (is_dir(WP_CONTENT_DIR . '/ocm_restore/')) { 354 self::delete_directory_recursive(WP_CONTENT_DIR . '/ocm_restore/'); 355 } 356 } catch (\Exception $e) { 357 // Silently fail during deactivation 358 } 359 360 // Clear tmp folder (silently - don't log errors during deactivation) 361 try { 362 if (is_dir(OCM_PLUGIN_WRITABLE_PATH)) { 363 self::delete_directory_recursive(OCM_PLUGIN_WRITABLE_PATH); 364 } 365 } catch (\Exception $e) { 366 // Silently fail during deactivation 367 } 368 369 // Load the background helper class before using it 370 if (!class_exists('OCM\OCM_BackgroundHelper')) { 371 require_once __DIR__ . '/inc/background/class-background-helper.php'; 358 372 } 359 373 OCM_BackgroundHelper::delete_all_batch_process(); … … 362 376 flush_rewrite_rules(); 363 377 378 } 379 380 /** 381 * Recursively delete a directory without logging (for safe deactivation) 382 * 383 * @param string $dir Directory path to delete 384 * @return bool True on success, false on failure 385 */ 386 private static function delete_directory_recursive($dir) 387 { 388 if (!is_dir($dir)) { 389 return false; 390 } 391 392 $items = @scandir($dir); 393 if ($items === false) { 394 return false; 395 } 396 397 foreach ($items as $item) { 398 if ($item === '.' || $item === '..') { 399 continue; 400 } 401 402 $path = $dir . '/' . $item; 403 404 if (is_dir($path)) { 405 self::delete_directory_recursive($path); 406 } else { 407 @unlink($path); 408 } 409 } 410 411 return @rmdir($dir); 364 412 } 365 413 … … 494 542 public static function cancel_all_process() 495 543 { 544 // Load the background helper class before using it 545 if (!class_exists('OCM\OCM_BackgroundHelper')) { 546 require_once __DIR__ . '/inc/background/class-background-helper.php'; 547 } 496 548 OCM_BackgroundHelper::delete_all_batch_process(); 497 self::$process_backup_single->cancel_all_process(); 498 self::$process_restore_single->cancel_all_process(); 549 550 // Only call cancel methods if the process objects exist 551 if (self::$process_backup_single) { 552 self::$process_backup_single->cancel_all_process(); 553 } 554 if (self::$process_restore_single) { 555 self::$process_restore_single->cancel_all_process(); 556 } 499 557 500 558 } … … 520 578 if (is_dir(OCM_PLUGIN_WRITABLE_PATH)) { 521 579 OCM_Backup::deleteDir(OCM_PLUGIN_WRITABLE_PATH, 'Deleting TMP Folder', null); 580 } 581 582 // Load the background helper class before using it 583 if (!class_exists('OCM\OCM_BackgroundHelper')) { 584 require_once __DIR__ . '/inc/background/class-background-helper.php'; 522 585 } 523 586 OCM_BackgroundHelper::delete_all_batch_process(); … … 630 693 public static function disable_maintenance_mode() 631 694 { 632 // Remove our custom maintenance mode option633 delete_option('ocm_maintenance_mode');634 635 // Also remove any .maintenance file that might exist636 695 $maintenance_file = ABSPATH . '.maintenance'; 696 637 697 if (file_exists($maintenance_file)) { 638 unlink($maintenance_file); 639 } 640 641 One_Click_Migration::write_to_log('Maintenance mode disabled'); 642 return true; 698 if (unlink($maintenance_file)) { 699 One_Click_Migration::write_to_log('Maintenance mode disabled'); 700 return true; 701 } else { 702 One_Click_Migration::write_to_log('Error: Failed to disable maintenance mode'); 703 return false; 704 } 705 } 706 707 return true; // Already disabled 643 708 } 644 709 } -
1-click-migration/trunk/readme.txt
r3372639 r3374608 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 Stable tag: 2.3 7 Stable tag: 2.3.1 8 8 Author URI: https://1clickmigration.com 9 9 License: GPLv3 or later … … 90 90 91 91 == Changelog == 92 = 2.3.1 = 93 * Fixed blank white screen issue when deactivating plugin 94 * Fixed endpoint_failure error on first backup attempt - added retry logic for presigned URL generation 95 * Improved deactivation cleanup process to prevent database errors 96 * Enhanced error handling during plugin deactivation 97 98 = 2.3 = 99 * Stability improvements 100 92 101 = 2.2 = 93 102 * CSRF fix & Updates
Note: See TracChangeset
for help on using the changeset viewer.