Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
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 * Defines backup_root_task class 20 * 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 26 */ 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 /** 31 * Start task that provides all the settings common to all backups and some initialization steps 32 * 33 * TODO: Finish phpdocs 34 */ 35 class backup_root_task extends backup_task { 36 37 /** 38 * Create all the steps that will be part of this task 39 */ 40 public function build() { 41 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')); 44 45 $this->built = true; 46 } 47 48 // Protected API starts here 49 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)); 57 } 58 } 59 } 60 } 61 62 /** 63 * Define the common setting that any backup type will have 64 */ 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); 72 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); 81 } 82 } 83 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); 89 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); 95 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); 101 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); 106 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); 112 113 // Define files. 114 $files = new backup_generic_setting('files', base_setting::IS_BOOLEAN, true); 115 $files->set_ui(new backup_setting_ui_checkbox($files, get_string('rootsettingfiles', 'backup'))); 116 $this->add_setting($files); 117 $this->converter_deps($files, $converters); 118 119 // Define filters 120 $filters = new backup_generic_setting('filters', base_setting::IS_BOOLEAN, true); 121 $filters->set_ui(new backup_setting_ui_checkbox($filters, get_string('rootsettingfilters', 'backup'))); 122 $this->add_setting($filters); 123 $this->converter_deps($filters, $converters); 124 125 // Define comments (dependent of users) 126 $comments = new backup_comments_setting('comments', base_setting::IS_BOOLEAN, true); 127 $comments->set_ui(new backup_setting_ui_checkbox($comments, get_string('rootsettingcomments', 'backup'))); 128 $this->add_setting($comments); 129 $users->add_dependency($comments); 130 131 // Define badges (dependent of activities). 132 $badges = new backup_badges_setting('badges', base_setting::IS_BOOLEAN, true); 133 $badges->set_ui(new backup_setting_ui_checkbox($badges, get_string('rootsettingbadges', 'backup'))); 134 $this->add_setting($badges); 135 $activities->add_dependency($badges); 136 $users->add_dependency($badges); 137 138 // Define calendar events. 139 $events = new backup_calendarevents_setting('calendarevents', base_setting::IS_BOOLEAN, true); 140 $events->set_ui(new backup_setting_ui_checkbox($events, get_string('rootsettingcalendarevents', 'backup'))); 141 $this->add_setting($events); 142 143 // Define completion (dependent of users) 144 $completion = new backup_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, true); 145 $completion->set_ui(new backup_setting_ui_checkbox($completion, get_string('rootsettinguserscompletion', 'backup'))); 146 $this->add_setting($completion); 147 $users->add_dependency($completion); 148 149 // Define logs (dependent of users) 150 $logs = new backup_logs_setting('logs', base_setting::IS_BOOLEAN, true); 151 $logs->set_ui(new backup_setting_ui_checkbox($logs, get_string('rootsettinglogs', 'backup'))); 152 $this->add_setting($logs); 153 $users->add_dependency($logs); 154 155 // Define grade_histories (dependent of users) 156 $gradehistories = new backup_generic_setting('grade_histories', base_setting::IS_BOOLEAN, true); 157 $gradehistories->set_ui(new backup_setting_ui_checkbox($gradehistories, get_string('rootsettinggradehistories', 'backup'))); 158 $this->add_setting($gradehistories); 159 $users->add_dependency($gradehistories); 160 // The restore does not process the grade histories when some activities are ignored. 161 // So let's define a dependency to prevent false expectations from our users. 162 $activities->add_dependency($gradehistories); 163 164 // Define question bank inclusion setting. 165 $questionbank = new backup_generic_setting('questionbank', base_setting::IS_BOOLEAN, true); 166 $questionbank->set_ui(new backup_setting_ui_checkbox($questionbank, get_string('rootsettingquestionbank', 'backup'))); 167 $this->add_setting($questionbank); 168 169 $groups = new backup_groups_setting('groups', base_setting::IS_BOOLEAN, true); 170 $groups->set_ui(new backup_setting_ui_checkbox($groups, get_string('rootsettinggroups', 'backup'))); 171 $this->add_setting($groups); 172 173 // Define competencies inclusion setting if competencies are enabled. 174 $competencies = new backup_competencies_setting(); 175 $competencies->set_ui(new backup_setting_ui_checkbox($competencies, get_string('rootsettingcompetencies', 'backup'))); 176 $this->add_setting($competencies); 177 178 // Define custom fields inclusion setting if custom fields are used. 179 $customfields = new backup_customfield_setting('customfield', base_setting::IS_BOOLEAN, true); 180 $customfields->set_ui(new backup_setting_ui_checkbox($customfields, get_string('rootsettingcustomfield', 'backup'))); 181 $this->add_setting($customfields); 182 183 // Define content bank content inclusion setting. 184 $contentbank = new backup_contentbankcontent_setting('contentbankcontent', base_setting::IS_BOOLEAN, true); 185 $contentbank->set_ui(new backup_setting_ui_checkbox($contentbank, get_string('rootsettingcontentbankcontent', 'backup'))); 186 $this->add_setting($contentbank); 187 188 // Define legacy file inclusion setting. 189 $legacyfiles = new backup_generic_setting('legacyfiles', base_setting::IS_BOOLEAN, true); 190 $legacyfiles->set_ui(new backup_setting_ui_checkbox($legacyfiles, get_string('rootsettinglegacyfiles', 'backup'))); 191 $this->add_setting($legacyfiles); 192 } 193 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body