mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
MDL-61870 mod_assign: Fix/clean up imported group override duedates
Applying patch supplied from Damyon Wiese to address the root-cause of this issue in the backup/restore logic.
This commit is contained in:
parent
6bcc6f877a
commit
8ea4df50c9
@ -387,6 +387,12 @@ class restore_assign_activity_structure_step extends restore_activity_structure_
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip group overrides if we are not restoring groupinfo.
|
||||
$groupinfo = $this->get_setting_value('groups');
|
||||
if (!$groupinfo && !is_null($data->groupid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$data->assignid = $this->get_new_parentid('assign');
|
||||
|
||||
if (!is_null($data->userid)) {
|
||||
|
@ -171,15 +171,5 @@ function xmldb_assign_upgrade($oldversion) {
|
||||
// Automatically generated Moodle v3.5.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
if ($oldversion < 2018061100) {
|
||||
require_once($CFG->dirroot.'/mod/assign/upgradelib.php');
|
||||
|
||||
// Clean up duplicate event records that may have been generated from MDL-61870.
|
||||
delete_assignment_duplicate_group_events();
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2018061100, 'assign');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -260,6 +260,9 @@ function assign_update_events($assign, $override = null) {
|
||||
$conds['userid'] = $override->userid;
|
||||
} else if (isset($override->groupid)) {
|
||||
$conds['groupid'] = $override->groupid;
|
||||
} else {
|
||||
// This is not a valid override, it may have been left from a bad import or restore.
|
||||
$conds['groupid'] = $conds['userid'] = 0;
|
||||
}
|
||||
}
|
||||
$oldevents = $DB->get_records('event', $conds, 'id ASC');
|
||||
|
@ -438,78 +438,3 @@ function get_assignments_with_rescaled_null_grades() {
|
||||
|
||||
return $assignments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determined if the assignment has any duplicate group events generated from
|
||||
* restoring Course backup without groups, and deletes any records found.
|
||||
*
|
||||
* Bug fix data clean up for MDL-61870.
|
||||
*/
|
||||
function delete_assignment_duplicate_group_events() {
|
||||
global $DB;
|
||||
|
||||
// Get all Course's assign course modules to check for any duplicate group events to remove.
|
||||
list($coursesinsql, $coursesinparams) = $DB->get_in_or_equal(array_keys(get_courses()), SQL_PARAMS_NAMED);
|
||||
|
||||
$query = "SELECT cm.id AS id,
|
||||
cm.course AS courseid,
|
||||
cm.instance AS instanceid
|
||||
FROM {course_modules} cm
|
||||
JOIN {modules} m ON m.id = cm.module
|
||||
WHERE m.name = :modulename
|
||||
AND (cm.course $coursesinsql)";
|
||||
$params = ['modulename' => 'assign'];
|
||||
$params += $coursesinparams;
|
||||
|
||||
foreach ($DB->get_records_sql($query, $params) as $cm) {
|
||||
$selectgroupevents = "courseid = :courseid
|
||||
AND modulename = :modulename
|
||||
AND eventtype = :eventtype
|
||||
AND instance = :instance
|
||||
AND groupid <> :groupid
|
||||
AND priority <> :priority";
|
||||
$paramsgroupevents = [
|
||||
'courseid' => $cm->courseid,
|
||||
'modulename' => 'assign',
|
||||
'eventtype' => 'due',
|
||||
'instance' => $cm->instanceid,
|
||||
'groupid' => 0,
|
||||
'priority' => 0
|
||||
];
|
||||
|
||||
// Retrieve all the Course's assign events associated with group overrides,
|
||||
// which will be use to look for duplicate records that need to be deleted.
|
||||
foreach ($DB->get_records_select('event', $selectgroupevents, $paramsgroupevents) as $groupevent) {
|
||||
// Delete any duplicates that match the details of the current groupevent but the id does not
|
||||
// match the current groupevent id and course id, groupid is 0, and priority is NULL.
|
||||
$selectduplicates = "id != :eventid
|
||||
AND courseid != :courseid
|
||||
AND groupid = 0
|
||||
AND userid = :userid
|
||||
AND repeatid = :repeatid
|
||||
AND modulename = :modulename
|
||||
AND type = :type
|
||||
AND eventtype = :eventtype
|
||||
AND timestart = :timestart
|
||||
AND timeduration = :timeduration
|
||||
AND timesort = :timesort
|
||||
AND sequence = :sequence
|
||||
AND priority IS NULL";
|
||||
$paramsduplicates = [
|
||||
'eventid' => $groupevent->id,
|
||||
'courseid' => $groupevent->courseid,
|
||||
'groupid' => 0,
|
||||
'userid' => $groupevent->userid,
|
||||
'repeatid' => $groupevent->repeatid,
|
||||
'modulename' => $groupevent->modulename,
|
||||
'type' => $groupevent->type,
|
||||
'eventtype' => $groupevent->eventtype,
|
||||
'timestart' => $groupevent->timestart,
|
||||
'timeduration' => $groupevent->timeduration,
|
||||
'timesort' => $groupevent->timesort,
|
||||
'sequence' => $groupevent->sequence
|
||||
];
|
||||
$DB->delete_records_select('event', $selectduplicates, $paramsduplicates);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,6 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'mod_assign'; // Full name of the plugin (used for diagnostics).
|
||||
$plugin->version = 2018061100; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->version = 2018051400; // The current module version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2018050800; // Requires this Moodle version.
|
||||
$plugin->cron = 60;
|
||||
|
Loading…
x
Reference in New Issue
Block a user