mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 12:40:01 +01:00
Merge branch 'MDL-32215-master' of git://github.com/sammarshallou/moodle
Conflicts: course/simpletest/testcourselib.php lib/db/upgrade.php version.php
This commit is contained in:
commit
e7e0f8d27f
@ -2984,8 +2984,11 @@ function move_section($course, $section, $move) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$DB->set_field("course_sections", "section", $sectiondest, array("id"=>$sectionrecord->id));
|
||||
// Three-step change ensures that the section always remains unique (there is
|
||||
// a unique index now)
|
||||
$DB->set_field("course_sections", "section", -$sectiondest, array("id"=>$sectionrecord->id));
|
||||
$DB->set_field("course_sections", "section", $section, array("id"=>$sectiondestrecord->id));
|
||||
$DB->set_field("course_sections", "section", $sectiondest, array("id"=>$sectionrecord->id));
|
||||
|
||||
// Update highlighting if the move affects highlighted section
|
||||
if ($course->marker == $section) {
|
||||
@ -2999,8 +3002,8 @@ function move_section($course, $section, $move) {
|
||||
course_set_display($course->id, $sectiondest);
|
||||
}
|
||||
|
||||
// Check for duplicates and fix order if needed.
|
||||
// There is a very rare case that some sections in the same course have the same section id.
|
||||
// Fix order if needed. The database prevents duplicate sections, but it is
|
||||
// possible there could be a gap in the numbering.
|
||||
$sections = $DB->get_records('course_sections', array('course'=>$course->id), 'section ASC');
|
||||
$n = 0;
|
||||
foreach ($sections as $section) {
|
||||
@ -3040,17 +3043,27 @@ function move_section_to($course, $section, $destination) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sections = reorder_sections($sections, $section, $destination);
|
||||
$movedsections = reorder_sections($sections, $section, $destination);
|
||||
|
||||
// Update all sections
|
||||
foreach ($sections as $id => $position) {
|
||||
$DB->set_field('course_sections', 'section', $position, array('id' => $id));
|
||||
// Update all sections. Do this in 2 steps to avoid breaking database
|
||||
// uniqueness constraint
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
foreach ($movedsections as $id => $position) {
|
||||
if ($sections[$id] !== $position) {
|
||||
$DB->set_field('course_sections', 'section', -$position, array('id' => $id));
|
||||
}
|
||||
}
|
||||
foreach ($movedsections as $id => $position) {
|
||||
if ($sections[$id] !== $position) {
|
||||
$DB->set_field('course_sections', 'section', $position, array('id' => $id));
|
||||
}
|
||||
}
|
||||
|
||||
// if the focus is on the section that is being moved, then move the focus along
|
||||
if (course_get_display($course->id) == $section) {
|
||||
course_set_display($course->id, $destination);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -387,7 +387,7 @@
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
</KEYS>
|
||||
<INDEXES>
|
||||
<INDEX NAME="course_section" UNIQUE="false" FIELDS="course, section"/>
|
||||
<INDEX NAME="course_section" UNIQUE="true" FIELDS="course, section"/>
|
||||
</INDEXES>
|
||||
</TABLE>
|
||||
<TABLE NAME="course_request" COMMENT="course requests" PREVIOUS="course_sections" NEXT="filter_active">
|
||||
|
@ -358,6 +358,49 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2012032300.02);
|
||||
}
|
||||
|
||||
if ($oldversion < 2012042300.00) {
|
||||
// This change makes the course_section index unique.
|
||||
|
||||
// xmldb does not allow changing index uniqueness - instead we must drop
|
||||
// index then add it again
|
||||
$table = new xmldb_table('course_sections');
|
||||
$index = new xmldb_index('course_section', XMLDB_INDEX_NOTUNIQUE, array('course', 'section'));
|
||||
|
||||
// Conditionally launch drop index course_section
|
||||
if ($dbman->index_exists($table, $index)) {
|
||||
$dbman->drop_index($table, $index);
|
||||
}
|
||||
|
||||
// Look for any duplicate course_sections entries. There should not be
|
||||
// any but on some busy systems we found a few, maybe due to previous
|
||||
// bugs.
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$rs = $DB->get_recordset_sql('
|
||||
SELECT DISTINCT
|
||||
cs.id, cs.course
|
||||
FROM
|
||||
{course_sections} cs
|
||||
INNER JOIN {course_sections} older
|
||||
ON cs.course = older.course AND cs.section = older.section
|
||||
AND older.id < cs.id');
|
||||
foreach ($rs as $rec) {
|
||||
$DB->delete_records('course_sections', array('id' => $rec->id));
|
||||
rebuild_course_cache($rec->course, true);
|
||||
}
|
||||
$rs->close();
|
||||
$transaction->allow_commit();
|
||||
|
||||
// Define index course_section (unique) to be added to course_sections
|
||||
$index = new xmldb_index('course_section', XMLDB_INDEX_UNIQUE, array('course', 'section'));
|
||||
|
||||
// Conditionally launch add index course_section
|
||||
if (!$dbman->index_exists($table, $index)) {
|
||||
$dbman->add_index($table, $index);
|
||||
}
|
||||
|
||||
// Main savepoint reached
|
||||
upgrade_main_savepoint(true, 2012042300.00);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
$version = 2012041900.00; // YYYYMMDD = weekly release date of this DEV branch
|
||||
$version = 2012042300.00; // YYYYMMDD = weekly release date of this DEV branch
|
||||
// RR = release increments - 00 in DEV branches
|
||||
// .XX = incremental changes
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user