MDL-21432 backup - complete standard/course outcomes backup & restore
[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
c3ea499d
EL
69 // Unconditionally, load create all the needed outcomes.
70 // TODO: restore outcomes
71 // $this->add_step(new restore_outcomes_structure_step('create_outcomes', 'outcomes.xml'));
72
864842aa
EL
73 // At the end, mark it as built
74 $this->built = true;
75 }
76
77// Protected API starts here
78
79 /**
80 * Define the common setting that any restore type will have
81 */
82 protected function define_settings() {
83
84 // Load all the root settings found in backup file from controller
85 $rootsettings = $this->get_info()->root_settings;
86
87 // Define users setting (keeping it on hand to define dependencies)
88 $selectvalues = array(0=>get_string('no')); // Safer options
89 $defaultvalue = false; // Safer default
90 if (isset($rootsettings['users']) && $rootsettings['users']) { // Only enabled when available
91 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
92 $defaultvalue = true;
93 }
94 $users = new restore_users_setting('users', base_setting::IS_BOOLEAN, $defaultvalue);
95 $users->set_ui(new backup_setting_ui_select($users, $users->get_name(), $selectvalues));
96 $this->add_setting($users);
97
98 // Define role_assignments (dependent of users)
99 $selectvalues = array(0=>get_string('no')); // Safer options
100 $defaultvalue = false; // Safer default
101 if (isset($rootsettings['role_assignments']) && $rootsettings['role_assignments']) { // Only enabled when available
102 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
103 $defaultvalue = true;
104 }
105 $roleassignments = new restore_role_assignments_setting('role_assignments', base_setting::IS_BOOLEAN, $defaultvalue);
106 $roleassignments->set_ui(new backup_setting_ui_select($roleassignments, $roleassignments->get_name(), $selectvalues));
107 $this->add_setting($roleassignments);
108 $users->add_dependency($roleassignments);
109
110 // Define user_files (dependent of users)
111 $selectvalues = array(0=>get_string('no')); // Safer options
112 $defaultvalue = false; // Safer default
113 if (isset($rootsettings['user_files']) && $rootsettings['user_files']) { // Only enabled when available
114 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
115 $defaultvalue = true;
116 }
117 $userfiles = new restore_user_files_setting('user_files', base_setting::IS_BOOLEAN, $defaultvalue);
118 $userfiles->set_ui(new backup_setting_ui_select($userfiles, $userfiles->get_name(), $selectvalues));
119 $this->add_setting($userfiles);
120 $users->add_dependency($userfiles);
121
122 // Define activitites
123 $selectvalues = array(0=>get_string('no')); // Safer options
124 $defaultvalue = false; // Safer default
125 if (isset($rootsettings['activities']) && $rootsettings['activities']) { // Only enabled when available
126 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
127 $defaultvalue = true;
128 }
129 $activities = new restore_activities_setting('activities', base_setting::IS_BOOLEAN, $defaultvalue);
130 $activities->set_ui(new backup_setting_ui_select($activities, $activities->get_name(), $selectvalues));
131 $this->add_setting($activities);
132
133 // Define blocks
134 $selectvalues = array(0=>get_string('no')); // Safer options
135 $defaultvalue = false; // Safer default
136 if (isset($rootsettings['blocks']) && $rootsettings['blocks']) { // Only enabled when available
137 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
138 $defaultvalue = true;
139 }
140 $blocks = new restore_generic_setting('blocks', base_setting::IS_BOOLEAN, $defaultvalue);
141 $blocks->set_ui(new backup_setting_ui_select($blocks, $blocks->get_name(), $selectvalues));
142 $this->add_setting($blocks);
143
144 // Define filters
145 $selectvalues = array(0=>get_string('no')); // Safer options
146 $defaultvalue = false; // Safer default
147 if (isset($rootsettings['filters']) && $rootsettings['filters']) { // Only enabled when available
148 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
149 $defaultvalue = true;
150 }
151 $filters = new restore_generic_setting('filters', base_setting::IS_BOOLEAN, $defaultvalue);
152 $filters->set_ui(new backup_setting_ui_select($filters, $filters->get_name(), $selectvalues));
153 $this->add_setting($filters);
154
155 // Define comments (dependent of users)
156 $selectvalues = array(0=>get_string('no')); // Safer options
157 $defaultvalue = false; // Safer default
158 if (isset($rootsettings['comments']) && $rootsettings['comments']) { // Only enabled when available
159 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
160 $defaultvalue = true;
161 }
162 $comments = new restore_comments_setting('comments', base_setting::IS_BOOLEAN, $defaultvalue);
163 $comments->set_ui(new backup_setting_ui_select($comments, $comments->get_name(), $selectvalues));
164 $this->add_setting($comments);
165 $users->add_dependency($comments);
166
167 // Define completion (dependent of users)
168 $selectvalues = array(0=>get_string('no')); // Safer options
169 $defaultvalue = false; // Safer default
170 if (isset($rootsettings['userscompletion']) && $rootsettings['userscompletion']) { // Only enabled when available
171 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
172 $defaultvalue = true;
173 }
174 $completion = new restore_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, $defaultvalue);
175 $completion->set_ui(new backup_setting_ui_select($completion, $completion->get_name(), $selectvalues));
176 $this->add_setting($completion);
177 $users->add_dependency($completion);
178
179 // Define logs (dependent of users)
180 $selectvalues = array(0=>get_string('no')); // Safer options
181 $defaultvalue = false; // Safer default
182 if (isset($rootsettings['logs']) && $rootsettings['logs']) { // Only enabled when available
183 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
184 $defaultvalue = true;
185 }
186 $logs = new restore_logs_setting('logs', base_setting::IS_BOOLEAN, $defaultvalue);
187 $logs->set_ui(new backup_setting_ui_select($logs, $logs->get_name(), $selectvalues));
188 $this->add_setting($logs);
189 $users->add_dependency($logs);
190
191 // Define grade_histories (dependent of users)
192 $selectvalues = array(0=>get_string('no')); // Safer options
193 $defaultvalue = false; // Safer default
194 if (isset($rootsettings['grade_histories']) && $rootsettings['grade_histories']) { // Only enabled when available
195 $selectvalues = array(1=>get_string('yes'), 0=>get_string('no'));
196 $defaultvalue = true;
197 }
198 $gradehistories = new restore_grade_histories_setting('grade_histories', base_setting::IS_BOOLEAN, $defaultvalue);
199 $gradehistories->set_ui(new backup_setting_ui_select($gradehistories, $gradehistories->get_name(), $selectvalues));
200 $this->add_setting($gradehistories);
201 $users->add_dependency($gradehistories);
202 }
203}