function processRestoringBackup($url, $zipmode)
{
    wpa_cleanup(true);
    if (!is_string($url) || '' == $url) {
        wpa_backup_error('restore', sprintf(__('The provided URL "<code>%s</code>" is either not valid or empty'), $url), true);
    }
    global $wp_filesystem;
    $temp_dir = trailingslashit(WPCLONE_WP_CONTENT) . 'wpclone-temp';
    $temp_dir_err = $wp_filesystem->mkdir($temp_dir);
    if (is_wp_error($temp_dir_err)) {
        wpa_backup_error('dirrest', $temp_dir_err->get_error_message(), true);
    }
    $pathParts = pathinfo($url);
    $zipFilename = wpa_fetch_file($url);
    $result = wpa_unzip($zipFilename, $temp_dir, $zipmode);
    if ($result) {
        $unzippedFolderPath = wpCloneSafePathMode(trailingslashit($temp_dir) . 'wpclone_backup');
        if (!$wp_filesystem->is_dir($unzippedFolderPath)) {
            $unzippedFolderPath = wpCloneSafePathMode(trailingslashit($temp_dir) . $pathParts['filename']);
        }
        /* if we're here then the file extraction worked,but let's make doubly sure */
        if (!$wp_filesystem->is_dir($unzippedFolderPath)) {
            wpa_backup_error('restore', sprintf(__('Cannot find <code>%s<code>'), $unzippedFolderPath), true);
        }
        /* check the table prefixes */
        $old_db_prefix = $unzippedFolderPath . '/prefix.txt';
        $prefix = wpa_check_prefix($old_db_prefix);
        if ($prefix) {
            wpa_replace_prefix($prefix);
        }
        $wp_filesystem->delete($old_db_prefix);
        /* import db */
        $databaseFile = $unzippedFolderPath . '/database.sql';
        $currentSiteUrl = processConfigAndDatabaseFile($databaseFile);
        /*  */
        $wp_filesystem->delete($databaseFile);
        wpa_copy($unzippedFolderPath . '/wp-content', WPCLONE_WP_CONTENT);
        $wp_filesystem->delete($temp_dir, true);
        /* remove the zip file only if it was downloaded from an external location. */
        $wptmp = explode('.', $zipFilename);
        if (in_array('tmp', $wptmp)) {
            $wp_filesystem->delete($zipFilename);
        }
        echo "<div><h1>Restore Successful!</h1>";
        echo "Visit your restored site [ <a href='{$currentSiteUrl['url']}' target=blank>here</a> ]<br><br>";
        echo "<strong>You may need to re-save your permalink structure <a href='{$currentSiteUrl['url']}/wp-admin/options-permalink.php' target=blank>Here</a></strong>";
        $report = $currentSiteUrl['report'];
        /* copy pasta (more or less) from serialized search and replace script by interconnectit */
        $time = array_sum(explode(' ', $report['end'])) - array_sum(explode(' ', $report['start']));
        printf('<div class="info"><p>Search and replace scanned <strong>%d</strong> tables with a total of <strong>%d</strong> rows, ', $report['tables'], $report['rows']);
        printf('<strong>%d</strong> cells were changed and <strong>%d</strong> db updates were performed. it took <strong>%f</strong> seconds.</p></div>', $report['change'], $report['updates'], $time);
        if (!empty($report['errors']) && is_array($report['errors'])) {
            echo '<div class="error">';
            echo '<h3>The following errors were encountered during the search and replace process.</h3>';
            foreach ($report['errors'] as $error) {
                echo '<p>' . $error . '</p>';
            }
            echo '</div>';
        }
        echo '</div>';
    } else {
        echo "<h1>Restore unsuccessful!!!</h1>";
        echo "Please try again.";
    }
}
Example #2
0
            $all_tables[] = $table[0];
        }
    }
    $report = icit_srdb_replacer($connection, $search, $replace, $all_tables);
    return $report;
}
function processRestoringBackup($url, $zipmode)
{
    wpa_cleanup(true);
    if (!is_string($url) || '' == $url) {
        wpa_backup_error('restore', sprintf(__('The provided URL "<code>%s</code>" is either not valid or empty'), $url), true);
    }
    global $wp_filesystem;
    $temp_dir = trailingslashit(WPCLONE_WP_CONTENT) . 'wpclone-temp';
    $temp_dir_err = $wp_filesystem->mkdir($temp_dir);
    if (is_wp_error($temp_dir_err)) {
        wpa_backup_error('dirrest', $temp_dir_err->get_error_message(), true);
    }
    $pathParts = pathinfo($url);
    $zipFilename = wpa_fetch_file($url);
    $result = wpa_unzip($zipFilename, $temp_dir, $zipmode);
    if ($result) {
        $unzippedFolderPath = wpCloneSafePathMode(trailingslashit($temp_dir) . 'wpclone_backup');
        if (!$wp_filesystem->is_dir($unzippedFolderPath)) {
            $unzippedFolderPath = wpCloneSafePathMode(trailingslashit($temp_dir) . $pathParts['filename']);
        }
        /* if we're here then the file extraction worked,but let's make doubly sure */
        if (!$wp_filesystem->is_dir($unzippedFolderPath)) {
            wpa_backup_error('restore', sprintf(__('Cannot find <code>%s<code>'), $unzippedFolderPath), true);
        }
        /* check the table prefixes */
        $old_db_prefix = $unzippedFolderPath . '/prefix.txt';
        $prefix = wpa_check_prefix($old_db_prefix);
        if ($prefix) {
            wpa_replace_prefix($prefix);
        }
        $wp_filesystem->delete($old_db_prefix);
        /* import db */
        $databaseFile = $unzippedFolderPath . '/database.sql';
        $currentSiteUrl = processConfigAndDatabaseFile($databaseFile);
        /*  */
        $wp_filesystem->delete($databaseFile);
        wpa_copy($unzippedFolderPath . '/wp-content', WPCLONE_WP_CONTENT);
        $wp_filesystem->delete($temp_dir, true);
        /* remove the zip file only if it was downloaded from an external location. */
        $wptmp = explode('.', $zipFilename);
        if (in_array('tmp', $wptmp)) {
            $wp_filesystem->delete($zipFilename);
        }
        echo "<h1>Restore Successful!</h1>";
        echo "Visit your restored site [ <a href='{$currentSiteUrl}' target=blank>here</a> ]<br><br>";
Example #3
0
function processRestoringBackup($url, $zipmode)
{
    wpa_cleanup(true);
    if (!is_string($url) || '' == $url) {
        wpa_backup_error('restore', sprintf(__('The provided URL "<code>%s</code>" is either not valid or empty'), $url), true);
    }
    global $wp_filesystem;
    $GLOBALS['wpclone']['logfile'] = 'wpclone_restore_' . current_time('dS_M_Y_h-iA', false) . '_' . wp_generate_password(10, false) . '.log';
    wpa_wpc_log_start('restore');
    if ($zipmode) {
        define('PCLZIP_TEMPORARY_DIR', WPCLONE_DIR_BACKUP);
    }
    $temp_dir = wpa_wpc_temp_dir();
    $site_url = site_url();
    $permalink_url = admin_url('options-permalink.php');
    $zipfile = wpa_fetch_file($url);
    $report = wpa_wpc_process_db($zipfile, $zipmode);
    $unzipped_folder = wpCloneSafePathMode(trailingslashit($temp_dir) . 'wpclone_backup');
    wpa_unzip($zipfile, $temp_dir, $zipmode);
    wpa_wpc_log('copying files..');
    wpa_copy($unzipped_folder . '/wp-content', WPCLONE_WP_CONTENT);
    wpa_wpc_log('deleting temp directory..');
    $wp_filesystem->delete($temp_dir, true);
    /* remove the zip file only if it was downloaded from an external location. */
    $wptmp = explode('.', $zipfile);
    if (in_array('tmp', $wptmp)) {
        wpa_wpc_log('deleting downloaded zip file..');
        $wp_filesystem->delete($zipfile);
    }
    wpa_wpc_log('restore finished');
    echo '<div class="width-60"><h1>Restore Successful!</h1>';
    printf('Visit your restored site [ <a href="%s" target=blank>here</a> ]<br><br>', $site_url);
    printf('<strong>You may need to re-save your permalink structure <a href="%s" target=blank>Here</a></strong>', $permalink_url);
    printf('</br><a href="%s">log</a>', convertPathIntoUrl(WPCLONE_DIR_BACKUP . $GLOBALS['wpclone']['logfile']));
    unset($GLOBALS['wpclone']);
    echo wpa_wpc_search_n_replace_report($report);
}