Browse files

MDL-32827 calendar: update eventtype of broken event in bulk instead…

… of doing it one by one
  • Loading branch information...
1 parent 44793f3 commit a521e7e01f4211670819ea9ed1989e0add836f8f @ankitagarwal ankitagarwal committed Jul 31, 2012
Showing with 9 additions and 16 deletions.
  1. +9 −16 lib/db/upgrade.php
View
25 lib/db/upgrade.php
@@ -7122,22 +7122,15 @@ function xmldb_main_upgrade($oldversion) {
}
if ($oldversion < 2011120504.05) {
- $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, 2011120504.05);
}

0 comments on commit a521e7e

Please sign in to comment.