Merge branch 'MDL-55548_master' of git://github.com/markn86/moodle

This commit is contained in:
Dan Poltawski 2017-06-12 09:59:04 +01:00
commit a52d3abbb6
9 changed files with 72 additions and 13 deletions

View File

@ -62,8 +62,12 @@ class info_section extends info {
protected function set_in_database($availability) {
global $DB;
$DB->set_field('course_sections', 'availability', $availability,
array('id' => $this->section->id));
$section = new \stdClass();
$section->id = $this->section->id;
$section->availability = $availability;
$section->timemodified = time();
$DB->update_record('course_sections', $section);
}
/**

View File

@ -287,8 +287,12 @@ class condition extends \core_availability\condition {
// Save the updated course module.
if ($changed) {
$DB->set_field('course_sections', 'availability', json_encode($tree->save()),
array('id' => $section->id));
$updatesection = new \stdClass();
$updatesection->id = $section->id;
$updatesection->availability = json_encode($tree->save());
$updatesection->timemodified = time();
$DB->update_record('course_sections', $updatesection);
$anychanged = true;
}
}

View File

@ -325,7 +325,7 @@ class backup_section_structure_step extends backup_structure_step {
$section = new backup_nested_element('section', array('id'), array(
'number', 'name', 'summary', 'summaryformat', 'sequence', 'visible',
'availabilityjson'));
'availabilityjson', 'timemodified'));
// attach format plugin structure to $section element, only one allowed
$this->add_plugin_structure('format', $section, false);

View File

@ -795,7 +795,8 @@ class restore_rebuild_course_cache extends restore_execution_step {
if (!$DB->record_exists('course_sections', array('course' => $this->get_courseid(), 'section' => $i))) {
$sectionrec = array(
'course' => $this->get_courseid(),
'section' => $i);
'section' => $i,
'timemodified' => time());
$DB->insert_record('course_sections', $sectionrec); // missing section created
}
}
@ -1575,8 +1576,9 @@ class restore_section_structure_step extends restore_structure_step {
$section = new stdclass();
$section->course = $this->get_courseid();
$section->section = $data->number;
$section->timemodified = isset($data->timemodified) ? $this->apply_date_offset($data->timemodified) : 0;
// Section doesn't exist, create it with all the info from backup
if (!$secrec = $DB->get_record('course_sections', (array)$section)) {
if (!$secrec = $DB->get_record('course_sections', ['course' => $this->get_courseid(), 'section' => $data->number])) {
$section->name = $data->name;
$section->summary = $data->summary;
$section->summaryformat = $data->summaryformat;
@ -1721,8 +1723,12 @@ class restore_section_structure_step extends restore_structure_step {
array('id' => $availfield->coursesectionid), MUST_EXIST);
$newvalue = \core_availability\info::add_legacy_availability_field_condition(
$currentvalue, $availfield, $show);
$DB->set_field('course_sections', 'availability', $newvalue,
array('id' => $availfield->coursesectionid));
$section = new stdClass();
$section->id = $availfield->coursesectionid;
$section->availability = $newvalue;
$section->timemodified = time();
$DB->update_record('course_sections', $section);
}
}
@ -4032,11 +4038,13 @@ class restore_module_structure_step extends restore_structure_step {
if (!$data->section) { // no sections in course, create section 0 and 1 and assign module to 1
$sectionrec = array(
'course' => $this->get_courseid(),
'section' => 0);
'section' => 0,
'timemodified' => time());
$DB->insert_record('course_sections', $sectionrec); // section 0
$sectionrec = array(
'course' => $this->get_courseid(),
'section' => 1);
'section' => 1,
'timemodified' => time());
$data->section = $DB->insert_record('course_sections', $sectionrec); // section 1
}
$data->groupingid= $this->get_mappingid('grouping', $data->groupingid); // grouping
@ -4090,7 +4098,12 @@ class restore_module_structure_step extends restore_structure_step {
} else {
$sequence = $newitemid;
}
$DB->set_field('course_sections', 'sequence', $sequence, array('id' => $data->section));
$updatesection = new \stdClass();
$updatesection->id = $data->section;
$updatesection->sequence = $sequence;
$updatesection->timemodified = time();
$DB->update_record('course_sections', $updatesection);
// If there is the legacy showavailability data, store this for later use.
// (This data is not present when restoring 'new' backups.)

View File

@ -863,6 +863,7 @@ function course_create_section($courseorid, $position = 0, $skipcheck = false) {
$cw->name = null;
$cw->visible = 1;
$cw->availability = null;
$cw->timemodified = time();
$cw->id = $DB->insert_record("course_sections", $cw);
// Now move it to the specified position.
@ -1611,6 +1612,7 @@ function course_update_section($course, $section, $data) {
// Update record in the DB and course format options.
$data['id'] = $section->id;
$data['timemodified'] = time();
$DB->update_record('course_sections', $data);
rebuild_course_cache($courseid, true);
course_get_format($courseid)->update_section_format_options($data);

View File

@ -678,6 +678,29 @@ class core_course_courselib_testcase extends advanced_testcase {
}
}
public function test_update_course_section_time_modified() {
global $DB;
$this->resetAfterTest();
// Create the course with sections.
$course = $this->getDataGenerator()->create_course(array('numsections' => 10), array('createsections' => true));
$sections = $DB->get_records('course_sections', array('course' => $course->id));
// Get the last section's time modified value.
$section = array_pop($sections);
$oldtimemodified = $section->timemodified;
// Update the section.
sleep(1); // Ensuring that the section update occurs at a different timestamp.
course_update_section($course, $section, array());
// Check that the time has changed.
$section = $DB->get_record('course_sections', array('id' => $section->id));
$newtimemodified = $section->timemodified;
$this->assertGreaterThan($oldtimemodified, $newtimemodified);
}
public function test_course_add_cm_to_section() {
global $DB;
$this->resetAfterTest(true);

View File

@ -343,6 +343,7 @@
<FIELD NAME="sequence" TYPE="text" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="visible" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false"/>
<FIELD NAME="availability" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Availability restrictions for viewing this section, in JSON format. Null if no restrictions."/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Time at which the course section was last changed."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>

View File

@ -2865,5 +2865,17 @@ function xmldb_main_upgrade($oldversion) {
// Automatically generated Moodle v3.3.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2017061201.00) {
$table = new xmldb_table('course_sections');
$field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'availability');
// Define a field 'timemodified' in the 'course_sections' table, to background deletion tasks.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_main_savepoint(true, 2017061201.00);
}
return true;
}

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2017060800.01; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017061201.00; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.