return $backupSiteUrl; } function processConfigAndDatabaseFile($databaseFileInZip) { global $wp_filesystem; $dbFileContent = $wp_filesystem->get_contents($databaseFileInZip); /* we don't want to nuke the curret database if if something went wrong with the above operation */ if (false === $dbFileContent) { wpa_backup_error('dbrest', sprintf(__('Cannot read <code>%s</code>'), $databaseFileInZip), true); } $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); /* and we cannot nuke the db if the connection failed now can we */ if (false === $conn) { wpa_backup_error('dbrest', __('database connection failed'), true); } mysql_select_db(DB_NAME, $conn); $query = mysql_query("SHOW TABLES", $conn); /* point of no return,if it fails after this you're royally boned ;) */ while ($fetch = mysql_fetch_array($query)) { mysql_query("Drop table `{$fetch[0]}`"); } flush(); $res = explode(";\n", $dbFileContent); foreach ($res as $query) { mysql_query($query, $conn); } mysql_close($conn); $backupSiteUrl = replaceSiteUrlFromDatabaseFile($databaseFileInZip); /* don't let the name fool you,it just returns the old site's url */ $currentSiteUrl = site_url(); $backupSiteUrl = untrailingslashit($backupSiteUrl); $currentSiteUrl = untrailingslashit($currentSiteUrl); wpa_safe_replace_wrapper($backupSiteUrl, $currentSiteUrl);
function wpa_wpc_process_db($zipfile, $zipmode = false) { $files = wpa_wpc_get_db($zipfile, $zipmode); $prefix = wpa_wpc_get_prefix($files['prefix']); $old_url = untrailingslashit(wpa_wpc_get_url($files['database'])); $cur_url = untrailingslashit(site_url()); $found = false; $db = explode(";\n", $files['database']); $link = wpa_wpc_mysql_connect(); wpa_wpc_log('database import started'); foreach ($db as $query) { if (!$found && false !== strpos($query, '"siteurl",')) { $query = str_replace($old_url, $cur_url, $query, $count); wpa_wpc_log(sprintf('updating mysql query with current site\'s url - new query : "%s"', ltrim($query))); if ($count > 0) { $found = true; } } if (isset($_POST['mysql_check']) && 'true' === $_POST['mysql_check']) { if (!mysql_ping($link)) { mysql_close($link); $link = wpa_wpc_mysql_connect(); } } $status = mysql_query($query, $link); if (false === $status) { wpa_wpc_log(sprintf('mysql query failed. error : %d %s - query : "%s"', mysql_errno(), mysql_error(), ltrim($query))); } } wpa_wpc_log('database import finished'); if ($cur_url === $old_url) { wpa_wpc_log('URLs are similar, skipping search and replace'); $report = 'Search and replace did not run because the URLs are similar'; } else { $report = wpa_safe_replace_wrapper($old_url, $cur_url, $prefix); } return $report; }
function processConfigAndDatabaseFile($databaseFileInZip) { global $wp_filesystem; $dbFileContent = $wp_filesystem->get_contents($databaseFileInZip); /* we don't want to nuke the curret database if if something went wrong with the above operation */ if (false === $dbFileContent) { wpa_backup_error('dbrest', sprintf(__('Cannot read <code>%s</code>'), $databaseFileInZip), true); } $conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); /* and we cannot nuke the db if the connection failed now can we */ if (false === $conn) { wpa_backup_error('dbrest', __('database connection failed'), true); } mysql_select_db(DB_NAME, $conn); mysql_set_charset(DB_CHARSET, $conn); $res = explode(";\n", $dbFileContent); foreach ($res as $query) { mysql_query($query, $conn); } mysql_close($conn); $backupSiteUrl = replaceSiteUrlFromDatabaseFile($databaseFileInZip); /* don't let the name fool you,it just returns the old site's url */ $currentSiteUrl = site_url(); $backupSiteUrl = untrailingslashit($backupSiteUrl); $currentSiteUrl = untrailingslashit($currentSiteUrl); $report = wpa_safe_replace_wrapper($backupSiteUrl, $currentSiteUrl); return array('url' => $currentSiteUrl, 'report' => $report); }
function wpa_wpc_ajax_search_n_replace() { check_ajax_referer('wpclone-ajax-submit', 'nonce'); global $wpdb; $search = isset($_POST['search']) ? $_POST['search'] : ''; $replace = isset($_POST['replace']) ? $_POST['replace'] : ''; if (empty($search) || empty($replace)) { echo '<p class="error">Search and Replace values cannot be empty.</p>'; wp_die(); } wpa_bump_limits(); $report = wpa_safe_replace_wrapper($search, $replace, $wpdb->prefix); echo wpa_wpc_search_n_replace_report($report); wp_die(); }