// 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;
}
}
}
+ // 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) {
echo $OUTPUT->help_icon(moodle_help_icon::make("coursefullname", get_string("fullname"))) ;
if (isset($err["fullname"])) echo $OUTPUT->error_text($err["fullname"]);
echo"</td></tr>";
+ } 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 "<tr valign=\"top\"> ";
echo "<td align=\"right\"> ";
print_string("startdate");
}
echo "</td></tr>";
} else {
- /// If user cannot create course, prevent any change in startyear/month/day (so restore wont calculate any roll. MDL-12922
+ /// If user lacks the moodle/restore:rolldates completely, prevent any change in startyear/month/day (so restore won't perform any roll)
echo '<input type="hidden" name="startyear" value="0" />';
echo '<input type="hidden" name="startmonth" value="0" />';
echo '<input type="hidden" name="startday" value="0" />';
}
}
+ /**
+ * true or false function to see if user can roll dates on restore (any course is enough)
+ * @return bool
+ */
+ function restore_user_can_roll_dates() {
+ global $USER;
+ // if user has moodle/restore:rolldates capability at system or any course cat return true
+
+ if (has_capability('moodle/restore:rolldates', get_context_instance(CONTEXT_SYSTEM))) {
+ return true;
+ }
+
+ // Non-cached - get accessinfo
+ if (isset($USER->access)) {
+ $accessinfo = $USER->access;
+ } else {
+ $accessinfo = get_user_access_sitewide($USER->id);
+ }
+ $courses = get_user_courses_bycap($USER->id, 'moodle/restore:rolldates', $accessinfo, true);
+ return !empty($courses);
+ }
+
//write activity date changes to the html log file, and update date values in the the xml array
function restore_log_date_changes($recordtype, &$restore, &$xml, $TAGS, $NAMETAG='NAME') {