8b48c0cba9716aeb680d4ae36ffeff96cdfebef1
[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 {
40 }
42 /**
43  * root setting to control if backup will include user information
44  * A lot of other settings are dependant of this (module's user info,
45  * grades user info, messages, blogs...
46  */
47 class backup_users_setting extends backup_generic_setting {
48 }
50 /**
51  * root setting to control if backup will include activities or no.
52  * A lot of other settings (_included at activity levels)
53  * are dependent of this setting
54  */
55 class backup_activities_setting extends backup_generic_setting {
56 }
58 /**
59  * root setting to control if backup will generate anonymized
60  * user info or no, depends of @backup_users_setting so only is
61  * availabe if the former is enabled (apart from security
62  * that can change it
63  */
64 class backup_anonymize_setting extends root_backup_setting {
65     public function process_change($setting, $ctype, $oldv) {
66         // If change detected in backup_users_setting, proceed
67         if ($setting instanceof backup_users_setting) {
68             switch ($ctype) {
69                 case self::CHANGED_VALUE: // backup_users = false, this too, and locked
70                     if (!$setting->get_value()) {
71                         $this->set_value(false);
72                         $this->set_status(self::LOCKED_BY_HIERARCHY);
73                     }
74                     break;
75                 case self::CHANGED_VISIBILITY: // backup_users not visible, this too
76                     if (!$setting->get_visibility()) {
77                         $this->set_visibility(false);
78                     }
79                     break;
80                 case self::CHANGED_STATUS: // backup_users unlocked, this too
81                     if ($setting->get_status() == self::NOT_LOCKED) {
82                         $this->set_status(self::NOT_LOCKED);
83                     }
84                     break;
85             }
86         }
87     }
88 }
90 /**
91  * root setting to control if backup will include
92  * user files or no (images, local storage), depends of @backup_users_setting
93  * exactly in the same way than @backup_anonymize_setting so we extend from it
94  */
95 class backup_user_files_setting extends backup_anonymize_setting {
96     // Nothing to do. All the logic is in backup_anonymize_setting
97 }
99 /**
100  * root setting to control if backup will include
101  * role assignments or no (any level), depends of @backup_users_setting
102  * exactly in the same way than @backup_anonymize_setting so we extend from it
103  */
104 class backup_role_assignments_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  * logs 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_logs_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  * comments 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_comments_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  * users completion data 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_userscompletion_setting extends backup_anonymize_setting {
132     // Nothing to do. All the logic is in backup_anonymize_setting
135 // Section backup settings
137 /**
138  * generic section setting to pass various settings between tasks and steps
139  */
140 class backup_section_generic_setting extends section_backup_setting {
141     public function process_change($setting, $ctype, $oldv) {
142         // Nothing to do, no dependencies
143     }
146 /**
147  * Setting to define if one section is included or no. Activities _included
148  * settings depend of them if available
149  */
150 class backup_section_included_setting extends section_backup_setting {
151     public function process_change($setting, $ctype, $oldv) {
152         // Nothing to do, no dependencies
153     }
156 /**
157  * section backup setting to control if section will include
158  * user information or no, depends of @backup_users_setting
159  */
160 class backup_section_userinfo_setting extends section_backup_setting {
161     public function process_change($setting, $ctype, $oldv) {
162         // If change detected in backup_users_setting
163         if ($setting instanceof backup_users_setting) {
164             switch ($ctype) {
165                 case self::CHANGED_VALUE: // backup_users = false, this too, and locked
166                     if (!$setting->get_value()) {
167                         $this->set_value(false);
168                         $this->set_status(self::LOCKED_BY_HIERARCHY);
169                     }
170                     break;
171                 case self::CHANGED_VISIBILITY: // backup_users not visible, this too
172                     if (!$setting->get_visibility()) {
173                         $this->set_visibility(false);
174                     }
175                     break;
176                 case self::CHANGED_STATUS: // backup_users unlocked, this too
177                     if ($setting->get_status() == self::NOT_LOCKED) {
178                         $this->set_status(self::NOT_LOCKED);
179                     }
180                     break;
181             }
182         }
183     }
187 // Activity backup settings
189 /**
190  * generic activity setting to pass various settings between tasks and steps
191  */
192 class backup_activity_generic_setting extends activity_backup_setting {
193     public function process_change($setting, $ctype, $oldv) {
194         // Nothing to do, no dependencies
195     }
198 /**
199  * activity backup setting to control if activity will
200  * be included or no, depends of @backup_activities_setting and
201  * optionally parent section included setting
202  */
203 class backup_activity_included_setting extends activity_backup_setting {
204     public function process_change($setting, $ctype, $oldv) {
205         // If change detected in backup_activities_setting or backup_section_included_setting
206         if ($setting instanceof backup_activities_setting ||
207             $setting instanceof backup_section_included_setting) {
208             switch ($ctype) {
209                 case self::CHANGED_VALUE: // backup_users = false, this too, and locked
210                     if (!$setting->get_value()) {
211                         $this->set_value(false);
212                         $this->set_status(self::LOCKED_BY_HIERARCHY);
213                     }
214                     break;
215                 case self::CHANGED_VISIBILITY: // backup_users not visible, this too
216                     if (!$setting->get_visibility()) {
217                         $this->set_visibility(false);
218                     }
219                     break;
220                 case self::CHANGED_STATUS: // backup_users unlocked, this too
221                     if ($setting->get_status() == self::NOT_LOCKED) {
222                         $this->set_status(self::NOT_LOCKED);
223                     }
224                     break;
225             }
226         }
227     }
230 /**
231  * activity backup setting to control if activity will include
232  * user information or no, depends of @backup_users_setting
233  */
234 class backup_activity_userinfo_setting extends activity_backup_setting {
235     public function process_change($setting, $ctype, $oldv) {
236         // If change detected in backup_users_setting or backup_section_userinfo_setting
237         if ($setting instanceof backup_users_setting ||
238             $setting instanceof backup_section_userinfo_setting) {
239             switch ($ctype) {
240                 case self::CHANGED_VALUE: // backup_users = false, this too, and locked
241                     if (!$setting->get_value()) {
242                         $this->set_value(false);
243                         $this->set_status(self::LOCKED_BY_HIERARCHY);
244                     }
245                     break;
246                 case self::CHANGED_VISIBILITY: // backup_users not visible, this too
247                     if (!$setting->get_visibility()) {
248                         $this->set_visibility(false);
249                     }
250                     break;
251                 case self::CHANGED_STATUS: // backup_users unlocked, this too
252                     if ($setting->get_status() == self::NOT_LOCKED) {
253                         $this->set_status(self::NOT_LOCKED);
254                     }
255                     break;
256             }
257         }
258     }