MDL-21432 backup - restore course/tags/rolenames/files
[moodle.git] / backup / moodle2 / restore_root_task.class.php
CommitLineData
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/**
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 * Start task that provides all the settings common to all restores and other initial steps
27 *
28 * TODO: Finish phpdocs
29 */
30class restore_root_task extends restore_task {
31
32 /**
33 * Create all the steps that will be part of this task
34 */
35 public function build() {
36
482aac65
EL
37 // Conditionally create the temp table (can exist from prechecks) and delete old stuff
38 $this->add_step(new restore_create_and_clean_temp_stuff('create_and_clean_temp_stuff'));
39
40 // If we haven't preloaded information, load all the included inforef records to temp_ids table
41 $this->add_step(new restore_load_included_inforef_records('load_inforef_records'));
42
71a50b13
EL
43 // If we haven't preloaded information, load all the needed roles to temp_ids_table
44 $this->add_step(new restore_load_and_map_roles('load_and_map_roles'));
45
482aac65
EL
46 // If we haven't preloaded information and are restoring user info, load all the needed users to temp_ids table
47 $this->add_step(new restore_load_included_users('load_user_records'));
48
49 // If we haven't preloaded information and are restoring user info, process all those needed users
50 // creating/mapping them as needed. Any problem here will cause exception as far as prechecks have
51 // performed the same process so, it's not possible to have errors here
52 $this->add_step(new restore_process_included_users('process_user_records'));
864842aa 53
76cfb124
EL
54 // Load all the needed files to temp_ids table
55 $this->add_step(new restore_load_included_files('load_file_records', 'files.xml'));
56
57 // Unconditionally, create all the needed users calculated in the previous step
58 $this->add_step(new restore_create_included_users('create_users'));
59
60 // Unconditionally, load create all the needed groups and groupings
61 $this->add_step(new restore_groups_structure_step('create_groups_and_groupings', 'groups.xml'));
62
c0440b3f
EL
63 // Unconditionally, load create all the needed scales
64 $this->add_step(new restore_scales_structure_step('create_scales', 'scales.xml'));
65
c8730ff0
EL
66 // Unconditionally, load create all the needed outcomes
67 $this->add_step(new restore_outcomes_structure_step('create_scales', 'outcomes.xml'));
68
864842aa
EL
69 // At the end, mark it as built
70 $this->built = true;
71 }
72
73// Protected API starts here
74
75 /**
76 * Define the common setting that any restore type will have
77 */
78 protected function define_settings() {
79
80 // Load all the root settings found in backup file from controller
81 $rootsettings = $this->get_info()->root_settings;
82
83 // Define users setting (keeping it on hand to define dependencies)
84 $selectvalues = array(0=>get_string('no')); // Safer options
85 $defaultvalue = false; // Safer default
86 if (isset($rootsettings['users']) && $rootsettings['users']) { // Only enabled when available
87 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
88 $defaultvalue = true;
89 }
90 $users = new restore_users_setting('users', base_setting::IS_BOOLEAN, $defaultvalue);
91 $users->set_ui(new backup_setting_ui_select($users, $users->get_name(), $selectvalues));
92 $this->add_setting($users);
93
94 // Define role_assignments (dependent of users)
95 $selectvalues = array(0=>get_string('no')); // Safer options
96 $defaultvalue = false; // Safer default
97 if (isset($rootsettings['role_assignments']) && $rootsettings['role_assignments']) { // Only enabled when available
98 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
99 $defaultvalue = true;
100 }
101 $roleassignments = new restore_role_assignments_setting('role_assignments', base_setting::IS_BOOLEAN, $defaultvalue);
102 $roleassignments->set_ui(new backup_setting_ui_select($roleassignments, $roleassignments->get_name(), $selectvalues));
103 $this->add_setting($roleassignments);
104 $users->add_dependency($roleassignments);
105
106 // Define user_files (dependent of users)
107 $selectvalues = array(0=>get_string('no')); // Safer options
108 $defaultvalue = false; // Safer default
109 if (isset($rootsettings['user_files']) && $rootsettings['user_files']) { // Only enabled when available
110 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
111 $defaultvalue = true;
112 }
113 $userfiles = new restore_user_files_setting('user_files', base_setting::IS_BOOLEAN, $defaultvalue);
114 $userfiles->set_ui(new backup_setting_ui_select($userfiles, $userfiles->get_name(), $selectvalues));
115 $this->add_setting($userfiles);
116 $users->add_dependency($userfiles);
117
118 // Define activitites
119 $selectvalues = array(0=>get_string('no')); // Safer options
120 $defaultvalue = false; // Safer default
121 if (isset($rootsettings['activities']) && $rootsettings['activities']) { // Only enabled when available
122 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
123 $defaultvalue = true;
124 }
125 $activities = new restore_activities_setting('activities', base_setting::IS_BOOLEAN, $defaultvalue);
126 $activities->set_ui(new backup_setting_ui_select($activities, $activities->get_name(), $selectvalues));
127 $this->add_setting($activities);
128
129 // Define blocks
130 $selectvalues = array(0=>get_string('no')); // Safer options
131 $defaultvalue = false; // Safer default
132 if (isset($rootsettings['blocks']) && $rootsettings['blocks']) { // Only enabled when available
133 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
134 $defaultvalue = true;
135 }
136 $blocks = new restore_generic_setting('blocks', base_setting::IS_BOOLEAN, $defaultvalue);
137 $blocks->set_ui(new backup_setting_ui_select($blocks, $blocks->get_name(), $selectvalues));
138 $this->add_setting($blocks);
139
140 // Define filters
141 $selectvalues = array(0=>get_string('no')); // Safer options
142 $defaultvalue = false; // Safer default
143 if (isset($rootsettings['filters']) && $rootsettings['filters']) { // Only enabled when available
144 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
145 $defaultvalue = true;
146 }
147 $filters = new restore_generic_setting('filters', base_setting::IS_BOOLEAN, $defaultvalue);
148 $filters->set_ui(new backup_setting_ui_select($filters, $filters->get_name(), $selectvalues));
149 $this->add_setting($filters);
150
151 // Define comments (dependent of users)
152 $selectvalues = array(0=>get_string('no')); // Safer options
153 $defaultvalue = false; // Safer default
154 if (isset($rootsettings['comments']) && $rootsettings['comments']) { // Only enabled when available
155 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
156 $defaultvalue = true;
157 }
158 $comments = new restore_comments_setting('comments', base_setting::IS_BOOLEAN, $defaultvalue);
159 $comments->set_ui(new backup_setting_ui_select($comments, $comments->get_name(), $selectvalues));
160 $this->add_setting($comments);
161 $users->add_dependency($comments);
162
163 // Define completion (dependent of users)
164 $selectvalues = array(0=>get_string('no')); // Safer options
165 $defaultvalue = false; // Safer default
166 if (isset($rootsettings['userscompletion']) && $rootsettings['userscompletion']) { // Only enabled when available
167 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
168 $defaultvalue = true;
169 }
170 $completion = new restore_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, $defaultvalue);
171 $completion->set_ui(new backup_setting_ui_select($completion, $completion->get_name(), $selectvalues));
172 $this->add_setting($completion);
173 $users->add_dependency($completion);
174
175 // Define logs (dependent of users)
176 $selectvalues = array(0=>get_string('no')); // Safer options
177 $defaultvalue = false; // Safer default
178 if (isset($rootsettings['logs']) && $rootsettings['logs']) { // Only enabled when available
179 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
180 $defaultvalue = true;
181 }
182 $logs = new restore_logs_setting('logs', base_setting::IS_BOOLEAN, $defaultvalue);
183 $logs->set_ui(new backup_setting_ui_select($logs, $logs->get_name(), $selectvalues));
184 $this->add_setting($logs);
185 $users->add_dependency($logs);
186
187 // Define grade_histories (dependent of users)
188 $selectvalues = array(0=>get_string('no')); // Safer options
189 $defaultvalue = false; // Safer default
190 if (isset($rootsettings['grade_histories']) && $rootsettings['grade_histories']) { // Only enabled when available
191 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
192 $defaultvalue = true;
193 }
194 $gradehistories = new restore_grade_histories_setting('grade_histories', base_setting::IS_BOOLEAN, $defaultvalue);
195 $gradehistories->set_ui(new backup_setting_ui_select($gradehistories, $gradehistories->get_name(), $selectvalues));
196 $this->add_setting($gradehistories);
197 $users->add_dependency($gradehistories);
198 }
199}