Skip to content

Commit

Permalink
MDL-33133 Conditional section: restore to existing course fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed May 21, 2012
1 parent 4f7f2a8 commit 52e9dfc
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,10 +1110,19 @@ public function process_section($data) {
public function process_availability($data) {
global $DB;
$data = (object)$data;

$data->coursesectionid = $this->task->get_sectionid();

// NOTE: Other values in $data need updating, but these (cm,
// grade items) have not yet been restored.
$DB->insert_record('course_sections_availability', $data);
// grade items) have not yet been restored, so are done later.

$newid = $DB->insert_record('course_sections_availability', $data);

// We do not need to map between old and new id but storing a mapping
// means it gets added to the backup_ids table to record which ones
// need updating. The mapping is stored with $newid => $newid for
// convenience.
$this->set_mapping('course_sections_availability', $newid, $newid);
}

protected function after_execute() {
Expand All @@ -1126,16 +1135,20 @@ public function after_restore() {

$sectionid = $this->get_task()->get_sectionid();

// Get data object for current section availability (if any)
// TODO: This can be processing already existing records, we need to be able to know which ones
// are the just restored ones, perhaps creating 'course_sections_availability' mappings for them.
// TODO: Also, this must avoid duplicates, so if one course module or one grade item already is being
// used for some availability rule... we need to handle that carefully.
// Get data object for current section availability (if any).
$data = $DB->get_record('course_sections_availability',
array('coursesectionid' => $sectionid), 'id, sourcecmid, gradeitemid', IGNORE_MISSING);

// Update mappings
// If it exists, update mappings.
if ($data) {
// Only update mappings for entries which are created by this restore.
// Otherwise, when you restore to an existing course, it will mess up
// existing section availability entries.
if (!$this->get_mappingid('course_sections_availability', $data->id, false)) {
return;
}

// Update source cmid / grade id to new value.
$data->sourcecmid = $this->get_mappingid('course_module', $data->sourcecmid);
if (!$data->sourcecmid) {
$data->sourcecmid = null;
Expand Down

0 comments on commit 52e9dfc

Please sign in to comment.