Merge branch 'MDL-37939-m23' of https://github.com/andrewnicols/moodle into MOODLE_23...
authorDamyon Wiese <damyon@moodle.com>
Mon, 18 Feb 2013 05:31:40 +0000 (13:31 +0800)
committerDamyon Wiese <damyon@moodle.com>
Mon, 18 Feb 2013 05:31:40 +0000 (13:31 +0800)
Conflicts:
lib/db/upgrade.php

1  2 
lib/db/upgrade.php
version.php

@@@ -992,23 -992,54 +992,72 @@@ function xmldb_main_upgrade($oldversion
          upgrade_main_savepoint(true, 2012062503.07);
      }
  
 -    if ($oldversion < 2012062504.06) {
 +    if ($oldversion < 2012062504.07) {
 +        // Fixing possible wrong MIME types for SMART Notebook files.
 +        $extensions = array('%.gallery', '%.galleryitem', '%.gallerycollection', '%.nbk', '%.notebook', '%.xbk');
 +        $select = $DB->sql_like('filename', '?', false);
 +        foreach ($extensions as $extension) {
 +            $DB->set_field_select(
 +                'files',
 +                'mimetype',
 +                'application/x-smarttech-notebook',
 +                $select,
 +                array($extension)
 +            );
 +        }
 +
 +        // Main savepoint reached.
 +        upgrade_main_savepoint(true, 2012062504.07);
 +    }
 +
++    if ($oldversion < 2012062504.08) {
+         // Retrieve the list of course_sections as a recordset to save memory
+         $coursesections = $DB->get_recordset('course_sections', null, 'course, id', 'id, course, sequence');
+         foreach ($coursesections as $coursesection) {
+             // Retrieve all of the actual modules in this course and section combination to reduce DB calls
+             $actualsectionmodules = $DB->get_records('course_modules',
+                     array('course' => $coursesection->course, 'section' => $coursesection->id), '', 'id, section');
+             // Break out the current sequence so that we can compare it
+             $currentsequence = explode(',', $coursesection->sequence);
+             $newsequence = array();
+             // Check each of the modules in the current sequence
+             foreach ($currentsequence as $module) {
+                 if (isset($actualsectionmodules[$module])) {
+                     $newsequence[] = $module;
+                     // We unset the actualsectionmodules so that we don't get duplicates and that we can add orphaned
+                     // modules later
+                     unset($actualsectionmodules[$module]);
+                 }
+             }
+             // Append any modules which have somehow been orphaned
+             foreach ($actualsectionmodules as $module) {
+                 $newsequence[] = $module->id;
+             }
+             // Piece it all back together
+             $sequence = implode(',', $newsequence);
+             // Only update if there have been changes
+             if ($sequence !== $coursesection->sequence) {
+                 $coursesection->sequence = $sequence;
+                 $DB->update_record('course_sections', $coursesection);
+                 // And clear the sectioncache and modinfo cache - they'll be regenerated on next use
+                 $course = new stdClass();
+                 $course->id = $coursesection->course;
+                 $course->sectioncache = null;
+                 $course->modinfo = null;
+                 $DB->update_record('course', $course);
+             }
+         }
+         $coursesections->close();
+         // Main savepoint reached.
 -        upgrade_main_savepoint(true, 2012062504.06);
++        upgrade_main_savepoint(true, 2012062504.08);
+     }
      return true;
  }
diff --cc version.php
@@@ -30,7 -30,7 +30,7 @@@
  defined('MOODLE_INTERNAL') || die();
  
  
- $version  = 2012062504.07;              // YYYYMMDD      = weekly release date of this DEV branch
 -$version  = 2012062504.06;              // YYYYMMDD      = weekly release date of this DEV branch
++$version  = 2012062504.08;              // YYYYMMDD      = weekly release date of this DEV branch
                                          //         RR    = release increments - 00 in DEV branches
                                          //           .XX = incremental changes