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 |
* Defines restore_final_task class
|
|
|
20 |
*
|
|
|
21 |
* @package core_backup
|
|
|
22 |
* @subpackage moodle2
|
|
|
23 |
* @category backup
|
|
|
24 |
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
defined('MOODLE_INTERNAL') || die();
|
|
|
29 |
|
|
|
30 |
/**
|
|
|
31 |
* Final task that provides all the final steps necessary in order to finish one
|
|
|
32 |
* restore like gradebook, interlinks... apart from some final cleaning
|
|
|
33 |
*
|
|
|
34 |
* TODO: Finish phpdocs
|
|
|
35 |
*/
|
|
|
36 |
class restore_final_task extends restore_task {
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Create all the steps that will be part of this task
|
|
|
40 |
*/
|
|
|
41 |
public function build() {
|
|
|
42 |
|
|
|
43 |
// Move all the CONTEXT_MODULE question qcats to their
|
|
|
44 |
// final (newly created) module context
|
|
|
45 |
$this->add_step(new restore_move_module_questions_categories('move_module_question_categories'));
|
|
|
46 |
|
|
|
47 |
// Create all the question files now that every question is in place
|
|
|
48 |
// and every category has its final contextid associated
|
|
|
49 |
$this->add_step(new restore_create_question_files('create_question_files'));
|
|
|
50 |
|
|
|
51 |
// Review all the block_position records in backup_ids in order
|
|
|
52 |
// match them now that all the contexts are created populating DB
|
|
|
53 |
// as needed. Only if we are restoring blocks.
|
|
|
54 |
if ($this->get_setting_value('blocks')) {
|
|
|
55 |
$this->add_step(new restore_review_pending_block_positions('review_block_positions'));
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
// Gradebook. Don't restore the gradebook unless activities are being restored.
|
|
|
59 |
if ($this->get_setting_value('activities')) {
|
|
|
60 |
$this->add_step(new restore_gradebook_structure_step('gradebook_step','gradebook.xml'));
|
|
|
61 |
$this->add_step(new restore_grade_history_structure_step('grade_history', 'grade_history.xml'));
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
// Course completion.
|
|
|
65 |
$this->add_step(new restore_course_completion_structure_step('course_completion', 'completion.xml'));
|
|
|
66 |
|
|
|
67 |
// Conditionally restore course badges.
|
|
|
68 |
if ($this->get_setting_value('badges')) {
|
|
|
69 |
$this->add_step(new restore_badges_structure_step('course_badges', 'badges.xml'));
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
// Review all the legacy module_availability records in backup_ids in
|
|
|
73 |
// order to match them with existing modules / grade items and convert
|
|
|
74 |
// into the new system.
|
|
|
75 |
$this->add_step(new restore_process_course_modules_availability('process_modules_availability'));
|
|
|
76 |
|
|
|
77 |
// Update restored availability data to account for changes in IDs
|
|
|
78 |
// during backup/restore.
|
|
|
79 |
$this->add_step(new restore_update_availability('update_availability'));
|
|
|
80 |
|
|
|
81 |
// Refresh action events conditionally.
|
|
|
82 |
if ($this->get_setting_value('activities')) {
|
|
|
83 |
$this->add_step(new restore_calendar_action_events('restoring_action_events'));
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
// Decode all the interlinks
|
|
|
87 |
$this->add_step(new restore_decode_interlinks('decode_interlinks'));
|
|
|
88 |
|
|
|
89 |
// Restore course logs (conditionally). They are restored here because we need all
|
|
|
90 |
// the activities to be already restored.
|
|
|
91 |
if ($this->get_setting_value('logs')) {
|
|
|
92 |
// Legacy logs.
|
|
|
93 |
$this->add_step(new restore_course_logs_structure_step('course_logs', 'course/logs.xml'));
|
|
|
94 |
// New log stores.
|
|
|
95 |
$this->add_step(new restore_course_logstores_structure_step('course_logstores', 'course/logstores.xml'));
|
|
|
96 |
// Last access to course logs.
|
|
|
97 |
$this->add_step(new restore_course_loglastaccess_structure_step('course_loglastaccess', 'course/loglastaccess.xml'));
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
// Review all the executed tasks having one after_restore method
|
|
|
101 |
// executing it to perform some final adjustments of information
|
|
|
102 |
// not available when the task was executed.
|
|
|
103 |
// This step is always the last one performing modifications on restored information
|
|
|
104 |
// Don't add any new step after it. Only aliases queue, cache rebuild and clean are allowed.
|
|
|
105 |
$this->add_step(new restore_execute_after_restore('executing_after_restore'));
|
|
|
106 |
|
|
|
107 |
// All files were sent to the filepool by now. We need to process
|
|
|
108 |
// the aliases yet as they were not actually created but stashed for us instead.
|
|
|
109 |
// We execute this step after executing_after_restore so that there can't be no
|
|
|
110 |
// more files sent to the filepool after this.
|
|
|
111 |
$this->add_step(new restore_process_file_aliases_queue('process_file_aliases_queue'));
|
|
|
112 |
|
|
|
113 |
// Rebuild course cache to see results, whoah!
|
|
|
114 |
$this->add_step(new restore_rebuild_course_cache('rebuild_course_cache'));
|
|
|
115 |
|
|
|
116 |
// Clean the temp dir (conditionally) and drop temp table
|
|
|
117 |
$this->add_step(new restore_drop_and_clean_temp_stuff('drop_and_clean_temp_stuff'));
|
|
|
118 |
|
|
|
119 |
// If restoring to a new course or overwriting config, reindex the whole course.
|
|
|
120 |
if (\core_search\manager::is_indexing_enabled()) {
|
|
|
121 |
$wholecourse = $this->get_target() == backup::TARGET_NEW_COURSE;
|
|
|
122 |
$wholecourse = $wholecourse || $this->setting_exists('overwrite_conf') && $this->get_setting_value('overwrite_conf');
|
|
|
123 |
if ($wholecourse) {
|
|
|
124 |
$this->add_step(new restore_course_search_index('course_search_index'));
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
$this->built = true;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/**
|
|
|
132 |
* Special method, only available in the restore_final_task, able to invoke the
|
|
|
133 |
* restore_plan execute_after_restore() method, so restore_execute_after_restore step
|
|
|
134 |
* will be able to launch all the after_restore() methods of the executed tasks
|
|
|
135 |
*/
|
|
|
136 |
public function launch_execute_after_restore() {
|
|
|
137 |
$this->plan->execute_after_restore();
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
/**
|
|
|
141 |
* Define the restore log rules that will be applied
|
|
|
142 |
* by the {@link restore_logs_processor} when restoring
|
|
|
143 |
* course logs. It must return one array
|
|
|
144 |
* of {@link restore_log_rule} objects
|
|
|
145 |
*
|
|
|
146 |
* Note these are course logs, but are defined and restored
|
|
|
147 |
* in final task because we need all the activities to be
|
|
|
148 |
* restored in order to handle some log records properly
|
|
|
149 |
*/
|
|
|
150 |
public static function define_restore_log_rules() {
|
|
|
151 |
$rules = array();
|
|
|
152 |
|
|
|
153 |
// module 'course' rules
|
|
|
154 |
$rules[] = new restore_log_rule('course', 'view', 'view.php?id={course}', '{course}');
|
|
|
155 |
$rules[] = new restore_log_rule('course', 'guest', 'view.php?id={course}', null);
|
|
|
156 |
$rules[] = new restore_log_rule('course', 'user report', 'user.php?id={course}&user={user}&mode=[mode]', null);
|
|
|
157 |
$rules[] = new restore_log_rule('course', 'add mod', '../mod/[modname]/view.php?id={course_module}', '[modname] {[modname]}');
|
|
|
158 |
$rules[] = new restore_log_rule('course', 'update mod', '../mod/[modname]/view.php?id={course_module}', '[modname] {[modname]}');
|
|
|
159 |
$rules[] = new restore_log_rule('course', 'delete mod', 'view.php?id={course}', null);
|
|
|
160 |
$rules[] = new restore_log_rule('course', 'update', 'view.php?id={course}', '');
|
|
|
161 |
$rules[] = new restore_log_rule('course', 'enrol', 'view.php?id={course}', '{user}');
|
|
|
162 |
$rules[] = new restore_log_rule('course', 'unenrol', 'view.php?id={course}', '{user}');
|
|
|
163 |
$rules[] = new restore_log_rule('course', 'editsection', 'editsection.php?id={course_section}', null);
|
|
|
164 |
$rules[] = new restore_log_rule('course', 'new', 'view.php?id={course}', '');
|
|
|
165 |
$rules[] = new restore_log_rule('course', 'recent', 'recent.php?id={course}', '');
|
|
|
166 |
$rules[] = new restore_log_rule('course', 'report log', 'report/log/index.php?id={course}', '{course}');
|
|
|
167 |
$rules[] = new restore_log_rule('course', 'report live', 'report/live/index.php?id={course}', '{course}');
|
|
|
168 |
$rules[] = new restore_log_rule('course', 'report outline', 'report/outline/index.php?id={course}', '{course}');
|
|
|
169 |
$rules[] = new restore_log_rule('course', 'report participation', 'report/participation/index.php?id={course}', '{course}');
|
|
|
170 |
$rules[] = new restore_log_rule('course', 'report stats', 'report/stats/index.php?id={course}', '{course}');
|
|
|
171 |
$rules[] = new restore_log_rule('course', 'view section', 'view.php?id={course}§ionid={course_section}', '{course_section}');
|
|
|
172 |
|
|
|
173 |
// module 'grade' rules
|
|
|
174 |
$rules[] = new restore_log_rule('grade', 'update', 'report/grader/index.php?id={course}', null);
|
|
|
175 |
|
|
|
176 |
// module 'user' rules
|
|
|
177 |
$rules[] = new restore_log_rule('user', 'view', 'view.php?id={user}&course={course}', '{user}');
|
|
|
178 |
$rules[] = new restore_log_rule('user', 'change password', 'view.php?id={user}&course={course}', '{user}');
|
|
|
179 |
$rules[] = new restore_log_rule('user', 'login', 'view.php?id={user}&course={course}', '{user}');
|
|
|
180 |
$rules[] = new restore_log_rule('user', 'logout', 'view.php?id={user}&course={course}', '{user}');
|
|
|
181 |
$rules[] = new restore_log_rule('user', 'view all', 'index.php?id={course}', '');
|
|
|
182 |
$rules[] = new restore_log_rule('user', 'update', 'view.php?id={user}&course={course}', '');
|
|
|
183 |
|
|
|
184 |
// rules from other tasks (activities) not belonging to one module instance (cmid = 0), so are restored here
|
|
|
185 |
$rules = array_merge($rules, restore_logs_processor::register_log_rules_for_course());
|
|
|
186 |
|
|
|
187 |
// Calendar rules.
|
|
|
188 |
$rules[] = new restore_log_rule('calendar', 'add', 'event.php?action=edit&id={event}', '[name]');
|
|
|
189 |
$rules[] = new restore_log_rule('calendar', 'edit', 'event.php?action=edit&id={event}', '[name]');
|
|
|
190 |
$rules[] = new restore_log_rule('calendar', 'edit all', 'event.php?action=edit&id={event}', '[name]');
|
|
|
191 |
|
|
|
192 |
// TODO: Other logs like 'upload'... will go here
|
|
|
193 |
|
|
|
194 |
return $rules;
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
// Protected API starts here
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* Define the common setting that any restore type will have
|
|
|
202 |
*/
|
|
|
203 |
protected function define_settings() {
|
|
|
204 |
// This task has not settings (could have them, like destination or so in the future, let's see)
|
|
|
205 |
}
|
|
|
206 |
}
|