Commit | Line | Data |
---|---|---|
36ee2cae DM |
1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * @package moodlecore | |
20 | * @subpackage backup-moodle2 | |
21 | * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} | |
22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
23 | */ | |
24 | ||
25 | /** | |
26 | * Define all the restore steps that will be used by the restore_wiki_activity_task | |
27 | */ | |
28 | ||
29 | /** | |
30 | * Structure step to restore one wiki activity | |
31 | */ | |
32 | class restore_wiki_activity_structure_step extends restore_activity_structure_step { | |
33 | ||
34 | protected function define_structure() { | |
35 | ||
36 | $paths = array(); | |
37 | $userinfo = $this->get_setting_value('userinfo'); | |
38 | ||
39 | $paths[] = new restore_path_element('wiki', '/activity/wiki'); | |
40 | if ($userinfo) { | |
41 | $paths[] = new restore_path_element('wiki_subwiki', '/activity/wiki/subwikis/subwiki'); | |
42 | $paths[] = new restore_path_element('wiki_page', '/activity/wiki/subwikis/subwiki/pages/page'); | |
43 | $paths[] = new restore_path_element('wiki_version', '/activity/wiki/subwikis/subwiki/pages/page/versions/version'); | |
44 | $paths[] = new restore_path_element('wiki_synonym', '/activity/wiki/subwikis/subwiki/synonyms/synonym'); | |
45 | $paths[] = new restore_path_element('wiki_link', '/activity/wiki/subwikis/subwiki/links/link'); | |
46 | $paths[] = new restore_path_element('wiki_comment', '/activity/wiki/subwikis/subwiki/pages/page/comments/comment'); | |
47 | } | |
48 | ||
49 | // Return the paths wrapped into standard activity structure | |
50 | return $this->prepare_activity_structure($paths); | |
51 | } | |
52 | ||
53 | protected function process_wiki($data) { | |
54 | global $DB; | |
55 | ||
56 | $data = (object)$data; | |
57 | $oldid = $data->id; | |
58 | $data->course = $this->get_courseid(); | |
59 | ||
60 | $data->editbegin = $this->apply_date_offset($data->editbegin); | |
61 | $data->editend = $this->apply_date_offset($data->editend); | |
26cf184c | 62 | $data->timemodified = $this->apply_date_offset($data->timemodified); |
36ee2cae DM |
63 | |
64 | // insert the wiki record | |
65 | $newitemid = $DB->insert_record('wiki', $data); | |
66 | // inmediately after inserting "activity" record, call this | |
67 | $this->apply_activity_instance($newitemid); | |
68 | } | |
69 | ||
70 | protected function process_wiki_subwiki($data) { | |
71 | global $DB; | |
72 | ||
73 | ||
74 | $data = (object)$data; | |
75 | $oldid = $data->id; | |
76 | $data->wikiid = $this->get_new_parentid('wiki'); | |
77 | $data->groupid = $this->get_mappingid('group', $data->groupid); | |
78 | $data->userid = $this->get_mappingid('user', $data->userid); | |
79 | ||
80 | $newitemid = $DB->insert_record('wiki_subwikis', $data); | |
81 | $this->set_mapping('wiki_subwiki', $oldid, $newitemid); | |
82 | } | |
83 | protected function process_wiki_page($data) { | |
84 | global $DB; | |
85 | ||
86 | $data = (object)$data; | |
87 | $oldid = $data->id; | |
88 | $data->subwikiid = $this->get_new_parentid('wiki_subwiki'); | |
89 | $data->userid = $this->get_mappingid('user', $data->userid); | |
26cf184c DM |
90 | $data->timemodified = $this->apply_date_offset($data->timemodified); |
91 | $data->timecreated = $this->apply_date_offset($data->timecreated); | |
92 | $data->timerendered = $this->apply_date_offset($data->timerendered); | |
36ee2cae DM |
93 | |
94 | $newitemid = $DB->insert_record('wiki_pages', $data); | |
95 | $this->set_mapping('wiki_page', $oldid, $newitemid); | |
96 | } | |
97 | protected function process_wiki_version($data) { | |
98 | global $DB; | |
99 | ||
100 | $data = (object)$data; | |
101 | $oldid = $data->id; | |
102 | $data->pageid = $this->get_new_parentid('wiki_page'); | |
103 | $data->userid = $this->get_mappingid('user', $data->userid); | |
26cf184c | 104 | $data->timecreated = $this->apply_date_offset($data->timecreated); |
36ee2cae DM |
105 | |
106 | $newitemid = $DB->insert_record('wiki_versions', $data); | |
26cf184c | 107 | $this->set_mapping('wiki_version', $oldid, $newitemid); |
36ee2cae DM |
108 | } |
109 | protected function process_wiki_synonym($data) { | |
110 | global $DB; | |
111 | ||
112 | $data = (object)$data; | |
113 | $oldid = $data->id; | |
114 | $data->subwikiid = $this->get_new_parentid('wiki_subwiki'); | |
115 | $data->pageid = $this->get_mappingid('wiki_page', $data->pageid); | |
116 | ||
117 | $newitemid = $DB->insert_record('wiki_synonyms', $data); | |
118 | // No need to save this mapping as far as nothing depend on it | |
119 | // (child paths, file areas nor links decoder) | |
120 | } | |
121 | protected function process_wiki_link($data) { | |
122 | global $DB; | |
123 | ||
124 | $data = (object)$data; | |
125 | $oldid = $data->id; | |
126 | $data->subwikiid = $this->get_new_parentid('wiki_subwiki'); | |
127 | $data->frompageid = $this->get_mappingid('wiki_page', $data->frompageid); | |
128 | $data->topageid = $this->get_mappingid('wiki_page', $data->topageid); | |
129 | ||
130 | $newitemid = $DB->insert_record('wiki_links', $data); | |
131 | // No need to save this mapping as far as nothing depend on it | |
132 | // (child paths, file areas nor links decoder) | |
133 | } | |
134 | ||
135 | protected function process_wiki_comment($data) { | |
136 | global $DB; | |
137 | ||
138 | $data = (object)$data; | |
139 | $oldid = $data->id; | |
140 | $data->contextid = $this->get_mappingid('context', $data->contextid); | |
141 | $data->userid = $this->get_mappingid('user', $data->userid); | |
142 | ||
143 | $newitemid = $DB->insert_record('comments', $data); | |
144 | // No need to save this mapping as far as nothing depend on it | |
145 | // (child paths, file areas nor links decoder) | |
146 | } | |
147 | ||
148 | ||
149 | protected function after_execute() { | |
150 | // Add wiki related files, no need to match by itemname (just internally handled context) | |
151 | $this->add_related_files('mod_wiki', 'intro', null); | |
152 | } | |
153 | } |