Merge branch 'MDL-29877_bad_grade_item' of git://github.com/andyjdavis/moodle
authorDamyon Wiese <damyon@moodle.com>
Fri, 12 Apr 2013 03:14:10 +0000 (11:14 +0800)
committerDamyon Wiese <damyon@moodle.com>
Fri, 12 Apr 2013 03:14:10 +0000 (11:14 +0800)
Conflicts:
version.php

1  2 
lib/db/upgrade.php

diff --combined lib/db/upgrade.php
@@@ -1460,7 -1460,7 +1460,7 @@@ function xmldb_main_upgrade($oldversion
  
      if ($oldversion < 2012111200.01) {
          // Force the rebuild of the cache of every courses, some cached information could contain wrong icon references.
 -        rebuild_course_cache();
 +        $DB->execute('UPDATE {course} set modinfo = ?, sectioncache = ?', array(null, null));
  
          // Main savepoint reached.
          upgrade_main_savepoint(true, 2012111200.01);
          $DB->delete_records('course_sections_avail_fields', array('userfield' => 'interests'));
          $DB->delete_records('course_modules_avail_fields', array('userfield' => 'interests'));
          // Clear course cache (will be rebuilt on first visit) in case of changes to these.
 -        rebuild_course_cache(0, true);
 +        $DB->execute('UPDATE {course} set modinfo = ?, sectioncache = ?', array(null, null));
  
          upgrade_main_savepoint(true, 2013022600.00);
      }
          upgrade_main_savepoint(true, 2013040300.01);
      }
  
+     if ($oldversion < 2013040500.01) {
+         // MDL-29877 Some bad restores created grade items with no category information.
+         $sql = "UPDATE mdl_grade_items
+                    SET categoryid = courseid
+                  WHERE itemtype <> 'course' and itemtype <> 'category'
+                        AND categoryid IS NULL";
+         $DB->execute($sql);
+         upgrade_main_savepoint(true, 2013040500.01);
+     }
      return true;
  }