diff --git a/mod/wiki/backup/moodle2/restore_wiki_activity_task.class.php b/mod/wiki/backup/moodle2/restore_wiki_activity_task.class.php new file mode 100644 index 00000000000..52de9d326c5 --- /dev/null +++ b/mod/wiki/backup/moodle2/restore_wiki_activity_task.class.php @@ -0,0 +1,75 @@ +. + +/** + * @package moodlecore + * @subpackage backup-moodle2 + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once($CFG->dirroot . '/mod/wiki/backup/moodle2/restore_wiki_stepslib.php'); // Because it exists (must) + +/** + * wiki restore task that provides all the settings and steps to perform one + * complete restore of the activity + */ +class restore_wiki_activity_task extends restore_activity_task { + + /** + * Define (add) particular settings this activity can have + */ + protected function define_my_settings() { + // No particular settings for this activity + } + + /** + * Define (add) particular steps this activity can have + */ + protected function define_my_steps() { + // wiki only has one structure step + $this->add_step(new restore_wiki_activity_structure_step('wiki_structure', 'wiki.xml')); + } + + /** + * Define the contents in the activity that must be + * processed by the link decoder + */ + static public function define_decode_contents() { + $contents = array(); + + $contents[] = new restore_decode_content('wiki', array('intro'), 'wiki'); + + return $contents; + } + + /** + * Define the decoding rules for links belonging + * to the activity to be executed by the link decoder + */ + static public function define_decode_rules() { + $rules = array(); + + $rules[] = new restore_decode_rule('WIKIVIEWBYID', '/mod/wiki/view.php?id=$1', 'course_module'); + $rules[] = new restore_decode_rule('WIKIINDEX', '/mod/wiki/index.php?id=$1', 'course'); + + return $rules; + + } +} diff --git a/mod/wiki/backup/moodle2/restore_wiki_stepslib.php b/mod/wiki/backup/moodle2/restore_wiki_stepslib.php new file mode 100644 index 00000000000..4f59b129f9c --- /dev/null +++ b/mod/wiki/backup/moodle2/restore_wiki_stepslib.php @@ -0,0 +1,149 @@ +. + +/** + * @package moodlecore + * @subpackage backup-moodle2 + * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Define all the restore steps that will be used by the restore_wiki_activity_task + */ + +/** + * Structure step to restore one wiki activity + */ +class restore_wiki_activity_structure_step extends restore_activity_structure_step { + + protected function define_structure() { + + $paths = array(); + $userinfo = $this->get_setting_value('userinfo'); + + $paths[] = new restore_path_element('wiki', '/activity/wiki'); + if ($userinfo) { + $paths[] = new restore_path_element('wiki_subwiki', '/activity/wiki/subwikis/subwiki'); + $paths[] = new restore_path_element('wiki_page', '/activity/wiki/subwikis/subwiki/pages/page'); + $paths[] = new restore_path_element('wiki_version', '/activity/wiki/subwikis/subwiki/pages/page/versions/version'); + $paths[] = new restore_path_element('wiki_synonym', '/activity/wiki/subwikis/subwiki/synonyms/synonym'); + $paths[] = new restore_path_element('wiki_link', '/activity/wiki/subwikis/subwiki/links/link'); + $paths[] = new restore_path_element('wiki_comment', '/activity/wiki/subwikis/subwiki/pages/page/comments/comment'); + } + + // Return the paths wrapped into standard activity structure + return $this->prepare_activity_structure($paths); + } + + protected function process_wiki($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + $data->course = $this->get_courseid(); + + $data->editbegin = $this->apply_date_offset($data->editbegin); + $data->editend = $this->apply_date_offset($data->editend); + + // insert the wiki record + $newitemid = $DB->insert_record('wiki', $data); + // inmediately after inserting "activity" record, call this + $this->apply_activity_instance($newitemid); + } + + protected function process_wiki_subwiki($data) { + global $DB; + + + $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); + + $newitemid = $DB->insert_record('wiki_subwikis', $data); + $this->set_mapping('wiki_subwiki', $oldid, $newitemid); + } + protected function process_wiki_page($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + $data->subwikiid = $this->get_new_parentid('wiki_subwiki'); + $data->userid = $this->get_mappingid('user', $data->userid); + + $newitemid = $DB->insert_record('wiki_pages', $data); + $this->set_mapping('wiki_page', $oldid, $newitemid); + } + protected function process_wiki_version($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + $data->pageid = $this->get_new_parentid('wiki_page'); + $data->userid = $this->get_mappingid('user', $data->userid); + + $newitemid = $DB->insert_record('wiki_versions', $data); + // No need to save this mapping as far as nothing depend on it + // (child paths, file areas nor links decoder) + } + protected function process_wiki_synonym($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + $data->subwikiid = $this->get_new_parentid('wiki_subwiki'); + $data->pageid = $this->get_mappingid('wiki_page', $data->pageid); + + $newitemid = $DB->insert_record('wiki_synonyms', $data); + // No need to save this mapping as far as nothing depend on it + // (child paths, file areas nor links decoder) + } + protected function process_wiki_link($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + $data->subwikiid = $this->get_new_parentid('wiki_subwiki'); + $data->frompageid = $this->get_mappingid('wiki_page', $data->frompageid); + $data->topageid = $this->get_mappingid('wiki_page', $data->topageid); + + $newitemid = $DB->insert_record('wiki_links', $data); + // No need to save this mapping as far as nothing depend on it + // (child paths, file areas nor links decoder) + } + + protected function process_wiki_comment($data) { + global $DB; + + $data = (object)$data; + $oldid = $data->id; + $data->contextid = $this->get_mappingid('context', $data->contextid); + $data->userid = $this->get_mappingid('user', $data->userid); + + $newitemid = $DB->insert_record('comments', $data); + // No need to save this mapping as far as nothing depend on it + // (child paths, file areas nor links decoder) + } + + + protected function after_execute() { + // Add wiki related files, no need to match by itemname (just internally handled context) + $this->add_related_files('mod_wiki', 'intro', null); + } +}