Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp...
File: admin.php
* @param Boolean|String $job_id - the job to get information about; or, if not specified, all jobs
[3500] Fix | Delete
*
[3501] Fix | Delete
* @return Array|Boolean - the requested information, or false if it was not found. Format differs depending on whether info on all jobs, or a single job, was requested.
[3502] Fix | Delete
*/
[3503] Fix | Delete
public function get_cron($job_id = false) {
[3504] Fix | Delete
[3505] Fix | Delete
$cron = get_option('cron');
[3506] Fix | Delete
if (!is_array($cron)) $cron = array();
[3507] Fix | Delete
if (false === $job_id) return $cron;
[3508] Fix | Delete
[3509] Fix | Delete
foreach ($cron as $time => $job) {
[3510] Fix | Delete
if (!isset($job['updraft_backup_resume'])) continue;
[3511] Fix | Delete
foreach ($job['updraft_backup_resume'] as $info) {
[3512] Fix | Delete
if (isset($info['args'][1]) && $job_id == $info['args'][1]) {
[3513] Fix | Delete
global $updraftplus;
[3514] Fix | Delete
$jobdata = $updraftplus->jobdata_getarray($job_id);
[3515] Fix | Delete
return is_array($jobdata) ? array($time, $jobdata) : false;
[3516] Fix | Delete
}
[3517] Fix | Delete
}
[3518] Fix | Delete
}
[3519] Fix | Delete
}
[3520] Fix | Delete
[3521] Fix | Delete
/**
[3522] Fix | Delete
* Gets HTML describing the active jobs
[3523] Fix | Delete
*
[3524] Fix | Delete
* @param Boolean $this_job_only A value for $this_job_only also causes something non-empty to always be returned (to allow detection of the job having started on the front-end)
[3525] Fix | Delete
*
[3526] Fix | Delete
* @return String - the HTML
[3527] Fix | Delete
*/
[3528] Fix | Delete
private function print_active_jobs($this_job_only = false) {
[3529] Fix | Delete
$cron = $this->get_cron();
[3530] Fix | Delete
$ret = '';
[3531] Fix | Delete
[3532] Fix | Delete
foreach ($cron as $time => $job) {
[3533] Fix | Delete
if (!isset($job['updraft_backup_resume'])) continue;
[3534] Fix | Delete
foreach ($job['updraft_backup_resume'] as $info) {
[3535] Fix | Delete
if (isset($info['args'][1])) {
[3536] Fix | Delete
$job_id = $info['args'][1];
[3537] Fix | Delete
if (false === $this_job_only || $job_id == $this_job_only) {
[3538] Fix | Delete
$ret .= $this->print_active_job($job_id, false, $time, $info['args'][0]);
[3539] Fix | Delete
}
[3540] Fix | Delete
}
[3541] Fix | Delete
}
[3542] Fix | Delete
}
[3543] Fix | Delete
// A value for $this_job_only implies that output is required
[3544] Fix | Delete
if (false !== $this_job_only && !$ret) {
[3545] Fix | Delete
$ret = $this->print_active_job($this_job_only);
[3546] Fix | Delete
if ('' == $ret) {
[3547] Fix | Delete
global $updraftplus;
[3548] Fix | Delete
$log_file = $updraftplus->get_logfile_name($this_job_only);
[3549] Fix | Delete
// if the file exists, the backup was booted. Check if the information about completion is found in the log, or if it was modified at least 2 minutes ago.
[3550] Fix | Delete
if (file_exists($log_file) && ($updraftplus->found_backup_complete_in_logfile($this_job_only) || (time() - filemtime($log_file)) > 120)) {
[3551] Fix | Delete
// The presence of the exact ID matters to the front-end - indicates that the backup job has at least begun
[3552] Fix | Delete
$ret = '<div class="active-jobs updraft_finished" id="updraft-jobid-'.$this_job_only.'"><em>'.__('The backup has finished running', 'updraftplus').'</em> - <a class="updraft-log-link" data-jobid="'.$this_job_only.'">'.__('View Log', 'updraftplus').'</a></div>';
[3553] Fix | Delete
}
[3554] Fix | Delete
}
[3555] Fix | Delete
}
[3556] Fix | Delete
[3557] Fix | Delete
return $ret;
[3558] Fix | Delete
}
[3559] Fix | Delete
[3560] Fix | Delete
/**
[3561] Fix | Delete
* Print the HTML for a particular job
[3562] Fix | Delete
*
[3563] Fix | Delete
* @param String $job_id - the job identifier/nonce
[3564] Fix | Delete
* @param Boolean $is_oneshot - whether this backup should be 'one shot', i.e. no resumptions
[3565] Fix | Delete
* @param Boolean|Integer $time
[3566] Fix | Delete
* @param Integer $next_resumption
[3567] Fix | Delete
*
[3568] Fix | Delete
* @return String
[3569] Fix | Delete
*/
[3570] Fix | Delete
private function print_active_job($job_id, $is_oneshot = false, $time = false, $next_resumption = false) {
[3571] Fix | Delete
[3572] Fix | Delete
$ret = '';
[3573] Fix | Delete
[3574] Fix | Delete
global $updraftplus;
[3575] Fix | Delete
$jobdata = $updraftplus->jobdata_getarray($job_id);
[3576] Fix | Delete
[3577] Fix | Delete
if (false == apply_filters('updraftplus_print_active_job_continue', true, $is_oneshot, $next_resumption, $jobdata)) return '';
[3578] Fix | Delete
[3579] Fix | Delete
if (!isset($jobdata['backup_time'])) return '';
[3580] Fix | Delete
[3581] Fix | Delete
$backupable_entities = $updraftplus->get_backupable_file_entities(true, true);
[3582] Fix | Delete
[3583] Fix | Delete
$began_at = isset($jobdata['backup_time']) ? get_date_from_gmt(gmdate('Y-m-d H:i:s', (int) $jobdata['backup_time']), 'D, F j, Y H:i') : '?';
[3584] Fix | Delete
[3585] Fix | Delete
$backup_label = !empty($jobdata['label']) ? $jobdata['label'] : '';
[3586] Fix | Delete
[3587] Fix | Delete
$remote_sent = (!empty($jobdata['service']) && ((is_array($jobdata['service']) && in_array('remotesend', $jobdata['service'])) || 'remotesend' === $jobdata['service'])) ? true : false;
[3588] Fix | Delete
[3589] Fix | Delete
$jobstatus = empty($jobdata['jobstatus']) ? 'unknown' : $jobdata['jobstatus'];
[3590] Fix | Delete
$stage = 0;
[3591] Fix | Delete
switch ($jobstatus) {
[3592] Fix | Delete
// Stage 0
[3593] Fix | Delete
case 'begun':
[3594] Fix | Delete
$curstage = __('Backup begun', 'updraftplus');
[3595] Fix | Delete
break;
[3596] Fix | Delete
// Stage 1
[3597] Fix | Delete
case 'filescreating':
[3598] Fix | Delete
$stage = 1;
[3599] Fix | Delete
$curstage = __('Creating file backup zips', 'updraftplus');
[3600] Fix | Delete
if (!empty($jobdata['filecreating_substatus']) && isset($backupable_entities[$jobdata['filecreating_substatus']['e']]['description'])) {
[3601] Fix | Delete
[3602] Fix | Delete
$sdescrip = preg_replace('/ \(.*\)$/', '', $backupable_entities[$jobdata['filecreating_substatus']['e']]['description']);
[3603] Fix | Delete
if (strlen($sdescrip) > 20 && isset($jobdata['filecreating_substatus']['e']) && is_array($jobdata['filecreating_substatus']['e']) && isset($backupable_entities[$jobdata['filecreating_substatus']['e']]['shortdescription'])) $sdescrip = $backupable_entities[$jobdata['filecreating_substatus']['e']]['shortdescription'];
[3604] Fix | Delete
$curstage .= ' ('.$sdescrip.')';
[3605] Fix | Delete
if (isset($jobdata['filecreating_substatus']['i']) && isset($jobdata['filecreating_substatus']['t'])) {
[3606] Fix | Delete
$stage = min(2, 1 + ($jobdata['filecreating_substatus']['i']/max($jobdata['filecreating_substatus']['t'], 1)));
[3607] Fix | Delete
}
[3608] Fix | Delete
}
[3609] Fix | Delete
break;
[3610] Fix | Delete
case 'filescreated':
[3611] Fix | Delete
$stage = 2;
[3612] Fix | Delete
$curstage = __('Created file backup zips', 'updraftplus');
[3613] Fix | Delete
break;
[3614] Fix | Delete
// Stage 4
[3615] Fix | Delete
case 'clonepolling':
[3616] Fix | Delete
$stage = 4;
[3617] Fix | Delete
$curstage = __('Clone server being provisioned and booted (can take several minutes)', 'updraftplus');
[3618] Fix | Delete
break;
[3619] Fix | Delete
case 'clouduploading':
[3620] Fix | Delete
$stage = 4;
[3621] Fix | Delete
$curstage = __('Uploading files to remote storage', 'updraftplus');
[3622] Fix | Delete
if ($remote_sent) $curstage = __('Sending files to remote site', 'updraftplus');
[3623] Fix | Delete
if (isset($jobdata['uploading_substatus']['t']) && isset($jobdata['uploading_substatus']['i'])) {
[3624] Fix | Delete
$t = max((int) $jobdata['uploading_substatus']['t'], 1);
[3625] Fix | Delete
$i = min($jobdata['uploading_substatus']['i']/$t, 1);
[3626] Fix | Delete
$p = min($jobdata['uploading_substatus']['p'], 1);
[3627] Fix | Delete
$pd = $i + $p/$t;
[3628] Fix | Delete
$stage = 4 + $pd;
[3629] Fix | Delete
$curstage .= ' ('.floor(100*$pd).'%, '.sprintf(__('file %d of %d', 'updraftplus'), (int)$jobdata['uploading_substatus']['i']+1, $t).')';
[3630] Fix | Delete
}
[3631] Fix | Delete
break;
[3632] Fix | Delete
case 'pruning':
[3633] Fix | Delete
$stage = 5;
[3634] Fix | Delete
$curstage = __('Pruning old backup sets', 'updraftplus');
[3635] Fix | Delete
break;
[3636] Fix | Delete
case 'resumingforerrors':
[3637] Fix | Delete
$stage = -1;
[3638] Fix | Delete
$curstage = __('Waiting until scheduled time to retry because of errors', 'updraftplus');
[3639] Fix | Delete
break;
[3640] Fix | Delete
// Stage 6
[3641] Fix | Delete
case 'finished':
[3642] Fix | Delete
$stage = 6;
[3643] Fix | Delete
$curstage = __('Backup finished', 'updraftplus');
[3644] Fix | Delete
break;
[3645] Fix | Delete
default:
[3646] Fix | Delete
// Database creation and encryption occupies the space from 2 to 4. Databases are created then encrypted, then the next database is created/encrypted, etc.
[3647] Fix | Delete
if ('dbcreated' == substr($jobstatus, 0, 9)) {
[3648] Fix | Delete
$jobstatus = 'dbcreated';
[3649] Fix | Delete
$whichdb = substr($jobstatus, 9);
[3650] Fix | Delete
if (!is_numeric($whichdb)) $whichdb = 0;
[3651] Fix | Delete
$howmanydbs = max((empty($jobdata['backup_database']) || !is_array($jobdata['backup_database'])) ? 1 : count($jobdata['backup_database']), 1);
[3652] Fix | Delete
$perdbspace = 2/$howmanydbs;
[3653] Fix | Delete
[3654] Fix | Delete
$stage = min(4, 2 + ($whichdb+2)*$perdbspace);
[3655] Fix | Delete
[3656] Fix | Delete
$curstage = __('Created database backup', 'updraftplus');
[3657] Fix | Delete
[3658] Fix | Delete
} elseif ('dbcreating' == substr($jobstatus, 0, 10)) {
[3659] Fix | Delete
$whichdb = substr($jobstatus, 10);
[3660] Fix | Delete
if (!is_numeric($whichdb)) $whichdb = 0;
[3661] Fix | Delete
$howmanydbs = (empty($jobdata['backup_database']) || !is_array($jobdata['backup_database'])) ? 1 : count($jobdata['backup_database']);
[3662] Fix | Delete
$perdbspace = 2/$howmanydbs;
[3663] Fix | Delete
$jobstatus = 'dbcreating';
[3664] Fix | Delete
[3665] Fix | Delete
$stage = min(4, 2 + $whichdb*$perdbspace);
[3666] Fix | Delete
[3667] Fix | Delete
$curstage = __('Creating database backup', 'updraftplus');
[3668] Fix | Delete
if (!empty($jobdata['dbcreating_substatus']['t'])) {
[3669] Fix | Delete
$curstage .= ' ('.sprintf(__('table: %s', 'updraftplus'), $jobdata['dbcreating_substatus']['t']).')';
[3670] Fix | Delete
if (!empty($jobdata['dbcreating_substatus']['i']) && !empty($jobdata['dbcreating_substatus']['a'])) {
[3671] Fix | Delete
$substage = max(0.001, ($jobdata['dbcreating_substatus']['i'] / max($jobdata['dbcreating_substatus']['a'], 1)));
[3672] Fix | Delete
$stage += $substage * $perdbspace * 0.5;
[3673] Fix | Delete
}
[3674] Fix | Delete
}
[3675] Fix | Delete
} elseif ('dbencrypting' == substr($jobstatus, 0, 12)) {
[3676] Fix | Delete
$whichdb = substr($jobstatus, 12);
[3677] Fix | Delete
if (!is_numeric($whichdb)) $whichdb = 0;
[3678] Fix | Delete
$howmanydbs = (empty($jobdata['backup_database']) || !is_array($jobdata['backup_database'])) ? 1 : count($jobdata['backup_database']);
[3679] Fix | Delete
$perdbspace = 2/$howmanydbs;
[3680] Fix | Delete
$stage = min(4, 2 + $whichdb*$perdbspace + $perdbspace*0.5);
[3681] Fix | Delete
$jobstatus = 'dbencrypting';
[3682] Fix | Delete
$curstage = __('Encrypting database', 'updraftplus');
[3683] Fix | Delete
} elseif ('dbencrypted' == substr($jobstatus, 0, 11)) {
[3684] Fix | Delete
$whichdb = substr($jobstatus, 11);
[3685] Fix | Delete
if (!is_numeric($whichdb)) $whichdb = 0;
[3686] Fix | Delete
$howmanydbs = (empty($jobdata['backup_database']) || !is_array($jobdata['backup_database'])) ? 1 : count($jobdata['backup_database']);
[3687] Fix | Delete
$jobstatus = 'dbencrypted';
[3688] Fix | Delete
$perdbspace = 2/$howmanydbs;
[3689] Fix | Delete
$stage = min(4, 2 + $whichdb*$perdbspace + $perdbspace);
[3690] Fix | Delete
$curstage = __('Encrypted database', 'updraftplus');
[3691] Fix | Delete
} else {
[3692] Fix | Delete
$curstage = __('Unknown', 'updraftplus');
[3693] Fix | Delete
}
[3694] Fix | Delete
}
[3695] Fix | Delete
[3696] Fix | Delete
$runs_started = empty($jobdata['runs_started']) ? array() : $jobdata['runs_started'];
[3697] Fix | Delete
$time_passed = empty($jobdata['run_times']) ? array() : $jobdata['run_times'];
[3698] Fix | Delete
$last_checkin_ago = -1;
[3699] Fix | Delete
if (is_array($time_passed)) {
[3700] Fix | Delete
foreach ($time_passed as $run => $passed) {
[3701] Fix | Delete
if (isset($runs_started[$run])) {
[3702] Fix | Delete
$time_ago = microtime(true) - ($runs_started[$run] + $time_passed[$run]);
[3703] Fix | Delete
if ($time_ago < $last_checkin_ago || -1 == $last_checkin_ago) $last_checkin_ago = $time_ago;
[3704] Fix | Delete
}
[3705] Fix | Delete
}
[3706] Fix | Delete
}
[3707] Fix | Delete
[3708] Fix | Delete
$next_res_after = (int) $time-time();
[3709] Fix | Delete
$next_res_txt = $is_oneshot ? '' : sprintf(__('next resumption: %d', 'updraftplus'), $next_resumption).($next_resumption ? ' '.sprintf(__('(after %ss)', 'updraftplus'), $next_res_after) : '').' ';
[3710] Fix | Delete
$last_activity_txt = ($last_checkin_ago >= 0) ? sprintf(__('last activity: %ss ago', 'updraftplus'), floor($last_checkin_ago)).' ' : '';
[3711] Fix | Delete
[3712] Fix | Delete
if (($last_checkin_ago < 50 && $next_res_after>30) || $is_oneshot) {
[3713] Fix | Delete
$show_inline_info = $last_activity_txt;
[3714] Fix | Delete
$title_info = $next_res_txt;
[3715] Fix | Delete
} else {
[3716] Fix | Delete
$show_inline_info = $next_res_txt;
[3717] Fix | Delete
$title_info = $last_activity_txt;
[3718] Fix | Delete
}
[3719] Fix | Delete
[3720] Fix | Delete
$ret .= '<div class="updraft_row">';
[3721] Fix | Delete
[3722] Fix | Delete
$ret .= '<div class="updraft_col"><div class="updraft_jobtimings next-resumption';
[3723] Fix | Delete
[3724] Fix | Delete
if (!empty($jobdata['is_autobackup'])) $ret .= ' isautobackup';
[3725] Fix | Delete
[3726] Fix | Delete
$is_clone = empty($jobdata['clone_job']) ? '0' : '1';
[3727] Fix | Delete
[3728] Fix | Delete
$clone_url = empty($jobdata['clone_url']) ? false : true;
[3729] Fix | Delete
[3730] Fix | Delete
$ret .= '" data-jobid="'.$job_id.'" data-lastactivity="'.(int) $last_checkin_ago.'" data-nextresumption="'.$next_resumption.'" data-nextresumptionafter="'.$next_res_after.'" title="'.esc_attr(sprintf(__('Job ID: %s', 'updraftplus'), $job_id)).$title_info.'">'.(!empty($backup_label) ? esc_html($backup_label) : $began_at).
[3731] Fix | Delete
'</div></div>';
[3732] Fix | Delete
[3733] Fix | Delete
$ret .= '<div class="updraft_col updraft_progress_container">';
[3734] Fix | Delete
// Existence of the 'updraft-jobid-(id)' id is checked for in other places, so do not modify this
[3735] Fix | Delete
$ret .= '<div class="job-id" data-isclone="'.$is_clone.'" id="updraft-jobid-'.$job_id.'">';
[3736] Fix | Delete
[3737] Fix | Delete
if ($clone_url) $ret .= '<div class="updraft_clone_url" data-clone_url="' . $jobdata['clone_url'] . '"></div>';
[3738] Fix | Delete
[3739] Fix | Delete
$ret .= apply_filters('updraft_printjob_beforewarnings', '', $jobdata, $job_id);
[3740] Fix | Delete
[3741] Fix | Delete
if (!empty($jobdata['warnings']) && is_array($jobdata['warnings'])) {
[3742] Fix | Delete
$ret .= '<ul class="disc">';
[3743] Fix | Delete
foreach ($jobdata['warnings'] as $warning) {
[3744] Fix | Delete
$ret .= '<li>'.sprintf(__('Warning: %s', 'updraftplus'), make_clickable(htmlspecialchars($warning))).'</li>';
[3745] Fix | Delete
}
[3746] Fix | Delete
$ret .= '</ul>';
[3747] Fix | Delete
}
[3748] Fix | Delete
[3749] Fix | Delete
$ret .= '<div class="curstage">';
[3750] Fix | Delete
// $ret .= '<span class="curstage-info">'.htmlspecialchars($curstage).'</span>';
[3751] Fix | Delete
$ret .= htmlspecialchars($curstage);
[3752] Fix | Delete
// we need to add this data-progress attribute in order to be able to update the progress bar in UDC
[3753] Fix | Delete
[3754] Fix | Delete
$ret .= '<div class="updraft_percentage" data-info="'.esc_attr($curstage).'" data-progress="'.(($stage>0) ? (ceil((100/6)*$stage)) : '0').'" style="height: 100%; width:'.(($stage>0) ? (ceil((100/6)*$stage)) : '0').'%"></div>';
[3755] Fix | Delete
$ret .= '</div></div>';
[3756] Fix | Delete
[3757] Fix | Delete
$ret .= '<div class="updraft_last_activity">';
[3758] Fix | Delete
[3759] Fix | Delete
$ret .= $show_inline_info;
[3760] Fix | Delete
if (!empty($show_inline_info)) $ret .= ' - ';
[3761] Fix | Delete
[3762] Fix | Delete
$file_nonce = empty($jobdata['file_nonce']) ? $job_id : $jobdata['file_nonce'];
[3763] Fix | Delete
[3764] Fix | Delete
$ret .= '<a data-fileid="'.$file_nonce.'" data-jobid="'.$job_id.'" href="'.UpdraftPlus_Options::admin_page_url().'?page=updraftplus&action=downloadlog&updraftplus_backup_nonce='.$file_nonce.'" class="updraft-log-link">'.__('show log', 'updraftplus').'</a>';
[3765] Fix | Delete
if (!$is_oneshot) $ret .=' - <a href="#" data-jobid="'.$job_id.'" title="'.esc_attr(__('Note: the progress bar below is based on stages, NOT time. Do not stop the backup simply because it seems to have remained in the same place for a while - that is normal.', 'updraftplus')).'" class="updraft_jobinfo_delete">'.__('stop', 'updraftplus').'</a>';
[3766] Fix | Delete
$ret .= '</div>';
[3767] Fix | Delete
[3768] Fix | Delete
$ret .= '</div></div>';
[3769] Fix | Delete
[3770] Fix | Delete
return $ret;
[3771] Fix | Delete
[3772] Fix | Delete
}
[3773] Fix | Delete
[3774] Fix | Delete
private function delete_old_dirs_go($show_return = true) {
[3775] Fix | Delete
echo $show_return ? '<h1>UpdraftPlus - '.__('Remove old directories', 'updraftplus').'</h1>' : '<h2>'.__('Remove old directories', 'updraftplus').'</h2>';
[3776] Fix | Delete
[3777] Fix | Delete
if ($this->delete_old_dirs()) {
[3778] Fix | Delete
echo '<p>'.__('Old directories successfully removed.', 'updraftplus').'</p><br>';
[3779] Fix | Delete
} else {
[3780] Fix | Delete
echo '<p>',__('Old directory removal failed for some reason. You may want to do this manually.', 'updraftplus').'</p><br>';
[3781] Fix | Delete
}
[3782] Fix | Delete
if ($show_return) echo '<b>'.__('Actions', 'updraftplus').':</b> <a href="'.UpdraftPlus_Options::admin_page_url().'?page=updraftplus">'.__('Return to UpdraftPlus configuration', 'updraftplus').'</a>';
[3783] Fix | Delete
}
[3784] Fix | Delete
[3785] Fix | Delete
/**
[3786] Fix | Delete
* Deletes the -old directories that are created when a backup is restored.
[3787] Fix | Delete
*
[3788] Fix | Delete
* @return Boolean. Can also exit (something we ought to probably review)
[3789] Fix | Delete
*/
[3790] Fix | Delete
private function delete_old_dirs() {
[3791] Fix | Delete
global $wp_filesystem, $updraftplus;
[3792] Fix | Delete
$credentials = request_filesystem_credentials(wp_nonce_url(UpdraftPlus_Options::admin_page_url()."?page=updraftplus&action=updraft_delete_old_dirs", 'updraftplus-credentialtest-nonce', 'updraft_delete_old_dirs_nonce'));
[3793] Fix | Delete
$wpfs = WP_Filesystem($credentials);
[3794] Fix | Delete
if (!empty($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
[3795] Fix | Delete
foreach ($wp_filesystem->errors->get_error_messages() as $message) show_message($message);
[3796] Fix | Delete
exit;
[3797] Fix | Delete
}
[3798] Fix | Delete
if (!$wpfs) exit;
[3799] Fix | Delete
[3800] Fix | Delete
// From WP_CONTENT_DIR - which contains 'themes'
[3801] Fix | Delete
$ret = $this->delete_old_dirs_dir($wp_filesystem->wp_content_dir());
[3802] Fix | Delete
[3803] Fix | Delete
$updraft_dir = $updraftplus->backups_dir_location();
[3804] Fix | Delete
if ($updraft_dir) {
[3805] Fix | Delete
$ret4 = $updraft_dir ? $this->delete_old_dirs_dir($updraft_dir, false) : true;
[3806] Fix | Delete
} else {
[3807] Fix | Delete
$ret4 = true;
[3808] Fix | Delete
}
[3809] Fix | Delete
[3810] Fix | Delete
$plugs = untrailingslashit($wp_filesystem->wp_plugins_dir());
[3811] Fix | Delete
if ($wp_filesystem->is_dir($plugs.'-old')) {
[3812] Fix | Delete
echo "<strong>".__('Delete', 'updraftplus').": </strong>plugins-old: ";
[3813] Fix | Delete
if (!$wp_filesystem->delete($plugs.'-old', true)) {
[3814] Fix | Delete
$ret3 = false;
[3815] Fix | Delete
echo "<strong>".__('Failed', 'updraftplus')."</strong><br>";
[3816] Fix | Delete
echo $updraftplus->log_permission_failure_message($wp_filesystem->wp_content_dir(), 'Delete '.$plugs.'-old');
[3817] Fix | Delete
} else {
[3818] Fix | Delete
$ret3 = true;
[3819] Fix | Delete
echo "<strong>".__('OK', 'updraftplus')."</strong><br>";
[3820] Fix | Delete
}
[3821] Fix | Delete
} else {
[3822] Fix | Delete
$ret3 = true;
[3823] Fix | Delete
}
[3824] Fix | Delete
[3825] Fix | Delete
return $ret && $ret3 && $ret4;
[3826] Fix | Delete
}
[3827] Fix | Delete
[3828] Fix | Delete
private function delete_old_dirs_dir($dir, $wpfs = true) {
[3829] Fix | Delete
[3830] Fix | Delete
$dir = trailingslashit($dir);
[3831] Fix | Delete
[3832] Fix | Delete
global $wp_filesystem, $updraftplus;
[3833] Fix | Delete
[3834] Fix | Delete
if ($wpfs) {
[3835] Fix | Delete
$list = $wp_filesystem->dirlist($dir);
[3836] Fix | Delete
} else {
[3837] Fix | Delete
$list = scandir($dir);
[3838] Fix | Delete
}
[3839] Fix | Delete
if (!is_array($list)) return false;
[3840] Fix | Delete
[3841] Fix | Delete
$ret = true;
[3842] Fix | Delete
foreach ($list as $item) {
[3843] Fix | Delete
$name = (is_array($item)) ? $item['name'] : $item;
[3844] Fix | Delete
if ("-old" == substr($name, -4, 4)) {
[3845] Fix | Delete
// recursively delete
[3846] Fix | Delete
print "<strong>".__('Delete', 'updraftplus').": </strong>".htmlspecialchars($name).": ";
[3847] Fix | Delete
[3848] Fix | Delete
if ($wpfs) {
[3849] Fix | Delete
if (!$wp_filesystem->delete($dir.$name, true)) {
[3850] Fix | Delete
$ret = false;
[3851] Fix | Delete
echo "<strong>".__('Failed', 'updraftplus')."</strong><br>";
[3852] Fix | Delete
echo $updraftplus->log_permission_failure_message($dir, 'Delete '.$dir.$name);
[3853] Fix | Delete
} else {
[3854] Fix | Delete
echo "<strong>".__('OK', 'updraftplus')."</strong><br>";
[3855] Fix | Delete
}
[3856] Fix | Delete
} else {
[3857] Fix | Delete
if (UpdraftPlus_Filesystem_Functions::remove_local_directory($dir.$name)) {
[3858] Fix | Delete
echo "<strong>".__('OK', 'updraftplus')."</strong><br>";
[3859] Fix | Delete
} else {
[3860] Fix | Delete
$ret = false;
[3861] Fix | Delete
echo "<strong>".__('Failed', 'updraftplus')."</strong><br>";
[3862] Fix | Delete
echo $updraftplus->log_permission_failure_message($dir, 'Delete '.$dir.$name);
[3863] Fix | Delete
}
[3864] Fix | Delete
}
[3865] Fix | Delete
}
[3866] Fix | Delete
}
[3867] Fix | Delete
return $ret;
[3868] Fix | Delete
}
[3869] Fix | Delete
[3870] Fix | Delete
/**
[3871] Fix | Delete
* The aim is to get a directory that is writable by the webserver, because that's the only way we can create zip files
[3872] Fix | Delete
*
[3873] Fix | Delete
* @return Boolean|WP_Error true if successful, otherwise false or a WP_Error
[3874] Fix | Delete
*/
[3875] Fix | Delete
private function create_backup_dir() {
[3876] Fix | Delete
[3877] Fix | Delete
global $wp_filesystem, $updraftplus;
[3878] Fix | Delete
[3879] Fix | Delete
if (false === ($credentials = request_filesystem_credentials(UpdraftPlus_Options::admin_page().'?page=updraftplus&action=updraft_create_backup_dir&nonce='.wp_create_nonce('create_backup_dir')))) {
[3880] Fix | Delete
return false;
[3881] Fix | Delete
}
[3882] Fix | Delete
[3883] Fix | Delete
if (!WP_Filesystem($credentials)) {
[3884] Fix | Delete
// our credentials were no good, ask the user for them again
[3885] Fix | Delete
request_filesystem_credentials(UpdraftPlus_Options::admin_page().'?page=updraftplus&action=updraft_create_backup_dir&nonce='.wp_create_nonce('create_backup_dir'), '', true);
[3886] Fix | Delete
return false;
[3887] Fix | Delete
}
[3888] Fix | Delete
[3889] Fix | Delete
$updraft_dir = $updraftplus->backups_dir_location();
[3890] Fix | Delete
[3891] Fix | Delete
$default_backup_dir = $wp_filesystem->find_folder(dirname($updraft_dir)).basename($updraft_dir);
[3892] Fix | Delete
[3893] Fix | Delete
$updraft_dir = ($updraft_dir) ? $wp_filesystem->find_folder(dirname($updraft_dir)).basename($updraft_dir) : $default_backup_dir;
[3894] Fix | Delete
[3895] Fix | Delete
if (!$wp_filesystem->is_dir($default_backup_dir) && !$wp_filesystem->mkdir($default_backup_dir, 0775)) {
[3896] Fix | Delete
$wperr = new WP_Error;
[3897] Fix | Delete
if ($wp_filesystem->errors->get_error_code()) {
[3898] Fix | Delete
foreach ($wp_filesystem->errors->get_error_messages() as $message) {
[3899] Fix | Delete
$wperr->add('mkdir_error', $message);
[3900] Fix | Delete
}
[3901] Fix | Delete
return $wperr;
[3902] Fix | Delete
} else {
[3903] Fix | Delete
return new WP_Error('mkdir_error', __('The request to the filesystem to create the directory failed.', 'updraftplus'));
[3904] Fix | Delete
}
[3905] Fix | Delete
}
[3906] Fix | Delete
[3907] Fix | Delete
if ($wp_filesystem->is_dir($default_backup_dir)) {
[3908] Fix | Delete
[3909] Fix | Delete
if (UpdraftPlus_Filesystem_Functions::really_is_writable($updraft_dir)) return true;
[3910] Fix | Delete
[3911] Fix | Delete
@$wp_filesystem->chmod($default_backup_dir, 0775);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[3912] Fix | Delete
if (UpdraftPlus_Filesystem_Functions::really_is_writable($updraft_dir)) return true;
[3913] Fix | Delete
[3914] Fix | Delete
@$wp_filesystem->chmod($default_backup_dir, 0777);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[3915] Fix | Delete
[3916] Fix | Delete
if (UpdraftPlus_Filesystem_Functions::really_is_writable($updraft_dir)) {
[3917] Fix | Delete
echo '<p>'.__('The folder was created, but we had to change its file permissions to 777 (world-writable) to be able to write to it. You should check with your hosting provider that this will not cause any problems', 'updraftplus').'</p>';
[3918] Fix | Delete
return true;
[3919] Fix | Delete
} else {
[3920] Fix | Delete
@$wp_filesystem->chmod($default_backup_dir, 0775);// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[3921] Fix | Delete
$show_dir = (0 === strpos($default_backup_dir, ABSPATH)) ? substr($default_backup_dir, strlen(ABSPATH)) : $default_backup_dir;
[3922] Fix | Delete
return new WP_Error('writable_error', __('The folder exists, but your webserver does not have permission to write to it.', 'updraftplus').' '.__('You will need to consult with your web hosting provider to find out how to set permissions for a WordPress plugin to write to the directory.', 'updraftplus').' ('.$show_dir.')');
[3923] Fix | Delete
}
[3924] Fix | Delete
}
[3925] Fix | Delete
[3926] Fix | Delete
return true;
[3927] Fix | Delete
}
[3928] Fix | Delete
[3929] Fix | Delete
/**
[3930] Fix | Delete
* scans the content dir to see if any -old dirs are present
[3931] Fix | Delete
*
[3932] Fix | Delete
* @param Boolean $print_as_comment Echo information in an HTML comment
[3933] Fix | Delete
* @return Boolean
[3934] Fix | Delete
*/
[3935] Fix | Delete
private function scan_old_dirs($print_as_comment = false) {
[3936] Fix | Delete
global $updraftplus;
[3937] Fix | Delete
$dirs = scandir(untrailingslashit(WP_CONTENT_DIR));
[3938] Fix | Delete
if (!is_array($dirs)) $dirs = array();
[3939] Fix | Delete
$dirs_u = @scandir($updraftplus->backups_dir_location());// phpcs:ignore Generic.PHP.NoSilencedErrors.Discouraged
[3940] Fix | Delete
if (!is_array($dirs_u)) $dirs_u = array();
[3941] Fix | Delete
foreach (array_merge($dirs, $dirs_u) as $dir) {
[3942] Fix | Delete
if (preg_match('/-old$/', $dir)) {
[3943] Fix | Delete
if ($print_as_comment) echo '<!--'.htmlspecialchars($dir).'-->';
[3944] Fix | Delete
return true;
[3945] Fix | Delete
}
[3946] Fix | Delete
}
[3947] Fix | Delete
// No need to scan ABSPATH - we don't backup there
[3948] Fix | Delete
if (is_dir(untrailingslashit(WP_PLUGIN_DIR).'-old')) {
[3949] Fix | Delete
if ($print_as_comment) echo '<!--'.htmlspecialchars(untrailingslashit(WP_PLUGIN_DIR).'-old').'-->';
[3950] Fix | Delete
return true;
[3951] Fix | Delete
}
[3952] Fix | Delete
return false;
[3953] Fix | Delete
}
[3954] Fix | Delete
[3955] Fix | Delete
/**
[3956] Fix | Delete
* Outputs html for a storage method using the parameters passed in, this version should be removed when all remote storages use the multi version
[3957] Fix | Delete
*
[3958] Fix | Delete
* @param String $method a list of methods to be used when
[3959] Fix | Delete
* @param String $header the table header content
[3960] Fix | Delete
* @param String $contents the table contents
[3961] Fix | Delete
*/
[3962] Fix | Delete
public function storagemethod_row($method, $header, $contents) {
[3963] Fix | Delete
?>
[3964] Fix | Delete
<tr class="updraftplusmethod <?php echo $method;?>">
[3965] Fix | Delete
<th><?php echo $header;?></th>
[3966] Fix | Delete
<td><?php echo $contents;?></td>
[3967] Fix | Delete
</tr>
[3968] Fix | Delete
<?php
[3969] Fix | Delete
}
[3970] Fix | Delete
[3971] Fix | Delete
/**
[3972] Fix | Delete
* Outputs html for a storage method using the parameters passed in, this version of the method is compatible with multi storage options
[3973] Fix | Delete
*
[3974] Fix | Delete
* @param string $classes a list of classes to be used when
[3975] Fix | Delete
* @param string $header the table header content
[3976] Fix | Delete
* @param string $contents the table contents
[3977] Fix | Delete
*/
[3978] Fix | Delete
public function storagemethod_row_multi($classes, $header, $contents) {
[3979] Fix | Delete
?>
[3980] Fix | Delete
<tr class="<?php echo $classes;?>">
[3981] Fix | Delete
<th><?php echo $header;?></th>
[3982] Fix | Delete
<td><?php echo $contents;?></td>
[3983] Fix | Delete
</tr>
[3984] Fix | Delete
<?php
[3985] Fix | Delete
}
[3986] Fix | Delete
[3987] Fix | Delete
/**
[3988] Fix | Delete
* Returns html for a storage method using the parameters passed in, this version of the method is compatible with multi storage options
[3989] Fix | Delete
*
[3990] Fix | Delete
* @param string $classes a list of classes to be used when
[3991] Fix | Delete
* @param string $header the table header content
[3992] Fix | Delete
* @param string $contents the table contents
[3993] Fix | Delete
* @return string handlebars html template
[3994] Fix | Delete
*/
[3995] Fix | Delete
public function get_storagemethod_row_multi_configuration_template($classes, $header, $contents) {
[3996] Fix | Delete
return '<tr class="'.esc_attr($classes).'">
[3997] Fix | Delete
<th>'.$header.'</th>
[3998] Fix | Delete
<td>'.$contents.'</td>
[3999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function