Merge branch 'MDL-42956-master' of git://github.com/lameze/moodle
[moodle.git] / backup / moodle2 / backup_root_task.class.php
blob3e97f689ff45ff20f74e0a27bfb04c3e44b7c999
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.
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 * Defines backup_root_task class
21 * @package core_backup
22 * @subpackage moodle2
23 * @category backup
24 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
30 /**
31 * Start task that provides all the settings common to all backups and some initialization steps
33 * TODO: Finish phpdocs
35 class backup_root_task extends backup_task {
37 /**
38 * Create all the steps that will be part of this task
40 public function build() {
42 // Add all the steps needed to prepare any moodle2 backup to work
43 $this->add_step(new create_and_clean_temp_stuff('create_and_clean_temp_stuff'));
45 $this->built = true;
48 // Protected API starts here
50 protected function converter_deps($main_setting, $converters) {
51 foreach ($this->settings as $setting) {
52 $name = $setting->get_name();
53 if (in_array($name, $converters)) {
54 $setvalue = convert_helper::export_converter_dependencies($name, $main_setting->get_name());
55 if ($setvalue !== false) {
56 $setting->add_dependency($main_setting, $setvalue, array('value' => $name));
62 /**
63 * Define the common setting that any backup type will have
65 protected function define_settings() {
66 global $CFG;
67 require_once($CFG->dirroot . '/backup/util/helper/convert_helper.class.php');
68 // Define filename setting
69 $filename = new backup_filename_setting('filename', base_setting::IS_FILENAME, 'backup.mbz');
70 $filename->set_ui_filename(get_string('filename', 'backup'), 'backup.mbz', array('size'=>50));
71 $this->add_setting($filename);
73 // Present converter settings only in type course and mode general backup operations.
74 $converters = array();
75 if ($this->plan->get_type() == backup::TYPE_1COURSE and $this->plan->get_mode() == backup::MODE_GENERAL) {
76 $converters = convert_helper::available_converters(false);
77 foreach ($converters as $cnv) {
78 $formatcnv = new backup_users_setting($cnv, base_setting::IS_BOOLEAN, false);
79 $formatcnv->set_ui(new backup_setting_ui_checkbox($formatcnv, get_string('backupformat'.$cnv, 'backup')));
80 $this->add_setting($formatcnv);
84 // Define users setting (keeping it on hand to define dependencies)
85 $users = new backup_users_setting('users', base_setting::IS_BOOLEAN, true);
86 $users->set_ui(new backup_setting_ui_checkbox($users, get_string('rootsettingusers', 'backup')));
87 $this->add_setting($users);
88 $this->converter_deps($users, $converters);
90 // Define anonymize (dependent of users)
91 $anonymize = new backup_anonymize_setting('anonymize', base_setting::IS_BOOLEAN, false);
92 $anonymize->set_ui(new backup_setting_ui_checkbox($anonymize, get_string('rootsettinganonymize', 'backup')));
93 $this->add_setting($anonymize);
94 $users->add_dependency($anonymize);
96 // Define role_assignments (dependent of users)
97 $roleassignments = new backup_role_assignments_setting('role_assignments', base_setting::IS_BOOLEAN, true);
98 $roleassignments->set_ui(new backup_setting_ui_checkbox($roleassignments, get_string('rootsettingroleassignments', 'backup')));
99 $this->add_setting($roleassignments);
100 $users->add_dependency($roleassignments);
102 // Define activities
103 $activities = new backup_activities_setting('activities', base_setting::IS_BOOLEAN, true);
104 $activities->set_ui(new backup_setting_ui_checkbox($activities, get_string('rootsettingactivities', 'backup')));
105 $this->add_setting($activities);
107 // Define blocks
108 $blocks = new backup_generic_setting('blocks', base_setting::IS_BOOLEAN, true);
109 $blocks->set_ui(new backup_setting_ui_checkbox($blocks, get_string('rootsettingblocks', 'backup')));
110 $this->add_setting($blocks);
111 $this->converter_deps($blocks, $converters);
113 // Define filters
114 $filters = new backup_generic_setting('filters', base_setting::IS_BOOLEAN, true);
115 $filters->set_ui(new backup_setting_ui_checkbox($filters, get_string('rootsettingfilters', 'backup')));
116 $this->add_setting($filters);
117 $this->converter_deps($filters, $converters);
119 // Define comments (dependent of users)
120 $comments = new backup_comments_setting('comments', base_setting::IS_BOOLEAN, true);
121 $comments->set_ui(new backup_setting_ui_checkbox($comments, get_string('rootsettingcomments', 'backup')));
122 $this->add_setting($comments);
123 $users->add_dependency($comments);
125 // Define badges (dependent of activities).
126 $badges = new backup_badges_setting('badges', base_setting::IS_BOOLEAN, true);
127 $badges->set_ui(new backup_setting_ui_checkbox($badges, get_string('rootsettingbadges', 'backup')));
128 $this->add_setting($badges);
129 $activities->add_dependency($badges);
130 $users->add_dependency($badges);
132 // Define calendar events (dependent of users)
133 $events = new backup_calendarevents_setting('calendarevents', base_setting::IS_BOOLEAN, true);
134 $events->set_ui(new backup_setting_ui_checkbox($events, get_string('rootsettingcalendarevents', 'backup')));
135 $this->add_setting($events);
136 $users->add_dependency($events);
138 // Define completion (dependent of users)
139 $completion = new backup_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, true);
140 $completion->set_ui(new backup_setting_ui_checkbox($completion, get_string('rootsettinguserscompletion', 'backup')));
141 $this->add_setting($completion);
142 $users->add_dependency($completion);
144 // Define logs (dependent of users)
145 $logs = new backup_logs_setting('logs', base_setting::IS_BOOLEAN, true);
146 $logs->set_ui(new backup_setting_ui_checkbox($logs, get_string('rootsettinglogs', 'backup')));
147 $this->add_setting($logs);
148 $users->add_dependency($logs);
150 // Define grade_histories (dependent of users)
151 $gradehistories = new backup_generic_setting('grade_histories', base_setting::IS_BOOLEAN, true);
152 $gradehistories->set_ui(new backup_setting_ui_checkbox($gradehistories, get_string('rootsettinggradehistories', 'backup')));
153 $this->add_setting($gradehistories);
154 $users->add_dependency($gradehistories);
156 // Define question bank inclusion setting.
157 $questionbank = new backup_generic_setting('questionbank', base_setting::IS_BOOLEAN, true);
158 $questionbank->set_ui(new backup_setting_ui_checkbox($questionbank, get_string('rootsettingquestionbank', 'backup')));
159 $this->add_setting($questionbank);