diff --git a/backup/restore_check.html b/backup/restore_check.html index f2ac3785432..528f3988cb0 100644 --- a/backup/restore_check.html +++ b/backup/restore_check.html @@ -35,7 +35,7 @@ // Only apply rolling of dates if differences are bigger than one day // that should solve current problems with daylight changes between // backup and restore - if ($restore->course_startdateoffset < 24 * 60 * 60) { + if (abs($restore->course_startdateoffset) < 24 * 60 * 60) { $coursestartdatedateoffset = 0; $restore->course_startdateoffset = 0; } @@ -282,6 +282,26 @@ } } + // If we have selected to roll dates on restore and the user is missing + // such capability (moodle/restore:rolldates) in the target course/category, + // disable roll of dates and warn + if ($restore->course_startdateoffset != 0) { + $canrolldates = false; // init to false + + // if we know the target course, check the capability on it + if (!empty($restore->course_id)) { + $canrolldates = has_capability('moodle/restore:rolldates', get_context_instance(CONTEXT_COURSE, $restore->course_id)); + // if we know the target category, check capability on it + } else if (!empty($restore->restore_restorecatto)) { + $canrolldates = has_capability('moodle/restore:rolldates', get_context_instance(CONTEXT_COURSECAT, $restore->restore_restorecatto)); + } + + if (!$canrolldates) { + $messages[] = get_string ("noteusercannotrolldatesoncontext"); + $restore->course_startdateoffset = 0; + } + } + //Check if we've selected any mod's user info and restore->users //is set to none. Change it to course and inform. if ($restore->users == 2) { diff --git a/backup/restore_form.html b/backup/restore_form.html index 982ee1b29a5..3e4c90354b8 100644 --- a/backup/restore_form.html +++ b/backup/restore_form.html @@ -276,6 +276,15 @@ function selectItemInCheckboxByName(formId, checkName, checked ) { echo $OUTPUT->help_icon(moodle_help_icon::make("coursefullname", get_string("fullname"))) ; if (isset($err["fullname"])) echo $OUTPUT->error_text($err["fullname"]); echo""; + } else { + // nothing to show here if the user cannot create users + } + + // If user can roll dates (in any course is enough for now) show the roll dates option. + // Important: The final restore check step will validate, once we know the final category/course + // where the restore is happening, if the user is really capable of rolling dates there, noticing + // and disabling roll if not allowed. + if (restore_user_can_roll_dates()) { echo "