Plugin Directory

Changeset 3176208


Ignore:
Timestamp:
10/27/2024 01:24:43 AM (17 months ago)
Author:
deltabackups
Message:

Updated readme 1.0.4

Location:
deltabackups
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • deltabackups/tags/1.0.4/deltabackups-files-utils.php

    r3176127 r3176208  
    123123function dtbps_get_local_backup($backupId) {
    124124    $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;
    126126    $zipsFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR .  DTBPS_PATH_BACKUP_FILES;
    127127    $files = dtbps_get_local_files($zipsFilePath);
  • deltabackups/tags/1.0.4/deltabackups-main.php

    r3176146 r3176208  
    5353                    set_time_limit(0);
    5454                    $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);
    5662
    5763                    $divStyle = 'error';
     
    158164                    . wp_nonce_field($action, $nonce) .
    159165                    '<input type="hidden" name="backup_restore" value="' . esc_html($item['backupId']) . '">
     166                    <input type="hidden" name="backup_restore_siteurl" value="' . esc_html($item['siteUrl']) . '">
    160167                    <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>
    161168                </form>
     
    458465
    459466
    460 function dtbps_plugin_restore($backupId) {
     467function dtbps_plugin_restore($backupId, $backupSiteUrl) {
    461468    $isMultisite = is_multisite();
    462469    $currentBlogId = get_current_blog_id();
     
    569576    $zipDatabase->extractTo($backupPath);
    570577    $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);
    572579
    573580    if(!empty($backupMetadataMap) && !empty($toDeleteFilesList)){
     
    629636
    630637// Restore Database
    631 function dtbps_restore_wp_database($file_path) {
     638function dtbps_restore_wp_database($file_path, $backupSiteUrl) {
    632639    global $wpdb;
    633640    // Disable foreign key checks during the restore
     
    648655    // Check if the file opened successfully
    649656    if ($fileHandle) {
     657        $currentSiteUrl = get_site_url();
    650658        $line = "";
    651659        // Read the file line by line until end of file (EOF) is reached
     
    655663
    656664            // Replace the default database prefix with the current prefix
    657             $modifiedLine = dtbps_modify_sql_query($line, $wpdb->prefix);
     665            $modifiedLine = dtbps_modify_sql_query($line, $wpTablePrefix, $currentSiteUrl, $backupSiteUrl);
    658666            $queries = explode(";;;\n", $modifiedLine);
    659667            if(count($queries)>1){
     
    981989}
    982990
    983 function dtbps_modify_sql_query($line, $wpPrefix) {
     991function dtbps_modify_sql_query($line, $wpTablePrefix, $currentSiteUrl, $backupSiteUrl) {
    984992    // 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
    988997    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);
    9901004    }
    9911005
    9921006    // replace all prefixes for the query
    993     return str_replace(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, $wpPrefix, $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  
    3333        'backupId' => $backupId,
    3434        'fileIndex' => $zip_fileNumber,
     35        'siteUrl' => get_site_url(),
    3536    ];
    3637    $jsonBody = dtbps_make_request_post_request(DTBPS_ENDPOINT_SERVICE, $requestPayload);
  • deltabackups/trunk/deltabackups-files-utils.php

    r3139881 r3176208  
    123123function dtbps_get_local_backup($backupId) {
    124124    $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;
    126126    $zipsFilePath = DTBPS_PATH_BACKUPS_CACHE_WP_ID . DTBPS_DIR . $backupId . DTBPS_DIR .  DTBPS_PATH_BACKUP_FILES;
    127127    $files = dtbps_get_local_files($zipsFilePath);
  • deltabackups/trunk/deltabackups-main.php

    r3176146 r3176208  
    5353                    set_time_limit(0);
    5454                    $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);
    5662
    5763                    $divStyle = 'error';
     
    158164                    . wp_nonce_field($action, $nonce) .
    159165                    '<input type="hidden" name="backup_restore" value="' . esc_html($item['backupId']) . '">
     166                    <input type="hidden" name="backup_restore_siteurl" value="' . esc_html($item['siteUrl']) . '">
    160167                    <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>
    161168                </form>
     
    458465
    459466
    460 function dtbps_plugin_restore($backupId) {
     467function dtbps_plugin_restore($backupId, $backupSiteUrl) {
    461468    $isMultisite = is_multisite();
    462469    $currentBlogId = get_current_blog_id();
     
    569576    $zipDatabase->extractTo($backupPath);
    570577    $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);
    572579
    573580    if(!empty($backupMetadataMap) && !empty($toDeleteFilesList)){
     
    629636
    630637// Restore Database
    631 function dtbps_restore_wp_database($file_path) {
     638function dtbps_restore_wp_database($file_path, $backupSiteUrl) {
    632639    global $wpdb;
    633640    // Disable foreign key checks during the restore
     
    648655    // Check if the file opened successfully
    649656    if ($fileHandle) {
     657        $currentSiteUrl = get_site_url();
    650658        $line = "";
    651659        // Read the file line by line until end of file (EOF) is reached
     
    655663
    656664            // Replace the default database prefix with the current prefix
    657             $modifiedLine = dtbps_modify_sql_query($line, $wpdb->prefix);
     665            $modifiedLine = dtbps_modify_sql_query($line, $wpTablePrefix, $currentSiteUrl, $backupSiteUrl);
    658666            $queries = explode(";;;\n", $modifiedLine);
    659667            if(count($queries)>1){
     
    981989}
    982990
    983 function dtbps_modify_sql_query($line, $wpPrefix) {
     991function dtbps_modify_sql_query($line, $wpTablePrefix, $currentSiteUrl, $backupSiteUrl) {
    984992    // 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
    988997    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);
    9901004    }
    9911005
    9921006    // replace all prefixes for the query
    993     return str_replace(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, $wpPrefix, $line);
    994 }
     1007    return str_replace(DTBPS_DB_SQL_TABLE_DEFAULT_PREFIX, $wpTablePrefix, $line);
     1008}
  • deltabackups/trunk/deltabackups-network-utils.php

    r3139881 r3176208  
    3333        'backupId' => $backupId,
    3434        'fileIndex' => $zip_fileNumber,
     35        'siteUrl' => get_site_url(),
    3536    ];
    3637    $jsonBody = dtbps_make_request_post_request(DTBPS_ENDPOINT_SERVICE, $requestPayload);
Note: See TracChangeset for help on using the changeset viewer.