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_glossary
|
|
|
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_glossary_activity_task
|
|
|
27 |
*/
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Structure step to restore one glossary activity
|
|
|
31 |
*/
|
|
|
32 |
class restore_glossary_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('glossary', '/activity/glossary');
|
|
|
40 |
$paths[] = new restore_path_element('glossary_category', '/activity/glossary/categories/category');
|
|
|
41 |
if ($userinfo) {
|
|
|
42 |
$paths[] = new restore_path_element('glossary_entry', '/activity/glossary/entries/entry');
|
|
|
43 |
$paths[] = new restore_path_element('glossary_entry_tag', '/activity/glossary/entriestags/tag');
|
|
|
44 |
$paths[] = new restore_path_element('glossary_alias', '/activity/glossary/entries/entry/aliases/alias');
|
|
|
45 |
$paths[] = new restore_path_element('glossary_rating', '/activity/glossary/entries/entry/ratings/rating');
|
|
|
46 |
$paths[] = new restore_path_element('glossary_category_entry',
|
|
|
47 |
'/activity/glossary/categories/category/category_entries/category_entry');
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
// Return the paths wrapped into standard activity structure
|
|
|
51 |
return $this->prepare_activity_structure($paths);
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
protected function process_glossary($data) {
|
|
|
55 |
global $DB;
|
|
|
56 |
|
|
|
57 |
$data = (object)$data;
|
|
|
58 |
$oldid = $data->id;
|
|
|
59 |
$data->course = $this->get_courseid();
|
|
|
60 |
|
|
|
61 |
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
|
|
|
62 |
// See MDL-9367.
|
|
|
63 |
$data->assesstimestart = $this->apply_date_offset($data->assesstimestart);
|
|
|
64 |
$data->assesstimefinish = $this->apply_date_offset($data->assesstimefinish);
|
|
|
65 |
if ($data->scale < 0) { // scale found, get mapping
|
|
|
66 |
$data->scale = -($this->get_mappingid('scale', abs($data->scale)));
|
|
|
67 |
}
|
|
|
68 |
$formats = get_list_of_plugins('mod/glossary/formats'); // Check format
|
|
|
69 |
if (!in_array($data->displayformat, $formats)) {
|
|
|
70 |
$data->displayformat = 'dictionary';
|
|
|
71 |
}
|
11 |
efrain |
72 |
if (!empty($data->globalglossary) && !has_capability('mod/glossary:manageentries', context_system::instance())) {
|
|
|
73 |
$data->globalglossary = 0;
|
|
|
74 |
}
|
1 |
efrain |
75 |
if (!empty($data->mainglossary) and $data->mainglossary == 1 and
|
|
|
76 |
$DB->record_exists('glossary', array('mainglossary' => 1, 'course' => $this->get_courseid()))) {
|
|
|
77 |
// Only allow one main glossary in the course
|
|
|
78 |
$data->mainglossary = 0;
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
// insert the glossary record
|
|
|
82 |
$newitemid = $DB->insert_record('glossary', $data);
|
|
|
83 |
$this->apply_activity_instance($newitemid);
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
protected function process_glossary_entry($data) {
|
|
|
87 |
global $DB;
|
|
|
88 |
|
|
|
89 |
$data = (object)$data;
|
|
|
90 |
$oldid = $data->id;
|
|
|
91 |
|
|
|
92 |
$data->glossaryid = $this->get_new_parentid('glossary');
|
|
|
93 |
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
94 |
$data->sourceglossaryid = $this->get_mappingid('glossary', $data->sourceglossaryid);
|
|
|
95 |
|
|
|
96 |
// insert the entry record
|
|
|
97 |
$newitemid = $DB->insert_record('glossary_entries', $data);
|
|
|
98 |
$this->set_mapping('glossary_entry', $oldid, $newitemid, true); // childs and files by itemname
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
protected function process_glossary_alias($data) {
|
|
|
102 |
global $DB;
|
|
|
103 |
|
|
|
104 |
$data = (object)$data;
|
|
|
105 |
$oldid = $data->id;
|
|
|
106 |
|
|
|
107 |
$data->entryid = $this->get_new_parentid('glossary_entry');
|
|
|
108 |
$data->alias = $data->alias_text;
|
|
|
109 |
$newitemid = $DB->insert_record('glossary_alias', $data);
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
protected function process_glossary_rating($data) {
|
|
|
113 |
global $DB;
|
|
|
114 |
|
|
|
115 |
$data = (object)$data;
|
|
|
116 |
|
|
|
117 |
// Cannot use ratings API, cause, it's missing the ability to specify times (modified/created)
|
|
|
118 |
$data->contextid = $this->task->get_contextid();
|
|
|
119 |
$data->itemid = $this->get_new_parentid('glossary_entry');
|
|
|
120 |
if ($data->scaleid < 0) { // scale found, get mapping
|
|
|
121 |
$data->scaleid = -($this->get_mappingid('scale', abs($data->scaleid)));
|
|
|
122 |
}
|
|
|
123 |
$data->rating = $data->value;
|
|
|
124 |
$data->userid = $this->get_mappingid('user', $data->userid);
|
|
|
125 |
|
|
|
126 |
// Make sure that we have both component and ratingarea set. These were added in 2.1.
|
|
|
127 |
// Prior to that all ratings were for entries so we know what to set them too.
|
|
|
128 |
if (empty($data->component)) {
|
|
|
129 |
$data->component = 'mod_glossary';
|
|
|
130 |
}
|
|
|
131 |
if (empty($data->ratingarea)) {
|
|
|
132 |
$data->ratingarea = 'entry';
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
$newitemid = $DB->insert_record('rating', $data);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
protected function process_glossary_entry_tag($data) {
|
|
|
139 |
$data = (object)$data;
|
|
|
140 |
|
|
|
141 |
if (!core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { // Tags disabled in server, nothing to process.
|
|
|
142 |
return;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
$tag = $data->rawname;
|
|
|
146 |
if (!$itemid = $this->get_mappingid('glossary_entry', $data->itemid)) {
|
|
|
147 |
// Some orphaned tag, we could not find the glossary entry for it - ignore.
|
|
|
148 |
return;
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
$context = context_module::instance($this->task->get_moduleid());
|
|
|
152 |
core_tag_tag::add_item_tag('mod_glossary', 'glossary_entries', $itemid, $context, $tag);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
protected function process_glossary_category($data) {
|
|
|
156 |
global $DB;
|
|
|
157 |
|
|
|
158 |
$data = (object)$data;
|
|
|
159 |
$oldid = $data->id;
|
|
|
160 |
|
|
|
161 |
$data->glossaryid = $this->get_new_parentid('glossary');
|
|
|
162 |
$newitemid = $DB->insert_record('glossary_categories', $data);
|
|
|
163 |
$this->set_mapping('glossary_category', $oldid, $newitemid);
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
protected function process_glossary_category_entry($data) {
|
|
|
167 |
global $DB;
|
|
|
168 |
|
|
|
169 |
$data = (object)$data;
|
|
|
170 |
$oldid = $data->id;
|
|
|
171 |
|
|
|
172 |
$data->categoryid = $this->get_new_parentid('glossary_category');
|
|
|
173 |
$data->entryid = $this->get_mappingid('glossary_entry', $data->entryid);
|
|
|
174 |
$newitemid = $DB->insert_record('glossary_entries_categories', $data);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
protected function after_execute() {
|
|
|
178 |
// Add glossary related files, no need to match by itemname (just internally handled context)
|
|
|
179 |
$this->add_related_files('mod_glossary', 'intro', null);
|
|
|
180 |
// Add entries related files, matching by itemname (glossary_entry)
|
|
|
181 |
$this->add_related_files('mod_glossary', 'entry', 'glossary_entry');
|
|
|
182 |
$this->add_related_files('mod_glossary', 'attachment', 'glossary_entry');
|
|
|
183 |
}
|
|
|
184 |
}
|