backup MDL-22142 This is the user interface for backups, several minor/cosmetic issue...
[moodle.git] / backup / moodle2 / backup_settingslib.php
1 <?php
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/>.
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  */
25 // Root backup settings
27 /**
28  * root generic setting to store different things without dependencies
29  */
30 class backup_generic_setting extends root_backup_setting {
31     public function process_change($setting, $ctype, $oldv) {
32         // Nothing to do, no dependencies
33     }
34 }
36 /**
37  * root setting to handle backup file names (no dependencies nor anything else)
38  */
39 class backup_filename_setting extends backup_generic_setting {
41     public function  __construct($name, $vtype, $value = null, $visibility = self::VISIBLE, $status = self::NOT_LOCKED) {
42         parent::__construct($name, $vtype, $value, $visibility, $status);
43     }
45     public function set_ui($label, $value, array $options = null) {
46         parent::make_ui(self::UI_HTML_TEXTFIELD, $label, null, $options);
47         $this->set_value($value);
48     }
49 }
51 /**
52  * root setting to control if backup will include user information
53  * A lot of other settings are dependant of this (module's user info,
54  * grades user info, messages, blogs...
55  */
56 class backup_users_setting extends backup_generic_setting {
57 }
59 /**
60  * root setting to control if backup will include activities or no.
61  * A lot of other settings (_included at activity levels)
62  * are dependent of this setting
63  */
64 class backup_activities_setting extends backup_generic_setting {
65 }
67 /**
68  * root setting to control if backup will generate anonymized
69  * user info or no, depends of @backup_users_setting so only is
70  * availabe if the former is enabled (apart from security
71  * that can change it
72  */
73 class backup_anonymize_setting extends root_backup_setting {
74     public function process_change($setting, $ctype, $oldv) {
75         // If change detected in backup_users_setting, proceed
76         if ($setting instanceof backup_users_setting) {
77             switch ($ctype) {
78                 case self::CHANGED_VALUE: // backup_users = false, this too, and locked
79                     if (!$setting->get_value()) {
80                         $this->set_value(false);
81                         $this->set_status(self::LOCKED_BY_HIERARCHY);
82                     }
83                     break;
84                 case self::CHANGED_VISIBILITY: // backup_users not visible, this too
85                     if (!$setting->get_visibility()) {
86                         $this->set_visibility(false);
87                     }
88                     break;
89                 case self::CHANGED_STATUS: // backup_users unlocked, this too
90                     if ($setting->get_status() == self::NOT_LOCKED) {
91                         $this->set_status(self::NOT_LOCKED);
92                     }
93                     break;
94             }
95         }
96     }
97 }
99 /**
100  * root setting to control if backup will include
101  * user files or no (images, local storage), depends of @backup_users_setting
102  * exactly in the same way than @backup_anonymize_setting so we extend from it
103  */
104 class backup_user_files_setting extends backup_anonymize_setting {
105     // Nothing to do. All the logic is in backup_anonymize_setting
108 /**
109  * root setting to control if backup will include
110  * role assignments or no (any level), depends of @backup_users_setting
111  * exactly in the same way than @backup_anonymize_setting so we extend from it
112  */
113 class backup_role_assignments_setting extends backup_anonymize_setting {
114     // Nothing to do. All the logic is in backup_anonymize_setting
117 /**
118  * root setting to control if backup will include
119  * logs or no (any level), depends of @backup_users_setting
120  * exactly in the same way than @backup_anonymize_setting so we extend from it
121  */
122 class backup_logs_setting extends backup_anonymize_setting {
123     // Nothing to do. All the logic is in backup_anonymize_setting
126 /**
127  * root setting to control if backup will include
128  * comments or no (any level), depends of @backup_users_setting
129  * exactly in the same way than @backup_anonymize_setting so we extend from it
130  */
131 class backup_comments_setting extends backup_anonymize_setting {
132     // Nothing to do. All the logic is in backup_anonymize_setting
135 /**
136  * root setting to control if backup will include
137  * users completion data or no (any level), depends of @backup_users_setting
138  * exactly in the same way than @backup_anonymize_setting so we extend from it
139  */
140 class backup_userscompletion_setting extends backup_anonymize_setting {
141     // Nothing to do. All the logic is in backup_anonymize_setting
144 // Section backup settings
146 /**
147  * generic section setting to pass various settings between tasks and steps
148  */
149 class backup_section_generic_setting extends section_backup_setting {
150     public function process_change($setting, $ctype, $oldv) {
151         // Nothing to do, no dependencies
152     }
155 /**
156  * Setting to define if one section is included or no. Activities _included
157  * settings depend of them if available
158  */
159 class backup_section_included_setting extends section_backup_setting {
160     public function process_change($setting, $ctype, $oldv) {
161         // Nothing to do, no dependencies
162     }
165 /**
166  * section backup setting to control if section will include
167  * user information or no, depends of @backup_users_setting
168  */
169 class backup_section_userinfo_setting extends section_backup_setting {
170     public function process_change($setting, $ctype, $oldv) {
171         // If change detected in backup_users_setting
172         if ($setting instanceof backup_users_setting) {
173             switch ($ctype) {
174                 case self::CHANGED_VALUE: // backup_users = false, this too, and locked
175                     if (!$setting->get_value()) {
176                         $this->set_value(false);
177                         $this->set_status(self::LOCKED_BY_HIERARCHY);
178                     }
179                     break;
180                 case self::CHANGED_VISIBILITY: // backup_users not visible, this too
181                     if (!$setting->get_visibility()) {
182                         $this->set_visibility(false);
183                     }
184                     break;
185                 case self::CHANGED_STATUS: // backup_users unlocked, this too
186                     if ($setting->get_status() == self::NOT_LOCKED) {
187                         $this->set_status(self::NOT_LOCKED);
188                     }
189                     break;
190             }
191         }
192     }
196 // Activity backup settings
198 /**
199  * generic activity setting to pass various settings between tasks and steps
200  */
201 class backup_activity_generic_setting extends activity_backup_setting {
202     public function process_change($setting, $ctype, $oldv) {
203         // Nothing to do, no dependencies
204     }
207 /**
208  * activity backup setting to control if activity will
209  * be included or no, depends of @backup_activities_setting and
210  * optionally parent section included setting
211  */
212 class backup_activity_included_setting extends activity_backup_setting {
213     public function process_change($setting, $ctype, $oldv) {
214         // If change detected in backup_activities_setting or backup_section_included_setting
215         if ($setting instanceof backup_activities_setting ||
216             $setting instanceof backup_section_included_setting) {
217             switch ($ctype) {
218                 case self::CHANGED_VALUE: // backup_users = false, this too, and locked
219                     if (!$setting->get_value()) {
220                         $this->set_value(false);
221                         $this->set_status(self::LOCKED_BY_HIERARCHY);
222                     }
223                     break;
224                 case self::CHANGED_VISIBILITY: // backup_users not visible, this too
225                     if (!$setting->get_visibility()) {
226                         $this->set_visibility(false);
227                     }
228                     break;
229                 case self::CHANGED_STATUS: // backup_users unlocked, this too
230                     if ($setting->get_status() == self::NOT_LOCKED) {
231                         $this->set_status(self::NOT_LOCKED);
232                     }
233                     break;
234             }
235         }
236     }
239 /**
240  * activity backup setting to control if activity will include
241  * user information or no, depends of @backup_users_setting
242  */
243 class backup_activity_userinfo_setting extends activity_backup_setting {
244     public function process_change($setting, $ctype, $oldv) {
245         // If change detected in backup_users_setting or backup_section_userinfo_setting
246         if ($setting instanceof backup_users_setting ||
247             $setting instanceof backup_section_userinfo_setting) {
248             switch ($ctype) {
249                 case self::CHANGED_VALUE: // backup_users = false, this too, and locked
250                     if (!$setting->get_value()) {
251                         $this->set_value(false);
252                         $this->set_status(self::LOCKED_BY_HIERARCHY);
253                     }
254                     break;
255                 case self::CHANGED_VISIBILITY: // backup_users not visible, this too
256                     if (!$setting->get_visibility()) {
257                         $this->set_visibility(false);
258                     }
259                     break;
260                 case self::CHANGED_STATUS: // backup_users unlocked, this too
261                     if ($setting->get_status() == self::NOT_LOCKED) {
262                         $this->set_status(self::NOT_LOCKED);
263                     }
264                     break;
265             }
266         }
267     }