Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp...
File: admin.php
echo ' <p><a target="_blank" href="?action=downloadlog&page=updraftplus&updraftplus_backup_nonce='.esc_attr($updraftplus->nonce).'">'.__('Follow this link to download the log file for this restoration (needed for any support requests).', 'updraftplus').'</a></p>';
[5000] Fix | Delete
echo '</div>'; // end .updraft_restore_main--components
[5001] Fix | Delete
echo '<div class="updraft_restore_main--activity">';
[5002] Fix | Delete
echo ' <h2 class="updraft_restore_main--activity-title">'.__('Activity log', 'updraftplus').' <i id="activity-full-log" title="'.__('Full-screen', 'updraftplus').'" class="dashicons dashicons-fullscreen-alt" style="float: right; cursor: pointer; margin-left: 7px;"></i> <span id="updraftplus_ajax_restore_last_activity"></span></h2>';
[5003] Fix | Delete
echo ' <div id="updraftplus_ajax_restore_output"></div>';
[5004] Fix | Delete
echo '</div>'; // end .updraft_restore_main--activity
[5005] Fix | Delete
echo '
[5006] Fix | Delete
<div class="updraft-restore--footer">
[5007] Fix | Delete
<ul class="updraft-restore--stages">
[5008] Fix | Delete
<li><span>'.__('1. Component selection', 'updraftplus').'</span></li>
[5009] Fix | Delete
<li><span>'.__('2. Verifications', 'updraftplus').'</span></li>
[5010] Fix | Delete
<li class="active"><span>'.__('3. Restoration', 'updraftplus').'</span></li>
[5011] Fix | Delete
</ul>
[5012] Fix | Delete
</div>';
[5013] Fix | Delete
echo '</div>'; // end .updraft_restore_main
[5014] Fix | Delete
echo '</div>'; // end .updraft_restore_container
[5015] Fix | Delete
}
[5016] Fix | Delete
[5017] Fix | Delete
/**
[5018] Fix | Delete
* Processes the jobdata to build an array of entities to restore.
[5019] Fix | Delete
*
[5020] Fix | Delete
* @param Array $backup_set - information on the backup to restore
[5021] Fix | Delete
*
[5022] Fix | Delete
* @return Array - the entities to restore built from the restore jobdata
[5023] Fix | Delete
*/
[5024] Fix | Delete
private function get_entities_to_restore_from_jobdata($backup_set) {
[5025] Fix | Delete
[5026] Fix | Delete
global $updraftplus;
[5027] Fix | Delete
[5028] Fix | Delete
$updraft_restore = $updraftplus->jobdata_get('updraft_restore');
[5029] Fix | Delete
[5030] Fix | Delete
if (empty($updraft_restore) || (!is_array($updraft_restore))) $updraft_restore = array();
[5031] Fix | Delete
[5032] Fix | Delete
$entities_to_restore = array();
[5033] Fix | Delete
$foreign_known = apply_filters('updraftplus_accept_archivename', array());
[5034] Fix | Delete
[5035] Fix | Delete
foreach ($updraft_restore as $entity) {
[5036] Fix | Delete
if (empty($backup_set['meta_foreign'])) {
[5037] Fix | Delete
$entities_to_restore[$entity] = $entity;
[5038] Fix | Delete
} else {
[5039] Fix | Delete
if ('db' == $entity && !empty($foreign_known[$backup_set['meta_foreign']]) && !empty($foreign_known[$backup_set['meta_foreign']]['separatedb'])) {
[5040] Fix | Delete
$entities_to_restore[$entity] = 'db';
[5041] Fix | Delete
} else {
[5042] Fix | Delete
$entities_to_restore[$entity] = 'wpcore';
[5043] Fix | Delete
}
[5044] Fix | Delete
}
[5045] Fix | Delete
}
[5046] Fix | Delete
[5047] Fix | Delete
return $entities_to_restore;
[5048] Fix | Delete
}
[5049] Fix | Delete
[5050] Fix | Delete
/**
[5051] Fix | Delete
* Processes the jobdata to build an array of restoration options
[5052] Fix | Delete
*
[5053] Fix | Delete
* @return Array - the restore options built from the restore jobdata
[5054] Fix | Delete
*/
[5055] Fix | Delete
private function get_restore_options_from_jobdata() {
[5056] Fix | Delete
[5057] Fix | Delete
global $updraftplus;
[5058] Fix | Delete
[5059] Fix | Delete
$restore_options = $updraftplus->jobdata_get('updraft_restorer_restore_options');
[5060] Fix | Delete
$updraft_encryptionphrase = $updraftplus->jobdata_get('updraft_encryptionphrase');
[5061] Fix | Delete
$include_wpconfig = $updraftplus->jobdata_get('updraft_restorer_wpcore_includewpconfig');
[5062] Fix | Delete
[5063] Fix | Delete
$restore_options['updraft_encryptionphrase'] = empty($updraft_encryptionphrase) ? '' : $updraft_encryptionphrase;
[5064] Fix | Delete
[5065] Fix | Delete
$restore_options['updraft_restorer_wpcore_includewpconfig'] = !empty($include_wpconfig);
[5066] Fix | Delete
[5067] Fix | Delete
$restore_options['updraft_incremental_restore_point'] = empty($restore_options['updraft_incremental_restore_point']) ? -1 : (int) $restore_options['updraft_incremental_restore_point'];
[5068] Fix | Delete
[5069] Fix | Delete
return $restore_options;
[5070] Fix | Delete
}
[5071] Fix | Delete
[5072] Fix | Delete
/**
[5073] Fix | Delete
* Carry out the restore process within the WP admin dashboard, using data from $_POST
[5074] Fix | Delete
*
[5075] Fix | Delete
* @param Integer $timestamp Identifying the backup to be restored
[5076] Fix | Delete
* @param Array|null $continuation_data For continuing a multi-stage restore; this is the saved jobdata for the job; in this method the keys used are second_loop_entities, restore_options; but it is also passed on to Updraft_Restorer::perform_restore()
[5077] Fix | Delete
* @return Boolean|WP_Error - a WP_Error indicates a terminal failure; false indicates not-yet complete (not necessarily terminal); true indicates complete.
[5078] Fix | Delete
*/
[5079] Fix | Delete
private function restore_backup($timestamp, $continuation_data = null) {
[5080] Fix | Delete
[5081] Fix | Delete
global $updraftplus, $updraftplus_restorer;
[5082] Fix | Delete
[5083] Fix | Delete
$second_loop_entities = empty($continuation_data['second_loop_entities']) ? array() : $continuation_data['second_loop_entities'];
[5084] Fix | Delete
[5085] Fix | Delete
// If this is a resumption and we still need to restore the database we should rebuild the backup history to ensure the database is in there.
[5086] Fix | Delete
if (!empty($second_loop_entities['db'])) UpdraftPlus_Backup_History::rebuild();
[5087] Fix | Delete
[5088] Fix | Delete
$backup_set = UpdraftPlus_Backup_History::get_history($timestamp);
[5089] Fix | Delete
[5090] Fix | Delete
if (empty($backup_set)) {
[5091] Fix | Delete
echo '<p>'.__('This backup does not exist in the backup history - restoration aborted. Timestamp:', 'updraftplus').' '.htmlspecialchars($timestamp).'</p><br>';
[5092] Fix | Delete
return new WP_Error('does_not_exist', __('Backup does not exist in the backup history', 'updraftplus')." ($timestamp)");
[5093] Fix | Delete
}
[5094] Fix | Delete
[5095] Fix | Delete
$backup_set['timestamp'] = $timestamp;
[5096] Fix | Delete
[5097] Fix | Delete
$url_parameters = array(
[5098] Fix | Delete
'backup_timestamp' => $timestamp,
[5099] Fix | Delete
'job_id' => $updraftplus->nonce
[5100] Fix | Delete
);
[5101] Fix | Delete
[5102] Fix | Delete
if (!empty($continuation_data['updraftplus_ajax_restore'])) {
[5103] Fix | Delete
$url_parameters['updraftplus_ajax_restore'] = 'continue_ajax_restore';
[5104] Fix | Delete
$updraftplus->output_to_browser(''); // Start timer
[5105] Fix | Delete
// Force output buffering off so that we get log lines sent to the browser as they come not all at once at the end of the ajax restore
[5106] Fix | Delete
// zlib creates an output buffer, and waits for the entire page to be generated before it can send it to the client try to turn it off
[5107] Fix | Delete
@ini_set("zlib.output_compression", 0);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[5108] Fix | Delete
// Turn off PHP output buffering for NGINX
[5109] Fix | Delete
header('X-Accel-Buffering: no');
[5110] Fix | Delete
header('Content-Encoding: none');
[5111] Fix | Delete
while (ob_get_level()) {
[5112] Fix | Delete
ob_end_flush();
[5113] Fix | Delete
}
[5114] Fix | Delete
ob_implicit_flush(1);
[5115] Fix | Delete
}
[5116] Fix | Delete
[5117] Fix | Delete
$updraftplus->log("Ensuring WP_Filesystem is setup for a restore");
[5118] Fix | Delete
[5119] Fix | Delete
// This will print HTML and die() if necessary
[5120] Fix | Delete
UpdraftPlus_Filesystem_Functions::ensure_wp_filesystem_set_up_for_restore($url_parameters);
[5121] Fix | Delete
[5122] Fix | Delete
$updraftplus->log("WP_Filesystem is setup and ready for a restore");
[5123] Fix | Delete
[5124] Fix | Delete
$entities_to_restore = $this->get_entities_to_restore_from_jobdata($backup_set);
[5125] Fix | Delete
[5126] Fix | Delete
if (empty($entities_to_restore)) {
[5127] Fix | Delete
$restore_jobdata = $updraftplus->jobdata_getarray($updraftplus->nonce);
[5128] Fix | Delete
echo '<p>'.__('ABORT: Could not find the information on which entities to restore.', 'updraftplus').'</p><p>'.__('If making a request for support, please include this information:', 'updraftplus').' '.count($restore_jobdata).' : '.htmlspecialchars(serialize($restore_jobdata)).'</p>';
[5129] Fix | Delete
return new WP_Error('missing_info', 'Backup information not found');
[5130] Fix | Delete
}
[5131] Fix | Delete
[5132] Fix | Delete
// This is used in painting the admin page after a successful restore
[5133] Fix | Delete
$this->entities_to_restore = $entities_to_restore;
[5134] Fix | Delete
[5135] Fix | Delete
// This will be removed by Updraft_Restorer::post_restore_clean_up()
[5136] Fix | Delete
set_error_handler(array($updraftplus, 'php_error'), E_ALL & ~E_STRICT);
[5137] Fix | Delete
[5138] Fix | Delete
// Set $restore_options, either from the continuation data, or from $_POST
[5139] Fix | Delete
if (!empty($continuation_data['restore_options'])) {
[5140] Fix | Delete
$restore_options = $continuation_data['restore_options'];
[5141] Fix | Delete
} else {
[5142] Fix | Delete
// Gather the restore options into one place - code after here should read the options
[5143] Fix | Delete
$restore_options = $this->get_restore_options_from_jobdata();
[5144] Fix | Delete
$updraftplus->jobdata_set('restore_options', $restore_options);
[5145] Fix | Delete
}
[5146] Fix | Delete
[5147] Fix | Delete
add_action('updraftplus_restoration_title', array($this, 'restoration_title'));
[5148] Fix | Delete
[5149] Fix | Delete
$updraftplus->log_restore_update(array('type' => 'state', 'stage' => 'started', 'data' => array()));
[5150] Fix | Delete
[5151] Fix | Delete
// We use a single object for each entity, because we want to store information about the backup set
[5152] Fix | Delete
$updraftplus_restorer = new Updraft_Restorer(new Updraft_Restorer_Skin, $backup_set, false, $restore_options, $continuation_data);
[5153] Fix | Delete
[5154] Fix | Delete
$restore_result = $updraftplus_restorer->perform_restore($entities_to_restore, $restore_options);
[5155] Fix | Delete
[5156] Fix | Delete
$updraftplus_restorer->post_restore_clean_up($restore_result);
[5157] Fix | Delete
[5158] Fix | Delete
$pval = $updraftplus->have_addons ? 1 : 0;
[5159] Fix | Delete
$sval = (true === $restore_result) ? 1 : 0;
[5160] Fix | Delete
[5161] Fix | Delete
$pages = get_pages(array('number' => 2));
[5162] Fix | Delete
$page_urls = array(
[5163] Fix | Delete
'home' => get_home_url(),
[5164] Fix | Delete
);
[5165] Fix | Delete
[5166] Fix | Delete
foreach ($pages as $page_info) {
[5167] Fix | Delete
$page_urls[$page_info->post_name] = get_page_link($page_info->ID);
[5168] Fix | Delete
}
[5169] Fix | Delete
[5170] Fix | Delete
$updraftplus->log_restore_update(
[5171] Fix | Delete
array(
[5172] Fix | Delete
'type' => 'state',
[5173] Fix | Delete
'stage' => 'finished',
[5174] Fix | Delete
'data' => array(
[5175] Fix | Delete
'actions' => array(
[5176] Fix | Delete
__('Return to UpdraftPlus configuration', 'updraftplus') => UpdraftPlus_Options::admin_page_url() . '?page=updraftplus&updraft_restore_success=' . $sval . '&pval=' . $pval
[5177] Fix | Delete
),
[5178] Fix | Delete
'urls' => $page_urls,
[5179] Fix | Delete
)
[5180] Fix | Delete
)
[5181] Fix | Delete
);
[5182] Fix | Delete
[5183] Fix | Delete
return $restore_result;
[5184] Fix | Delete
}
[5185] Fix | Delete
[5186] Fix | Delete
/**
[5187] Fix | Delete
* Called when the restore process wants to print a title
[5188] Fix | Delete
*
[5189] Fix | Delete
* @param String $title - title
[5190] Fix | Delete
*/
[5191] Fix | Delete
public function restoration_title($title) {
[5192] Fix | Delete
echo '<h2>'.$title.'</h2>';
[5193] Fix | Delete
}
[5194] Fix | Delete
[5195] Fix | Delete
/**
[5196] Fix | Delete
* Logs a line from the restore process, being called from UpdraftPlus::log().
[5197] Fix | Delete
* Hooks the WordPress filter updraftplus_logline
[5198] Fix | Delete
* In future, this can get more sophisticated. For now, things are funnelled through here, giving the future possibility.
[5199] Fix | Delete
*
[5200] Fix | Delete
* @param String $line - the line to be logged
[5201] Fix | Delete
* @param String $nonce - the job ID of the restore job
[5202] Fix | Delete
* @param String $level - the level of the log notice
[5203] Fix | Delete
* @param String|Boolean $uniq_id - a unique ID for the log if it should only be logged once; or false otherwise
[5204] Fix | Delete
* @param String $destination - the type of job ongoing. If it is not 'restore', then we will skip the logging.
[5205] Fix | Delete
*
[5206] Fix | Delete
* @return String|Boolean - the filtered value. If set to false, then UpdraftPlus::log() will stop processing the log line.
[5207] Fix | Delete
*/
[5208] Fix | Delete
public function updraftplus_logline($line, $nonce, $level, $uniq_id, $destination) {// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
[5209] Fix | Delete
[5210] Fix | Delete
if ('progress' != $destination || (defined('WP_CLI') && WP_CLI) || false === $line || false === strpos($line, 'RINFO:')) return $line;
[5211] Fix | Delete
[5212] Fix | Delete
global $updraftplus;
[5213] Fix | Delete
[5214] Fix | Delete
$updraftplus->output_to_browser($line);
[5215] Fix | Delete
[5216] Fix | Delete
// Indicate that we have completely handled all logging needed
[5217] Fix | Delete
return false;
[5218] Fix | Delete
}
[5219] Fix | Delete
[5220] Fix | Delete
/**
[5221] Fix | Delete
* Ensure that what is returned is an array. Used as a WP options filter.
[5222] Fix | Delete
*
[5223] Fix | Delete
* @param Array $input - input
[5224] Fix | Delete
*
[5225] Fix | Delete
* @return Array
[5226] Fix | Delete
*/
[5227] Fix | Delete
public function return_array($input) {
[5228] Fix | Delete
return is_array($input) ? $input : array();
[5229] Fix | Delete
}
[5230] Fix | Delete
[5231] Fix | Delete
/**
[5232] Fix | Delete
* Called upon the WP action wp_ajax_updraft_savesettings. Will die().
[5233] Fix | Delete
*/
[5234] Fix | Delete
public function updraft_ajax_savesettings() {
[5235] Fix | Delete
try {
[5236] Fix | Delete
if (empty($_POST) || empty($_POST['subaction']) || 'savesettings' != $_POST['subaction'] || !isset($_POST['nonce']) || !is_user_logged_in() || !UpdraftPlus_Options::user_can_manage() || !wp_verify_nonce($_POST['nonce'], 'updraftplus-settings-nonce')) die('Security check');
[5237] Fix | Delete
[5238] Fix | Delete
if (empty($_POST['settings']) || !is_string($_POST['settings'])) die('Invalid data');
[5239] Fix | Delete
[5240] Fix | Delete
parse_str(stripslashes($_POST['settings']), $posted_settings);
[5241] Fix | Delete
// We now have $posted_settings as an array
[5242] Fix | Delete
if (!empty($_POST['updraftplus_version'])) $posted_settings['updraftplus_version'] = $_POST['updraftplus_version'];
[5243] Fix | Delete
[5244] Fix | Delete
echo json_encode($this->save_settings($posted_settings));
[5245] Fix | Delete
} catch (Exception $e) {
[5246] Fix | Delete
$log_message = 'PHP Fatal Exception error ('.get_class($e).') has occurred during save settings. Error Message: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
[5247] Fix | Delete
error_log($log_message);
[5248] Fix | Delete
echo json_encode(array(
[5249] Fix | Delete
'fatal_error' => true,
[5250] Fix | Delete
'fatal_error_message' => $log_message
[5251] Fix | Delete
));
[5252] Fix | Delete
// @codingStandardsIgnoreLine
[5253] Fix | Delete
} catch (Error $e) {
[5254] Fix | Delete
$log_message = 'PHP Fatal error ('.get_class($e).') has occurred during save settings. Error Message: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
[5255] Fix | Delete
error_log($log_message);
[5256] Fix | Delete
echo json_encode(array(
[5257] Fix | Delete
'fatal_error' => true,
[5258] Fix | Delete
'fatal_error_message' => $log_message
[5259] Fix | Delete
));
[5260] Fix | Delete
}
[5261] Fix | Delete
die;
[5262] Fix | Delete
}
[5263] Fix | Delete
[5264] Fix | Delete
public function updraft_ajax_importsettings() {
[5265] Fix | Delete
try {
[5266] Fix | Delete
if (empty($_POST) || empty($_POST['subaction']) || 'importsettings' != $_POST['subaction'] || !isset($_POST['nonce']) || !is_user_logged_in() || !UpdraftPlus_Options::user_can_manage() || !wp_verify_nonce($_POST['nonce'], 'updraftplus-settings-nonce')) die('Security check');
[5267] Fix | Delete
[5268] Fix | Delete
if (empty($_POST['settings']) || !is_string($_POST['settings'])) die('Invalid data');
[5269] Fix | Delete
[5270] Fix | Delete
$this->import_settings($_POST);
[5271] Fix | Delete
} catch (Exception $e) {
[5272] Fix | Delete
$log_message = 'PHP Fatal Exception error ('.get_class($e).') has occurred during import settings. Error Message: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
[5273] Fix | Delete
error_log($log_message);
[5274] Fix | Delete
echo json_encode(array(
[5275] Fix | Delete
'fatal_error' => true,
[5276] Fix | Delete
'fatal_error_message' => $log_message
[5277] Fix | Delete
));
[5278] Fix | Delete
// @codingStandardsIgnoreLine
[5279] Fix | Delete
} catch (Error $e) {
[5280] Fix | Delete
$log_message = 'PHP Fatal error ('.get_class($e).') has occurred during import settings. Error Message: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
[5281] Fix | Delete
error_log($log_message);
[5282] Fix | Delete
echo json_encode(array(
[5283] Fix | Delete
'fatal_error' => true,
[5284] Fix | Delete
'fatal_error_message' => $log_message
[5285] Fix | Delete
));
[5286] Fix | Delete
}
[5287] Fix | Delete
}
[5288] Fix | Delete
[5289] Fix | Delete
/**
[5290] Fix | Delete
* This method handles the imported json settings it will convert them into a readable format for the existing save settings function, it will also update some of the options to match the new remote storage options format (Apr 2017)
[5291] Fix | Delete
*
[5292] Fix | Delete
* @param Array $settings - The settings from the imported json file
[5293] Fix | Delete
*/
[5294] Fix | Delete
public function import_settings($settings) {
[5295] Fix | Delete
// A bug in UD releases around 1.12.40 - 1.13.3 meant that it was saved in URL-string format, instead of JSON
[5296] Fix | Delete
$perhaps_not_yet_parsed = json_decode(stripslashes($settings['settings']), true);
[5297] Fix | Delete
[5298] Fix | Delete
if (!is_array($perhaps_not_yet_parsed)) {
[5299] Fix | Delete
parse_str($perhaps_not_yet_parsed, $posted_settings);
[5300] Fix | Delete
} else {
[5301] Fix | Delete
$posted_settings = $perhaps_not_yet_parsed;
[5302] Fix | Delete
}
[5303] Fix | Delete
[5304] Fix | Delete
if (!empty($settings['updraftplus_version'])) $posted_settings['updraftplus_version'] = $settings['updraftplus_version'];
[5305] Fix | Delete
[5306] Fix | Delete
// Handle the settings name change of WebDAV and SFTP (Apr 2017) if someone tries to import an old settings to this version
[5307] Fix | Delete
if (isset($posted_settings['updraft_webdav_settings'])) {
[5308] Fix | Delete
$posted_settings['updraft_webdav'] = $posted_settings['updraft_webdav_settings'];
[5309] Fix | Delete
unset($posted_settings['updraft_webdav_settings']);
[5310] Fix | Delete
}
[5311] Fix | Delete
[5312] Fix | Delete
if (isset($posted_settings['updraft_sftp_settings'])) {
[5313] Fix | Delete
$posted_settings['updraft_sftp'] = $posted_settings['updraft_sftp_settings'];
[5314] Fix | Delete
unset($posted_settings['updraft_sftp_settings']);
[5315] Fix | Delete
}
[5316] Fix | Delete
[5317] Fix | Delete
// We also need to wrap some of the options in the new style settings array otherwise later on we will lose the settings if this information is missing
[5318] Fix | Delete
if (empty($posted_settings['updraft_webdav']['settings'])) $posted_settings['updraft_webdav'] = UpdraftPlus_Storage_Methods_Interface::wrap_remote_storage_options($posted_settings['updraft_webdav']);
[5319] Fix | Delete
if (empty($posted_settings['updraft_googledrive']['settings'])) $posted_settings['updraft_googledrive'] = UpdraftPlus_Storage_Methods_Interface::wrap_remote_storage_options($posted_settings['updraft_googledrive']);
[5320] Fix | Delete
if (empty($posted_settings['updraft_googlecloud']['settings'])) $posted_settings['updraft_googlecloud'] = UpdraftPlus_Storage_Methods_Interface::wrap_remote_storage_options($posted_settings['updraft_googlecloud']);
[5321] Fix | Delete
if (empty($posted_settings['updraft_onedrive']['settings'])) $posted_settings['updraft_onedrive'] = UpdraftPlus_Storage_Methods_Interface::wrap_remote_storage_options($posted_settings['updraft_onedrive']);
[5322] Fix | Delete
if (empty($posted_settings['updraft_azure']['settings'])) $posted_settings['updraft_azure'] = UpdraftPlus_Storage_Methods_Interface::wrap_remote_storage_options($posted_settings['updraft_azure']);
[5323] Fix | Delete
if (empty($posted_settings['updraft_dropbox']['settings'])) $posted_settings['updraft_dropbox'] = UpdraftPlus_Storage_Methods_Interface::wrap_remote_storage_options($posted_settings['updraft_dropbox']);
[5324] Fix | Delete
[5325] Fix | Delete
echo json_encode($this->save_settings($posted_settings));
[5326] Fix | Delete
[5327] Fix | Delete
die;
[5328] Fix | Delete
}
[5329] Fix | Delete
[5330] Fix | Delete
/**
[5331] Fix | Delete
* This function will get a list of remote storage methods with valid connection details and create a HTML list of checkboxes
[5332] Fix | Delete
*
[5333] Fix | Delete
* @return String - HTML checkbox list of remote storage methods with valid connection details
[5334] Fix | Delete
*/
[5335] Fix | Delete
private function backup_now_remote_message() {
[5336] Fix | Delete
global $updraftplus;
[5337] Fix | Delete
[5338] Fix | Delete
$services = (array) $updraftplus->just_one($updraftplus->get_canonical_service_list());
[5339] Fix | Delete
$all_services = UpdraftPlus_Storage_Methods_Interface::get_storage_objects_and_ids($services);
[5340] Fix | Delete
$active_remote_storage_list = '';
[5341] Fix | Delete
[5342] Fix | Delete
foreach ($all_services as $method => $sinfo) {
[5343] Fix | Delete
if ('email' == $method) {
[5344] Fix | Delete
$possible_emails = $updraftplus->just_one_email(UpdraftPlus_Options::get_updraft_option('updraft_email'));
[5345] Fix | Delete
if (!empty($possible_emails)) {
[5346] Fix | Delete
$active_remote_storage_list .= '<input class="updraft_remote_service_entity" id="'.$method.'updraft_service" checked="checked" type="checkbox" name="updraft_include_remote_service_'. $method . '" value=""> <label for="'.$method.'updraft_service">'.$updraftplus->backup_methods[$method].'</label><br>';
[5347] Fix | Delete
}
[5348] Fix | Delete
} elseif (empty($sinfo['object']) || empty($sinfo['instance_settings']) || !is_callable(array($sinfo['object'], 'options_exist'))) {
[5349] Fix | Delete
continue;
[5350] Fix | Delete
}
[5351] Fix | Delete
[5352] Fix | Delete
$instance_count = 1;
[5353] Fix | Delete
foreach ($sinfo['instance_settings'] as $instance => $opt) {
[5354] Fix | Delete
if ($sinfo['object']->options_exist($opt)) {
[5355] Fix | Delete
$instance_count_label = (1 == $instance_count) ? '' : ' ('.$instance_count.')';
[5356] Fix | Delete
$label = empty($opt['instance_label']) ? $sinfo['object']->get_description() . $instance_count_label : $opt['instance_label'];
[5357] Fix | Delete
if (!isset($opt['instance_enabled'])) $opt['instance_enabled'] = 1;
[5358] Fix | Delete
$checked = empty($opt['instance_enabled']) ? '' : 'checked="checked"';
[5359] Fix | Delete
$active_remote_storage_list .= '<input class="updraft_remote_service_entity" id="'.$method.'updraft_service_'.$instance.'" ' . $checked . ' type="checkbox" name="updraft_include_remote_service_'. $method . '" value="'.$instance.'"> <label for="'.$method.'updraft_service_'.$instance.'">'.$label.'</label><br>';
[5360] Fix | Delete
$instance_count++;
[5361] Fix | Delete
}
[5362] Fix | Delete
}
[5363] Fix | Delete
}
[5364] Fix | Delete
[5365] Fix | Delete
$service = $updraftplus->just_one(UpdraftPlus_Options::get_updraft_option('updraft_service'));
[5366] Fix | Delete
if (is_string($service)) $service = array($service);
[5367] Fix | Delete
if (!is_array($service)) $service = array();
[5368] Fix | Delete
[5369] Fix | Delete
$no_remote_configured = (empty($service) || array('none') === $service || array('') === $service) ? true : false;
[5370] Fix | Delete
[5371] Fix | Delete
if ($no_remote_configured && empty($active_remote_storage_list)) {
[5372] Fix | Delete
return '<input type="checkbox" disabled="disabled" id="backupnow_includecloud"> <em>'.sprintf(__("Backup won't be sent to any remote storage - none has been saved in the %s", 'updraftplus'), '<a href="'.UpdraftPlus_Options::admin_page_url().'?page=updraftplus&amp;tab=settings" id="updraft_backupnow_gotosettings">'.__('settings', 'updraftplus')).'</a>. '.__('Not got any remote storage?', 'updraftplus').' <a href="'.apply_filters('updraftplus_com_link', "https://updraftplus.com/landing/vault/").'" target="_blank">'.__("Check out UpdraftPlus Vault.", 'updraftplus').'</a></em>';
[5373] Fix | Delete
}
[5374] Fix | Delete
[5375] Fix | Delete
if (empty($active_remote_storage_list)) {
[5376] Fix | Delete
$active_remote_storage_list = '<p>'.__('No remote storage locations with valid options found.', 'updraftplus').'</p>';
[5377] Fix | Delete
}
[5378] Fix | Delete
[5379] Fix | Delete
return '<input type="checkbox" id="backupnow_includecloud" checked="checked"> <label for="backupnow_includecloud">'.__("Send this backup to remote storage", 'updraftplus').'</label> (<a href="'.$updraftplus->get_current_clean_url().'" id="backupnow_includecloud_showmoreoptions">...</a>)<br><div id="backupnow_includecloud_moreoptions" class="updraft-hidden" style="display:none;"><em>'. __('The following remote storage options are configured.', 'updraftplus').'</em><br>'.$active_remote_storage_list.'</div>';
[5380] Fix | Delete
}
[5381] Fix | Delete
[5382] Fix | Delete
/**
[5383] Fix | Delete
* This method works through the passed in settings array and saves the settings to the database clearing old data and setting up a return array with content to update the page via ajax
[5384] Fix | Delete
*
[5385] Fix | Delete
* @param array $settings An array of settings taking from the admin page ready to be saved to the database
[5386] Fix | Delete
* @return array An array response containing the status of the update along with content to be used to update the admin page.
[5387] Fix | Delete
*/
[5388] Fix | Delete
public function save_settings($settings) {
[5389] Fix | Delete
[5390] Fix | Delete
global $updraftplus;
[5391] Fix | Delete
[5392] Fix | Delete
// Make sure that settings filters are registered
[5393] Fix | Delete
UpdraftPlus_Options::admin_init();
[5394] Fix | Delete
[5395] Fix | Delete
$more_files_path_updated = false;
[5396] Fix | Delete
[5397] Fix | Delete
if (isset($settings['updraftplus_version']) && $updraftplus->version == $settings['updraftplus_version']) {
[5398] Fix | Delete
[5399] Fix | Delete
$return_array = array('saved' => true);
[5400] Fix | Delete
[5401] Fix | Delete
$add_to_post_keys = array('updraft_interval', 'updraft_interval_database', 'updraft_interval_increments', 'updraft_starttime_files', 'updraft_starttime_db', 'updraft_startday_files', 'updraft_startday_db');
[5402] Fix | Delete
[5403] Fix | Delete
// If database and files are on same schedule, override the db day/time settings
[5404] Fix | Delete
if (isset($settings['updraft_interval_database']) && isset($settings['updraft_interval_database']) && $settings['updraft_interval_database'] == $settings['updraft_interval'] && isset($settings['updraft_starttime_files'])) {
[5405] Fix | Delete
$settings['updraft_starttime_db'] = $settings['updraft_starttime_files'];
[5406] Fix | Delete
$settings['updraft_startday_db'] = $settings['updraft_startday_files'];
[5407] Fix | Delete
}
[5408] Fix | Delete
foreach ($add_to_post_keys as $key) {
[5409] Fix | Delete
// For add-ons that look at $_POST to find saved settings, add the relevant keys to $_POST so that they find them there
[5410] Fix | Delete
if (isset($settings[$key])) {
[5411] Fix | Delete
$_POST[$key] = $settings[$key];
[5412] Fix | Delete
}
[5413] Fix | Delete
}
[5414] Fix | Delete
[5415] Fix | Delete
// Check if updraft_include_more_path is set, if it is then we need to update the page, if it's not set but there's content already in the database that is cleared down below so again we should update the page.
[5416] Fix | Delete
$more_files_path_updated = false;
[5417] Fix | Delete
[5418] Fix | Delete
// i.e. If an option has been set, or if it was currently active in the settings
[5419] Fix | Delete
if (isset($settings['updraft_include_more_path']) || UpdraftPlus_Options::get_updraft_option('updraft_include_more_path')) {
[5420] Fix | Delete
$more_files_path_updated = true;
[5421] Fix | Delete
}
[5422] Fix | Delete
[5423] Fix | Delete
// Wipe the extra retention rules, as they are not saved correctly if the last one is deleted
[5424] Fix | Delete
UpdraftPlus_Options::update_updraft_option('updraft_retain_extrarules', array());
[5425] Fix | Delete
UpdraftPlus_Options::update_updraft_option('updraft_email', array());
[5426] Fix | Delete
UpdraftPlus_Options::update_updraft_option('updraft_report_warningsonly', array());
[5427] Fix | Delete
UpdraftPlus_Options::update_updraft_option('updraft_report_wholebackup', array());
[5428] Fix | Delete
UpdraftPlus_Options::update_updraft_option('updraft_extradbs', array());
[5429] Fix | Delete
UpdraftPlus_Options::update_updraft_option('updraft_include_more_path', array());
[5430] Fix | Delete
[5431] Fix | Delete
$relevant_keys = $updraftplus->get_settings_keys();
[5432] Fix | Delete
[5433] Fix | Delete
if (isset($settings['updraft_auto_updates']) && in_array('updraft_auto_updates', $relevant_keys)) {
[5434] Fix | Delete
$updraftplus->set_automatic_updates($settings['updraft_auto_updates']);
[5435] Fix | Delete
unset($settings['updraft_auto_updates']); // unset the key and its value to prevent being processed the second time
[5436] Fix | Delete
}
[5437] Fix | Delete
[5438] Fix | Delete
if (method_exists('UpdraftPlus_Options', 'mass_options_update')) {
[5439] Fix | Delete
$original_settings = $settings;
[5440] Fix | Delete
$settings = UpdraftPlus_Options::mass_options_update($settings);
[5441] Fix | Delete
$mass_updated = true;
[5442] Fix | Delete
}
[5443] Fix | Delete
[5444] Fix | Delete
foreach ($settings as $key => $value) {
[5445] Fix | Delete
[5446] Fix | Delete
if (in_array($key, $relevant_keys)) {
[5447] Fix | Delete
if ('updraft_service' == $key && is_array($value)) {
[5448] Fix | Delete
foreach ($value as $subkey => $subvalue) {
[5449] Fix | Delete
if ('0' == $subvalue) unset($value[$subkey]);
[5450] Fix | Delete
}
[5451] Fix | Delete
}
[5452] Fix | Delete
[5453] Fix | Delete
// This flag indicates that either the stored database option was changed, or that the supplied option was changed before being stored. It isn't comprehensive - it's only used to update some UI elements with invalid input.
[5454] Fix | Delete
$updated = empty($mass_updated) ? (is_string($value) && UpdraftPlus_Options::get_updraft_option($key) != $value) : (is_string($value) && (!isset($original_settings[$key]) || $original_settings[$key] != $value));
[5455] Fix | Delete
[5456] Fix | Delete
if (empty($mass_updated)) UpdraftPlus_Options::update_updraft_option($key, $value);
[5457] Fix | Delete
[5458] Fix | Delete
// Add information on what has changed to array to loop through to update links etc.
[5459] Fix | Delete
// Restricting to strings for now, to prevent any unintended leakage (since this is just used for UI updating)
[5460] Fix | Delete
if ($updated) {
[5461] Fix | Delete
$value = UpdraftPlus_Options::get_updraft_option($key);
[5462] Fix | Delete
if (is_string($value)) $return_array['changed'][$key] = $value;
[5463] Fix | Delete
}
[5464] Fix | Delete
// @codingStandardsIgnoreLine
[5465] Fix | Delete
} else {
[5466] Fix | Delete
// This section is ignored by CI otherwise it will complain the ELSE is empty.
[5467] Fix | Delete
[5468] Fix | Delete
// When last active, it was catching: option_page, action, _wpnonce, _wp_http_referer, updraft_s3_endpoint, updraft_dreamobjects_endpoint. The latter two are empty; probably don't need to be in the page at all.
[5469] Fix | Delete
// error_log("Non-UD key when saving from POSTed data: ".$key);
[5470] Fix | Delete
}
[5471] Fix | Delete
}
[5472] Fix | Delete
} else {
[5473] Fix | Delete
$return_array = array('saved' => false, 'error_message' => sprintf(__('UpdraftPlus seems to have been updated to version (%s), which is different to the version running when this settings page was loaded. Please reload the settings page before trying to save settings.', 'updraftplus'), $updraftplus->version));
[5474] Fix | Delete
}
[5475] Fix | Delete
[5476] Fix | Delete
// Checking for various possible messages
[5477] Fix | Delete
$updraft_dir = $updraftplus->backups_dir_location(false);
[5478] Fix | Delete
$really_is_writable = UpdraftPlus_Filesystem_Functions::really_is_writable($updraft_dir);
[5479] Fix | Delete
$dir_info = $this->really_writable_message($really_is_writable, $updraft_dir);
[5480] Fix | Delete
$button_title = esc_attr(__('This button is disabled because your backup directory is not writable (see the settings).', 'updraftplus'));
[5481] Fix | Delete
[5482] Fix | Delete
$return_array['backup_now_message'] = $this->backup_now_remote_message();
[5483] Fix | Delete
[5484] Fix | Delete
$return_array['backup_dir'] = array('writable' => $really_is_writable, 'message' => $dir_info, 'button_title' => $button_title);
[5485] Fix | Delete
[5486] Fix | Delete
// Check if $more_files_path_updated is true, is so then there's a change and we should update the backup modal
[5487] Fix | Delete
if ($more_files_path_updated) {
[5488] Fix | Delete
$return_array['updraft_include_more_path'] = $this->files_selector_widgetry('backupnow_files_', false, 'sometimes');
[5489] Fix | Delete
}
[5490] Fix | Delete
[5491] Fix | Delete
// Because of the single AJAX call, we need to remove the existing UD messages from the 'all_admin_notices' action
[5492] Fix | Delete
remove_all_actions('all_admin_notices');
[5493] Fix | Delete
[5494] Fix | Delete
// Moving from 2 to 1 ajax call
[5495] Fix | Delete
ob_start();
[5496] Fix | Delete
[5497] Fix | Delete
$service = UpdraftPlus_Options::get_updraft_option('updraft_service');
[5498] Fix | Delete
[5499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function