Commit | Line | Data |
---|---|---|
864842aa EL |
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 | /** | |
f9dab4be DM |
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 | |
864842aa EL |
26 | */ |
27 | ||
f9dab4be DM |
28 | defined('MOODLE_INTERNAL') || die(); |
29 | ||
864842aa EL |
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 | ||
41941110 EL |
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 | ||
b8e455a7 EL |
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 | ||
9a20df96 AD |
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 | } | |
5ab8d2de | 62 | |
cbed6472 DM |
63 | // Course completion, executed conditionally if restoring to new course |
64 | if ($this->get_target() !== backup::TARGET_CURRENT_ADDING && | |
65 | $this->get_target() !== backup::TARGET_EXISTING_ADDING) { | |
66 | $this->add_step(new restore_course_completion_structure_step('course_completion', 'completion.xml')); | |
67 | } | |
bd39b6f2 | 68 | |
5095f325 EL |
69 | // Review all the module_availability records in backup_ids in order |
70 | // to match them with existing modules / grade items. | |
71 | $this->add_step(new restore_process_course_modules_availability('process_modules_availability')); | |
72 | ||
5ab8d2de EL |
73 | // Decode all the interlinks |
74 | $this->add_step(new restore_decode_interlinks('decode_interlinks')); | |
75 | ||
0f66aced EL |
76 | // Restore course logs (conditionally). They are restored here because we need all |
77 | // the activities to be already restored | |
78 | if ($this->get_setting_value('logs')) { | |
79 | $this->add_step(new restore_course_logs_structure_step('course_logs', 'course/logs.xml')); | |
80 | } | |
81 | ||
648a575e EL |
82 | // Review all the executed tasks having one after_restore method |
83 | // executing it to perform some final adjustments of information | |
84 | // not available when the task was executed. | |
71cbb251 | 85 | // This step is always the last one performing modifications on restored information |
2c142674 | 86 | // Don't add any new step after it. Only aliases queue, cache rebuild and clean are allowed. |
648a575e EL |
87 | $this->add_step(new restore_execute_after_restore('executing_after_restore')); |
88 | ||
2c142674 DM |
89 | // All files were sent to the filepool by now. We need to process |
90 | // the aliases yet as they were not actually created but stashed for us instead. | |
91 | // We execute this step after executing_after_restore so that there can't be no | |
92 | // more files sent to the filepool after this. | |
93 | $this->add_step(new restore_process_file_aliases_queue('process_file_aliases_queue')); | |
94 | ||
71cbb251 EL |
95 | // Rebuild course cache to see results, whoah! |
96 | $this->add_step(new restore_rebuild_course_cache('rebuild_course_cache')); | |
97 | ||
482aac65 EL |
98 | // Clean the temp dir (conditionally) and drop temp table |
99 | $this->add_step(new restore_drop_and_clean_temp_stuff('drop_and_clean_temp_stuff')); | |
100 | ||
864842aa EL |
101 | $this->built = true; |
102 | } | |
103 | ||
648a575e EL |
104 | /** |
105 | * Special method, only available in the restore_final_task, able to invoke the | |
106 | * restore_plan execute_after_restore() method, so restore_execute_after_restore step | |
107 | * will be able to launch all the after_restore() methods of the executed tasks | |
108 | */ | |
109 | public function launch_execute_after_restore() { | |
110 | $this->plan->execute_after_restore(); | |
111 | } | |
112 | ||
0f66aced EL |
113 | /** |
114 | * Define the restore log rules that will be applied | |
115 | * by the {@link restore_logs_processor} when restoring | |
116 | * course logs. It must return one array | |
117 | * of {@link restore_log_rule} objects | |
118 | * | |
119 | * Note these are course logs, but are defined and restored | |
120 | * in final task because we need all the activities to be | |
121 | * restored in order to handle some log records properly | |
122 | */ | |
123 | static public function define_restore_log_rules() { | |
124 | $rules = array(); | |
125 | ||
126 | // module 'course' rules | |
127 | $rules[] = new restore_log_rule('course', 'view', 'view.php?id={course}', '{course}'); | |
128 | $rules[] = new restore_log_rule('course', 'guest', 'view.php?id={course}', null); | |
129 | $rules[] = new restore_log_rule('course', 'user report', 'user.php?id={course}&user={user}&mode=[mode]', null); | |
130 | $rules[] = new restore_log_rule('course', 'add mod', '../mod/[modname]/view.php?id={course_module}', '[modname] {[modname]}'); | |
131 | $rules[] = new restore_log_rule('course', 'update mod', '../mod/[modname]/view.php?id={course_module}', '[modname] {[modname]}'); | |
132 | $rules[] = new restore_log_rule('course', 'delete mod', 'view.php?id={course}', null); | |
133 | $rules[] = new restore_log_rule('course', 'update', 'view.php?id={course}', ''); | |
134 | $rules[] = new restore_log_rule('course', 'enrol', 'view.php?id={course}', '{user}'); | |
135 | $rules[] = new restore_log_rule('course', 'unenrol', 'view.php?id={course}', '{user}'); | |
136 | $rules[] = new restore_log_rule('course', 'editsection', 'editsection.php?id={course_section}', null); | |
137 | $rules[] = new restore_log_rule('course', 'new', 'view.php?id={course}', ''); | |
138 | $rules[] = new restore_log_rule('course', 'recent', 'recent.php?id={course}', ''); | |
139 | $rules[] = new restore_log_rule('course', 'report log', 'report/log/index.php?id={course}', '{course}'); | |
140 | $rules[] = new restore_log_rule('course', 'report live', 'report/live/index.php?id={course}', '{course}'); | |
141 | $rules[] = new restore_log_rule('course', 'report outline', 'report/outline/index.php?id={course}', '{course}'); | |
142 | $rules[] = new restore_log_rule('course', 'report participation', 'report/participation/index.php?id={course}', '{course}'); | |
143 | $rules[] = new restore_log_rule('course', 'report stats', 'report/stats/index.php?id={course}', '{course}'); | |
336d8c49 | 144 | $rules[] = new restore_log_rule('course', 'view section', 'view.php?id={course}§ionid={course_section}', '{course_section}'); |
0f66aced EL |
145 | |
146 | // module 'user' rules | |
147 | $rules[] = new restore_log_rule('user', 'view', 'view.php?id={user}&course={course}', '{user}'); | |
148 | $rules[] = new restore_log_rule('user', 'change password', 'view.php?id={user}&course={course}', '{user}'); | |
149 | $rules[] = new restore_log_rule('user', 'login', 'view.php?id={user}&course={course}', '{user}'); | |
150 | $rules[] = new restore_log_rule('user', 'logout', 'view.php?id={user}&course={course}', '{user}'); | |
151 | $rules[] = new restore_log_rule('user', 'view all', 'index.php?id={course}', ''); | |
152 | $rules[] = new restore_log_rule('user', 'update', 'view.php?id={user}&course={course}', ''); | |
153 | ||
154 | // rules from other tasks (activities) not belonging to one module instance (cmid = 0), so are restored here | |
155 | $rules = array_merge($rules, restore_logs_processor::register_log_rules_for_course()); | |
156 | ||
157 | // TODO: Other logs like 'calendar', 'upload'... will go here | |
158 | ||
159 | return $rules; | |
160 | } | |
161 | ||
162 | ||
864842aa EL |
163 | // Protected API starts here |
164 | ||
165 | /** | |
166 | * Define the common setting that any restore type will have | |
167 | */ | |
168 | protected function define_settings() { | |
169 | // This task has not settings (could have them, like destination or so in the future, let's see) | |
170 | } | |
171 | } |