/home/techb158/on-time-movers.com/wp-content/plugins/updraftplus
Edit: /home/techb158/on-time-movers.com/wp-content/plugins/updraftplus/restorer.php (260166B)
our_siteurl = untrailingslashit(site_url());
$this->continuation_data = $continuation_data;
$this->setup_database_objects();
$this->search_replace_obj = new UpdraftPlus_Search_Replace();
if ($short_init) return;
// If updraft_incremental_restore_point is equal to -1 then this is either not a incremental restore or we are going to restore up to the latest increment, so there is no need to prune the backup set of any unwanted backup archives.
if (isset($restore_options['updraft_incremental_restore_point']) && $restore_options['updraft_incremental_restore_point'] > 0) {
$restore_point = $restore_options['updraft_incremental_restore_point'];
foreach ($backup_set['incremental_sets'] as $increment_timestamp => $entities) {
if ($increment_timestamp > $restore_point) {
foreach ($entities as $entity => $backups) {
foreach ($backups as $key => $value) {
unset($backup_set[$entity][$key]);
}
}
}
}
}
// if updraft_include_more_path is set then, the user has chosen where they want these backup files to be restored as either UD did not know where to restore them or the original location is not found on disk any more
if (isset($restore_options['updraft_include_more_path'])) {
if (!isset($backup_set['morefiles_linked_indexes']) || !isset($backup_set['morefiles_more_locations'])) {
$backup_set['morefiles_more_locations'] = $restore_options['updraft_include_more_path'];
foreach ($restore_options['updraft_include_more_path'] as $key => $path) {
$backup_set['morefiles_linked_indexes'][] = $key;
}
} else {
foreach ($restore_options['updraft_include_more_path'] as $key => $path) {
$backup_set['morefiles_more_locations'][$key] = $path;
}
}
if (isset($restore_options['updraft_include_more_index'])) {
// unset any backups the user has chosen not to restore
foreach (array_keys($backup_set['more']) as $key) {
if (!in_array($key, $restore_options['updraft_include_more_index'])) unset($backup_set['more'][$key]);
}
}
}
if (isset($restore_options['include_unspecified_tables'])) $this->include_unspecified_tables = $restore_options['include_unspecified_tables'];
if (isset($restore_options['tables_to_restore'])) $this->tables_to_restore = $restore_options['tables_to_restore'];
if (isset($restore_options['tables_to_skip'])) $this->tables_to_skip = $restore_options['tables_to_skip'];
if (isset($restore_options['include_unspecified_plugins'])) $this->include_unspecified_plugins = $restore_options['include_unspecified_plugins'];
if (isset($restore_options['plugins_to_restore'])) $this->plugins_to_restore = $restore_options['plugins_to_restore'];
if (isset($restore_options['plugins_to_skip'])) $this->plugins_to_skip = (array) $restore_options['plugins_to_skip'];
if (isset($restore_options['include_unspecified_themes'])) $this->include_unspecified_themes = $restore_options['include_unspecified_themes'];
if (isset($restore_options['themes_to_restore'])) $this->themes_to_restore = $restore_options['themes_to_restore'];
if (isset($restore_options['themes_to_skip'])) $this->themes_to_skip = (array) $restore_options['themes_to_skip'];
// Restore in the most helpful order
uksort($backup_set, array('UpdraftPlus_Manipulation_Functions', 'sort_restoration_entities'));
$this->ud_backup_set = $backup_set;
add_filter('updraftplus_logline', array($this, 'updraftplus_logline'), 10, 5);
add_action('updraftplus_restored_db_table', array($this, 'updraftplus_restored_db_table'), 10, 3);
do_action('updraftplus_restorer_restore_options', $restore_options);
$this->ud_multisite_selective_restore = (is_array($restore_options) && !empty($restore_options['updraft_restore_ms_whichsites']) && $restore_options['updraft_restore_ms_whichsites'] > 0) ? $restore_options['updraft_restore_ms_whichsites'] : false;
$this->restore_options = $restore_options;
$this->ud_foreign = empty($backup_set['meta_foreign']) ? false : $backup_set['meta_foreign'];
if (isset($backup_set['is_multisite'])) $this->ud_backup_is_multisite = $backup_set['is_multisite'];
if (isset($backup_set['created_by_version'])) $this->created_by_version = $backup_set['created_by_version'];
$this->backup_strings();
$this->is_multisite = is_multisite();
updraft_try_include_file('includes/class-database-utility.php', 'require_once');
if (!class_exists('WP_Upgrader')) include_once(ABSPATH.'wp-admin/includes/class-wp-upgrader.php');
$this->skin = $skin;
$this->wp_upgrader = new WP_Upgrader($skin);
$this->wp_upgrader->init();
}
/**
* This function will check if we are using wpdb, if we are not then it will setup our wpdb-like objects
*
* @param boolean $reconnect_wpdb - if we should include and create a new instance of wpdb
*
* @return void
*/
private function setup_database_objects($reconnect_wpdb = false) {
global $wpdb;
if ($reconnect_wpdb) {
$wpdb->db_connect(true);
}
// Line up a wpdb-like object
if (!$this->use_wpdb()) {
// We have our own extension which drops lots of the overhead on the query
$wpdb_obj = new UpdraftPlus_WPDB(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
// Was that successful?
if (!$wpdb_obj->is_mysql || !$wpdb_obj->ready) {
$this->use_wpdb = true;
} else {
$this->wpdb_obj = $wpdb_obj;
$this->mysql_dbh = $wpdb_obj->updraftplus_get_database_handle();
$this->use_mysqli = $wpdb_obj->updraftplus_use_mysqli();
}
}
}
/**
* This function will try to restore the database connection, if it succeeds then it returns true otherwise false
*
* @return boolean - true if the connection is restored, otherwise false
*/
private function restore_database_connection() {
global $updraftplus, $wpdb;
$wpdb_connected = $updraftplus->check_db_connection($wpdb, false, false, true);
if (false === $wpdb_connected || -1 === $wpdb_connected) {
sleep(10);
$this->setup_database_objects(true);
return false;
}
return true;
}
/**
* Get the wpdb-like object that we are using, if we are using one
*
* @return UpdraftPlus_WPDB|Boolean
*/
public function get_db_object() {
return $this->wpdb_obj;
}
/**
* Restore has been completed - clean some things up
*
* @param Boolean|WP_Error $successful - if the restore was successful (true) or not (false or WP_Error). If not, then only a minimum of necessary clean-up things is done.
* @param Boolean $browser_context - if true, then extra messages will be echo-ed
*
* @uses UpdraftPlus::log()
*/
public function post_restore_clean_up($successful = true, $browser_context = true) {
global $updraftplus, $updraftplus_admin;
$updraftplus->log_restore_update(array('type' => 'state', 'stage' => 'cleaning', 'data' => array()));
if (is_wp_error($successful)) {
foreach ($successful->get_error_codes() as $code) {
if ('already_exists' == $code) {
if ($browser_context) {
global $updraftplus_admin;
$updraftplus_admin->print_delete_old_dirs_form(false);
} else {
$updraftplus->log(__('Your WordPress install has old directories from its state before you restored/migrated (technical information: these are suffixed with -old).', 'updraftplus'));
}
}
$data = $successful->get_error_data($code);
if (!empty($data)) {
$pdata = is_string($data) ? $data : serialize($data);
$updraftplus->log(__('Error data:', 'updraftplus').' '.$pdata, 'warning-restore');
if (false !== strpos($pdata, 'PCLZIP_ERR_BAD_FORMAT (-10)')) {
$url = apply_filters('updraftplus_com_link', 'https://teamupdraft.com/documentation/updraftplus/topics/restoration/troubleshooting/what-does-error-message-pclzip_err_bad_format-10-mean/?utm_source=udp-plugin&utm_medium=referral&utm_campaign=paac&utm_content=unknown&utm_creative_format=unknown');
if ($browser_context) {
echo '
'.esc_html__('Follow this link for more information', 'updraftplus').'';
} else {
$updraftplus->log(__('Follow this link for more information', 'updraftplus').': '.$url);
}
}
}
}
$successful = false;
}
// From this point on, $successful is a boolean
if ($successful) {
// All done - remove the intermediate marker
delete_site_option('updraft_restore_in_progress');
foreach (array('template', 'stylesheet', 'template_root', 'stylesheet_root') as $opt) {
add_filter('pre_option_'.$opt, array($this, 'option_filter_'.$opt));
}
// Clear any cached pages after the restore
$this->clear_caches();
// Have seen a case where the current theme in the DB began with a capital, but not on disk - and this breaks migrating from Windows to a case-sensitive system
$template = get_option('template');
if (!empty($template) && WP_DEFAULT_THEME != $template && strtolower($template) != $template) {
$theme_root = get_theme_root($template);
if (!file_exists("$theme_root/$template/style.css") && file_exists("$theme_root/".strtolower($template)."/style.css")) {
$updraftplus->log_e("Theme directory (%s) not found, but lower-case version exists; updating database option accordingly", $template);
update_option('template', strtolower($template));
}
}
if (!function_exists('validate_current_theme')) include_once(ABSPATH.WPINC.'/themes');
if (!validate_current_theme()) {
if ($browser_context) echo '
';
$updraftplus->log_e("The current theme was not found; to prevent this stopping the site from loading, your theme has been reverted to the default theme");
if ($browser_context) echo '';
}
do_action('updraftplus_restore_completed');
}
if ($browser_context) echo '
'; // Close the updraft_restore_progress div
restore_error_handler();
}
/**
* Whether or not we must use the global $wpdb object for database queries.
* That is to say: we *can* always use it. But we prefer to avoid the overhead since we are potentially doing very many queries.
*
* This is the getter. We have no use-case for a setter outside of this class, so we just set it directly.
*
* @return Boolean
*/
public function use_wpdb() {
if (!is_bool($this->use_wpdb)) {
global $wpdb;
if (defined('UPDRAFTPLUS_USE_WPDB')) {
$this->use_wpdb = (bool) UPDRAFTPLUS_USE_WPDB;
} else {
$this->use_wpdb = ((!function_exists('mysql_query') && !function_exists('mysqli_query')) || !$wpdb->is_mysql || !$wpdb->ready) ? true : false;
}
}
return $this->use_wpdb;
}
/**
* Get the skin
*
* @return WP_Upgrader_Skin
*/
public function ud_get_skin() {
return $this->skin;
}
/**
* Ensure that needed files are present locally, and return data for the next step (plus do some internal configuration)
*
* @param Array $entities_to_restore
* @param Array $backupable_entities - list of entities
* @param Array $services - list of services that the backup can be found at
*
* @uses self::pre_restore_backup() (and some other internal properties)
* @uses UpdraftPlus::log()
*
* @return Boolean|Array|WP_Error - a sorted array (of entity types and files for each entity type) or false or a WP_Error if there was an error
*/
private function ensure_restore_files_present($entities_to_restore, $backupable_entities, $services) {
global $updraftplus;
// First loop: make sure that files are present + readable; and populate array for second loop
$second_loop = $this->check_file_availability_and_log($entities_to_restore, $backupable_entities, $services);
// A WP_Error or boolean indicates that the restore cannot proceed
if (!is_array($second_loop)) return $second_loop;
$this->delete_archives_upon_restoration = UpdraftPlus_Options::get_updraft_option('updraft_delete_local', 1) ? true : false;
if (empty($services) || array('email') === $services || !empty($this->ud_foreign)) {
if ($this->delete_archives_upon_restoration) $updraftplus->log_e('Will not delete any archives after unpacking them, because there was no cloud storage for this backup');
$this->delete_archives_upon_restoration = false;
}
if (!empty($this->ud_foreign)) $updraftplus->log("Foreign backup; created by: ".$this->ud_foreign);
// Second loop: prepare to launch the restoration
uksort($second_loop, array('UpdraftPlus_Manipulation_Functions', 'sort_restoration_entities'));
// If continuing, then prune those already done
if (is_array($this->continuation_data) && isset($this->continuation_data['second_loop_entities'])) {
foreach ($second_loop as $type => $files) {
if (isset($this->continuation_data['second_loop_entities'][$type])) {
$second_loop[$type] = $this->continuation_data['second_loop_entities'][$type];
} else {
$updraftplus->log_restore_update(array('type' => 'state', 'stage' => 'files', 'data' => array('entity' => $type, 'index' => 0, 'file' => '', 'fileindex' => 0, 'size_written' => 0, 'total_files' => 0)));
unset($second_loop[$type]);
}
}
}
return $second_loop;
}
/**
* Check that the files in the backup set in self::$backup_set are available and as expected; log the results; return a processed array with information
*
* @param Array $entities_to_restore
* @param Array $backupable_entities - list of entities
* @param Array $services - services to fetch from if files are not available locally
*
* @uses self::$backup_set
* @uses self::$ud_backup_is_multisite
* @uses self::$continuation_data
* @uses self::$been_restored
* @uses self::$ud_foreign
*
* @return Array|WP_Error|Boolean - if successful, then an array for the second loop; otherwise, an error returned (either a WP_Error or boolean false)
*/
private function check_file_availability_and_log($entities_to_restore, $backupable_entities, $services) {
global $updraftplus;
$updraft_dir = $updraftplus->backups_dir_location();
$foreign_known = apply_filters('updraftplus_accept_archivename', array());
$entities_to_download = $this->get_entities_to_download($entities_to_restore);
$backup_set = $this->ud_backup_set;
$timestamp = $backup_set['timestamp'];
$second_loop = array();
foreach ($backup_set as $type => $files) {
// All restorable entities must be given explicitly, as we can store other arbitrary data in the history array
if (!isset($backupable_entities[$type]) && 'db' != $type) continue;
if (isset($backupable_entities[$type]['restorable']) && false == $backupable_entities[$type]['restorable']) continue;
if (!isset($entities_to_download[$type])) continue;
if ('wpcore' == $type && is_multisite() && 0 === $this->ud_backup_is_multisite) {
$updraftplus->log('wpcore: '.__('Skipping restoration of WordPress core when importing a single site into a multisite installation.', 'updraftplus').' '.__('If you had anything necessary in your WordPress directory then you will need to re-add it manually from the zip file.', 'updraftplus'), 'notice-restore');
// TODO
// $updraftplus->log_e('Skipping restoration of WordPress core when importing a single site into a multisite installation. If you had anything necessary in your WordPress directory then you will need to re-add it manually from the zip file.');
continue;
}
if (is_string($files)) $files = array($files);
foreach ($files as $ind => $file) {
$fullpath = $updraft_dir.'/'.$file;
/* translators: 1: Entity type, 2: File name */
$updraftplus->log(sprintf(__('Looking for %1$s archive: file name: %2$s', 'updraftplus'), $type, $file), 'notice-restore');
if (is_array($this->continuation_data) && isset($this->continuation_data['second_loop_entities'][$type]) && !in_array($file, $this->continuation_data['second_loop_entities'][$type])) {
$updraftplus->log(__('Skipping: this archive was already restored.', 'updraftplus'), 'notice-restore');
// Set the marker so that the existing directory isn't moved out of the way
$this->been_restored[$type] = true;
continue;
}
if (!is_readable($fullpath) || 0 == filesize($fullpath)) {
UpdraftPlus_Storage_Methods_Interface::get_remote_file($services, $file, $timestamp, true);
}
$index = (0 == $ind) ? '' : $ind;
// If a file size is stored in the backup data, then verify correctness of the local file
if (isset($backup_set[$type.$index.'-size'])) {
$fs = $backup_set[$type.$index.'-size'];
$print_message = __("Archive is expected to be size:", 'updraftplus')." ".round($fs/1024, 1)." KB: ";
$as = @filesize($fullpath);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- the ensuing code handles any issues
if ($as == $fs) {
$updraftplus->log($print_message.__('OK', 'updraftplus'), 'notice-restore');
} else {
$updraftplus->log($print_message.__('Error:', 'updraftplus')." ".__('file is size:', 'updraftplus')." ".round($as/1024)." ($fs, $as)", 'warning-restore');
}
} else {
$updraftplus->log(__("The backup records do not contain information about the proper size of this file.", 'updraftplus'), 'notice-restore');
}
if (!is_readable($fullpath)) {
$updraftplus->log(__('Could not read one of the files for restoration', 'updraftplus')." ($file)", 'warning-restore');
$updraftplus->log("$file: ".__('Could not read one of the files for restoration', 'updraftplus'), 'error');
return false;
}
}
if (empty($this->ud_foreign)) {
$types = array($type);
} else {
if ('db' != $type || empty($foreign_known[$this->ud_foreign]['separatedb'])) {
$types = array('wpcore');
} else {
$types = array('db');
}
}
foreach ($types as $check_type) {
$info = isset($backupable_entities[$check_type]) ? $backupable_entities[$check_type] : array();
$val = $this->pre_restore_backup($files, $check_type, $info);
if (is_wp_error($val)) {
$updraftplus->log_wp_error($val);
foreach ($val->get_error_messages() as $msg) {
$updraftplus->log(__('Error:', 'updraftplus').' '.$msg, 'warning-restore');
}
return $val;
} elseif (false === $val) {
return false;
}
}
foreach ($entities_to_restore as $entity => $via) {
if ($via == $type) {
if ('wpcore' == $via && 'db' == $entity && count($files) > 1) {
$second_loop[$entity] = apply_filters('updraftplus_select_wpcore_file_with_db', $files, $this->ud_foreign);
} else {
$second_loop[$entity] = $files;
}
}
}
}
return $second_loop;
}
/**
* Perform the restoration. No code here (or called) should assume anything about the method used to call it (e.g. wp-admin or WP-CLI); it should be independent of how it is being called.
*
* The path through this class is: perform_restore() -> restore_backup() -> unpack_package_(archive|database) and then (for standard UD archives) UpdraftPlus_Filesystem_Functions::unzip_file()
*
* @param Array $entities_to_restore - entities to restore
* @param Array $restore_options - restoration options
*
* @uses the WordPress action updraftplus_restoration_title, allowing the title to be printed
*
* @return Boolean|WP_Error
*/
public function perform_restore($entities_to_restore, $restore_options) {
global $updraftplus;
$updraftplus->log_restore_update(array('type' => 'state', 'stage' => 'verifying', 'data' => implode(', ', array_flip($entities_to_restore))));
// Now log. We first remove any encryption passphrase from the log data.
$copy_restore_options = $restore_options;
if (!empty($copy_restore_options['updraft_encryptionphrase'])) $copy_restore_options['updraft_encryptionphrase'] = '***';
$updraftplus->log("Restore job started. Entities to restore: ".implode(', ', array_flip($entities_to_restore)).'. Restore options: '.json_encode($copy_restore_options));
do_action('updraftplus_restoration_title', __('Final checks', 'updraftplus'));
add_action('updraftplus_unzip_progress_restore_info', array($this, 'unzip_progress_restore_info'), 10, 4);
$backup_set = $this->ud_backup_set;
$services = isset($backup_set['service']) ? $updraftplus->get_canonical_service_list($backup_set['service']) : array();
$backupable_entities = $updraftplus->get_backupable_file_entities(true, true);
$remove_zip = isset($restore_options['delete_during_restore']) ? $restore_options['delete_during_restore'] : false;
if (!empty($restore_options['dummy_db_restore'])) {
$this->is_dummy_db_restore = true;
add_filter('updraftplus_restore_table_prefix', array($this, 'updraftplus_random_restore_table_prefix'));
}
// Allow add-ons to adjust the restore directory (but only in the case of restore - otherwise, they could just use the filter built into UpdraftPlus::get_backupable_file_entities)
$backupable_entities = apply_filters('updraft_backupable_file_entities_on_restore', $backupable_entities, $restore_options, $backup_set);
if (function_exists('set_time_limit')) @set_time_limit(UPDRAFTPLUS_SET_TIME_LIMIT);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged -- Silenced to suppress errors that may arise because of the function.
// Get an ordered list of things to restore
// This requires the global $updraft_restorer to be set up
$second_loop = $this->ensure_restore_files_present($entities_to_restore, $backupable_entities, $services);
if (!is_array($second_loop)) return $second_loop;
$timestamp = $backup_set['timestamp'];
$updraftplus->jobdata_set('second_loop_entities', $second_loop);
$updraftplus->jobdata_set('backup_timestamp', $timestamp);
// Use a site option, as otherwise on multisite when all the array of options is updated via UpdraftPlus_Options::update_site_option(), it will over-write any restored UD options from the backup
update_site_option('updraft_restore_in_progress', $updraftplus->nonce);
// Now process the actual restoration of the entities
foreach ($second_loop as $type => $files) {
$this->current_type = $type;
// Types: uploads, themes, plugins, others, db
$info = isset($backupable_entities[$type]) ? $backupable_entities[$type] : array();
$restoration_title = ('db' == $type) ? __('Database', 'updraftplus') : $info['description'];
// Indicate the type changed
$updraftplus->log_restore_update(array('type' => 'state_change', 'stage' => $type, 'data' => array()));
do_action('updraftplus_restoration_title', $restoration_title);
$updraftplus->log('Entity: '.$type);
if (is_string($files)) $files = array($files);
// Don't assume that the caller pre-sorted the array. We do need it sorted, so that incremental zips get restored in the right order
ksort($files);
foreach ($files as $fkey => $file) {
$this->current_index = $fkey;
$last_one = (1 == count($second_loop) && 1 == count($files));
$last_entity = (1 == count($files));
try {
do_action('updraftplus_pre_entity_restoration', $type, $fkey);
// Returns a boolean or WP_Error
$restore_result = $this->restore_backup($file, $type, $info, $last_one, $last_entity);
} catch (Exception $e) {
$log_message = 'Exception ('.get_class($e).') occurred during restore: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
/* translators: 1: Class name, 2: Exception message */
$display_log_message = sprintf(__('A PHP exception (%1$s) has occurred: %2$s', 'updraftplus'), get_class($e), $e->getMessage());
UpdraftPlus_Manipulation_Functions::error_log($log_message);
// @codingStandardsIgnoreLine
if (function_exists('wp_debug_backtrace_summary')) $log_message .= ' Backtrace: '.str_replace(array(ABSPATH, "\n"), array('', ', '), $e->getTraceAsString());
$updraftplus->log($display_log_message, 'notice-restore');
die();
} catch (Error $e) { //phpcs:ignore PHPCompatibility.Classes.NewClasses.errorFound -- This Error class will only get triggered during runtime but we don't explicitly throw this class in our code; so we only catch it when PHP throws it.
$log_message = 'PHP Fatal error ('.get_class($e).') has occurred. Error Message: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
UpdraftPlus_Manipulation_Functions::error_log($log_message);
// @codingStandardsIgnoreLine
if (function_exists('wp_debug_backtrace_summary')) $log_message .= ' Backtrace: '.str_replace(array(ABSPATH, "\n"), array('', ', '), $e->getTraceAsString());
/* translators: 1: Class name, 2: Exception message */
$display_log_message = sprintf(__('A PHP fatal error (%1$s) has occurred: %2$s', 'updraftplus'), get_class($e), $e->getMessage());
$updraftplus->log($display_log_message, 'notice-restore');
die();
}
if (is_wp_error($restore_result)) {
$codes = $restore_result->get_error_codes();
if (is_array($codes) && in_array('not_found', $codes) && !empty($this->ud_foreign) && apply_filters('updraftplus_foreign_allow_missing_entity', false, $type, $this->ud_foreign)) {
$updraftplus->log('Entity to move not found in this zip - but this is possible with this foreign backup type');
} else {
$updraftplus->log_e($restore_result);
foreach ($restore_result->get_error_messages() as $msg) {
$updraftplus->log(__('Error message', 'updraftplus').': '.$msg, 'notice-restore');
}
return $restore_result;
}
} elseif (false === $restore_result) {
return false;
} elseif ($restore_result && $remove_zip) {
$deleted = unlink($updraftplus->backups_dir_location().'/'.$file);
$updraftplus->log("Delete zip during restore active; removing backup file: $file: ".($deleted ? 'OK' : 'Failed'));
}
unset($files[$fkey]);
$second_loop[$type] = $files;
$updraftplus->jobdata_set_multi(array('second_loop_entities' => $second_loop, 'backup_timestamp' => $timestamp));
do_action('updraft_restored_archive', $file, $type, $restore_result, $fkey, $timestamp);
}
// Update the job data each time we go round the loop, so that if it aborts, it can be resumed from the correct point
unset($second_loop[$type]);
update_site_option('updraft_restore_in_progress', $updraftplus->nonce);
$updraftplus->jobdata_set_multi(array('second_loop_entities' => $second_loop, 'backup_timestamp' => $timestamp));
}
// If the database was restored, then check active plugins and make sure they all exist; otherwise, the site may go down
if (null !== $this->final_import_table_prefix) $this->check_active_plugins($this->final_import_table_prefix);
return true;
}
/**
* Calculate the entities to download for a given backup set
*
* @param Array $entities_to_restore - entities to restore, in the format returned by UpdraftPlus_Admin::get_entities_to_restore
*
* @return Array - keys are entities, and values are 0|1
*/
public function get_entities_to_download($entities_to_restore) {
$backup_set = $this->ud_backup_set;
$foreign_known = apply_filters('updraftplus_accept_archivename', array());
if (empty($backup_set['meta_foreign'])) return $entities_to_restore;
if (empty($foreign_known[$backup_set['meta_foreign']]['separatedb'])) return array('wpcore' => 1);
$entities_to_download = array();
if (in_array('db', $entities_to_restore)) $entities_to_download['db'] = 1;
if (count($entities_to_restore) > 1 || !in_array('db', $entities_to_restore)) {
$entities_to_download['wpcore'] = 1;
}
return $entities_to_download;
}
/**
* Logs a line from the restore process, being called from UpdraftPlus::log(). Currently, this means adding it to the browser output log file and either (depending on the constant WP_CLI) echoing it or passing it to a WPCLI method.
* Hooks the WordPress filter updraftplus_logline
* In future, this can get more sophisticated. For now, things are funnelled through here, giving the future possibility.
*
* @param String $line the line to be logged
* @param String $nonce the job ID of the restore job
* @param String $level the level of the log notice
* @param String|Boolean $uniq_id a unique ID for the log if it should only be logged once; or false otherwise
* @param String $destination the type of job ongoing. If it is not 'restore', then we will skip the logging.
* @return The filtered value. If set to false, then UpdraftPlus::log() will stop processing the log line.
*/
public function updraftplus_logline($line, $nonce, $level, $uniq_id, $destination) {
if ('restore' != $destination) return $line;
global $updraftplus;
static $logfile_handle;
if (empty($logfile_handle)) {
$logfile_name = $updraftplus->backups_dir_location()."/log.$nonce-browser.txt";
$logfile_handle = fopen($logfile_name, 'a');
}
if (!empty($logfile_handle)) {
$rtime = microtime(true)-$updraftplus->job_time_ms;
fwrite($logfile_handle, sprintf("%08.03f", round($rtime, 3))." (R) ".'['.$level.'] '.$line."\n");
}
if (defined('WP_CLI') && WP_CLI) {
switch ($level) {
case 'error':
case 'warning':
// WP_CLI::error() displays message with the prefix "Error: ", We don't like message which are double prefixed like the "Error: Error: ".
if (0 === stripos($line, 'Error: ')) {
$log_line = substr($line, 7);
} else {
$log_line = $line;
}
WP_CLI::error($log_line, false);
break;
case 'notice':
default:
WP_CLI::log($line, false);
break;
}
} else {
if ('warning' == $level || 'error' == $level || $uniq_id) {
$line = '