Commit | Line | Data |
---|---|---|
482aac65 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 | /** | |
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 common tasks in restore | |
27 | */ | |
28 | ||
29 | /** | |
30 | * delete old directories and conditionally create backup_temp_ids table | |
31 | */ | |
32 | class restore_create_and_clean_temp_stuff extends restore_execution_step { | |
33 | ||
34 | protected function define_execution() { | |
35 | backup_helper::delete_old_backup_dirs(time() - (4 * 60 * 60)); // Delete > 4 hours temp dirs | |
36 | $exists = restore_controller_dbops::create_backup_ids_temp_table($this->get_restoreid()); // Create temp table conditionally | |
37 | // If the table already exists, it's because restore_prechecks have been executed in the same | |
38 | // request (without problems) and it already contains a bunch of preloaded information (users...) | |
39 | // that we aren't going to execute again | |
40 | if ($exists) { // Inform plan about preloaded information | |
41 | $this->task->set_preloaded_information(); | |
42 | } | |
43 | } | |
44 | } | |
45 | ||
46 | /** | |
47 | * delete the temp dir used by backup/restore (conditionally), | |
48 | * delete old directories and drop temp ids table | |
49 | */ | |
50 | class restore_drop_and_clean_temp_stuff extends restore_execution_step { | |
51 | ||
52 | protected function define_execution() { | |
53 | global $CFG; | |
54 | backup_controller_dbops::drop_backup_ids_temp_table($this->get_restoreid()); // Drop ids temp table | |
55 | backup_helper::delete_old_backup_dirs(time() - (4 * 60 * 60)); // Delete > 4 hours temp dirs | |
56 | if (empty($CFG->keeptempdirectoriesonbackup)) { // Conditionally | |
57 | backup_helper::delete_backup_dir($this->get_restoreid()); // Empty backup dir | |
58 | } | |
59 | } | |
60 | } | |
61 | ||
62 | /* | |
63 | * Execution step that, *conditionally* (if there isn't preloaded information) | |
64 | * will load the inforef files for all the included course/section/activity tasks | |
65 | * to backup_temp_ids. They will be stored with "xxxxref" as itemname | |
66 | */ | |
67 | class restore_load_included_inforef_records extends restore_execution_step { | |
68 | ||
69 | protected function define_execution() { | |
70 | ||
71 | if ($this->task->get_preloaded_information()) { // if info is already preloaded, nothing to do | |
72 | return; | |
73 | } | |
74 | ||
75 | // Get all the included inforef files | |
76 | $files = restore_dbops::get_needed_inforef_files($this->get_restoreid()); | |
77 | foreach ($files as $file) { | |
78 | restore_dbops::load_inforef_to_tempids($this->get_restoreid(), $file); // Load each inforef file to temp_ids | |
79 | } | |
80 | } | |
81 | } | |
82 | ||
83 | /** | |
84 | * Execution step that, *conditionally* (if there isn't preloaded information | |
85 | * and users have been selected in settings, will load all the needed users | |
86 | * to backup_temp_ids. They will be stored with "user" itemname and with | |
87 | * their original contextid as paremitemid. | |
88 | */ | |
89 | class restore_load_included_users extends restore_execution_step { | |
90 | ||
91 | protected function define_execution() { | |
92 | ||
93 | if ($this->task->get_preloaded_information()) { // if info is already preloaded, nothing to do | |
94 | return; | |
95 | } | |
96 | if (!$this->task->get_setting('users')) { // No userinfo being restored, nothing to do | |
97 | return; | |
98 | } | |
99 | $file = $this->get_basepath() . '/users.xml'; | |
100 | restore_dbops::load_users_to_tempids($this->get_restoreid(), $file); // Load needed users to temp_ids | |
101 | } | |
102 | } | |
103 | ||
104 | /** | |
105 | * Execution step that, *conditionally* (if there isn't preloaded information | |
106 | * and users have been selected in settings, will process all the needed users | |
107 | * in order to decide and perform any action with them (create / map / error) | |
108 | * Note: Any error will cause exception, as far as this is the same processing | |
109 | * than the one into restore prechecks (that should have stopped process earlier) | |
110 | */ | |
111 | class restore_process_included_users extends restore_execution_step { | |
112 | ||
113 | protected function define_execution() { | |
114 | ||
115 | if ($this->task->get_preloaded_information()) { // if info is already preloaded, nothing to do | |
116 | return; | |
117 | } | |
118 | if (!$this->task->get_setting('users')) { // No userinfo being restored, nothing to do | |
119 | return; | |
120 | } | |
121 | restore_dbops::process_included_users($this->get_restoreid(), $this->task->get_courseid(), $this->task->get_userid(), $this->task->is_samesite()); | |
122 | } | |
123 | } | |
124 | ||
125 | /* | |
126 | * Structure step that will read the course.xml file, loading it and performing | |
127 | * various actions depending of the site/restore settings | |
128 | */ | |
129 | class restore_course_structure_step extends restore_structure_step { | |
130 | ||
131 | protected function define_structure() { | |
132 | ||
133 | $course = new restore_path_element('course', '/course', true); // Grouped | |
134 | $category = new restore_path_element('category', '/course/category'); | |
135 | $tag = new restore_path_element('tag', '/course/tags/tag'); | |
136 | $allowed = new restore_path_element('allowed', '/course/allowed_modules/module'); | |
137 | ||
138 | return array($course, $category, $tag, $allowed); | |
139 | } | |
140 | ||
141 | // Processing functions go here | |
142 | public function process_course($data) { | |
143 | print_object('stopped before processing course. Continue here'); | |
144 | } | |
145 | ||
146 | } |