mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 13:38:32 +01:00
MDL-55548 backup: changes after review
1) There is no need to store the 'timemodified' value of the section when backing up a course module, they do not refer to the same time. 2) When creating a new course section during restore use the current time. 3) Added timemodified value to more places when updating the 'course_sections' table.
This commit is contained in:
parent
4ddf7c6025
commit
b75ff47441
@ -62,8 +62,12 @@ class info_section extends info {
|
|||||||
|
|
||||||
protected function set_in_database($availability) {
|
protected function set_in_database($availability) {
|
||||||
global $DB;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -287,8 +287,12 @@ class condition extends \core_availability\condition {
|
|||||||
|
|
||||||
// Save the updated course module.
|
// Save the updated course module.
|
||||||
if ($changed) {
|
if ($changed) {
|
||||||
$DB->set_field('course_sections', 'availability', json_encode($tree->save()),
|
$updatesection = new \stdClass();
|
||||||
array('id' => $section->id));
|
$updatesection->id = $section->id;
|
||||||
|
$updatesection->availability = json_encode($tree->save());
|
||||||
|
$updatesection->timemodified = time();
|
||||||
|
$DB->update_record('course_sections', $updatesection);
|
||||||
|
|
||||||
$anychanged = true;
|
$anychanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ class backup_module_structure_step extends backup_structure_step {
|
|||||||
'added', 'score', 'indent', 'visible', 'visibleoncoursepage',
|
'added', 'score', 'indent', 'visible', 'visibleoncoursepage',
|
||||||
'visibleold', 'groupmode', 'groupingid',
|
'visibleold', 'groupmode', 'groupingid',
|
||||||
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected',
|
'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected',
|
||||||
'availability', 'showdescription', 'timemodified'));
|
'availability', 'showdescription'));
|
||||||
|
|
||||||
$tags = new backup_nested_element('tags');
|
$tags = new backup_nested_element('tags');
|
||||||
$tag = new backup_nested_element('tag', array('id'), array('name', 'rawname'));
|
$tag = new backup_nested_element('tag', array('id'), array('name', 'rawname'));
|
||||||
@ -291,8 +291,7 @@ class backup_module_structure_step extends backup_structure_step {
|
|||||||
// Set the sources
|
// Set the sources
|
||||||
$concat = $DB->sql_concat("'mod_'", 'm.name');
|
$concat = $DB->sql_concat("'mod_'", 'm.name');
|
||||||
$module->set_source_sql("
|
$module->set_source_sql("
|
||||||
SELECT cm.*, cp.value AS version, m.name AS modulename, s.id AS sectionid, s.section AS sectionnumber,
|
SELECT cm.*, cp.value AS version, m.name AS modulename, s.id AS sectionid, s.section AS sectionnumber
|
||||||
s.timemodified AS timemodified
|
|
||||||
FROM {course_modules} cm
|
FROM {course_modules} cm
|
||||||
JOIN {modules} m ON m.id = cm.module
|
JOIN {modules} m ON m.id = cm.module
|
||||||
JOIN {config_plugins} cp ON cp.plugin = $concat AND cp.name = 'version'
|
JOIN {config_plugins} cp ON cp.plugin = $concat AND cp.name = 'version'
|
||||||
|
@ -796,7 +796,7 @@ class restore_rebuild_course_cache extends restore_execution_step {
|
|||||||
$sectionrec = array(
|
$sectionrec = array(
|
||||||
'course' => $this->get_courseid(),
|
'course' => $this->get_courseid(),
|
||||||
'section' => $i,
|
'section' => $i,
|
||||||
'timemodified' => 0);
|
'timemodified' => time());
|
||||||
$DB->insert_record('course_sections', $sectionrec); // missing section created
|
$DB->insert_record('course_sections', $sectionrec); // missing section created
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1576,8 +1576,9 @@ class restore_section_structure_step extends restore_structure_step {
|
|||||||
$section = new stdclass();
|
$section = new stdclass();
|
||||||
$section->course = $this->get_courseid();
|
$section->course = $this->get_courseid();
|
||||||
$section->section = $data->number;
|
$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
|
// 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->name = $data->name;
|
||||||
$section->summary = $data->summary;
|
$section->summary = $data->summary;
|
||||||
$section->summaryformat = $data->summaryformat;
|
$section->summaryformat = $data->summaryformat;
|
||||||
@ -1593,8 +1594,6 @@ class restore_section_structure_step extends restore_structure_step {
|
|||||||
$data, true);
|
$data, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$section->timemodified = !isset($data->timemodified) ? 0 : $this->apply_date_offset($data->timemodified);
|
|
||||||
$newitemid = $DB->insert_record('course_sections', $section);
|
$newitemid = $DB->insert_record('course_sections', $section);
|
||||||
$section->id = $newitemid;
|
$section->id = $newitemid;
|
||||||
|
|
||||||
@ -1614,7 +1613,6 @@ class restore_section_structure_step extends restore_structure_step {
|
|||||||
$restorefiles = true;
|
$restorefiles = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$section->timemodified = !isset($data->timemodified) ? 0 : $this->apply_date_offset($data->timemodified);
|
|
||||||
// Don't update availability (I didn't see a useful way to define
|
// Don't update availability (I didn't see a useful way to define
|
||||||
// whether existing or new one should take precedence).
|
// whether existing or new one should take precedence).
|
||||||
|
|
||||||
@ -1725,8 +1723,12 @@ class restore_section_structure_step extends restore_structure_step {
|
|||||||
array('id' => $availfield->coursesectionid), MUST_EXIST);
|
array('id' => $availfield->coursesectionid), MUST_EXIST);
|
||||||
$newvalue = \core_availability\info::add_legacy_availability_field_condition(
|
$newvalue = \core_availability\info::add_legacy_availability_field_condition(
|
||||||
$currentvalue, $availfield, $show);
|
$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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4018,8 +4020,6 @@ class restore_module_structure_step extends restore_structure_step {
|
|||||||
$oldid = $data->id;
|
$oldid = $data->id;
|
||||||
$this->task->set_old_moduleversion($data->version);
|
$this->task->set_old_moduleversion($data->version);
|
||||||
|
|
||||||
$timemodified = !isset($data->timemodified) ? 0 : $this->apply_date_offset($data->timemodified);
|
|
||||||
|
|
||||||
$data->course = $this->task->get_courseid();
|
$data->course = $this->task->get_courseid();
|
||||||
$data->module = $DB->get_field('modules', 'id', array('name' => $data->modulename));
|
$data->module = $DB->get_field('modules', 'id', array('name' => $data->modulename));
|
||||||
// Map section (first try by course_section mapping match. Useful in course and section restores)
|
// Map section (first try by course_section mapping match. Useful in course and section restores)
|
||||||
@ -4039,12 +4039,12 @@ class restore_module_structure_step extends restore_structure_step {
|
|||||||
$sectionrec = array(
|
$sectionrec = array(
|
||||||
'course' => $this->get_courseid(),
|
'course' => $this->get_courseid(),
|
||||||
'section' => 0,
|
'section' => 0,
|
||||||
'timemodified' => $timemodified);
|
'timemodified' => time());
|
||||||
$DB->insert_record('course_sections', $sectionrec); // section 0
|
$DB->insert_record('course_sections', $sectionrec); // section 0
|
||||||
$sectionrec = array(
|
$sectionrec = array(
|
||||||
'course' => $this->get_courseid(),
|
'course' => $this->get_courseid(),
|
||||||
'section' => 1,
|
'section' => 1,
|
||||||
'timemodified' => $timemodified);
|
'timemodified' => time());
|
||||||
$data->section = $DB->insert_record('course_sections', $sectionrec); // section 1
|
$data->section = $DB->insert_record('course_sections', $sectionrec); // section 1
|
||||||
}
|
}
|
||||||
$data->groupingid= $this->get_mappingid('grouping', $data->groupingid); // grouping
|
$data->groupingid= $this->get_mappingid('grouping', $data->groupingid); // grouping
|
||||||
@ -4098,7 +4098,12 @@ class restore_module_structure_step extends restore_structure_step {
|
|||||||
} else {
|
} else {
|
||||||
$sequence = $newitemid;
|
$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.
|
// If there is the legacy showavailability data, store this for later use.
|
||||||
// (This data is not present when restoring 'new' backups.)
|
// (This data is not present when restoring 'new' backups.)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user