Changeset 3176208
- Timestamp:
- 10/27/2024 01:24:43 AM (17 months ago)
- Location:
- deltabackups
- Files:
-
- 6 edited
-
tags/1.0.4/deltabackups-files-utils.php (modified) (1 diff)
-
tags/1.0.4/deltabackups-main.php (modified) (8 diffs)
-
tags/1.0.4/deltabackups-network-utils.php (modified) (1 diff)
-
trunk/deltabackups-files-utils.php (modified) (1 diff)
-
trunk/deltabackups-main.php (modified) (8 diffs)
-
trunk/deltabackups-network-utils.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
deltabackups/tags/1.0.4/deltabackups-files-utils.php
r3176127 r3176208 123 123 function dtbps_get_local_backup($backupId) { 124 124 $databaseFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR . DTBPS_FILE_DATABASE_NAME . DTBPS_FILE_COMPRESSED_EXTENSION; 125 $metadataFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR . DTBPS_FILE_METADATA_NAME . DTBPS_FILE_COMPRESSED_EXTENSION;125 $metadataFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR . DTBPS_FILE_METADATA_NAME . DTBPS_FILE_COMPRESSED_EXTENSION; 126 126 $zipsFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR . DTBPS_PATH_BACKUP_FILES; 127 127 $files = dtbps_get_local_files($zipsFilePath); -
deltabackups/tags/1.0.4/deltabackups-main.php
r3176146 r3176208 53 53 set_time_limit(0); 54 54 $backupId = sanitize_text_field($_POST['backup_restore']); 55 $rsp = dtbps_plugin_restore($backupId); 55 56 $backupSiteUrl = ""; 57 if (isset($_POST['backup_restore_siteurl'])) { 58 $backupSiteUrl = sanitize_text_field($_POST['backup_restore_siteurl']); 59 } 60 61 $rsp = dtbps_plugin_restore($backupId, $backupSiteUrl); 56 62 57 63 $divStyle = 'error'; … … 158 164 . wp_nonce_field($action, $nonce) . 159 165 '<input type="hidden" name="backup_restore" value="' . esc_html($item['backupId']) . '"> 166 <input type="hidden" name="backup_restore_siteurl" value="' . esc_html($item['siteUrl']) . '"> 160 167 <button type="button" class="button button-primary" name="backup_restore" onclick="areYouSureModal(\'Are you sure you want to restore?\').then(result => (result) ? getSubmitByElementId(\'backup_restore_' . esc_html($item['backupId']) . '\') : null);" ' . esc_html($disableRestore) . '>Restore</button> 161 168 </form> … … 458 465 459 466 460 function dtbps_plugin_restore($backupId ) {467 function dtbps_plugin_restore($backupId, $backupSiteUrl) { 461 468 $isMultisite = is_multisite(); 462 469 $currentBlogId = get_current_blog_id(); … … 569 576 $zipDatabase->extractTo($backupPath); 570 577 $zipDatabase->close(); 571 dtbps_restore_wp_database($backupPath . DTBPS_DIR . DTBPS_FILE_DATABASE_NAME . DTBPS_FILE_DB_EXTENSION );578 dtbps_restore_wp_database($backupPath . DTBPS_DIR . DTBPS_FILE_DATABASE_NAME . DTBPS_FILE_DB_EXTENSION, $backupSiteUrl); 572 579 573 580 if(!empty($backupMetadataMap) && !empty($toDeleteFilesList)){ … … 629 636 630 637 // Restore Database 631 function dtbps_restore_wp_database($file_path ) {638 function dtbps_restore_wp_database($file_path, $backupSiteUrl) { 632 639 global $wpdb; 633 640 // Disable foreign key checks during the restore … … 648 655 // Check if the file opened successfully 649 656 if ($fileHandle) { 657 $currentSiteUrl = get_site_url(); 650 658 $line = ""; 651 659 // Read the file line by line until end of file (EOF) is reached … … 655 663 656 664 // Replace the default database prefix with the current prefix 657 $modifiedLine = dtbps_modify_sql_query($line, $wp db->prefix);665 $modifiedLine = dtbps_modify_sql_query($line, $wpTablePrefix, $currentSiteUrl, $backupSiteUrl); 658 666 $queries = explode(";;;\n", $modifiedLine); 659 667 if(count($queries)>1){ … … 981 989 } 982 990 983 function dtbps_modify_sql_query($line, $wp Prefix) {991 function dtbps_modify_sql_query($line, $wpTablePrefix, $currentSiteUrl, $backupSiteUrl) { 984 992 // replace only first occurrence, create wp_options and all inserts to wp_options except wp_user_roles 985 $pattern = '/(wp_posts|wp_postmeta|wp_commentmeta|wp_term_taxonomy|wp_options(?!.*wp_user_roles))/'; 986 987 // Use preg_replace to perform the operation 993 $pattern = '/wp_posts|wp_postmeta|wp_commentmeta|wp_term_taxonomy|wp_options(?!.*wp_user_roles)/'; 994 // $patternDomain = '/wp_posts|wp_postmeta|wp_options(?=.*astra)|wp_options(?=.*elementor_log)/'; 995 $patternDomain = '/wp_posts|wp_postmeta|wp_options(?=.*elementor_log)/'; 996 988 997 if (preg_match($pattern, $line)) { 989 return preg_replace('/' . preg_quote(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, '/') . '/', $wpPrefix, $line, 1); 998 if (!DTBPS_LOCAL_MODE && $backupSiteUrl !== "" && $backupSiteUrl !== $currentSiteUrl && preg_match($patternDomain, $line)) { 999 // replace domains 1000 $line = str_replace($backupSiteUrl, $currentSiteUrl, $line); 1001 } 1002 1003 return preg_replace('/' . preg_quote(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, '/') . '/', $wpTablePrefix, $line, 1); 990 1004 } 991 1005 992 1006 // replace all prefixes for the query 993 return str_replace(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, $wp Prefix, $line);994 } 1007 return str_replace(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, $wpTablePrefix, $line); 1008 } -
deltabackups/tags/1.0.4/deltabackups-network-utils.php
r3176127 r3176208 33 33 'backupId' => $backupId, 34 34 'fileIndex' => $zip_fileNumber, 35 'siteUrl' => get_site_url(), 35 36 ]; 36 37 $jsonBody = dtbps_make_request_post_request(DTBPS_ENDPOINT_SERVICE, $requestPayload); -
deltabackups/trunk/deltabackups-files-utils.php
r3139881 r3176208 123 123 function dtbps_get_local_backup($backupId) { 124 124 $databaseFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR . DTBPS_FILE_DATABASE_NAME . DTBPS_FILE_COMPRESSED_EXTENSION; 125 $metadataFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR . DTBPS_FILE_METADATA_NAME . DTBPS_FILE_COMPRESSED_EXTENSION;125 $metadataFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR . DTBPS_FILE_METADATA_NAME . DTBPS_FILE_COMPRESSED_EXTENSION; 126 126 $zipsFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR . DTBPS_PATH_BACKUP_FILES; 127 127 $files = dtbps_get_local_files($zipsFilePath); -
deltabackups/trunk/deltabackups-main.php
r3176146 r3176208 53 53 set_time_limit(0); 54 54 $backupId = sanitize_text_field($_POST['backup_restore']); 55 $rsp = dtbps_plugin_restore($backupId); 55 56 $backupSiteUrl = ""; 57 if (isset($_POST['backup_restore_siteurl'])) { 58 $backupSiteUrl = sanitize_text_field($_POST['backup_restore_siteurl']); 59 } 60 61 $rsp = dtbps_plugin_restore($backupId, $backupSiteUrl); 56 62 57 63 $divStyle = 'error'; … … 158 164 . wp_nonce_field($action, $nonce) . 159 165 '<input type="hidden" name="backup_restore" value="' . esc_html($item['backupId']) . '"> 166 <input type="hidden" name="backup_restore_siteurl" value="' . esc_html($item['siteUrl']) . '"> 160 167 <button type="button" class="button button-primary" name="backup_restore" onclick="areYouSureModal(\'Are you sure you want to restore?\').then(result => (result) ? getSubmitByElementId(\'backup_restore_' . esc_html($item['backupId']) . '\') : null);" ' . esc_html($disableRestore) . '>Restore</button> 161 168 </form> … … 458 465 459 466 460 function dtbps_plugin_restore($backupId ) {467 function dtbps_plugin_restore($backupId, $backupSiteUrl) { 461 468 $isMultisite = is_multisite(); 462 469 $currentBlogId = get_current_blog_id(); … … 569 576 $zipDatabase->extractTo($backupPath); 570 577 $zipDatabase->close(); 571 dtbps_restore_wp_database($backupPath . DTBPS_DIR . DTBPS_FILE_DATABASE_NAME . DTBPS_FILE_DB_EXTENSION );578 dtbps_restore_wp_database($backupPath . DTBPS_DIR . DTBPS_FILE_DATABASE_NAME . DTBPS_FILE_DB_EXTENSION, $backupSiteUrl); 572 579 573 580 if(!empty($backupMetadataMap) && !empty($toDeleteFilesList)){ … … 629 636 630 637 // Restore Database 631 function dtbps_restore_wp_database($file_path ) {638 function dtbps_restore_wp_database($file_path, $backupSiteUrl) { 632 639 global $wpdb; 633 640 // Disable foreign key checks during the restore … … 648 655 // Check if the file opened successfully 649 656 if ($fileHandle) { 657 $currentSiteUrl = get_site_url(); 650 658 $line = ""; 651 659 // Read the file line by line until end of file (EOF) is reached … … 655 663 656 664 // Replace the default database prefix with the current prefix 657 $modifiedLine = dtbps_modify_sql_query($line, $wp db->prefix);665 $modifiedLine = dtbps_modify_sql_query($line, $wpTablePrefix, $currentSiteUrl, $backupSiteUrl); 658 666 $queries = explode(";;;\n", $modifiedLine); 659 667 if(count($queries)>1){ … … 981 989 } 982 990 983 function dtbps_modify_sql_query($line, $wp Prefix) {991 function dtbps_modify_sql_query($line, $wpTablePrefix, $currentSiteUrl, $backupSiteUrl) { 984 992 // replace only first occurrence, create wp_options and all inserts to wp_options except wp_user_roles 985 $pattern = '/(wp_posts|wp_postmeta|wp_commentmeta|wp_term_taxonomy|wp_options(?!.*wp_user_roles))/'; 986 987 // Use preg_replace to perform the operation 993 $pattern = '/wp_posts|wp_postmeta|wp_commentmeta|wp_term_taxonomy|wp_options(?!.*wp_user_roles)/'; 994 // $patternDomain = '/wp_posts|wp_postmeta|wp_options(?=.*astra)|wp_options(?=.*elementor_log)/'; 995 $patternDomain = '/wp_posts|wp_postmeta|wp_options(?=.*elementor_log)/'; 996 988 997 if (preg_match($pattern, $line)) { 989 return preg_replace('/' . preg_quote(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, '/') . '/', $wpPrefix, $line, 1); 998 if (!DTBPS_LOCAL_MODE && $backupSiteUrl !== "" && $backupSiteUrl !== $currentSiteUrl && preg_match($patternDomain, $line)) { 999 // replace domains 1000 $line = str_replace($backupSiteUrl, $currentSiteUrl, $line); 1001 } 1002 1003 return preg_replace('/' . preg_quote(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, '/') . '/', $wpTablePrefix, $line, 1); 990 1004 } 991 1005 992 1006 // replace all prefixes for the query 993 return str_replace(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, $wp Prefix, $line);994 } 1007 return str_replace(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, $wpTablePrefix, $line); 1008 } -
deltabackups/trunk/deltabackups-network-utils.php
r3139881 r3176208 33 33 'backupId' => $backupId, 34 34 'fileIndex' => $zip_fileNumber, 35 'siteUrl' => get_site_url(), 35 36 ]; 36 37 $jsonBody = dtbps_make_request_post_request(DTBPS_ENDPOINT_SERVICE, $requestPayload);
Note: See TracChangeset
for help on using the changeset viewer.