Example #1
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>";
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.";
    }
}