Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-37939 Course: Correct broken sequence data

  • Loading branch information...
commit 59a0ba3bdcfb4fab1e266541299cced0ec90aa85 1 parent 1dd6835
Andrew Nicols andrewnicols authored

Showing 2 changed files with 50 additions and 1 deletion. Show diff stats Hide diff stats

  1. +49 0 lib/db/upgrade.php
  2. +1 1  version.php
49 lib/db/upgrade.php
@@ -1577,5 +1577,54 @@ function xmldb_main_upgrade($oldversion) {
1577 1577 upgrade_main_savepoint(true, 2013021100.01);
1578 1578 }
1579 1579
  1580 + if ($oldversion < 2013021400.01) {
  1581 + // Retrieve the list of course_sections as a recordset to save memory
  1582 + $coursesections = $DB->get_recordset('course_sections', null, 'course, id', 'id, course, sequence');
  1583 + foreach ($coursesections as $coursesection) {
  1584 + // Retrieve all of the actual modules in this course and section combination to reduce DB calls
  1585 + $actualsectionmodules = $DB->get_records('course_modules',
  1586 + array('course' => $coursesection->course, 'section' => $coursesection->id), '', 'id, section');
  1587 +
  1588 + // Break out the current sequence so that we can compare it
  1589 + $currentsequence = explode(',', $coursesection->sequence);
  1590 + $newsequence = array();
  1591 +
  1592 + // Check each of the modules in the current sequence
  1593 + foreach ($currentsequence as $module) {
  1594 + if (isset($actualsectionmodules[$module])) {
  1595 + $newsequence[] = $module;
  1596 + // We unset the actualsectionmodules so that we don't get duplicates and that we can add orphaned
  1597 + // modules later
  1598 + unset($actualsectionmodules[$module]);
  1599 + }
  1600 + }
  1601 +
  1602 + // Append any modules which have somehow been orphaned
  1603 + foreach ($actualsectionmodules as $module) {
  1604 + $newsequence[] = $module->id;
  1605 + }
  1606 +
  1607 + // Piece it all back together
  1608 + $sequence = implode(',', $newsequence);
  1609 +
  1610 + // Only update if there have been changes
  1611 + if ($sequence !== $coursesection->sequence) {
  1612 + $coursesection->sequence = $sequence;
  1613 + $DB->update_record('course_sections', $coursesection);
  1614 +
  1615 + // And clear the sectioncache and modinfo cache - they'll be regenerated on next use
  1616 + $course = new stdClass();
  1617 + $course->id = $coursesection->course;
  1618 + $course->sectioncache = null;
  1619 + $course->modinfo = null;
  1620 + $DB->update_record('course', $course);
  1621 + }
  1622 + }
  1623 + $coursesections->close();
  1624 +
  1625 + // Main savepoint reached.
  1626 + upgrade_main_savepoint(true, 2013021400.01);
  1627 + }
  1628 +
1580 1629 return true;
1581 1630 }
2  version.php
@@ -30,7 +30,7 @@
30 30 defined('MOODLE_INTERNAL') || die();
31 31
32 32
33   -$version = 2013021400.00; // YYYYMMDD = weekly release date of this DEV branch
  33 +$version = 2013021400.01; // YYYYMMDD = weekly release date of this DEV branch
34 34 // RR = release increments - 00 in DEV branches
35 35 // .XX = incremental changes
36 36

0 comments on commit 59a0ba3

Please sign in to comment.
Something went wrong with that request. Please try again.