Commit f14f9842 authored by Ankit Agarwal's avatar Ankit Agarwal
Browse files

MDL-32827 calendar: update eventtype of broken event in bulk instead of doing it one by one

parent 686ca2f5
......@@ -1070,22 +1070,14 @@ function xmldb_main_upgrade($oldversion) {
}
if ($oldversion < 2012072600.01) {
$rs = $DB->get_recordset('event', array( 'eventtype' => ''), '', 'id, courseid, groupid, userid, modulename');
foreach ($rs as $event) {
if ($event->courseid == $SITE->id) { // Site event
$DB->set_field('event', 'eventtype', 'site', array('id' => $event->id));
} else if ($event->courseid != 0 && $event->groupid == 0 && ($event->modulename == 'assignment' || $event->modulename == 'assign')) {
// Course assingment event
$DB->set_field('event', 'eventtype', 'due', array('id' => $event->id));
} else if ($event->courseid != 0 && $event->groupid == 0) { // Course event
$DB->set_field('event', 'eventtype', 'course', array('id' => $event->id));
} else if ($event->groupid) { // Group event
$DB->set_field('event', 'eventtype', 'group', array('id' => $event->id));
} else if ($event->userid) { // User event
$DB->set_field('event', 'eventtype', 'user', array('id' => $event->id));
}
}
$rs->close();
// Handle events with empty eventtype //MDL-32827
$DB->set_field('event', 'eventtype', 'site', array('eventtype' => '', 'courseid' => $SITE->id));
$DB->set_field_select('event', 'eventtype', 'due', "eventtype = '' AND courseid != 0 AND groupid = 0 AND (modulename = 'assignment' OR modulename = 'assign')");
$DB->set_field_select('event', 'eventtype', 'course', "eventtype = '' AND courseid != 0 AND groupid = 0");
$DB->set_field_select('event', 'eventtype', 'group', "eventtype = '' AND groupid != 0");
$DB->set_field_select('event', 'eventtype', 'user', "eventtype = '' AND userid != 0");
// Main savepoint reached
upgrade_main_savepoint(true, 2012072600.01);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment