From 19b2d3fa9c9577fc960631c89cc3b3ae695bba9b Mon Sep 17 00:00:00 2001 From: Anton Fletcher Date: Fri, 4 Oct 2013 15:46:40 +0930 Subject: [PATCH 1/2] MDL-35146 mod_wiki: fixed issue where pages for deleted groups caused an error on restore --- .../backup/moodle2/restore_wiki_stepslib.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mod/wiki/backup/moodle2/restore_wiki_stepslib.php b/mod/wiki/backup/moodle2/restore_wiki_stepslib.php index e27abafebef..3e0aa3d8da2 100644 --- a/mod/wiki/backup/moodle2/restore_wiki_stepslib.php +++ b/mod/wiki/backup/moodle2/restore_wiki_stepslib.php @@ -74,10 +74,14 @@ class restore_wiki_activity_structure_step extends restore_activity_structure_st $data = (object)$data; $oldid = $data->id; $data->wikiid = $this->get_new_parentid('wiki'); - $data->groupid = $this->get_mappingid('group', $data->groupid); - $data->userid = $this->get_mappingid('user', $data->userid); + if($data->groupid !== '0') $data->groupid = $this->get_mappingid('group', $data->groupid); + if($date->userid !== '0') $data->userid = $this->get_mappingid('user', $data->userid); - $newitemid = $DB->insert_record('wiki_subwikis', $data); + if($data->groupid !== false && $data->userid !== false) { + $newitemid = $DB->insert_record('wiki_subwikis', $data); + } else { + $newitemid = false; + } $this->set_mapping('wiki_subwiki', $oldid, $newitemid); } protected function process_wiki_page($data) { @@ -91,7 +95,11 @@ class restore_wiki_activity_structure_step extends restore_activity_structure_st $data->timecreated = $this->apply_date_offset($data->timecreated); $data->timerendered = $this->apply_date_offset($data->timerendered); - $newitemid = $DB->insert_record('wiki_pages', $data); + if($data->subwikiid !== false) { + $newitemid = $DB->insert_record('wiki_pages', $data); + } else { + $newitemid = false; + } $this->set_mapping('wiki_page', $oldid, $newitemid, true); // There are files related to this } protected function process_wiki_version($data) { From 5311f38215e2a34b9909007efdb6bf33fefa5473 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 22 Oct 2013 12:04:06 +0800 Subject: [PATCH 2/2] MDL-35146 mod_wiki: fixed variable typo and altered code to conform to Moodle guidelines --- .../backup/moodle2/restore_wiki_stepslib.php | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/mod/wiki/backup/moodle2/restore_wiki_stepslib.php b/mod/wiki/backup/moodle2/restore_wiki_stepslib.php index 3e0aa3d8da2..60dcd2e7530 100644 --- a/mod/wiki/backup/moodle2/restore_wiki_stepslib.php +++ b/mod/wiki/backup/moodle2/restore_wiki_stepslib.php @@ -70,24 +70,34 @@ class restore_wiki_activity_structure_step extends restore_activity_structure_st protected function process_wiki_subwiki($data) { global $DB; - - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; $data->wikiid = $this->get_new_parentid('wiki'); - if($data->groupid !== '0') $data->groupid = $this->get_mappingid('group', $data->groupid); - if($date->userid !== '0') $data->userid = $this->get_mappingid('user', $data->userid); - if($data->groupid !== false && $data->userid !== false) { + // If the groupid is not equal to zero, get the mapping for the group. + if ((int) $data->groupid !== 0) { + $data->groupid = $this->get_mappingid('group', $data->groupid); + } + + // If the userid is not equal to zero, get the mapping for the user. + if ((int) $data->userid !== 0) { + $data->userid = $this->get_mappingid('user', $data->userid); + } + + // If these values are not equal to false then a mapping was successfully made. + if ($data->groupid !== false && $data->userid !== false) { $newitemid = $DB->insert_record('wiki_subwikis', $data); } else { $newitemid = false; } + $this->set_mapping('wiki_subwiki', $oldid, $newitemid); } + protected function process_wiki_page($data) { global $DB; - $data = (object)$data; + $data = (object) $data; $oldid = $data->id; $data->subwikiid = $this->get_new_parentid('wiki_subwiki'); $data->userid = $this->get_mappingid('user', $data->userid); @@ -95,13 +105,16 @@ class restore_wiki_activity_structure_step extends restore_activity_structure_st $data->timecreated = $this->apply_date_offset($data->timecreated); $data->timerendered = $this->apply_date_offset($data->timerendered); - if($data->subwikiid !== false) { + // Check that we were able to get a parentid for this page. + if ($data->subwikiid !== false) { $newitemid = $DB->insert_record('wiki_pages', $data); } else { $newitemid = false; } - $this->set_mapping('wiki_page', $oldid, $newitemid, true); // There are files related to this + + $this->set_mapping('wiki_page', $oldid, $newitemid, true); } + protected function process_wiki_version($data) { global $DB;