1 |
efrain |
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 mod_wiki
|
|
|
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_tag', '/activity/wiki/subwikis/subwiki/pages/page/tags/tag');
|
|
|
45 |
$paths[] = new restore_path_element('wiki_synonym', '/activity/wiki/subwikis/subwiki/synonyms/synonym');
|
|
|
46 |
$paths[] = new restore_path_element('wiki_link', '/activity/wiki/subwikis/subwiki/links/link');
|
|
|
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 |
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
|
|
|
61 |
// See MDL-9367.
|
|
|
62 |
$data->editbegin = $this->apply_date_offset($data->editbegin);
|
|
|
63 |
$data->editend = $this->apply_date_offset($data->editend);
|
|
|
64 |
$data->defaultformat = clean_param($data->defaultformat, PARAM_ALPHA);
|
|
|
65 |
|
|
|
66 |
// insert the wiki record
|
|
|
67 |
$newitemid = $DB->insert_record('wiki', $data);
|
|
|
68 |
// immediately after inserting "activity" record, call this
|
|
|
69 |
$this->apply_activity_instance($newitemid);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
protected function process_wiki_subwiki($data) {
|
|
|
73 |
global $DB;
|
|
|
74 |
|
|
|
75 |
$data = (object) $data;
|
|
|
76 |
$oldid = $data->id;
|
|
|
77 |
$data->wikiid = $this->get_new_parentid('wiki');
|
|
|
78 |
|
|
|
79 |
// If the groupid is not equal to zero, get the mapping for the group.
|
|
|
80 |
if ((int) $data->groupid !== 0) {
|
|
|
81 |
$data->groupid = $this->get_mappingid('group', $data->groupid);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
// If the userid is not equal to zero, get the mapping for the user.
|
|
|
85 |
if ((int) $data->userid !== 0) {
|
|
|
86 |
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
// If these values are not equal to false then a mapping was successfully made.
|
|
|
90 |
if ($data->groupid !== false && $data->userid !== false) {
|
|
|
91 |
$newitemid = $DB->insert_record('wiki_subwikis', $data);
|
|
|
92 |
} else {
|
|
|
93 |
$newitemid = false;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
$this->set_mapping('wiki_subwiki', $oldid, $newitemid, true);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
protected function process_wiki_page($data) {
|
|
|
100 |
global $DB;
|
|
|
101 |
|
|
|
102 |
$data = (object) $data;
|
|
|
103 |
$oldid = $data->id;
|
|
|
104 |
$data->subwikiid = $this->get_new_parentid('wiki_subwiki');
|
|
|
105 |
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
106 |
|
|
|
107 |
// Check that we were able to get a parentid for this page.
|
|
|
108 |
if ($data->subwikiid !== false) {
|
|
|
109 |
$newitemid = $DB->insert_record('wiki_pages', $data);
|
|
|
110 |
} else {
|
|
|
111 |
$newitemid = false;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
$this->set_mapping('wiki_page', $oldid, $newitemid, true);
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
protected function process_wiki_version($data) {
|
|
|
118 |
global $DB;
|
|
|
119 |
|
|
|
120 |
$data = (object)$data;
|
|
|
121 |
$oldid = $data->id;
|
|
|
122 |
$data->pageid = $this->get_new_parentid('wiki_page');
|
|
|
123 |
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
124 |
$data->contentformat = clean_param($data->contentformat, PARAM_ALPHA);
|
|
|
125 |
$newitemid = $DB->insert_record('wiki_versions', $data);
|
|
|
126 |
$this->set_mapping('wiki_version', $oldid, $newitemid);
|
|
|
127 |
}
|
|
|
128 |
protected function process_wiki_synonym($data) {
|
|
|
129 |
global $DB;
|
|
|
130 |
|
|
|
131 |
$data = (object)$data;
|
|
|
132 |
$oldid = $data->id;
|
|
|
133 |
$data->subwikiid = $this->get_new_parentid('wiki_subwiki');
|
|
|
134 |
$data->pageid = $this->get_mappingid('wiki_page', $data->pageid);
|
|
|
135 |
|
|
|
136 |
$newitemid = $DB->insert_record('wiki_synonyms', $data);
|
|
|
137 |
// No need to save this mapping as far as nothing depend on it
|
|
|
138 |
// (child paths, file areas nor links decoder)
|
|
|
139 |
}
|
|
|
140 |
protected function process_wiki_link($data) {
|
|
|
141 |
global $DB;
|
|
|
142 |
|
|
|
143 |
$data = (object)$data;
|
|
|
144 |
$oldid = $data->id;
|
|
|
145 |
$data->subwikiid = $this->get_new_parentid('wiki_subwiki');
|
|
|
146 |
$data->frompageid = $this->get_mappingid('wiki_page', $data->frompageid);
|
|
|
147 |
$data->topageid = $this->get_mappingid('wiki_page', $data->topageid);
|
|
|
148 |
|
|
|
149 |
$newitemid = $DB->insert_record('wiki_links', $data);
|
|
|
150 |
// No need to save this mapping as far as nothing depend on it
|
|
|
151 |
// (child paths, file areas nor links decoder)
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
protected function process_wiki_tag($data) {
|
|
|
155 |
global $CFG, $DB;
|
|
|
156 |
|
|
|
157 |
$data = (object)$data;
|
|
|
158 |
$oldid = $data->id;
|
|
|
159 |
|
|
|
160 |
if (!core_tag_tag::is_enabled('mod_wiki', 'wiki_pages')) { // Tags disabled in server, nothing to process.
|
|
|
161 |
return;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
$tag = $data->rawname;
|
|
|
165 |
$itemid = $this->get_new_parentid('wiki_page');
|
|
|
166 |
$wikiid = $this->get_new_parentid('wiki');
|
|
|
167 |
|
|
|
168 |
$context = context_module::instance($this->task->get_moduleid());
|
|
|
169 |
core_tag_tag::add_item_tag('mod_wiki', 'wiki_pages', $itemid, $context, $tag);
|
|
|
170 |
}
|
|
|
171 |
|
|
|
172 |
protected function after_execute() {
|
|
|
173 |
// Add wiki related files, no need to match by itemname (just internally handled context)
|
|
|
174 |
$this->add_related_files('mod_wiki', 'intro', null);
|
|
|
175 |
$this->add_related_files('mod_wiki', 'attachments', 'wiki_subwiki');
|
|
|
176 |
}
|
|
|
177 |
}
|