MDL-38173 Courselib: Improvements to the upgrade step for this issue.
Set the upgrade step to only run for affected versions correctly (use a range of affected versions) and make the query to find affected sections DISTINCT. Also rename aliases and variables to use cm and cmid.
This commit is contained in:
committed by
Damyon Wiese
parent
fcf890aa2b
commit
6369652f17
+15
-16
@@ -1063,7 +1063,7 @@ function xmldb_main_upgrade($oldversion) {
|
||||
|
||||
// This is checking to see if the site has been running a specific version with a bug in it
|
||||
// because this upgrade step is slow and is only needed if the site has been running with the previous patch installed.
|
||||
if ($oldversion == 2012062504.08) {
|
||||
if ($oldversion >= 2012062504.08 && $oldversion < 2012062504.11) {
|
||||
// Retrieve the list of course_sections as a recordset to save memory.
|
||||
// This is to fix a regression caused by MDL-37939.
|
||||
// In this case the upgrade step is fixing records where:
|
||||
@@ -1074,33 +1074,32 @@ function xmldb_main_upgrade($oldversion) {
|
||||
// The syntax for the like query is looking for a value in a comma separated list.
|
||||
// It adds a comma to either site of the list and then searches for LIKE '%,id,%'.
|
||||
$sequenceconcat = $DB->sql_concat("','", 's.sequence', "','");
|
||||
$moduleconcat = $DB->sql_concat("'%,'", 'm.id', "',%'");
|
||||
$sql = 'SELECT
|
||||
s.id,
|
||||
$moduleconcat = $DB->sql_concat("'%,'", 'cm.id', "',%'");
|
||||
$sql = 'SELECT
|
||||
DISTINCT(s.id),
|
||||
s.course,
|
||||
s.sequence
|
||||
FROM
|
||||
{course_modules} m
|
||||
{course_modules} cm
|
||||
JOIN {course_sections} s
|
||||
ON
|
||||
m.course = s.course AND
|
||||
m.section != s.id
|
||||
WHERE ' . $sequenceconcat . ' LIKE ' . $moduleconcat;
|
||||
cm.course = s.course
|
||||
WHERE cm.section != s.id AND ' . $sequenceconcat . ' LIKE ' . $moduleconcat;
|
||||
$coursesections = $DB->get_recordset_sql($sql);
|
||||
|
||||
foreach ($coursesections as $coursesection) {
|
||||
// Retrieve all of the actual modules in this course and section combination to reduce DB calls
|
||||
// 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
|
||||
// Break out the current sequence so that we can compare it.
|
||||
$currentsequence = explode(',', $coursesection->sequence);
|
||||
$orphanlist = array();
|
||||
|
||||
// Check each of the modules in the current sequence
|
||||
foreach ($currentsequence as $module) {
|
||||
if (!empty($module) && !isset($actualsectionmodules[$module])) {
|
||||
$orphanlist[] = $module;
|
||||
// Check each of the modules in the current sequence.
|
||||
foreach ($currentsequence as $cmid) {
|
||||
if (!empty($cmid) && !isset($actualsectionmodules[$cmid])) {
|
||||
$orphanlist[] = $cmid;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1110,7 +1109,7 @@ function xmldb_main_upgrade($oldversion) {
|
||||
|
||||
$DB->set_field_select('course_modules', 'section', $coursesection->id, $sql, $params);
|
||||
|
||||
// And clear the sectioncache and modinfo cache - they'll be regenerated on next use
|
||||
// And clear the sectioncache and modinfo cache - they'll be regenerated on next use.
|
||||
$course = new stdClass();
|
||||
$course->id = $coursesection->course;
|
||||
$course->sectioncache = null;
|
||||
@@ -1121,7 +1120,7 @@ function xmldb_main_upgrade($oldversion) {
|
||||
$coursesections->close();
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2012062504.10);
|
||||
upgrade_main_savepoint(true, 2012062504.11);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
$version = 2012062504.10; // YYYYMMDD = weekly release date of this DEV branch
|
||||
$version = 2012062504.11; // YYYYMMDD = weekly release date of this DEV branch
|
||||
// RR = release increments - 00 in DEV branches
|
||||
// .XX = incremental changes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user