Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/moodle2/restore_root_task.class.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00030 class restore_root_task extends restore_task {
00031 
00035     public function build() {
00036 
00037         // Conditionally create the temp table (can exist from prechecks) and delete old stuff
00038         $this->add_step(new restore_create_and_clean_temp_stuff('create_and_clean_temp_stuff'));
00039 
00040         // Now make sure the user that is running the restore can actually access the course
00041         // before executing any other step (potentially performing permission checks)
00042         $this->add_step(new restore_fix_restorer_access_step('fix_restorer_access'));
00043 
00044         // If we haven't preloaded information, load all the included inforef records to temp_ids table
00045         $this->add_step(new restore_load_included_inforef_records('load_inforef_records'));
00046 
00047         // Load all the needed files to temp_ids table
00048         $this->add_step(new restore_load_included_files('load_file_records', 'files.xml'));
00049 
00050         // If we haven't preloaded information, load all the needed roles to temp_ids_table
00051         $this->add_step(new restore_load_and_map_roles('load_and_map_roles'));
00052 
00053         // If we haven't preloaded information and are restoring user info, load all the needed users to temp_ids table
00054         $this->add_step(new restore_load_included_users('load_user_records'));
00055 
00056         // If we haven't preloaded information and are restoring user info, process all those needed users
00057         // marking for create/map them as needed. Any problem here will cause exception as far as prechecks have
00058         // performed the same process so, it's not possible to have errors here
00059         $this->add_step(new restore_process_included_users('process_user_records'));
00060 
00061         // Unconditionally, create all the needed users calculated in the previous step
00062         $this->add_step(new restore_create_included_users('create_users'));
00063 
00064         // Unconditionally, load create all the needed groups and groupings
00065         $this->add_step(new restore_groups_structure_step('create_groups_and_groupings', 'groups.xml'));
00066 
00067         // Unconditionally, load create all the needed scales
00068         $this->add_step(new restore_scales_structure_step('create_scales', 'scales.xml'));
00069 
00070         // Unconditionally, load create all the needed outcomes
00071         $this->add_step(new restore_outcomes_structure_step('create_scales', 'outcomes.xml'));
00072 
00073         // If we haven't preloaded information, load all the needed categories and questions (reduced) to temp_ids_table
00074         $this->add_step(new restore_load_categories_and_questions('load_categories_and_questions'));
00075 
00076         // If we haven't preloaded information, process all the loaded categories and questions
00077         // marking them for creation/mapping as needed. Any problem here will cause exception
00078         // because this same process has been executed and reported by restore prechecks, so
00079         // it is not possible to have errors here.
00080         $this->add_step(new restore_process_categories_and_questions('process_categories_and_questions'));
00081 
00082         // Unconditionally, create and map all the categories and questions
00083         $this->add_step(new restore_create_categories_and_questions('create_categories_and_questions', 'questions.xml'));
00084 
00085         // At the end, mark it as built
00086         $this->built = true;
00087     }
00088 
00089 // Protected API starts here
00090 
00094     protected function define_settings() {
00095 
00096         // Load all the root settings found in backup file from controller
00097         $rootsettings = $this->get_info()->root_settings;
00098 
00099         // Define users setting (keeping it on hand to define dependencies)
00100         $defaultvalue = false;                      // Safer default
00101         $changeable = false;
00102         if (isset($rootsettings['users']) && $rootsettings['users']) { // Only enabled when available
00103             $defaultvalue = true;
00104             $changeable = true;
00105         }
00106         $users = new restore_users_setting('users', base_setting::IS_BOOLEAN, $defaultvalue);
00107         $users->set_ui(new backup_setting_ui_checkbox($users, get_string('rootsettingusers', 'backup')));
00108         $users->get_ui()->set_changeable($changeable);
00109         $this->add_setting($users);
00110 
00111         // Define role_assignments (dependent of users)
00112         $defaultvalue = false;                      // Safer default
00113         $changeable = false;
00114         if (isset($rootsettings['role_assignments']) && $rootsettings['role_assignments']) { // Only enabled when available
00115             $defaultvalue = true;
00116             $changeable = true;
00117         }
00118         $roleassignments = new restore_role_assignments_setting('role_assignments', base_setting::IS_BOOLEAN, $defaultvalue);
00119         $roleassignments->set_ui(new backup_setting_ui_checkbox($roleassignments,get_string('rootsettingroleassignments', 'backup')));
00120         $roleassignments->get_ui()->set_changeable($changeable);
00121         $this->add_setting($roleassignments);
00122         $users->add_dependency($roleassignments);
00123 
00124         // Define user_files (dependent of users)
00125         $defaultvalue = false;                      // Safer default
00126         $changeable = false;
00127         if (isset($rootsettings['user_files']) && $rootsettings['user_files']) { // Only enabled when available
00128             $defaultvalue = true;
00129             $changeable = true;
00130         }
00131         $userfiles = new restore_user_files_setting('user_files', base_setting::IS_BOOLEAN, $defaultvalue);
00132         $userfiles->set_ui(new backup_setting_ui_checkbox($userfiles, get_string('rootsettinguserfiles', 'backup')));
00133         $userfiles->get_ui()->set_changeable($changeable);
00134         $this->add_setting($userfiles);
00135         $users->add_dependency($userfiles);
00136 
00137         // Define activitites
00138         $defaultvalue = false;                      // Safer default
00139         $changeable = false;
00140         if (isset($rootsettings['activities']) && $rootsettings['activities']) { // Only enabled when available
00141             $defaultvalue = true;
00142             $changeable = true;
00143         }
00144         $activities = new restore_activities_setting('activities', base_setting::IS_BOOLEAN, $defaultvalue);
00145         $activities->set_ui(new backup_setting_ui_checkbox($activities, get_string('rootsettingactivities', 'backup')));
00146         $activities->get_ui()->set_changeable($changeable);
00147         $this->add_setting($activities);
00148 
00149         // Define blocks
00150         $defaultvalue = false;                      // Safer default
00151         $changeable = false;
00152         if (isset($rootsettings['blocks']) && $rootsettings['blocks']) { // Only enabled when available
00153             $defaultvalue = true;
00154             $changeable = true;
00155         }
00156         $blocks = new restore_generic_setting('blocks', base_setting::IS_BOOLEAN, $defaultvalue);
00157         $blocks->set_ui(new backup_setting_ui_checkbox($blocks, get_string('rootsettingblocks', 'backup')));
00158         $blocks->get_ui()->set_changeable($changeable);
00159         $this->add_setting($blocks);
00160 
00161         // Define filters
00162         $defaultvalue = false;                      // Safer default
00163         $changeable = false;
00164         if (isset($rootsettings['filters']) && $rootsettings['filters']) { // Only enabled when available
00165             $defaultvalue = true;
00166             $changeable = true;
00167         }
00168         $filters = new restore_generic_setting('filters', base_setting::IS_BOOLEAN, $defaultvalue);
00169         $filters->set_ui(new backup_setting_ui_checkbox($filters, get_string('rootsettingfilters', 'backup')));
00170         $filters->get_ui()->set_changeable($changeable);
00171         $this->add_setting($filters);
00172 
00173         // Define comments (dependent of users)
00174         $defaultvalue = false;                      // Safer default
00175         $changeable = false;
00176         if (isset($rootsettings['comments']) && $rootsettings['comments']) { // Only enabled when available
00177             $defaultvalue = true;
00178             $changeable = true;
00179         }
00180         $comments = new restore_comments_setting('comments', base_setting::IS_BOOLEAN, $defaultvalue);
00181         $comments->set_ui(new backup_setting_ui_checkbox($comments, get_string('rootsettingcomments', 'backup')));
00182         $comments->get_ui()->set_changeable($changeable);
00183         $this->add_setting($comments);
00184         $users->add_dependency($comments);
00185 
00186         // Define completion (dependent of users)
00187         $defaultvalue = false;                      // Safer default
00188         $changeable = false;
00189         if (isset($rootsettings['userscompletion']) && $rootsettings['userscompletion']) { // Only enabled when available
00190             $defaultvalue = true;
00191             $changeable = true;
00192         }
00193         $completion = new restore_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, $defaultvalue);
00194         $completion->set_ui(new backup_setting_ui_checkbox($completion, get_string('rootsettinguserscompletion', 'backup')));
00195         $completion->get_ui()->set_changeable($changeable);
00196         $this->add_setting($completion);
00197         $users->add_dependency($completion);
00198 
00199         // Define logs (dependent of users)
00200         $defaultvalue = false;                      // Safer default
00201         $changeable = false;
00202         if (isset($rootsettings['logs']) && $rootsettings['logs']) { // Only enabled when available
00203             $defaultvalue = true;
00204             $changeable = true;
00205         }
00206         $logs = new restore_logs_setting('logs', base_setting::IS_BOOLEAN, $defaultvalue);
00207         $logs->set_ui(new backup_setting_ui_checkbox($logs, get_string('rootsettinglogs', 'backup')));
00208         $logs->get_ui()->set_changeable($changeable);
00209         $this->add_setting($logs);
00210         $users->add_dependency($logs);
00211 
00212         // Define grade_histories (dependent of users)
00213         $defaultvalue = false;                      // Safer default
00214         $changeable = false;
00215         if (isset($rootsettings['grade_histories']) && $rootsettings['grade_histories']) { // Only enabled when available
00216             $defaultvalue = true;
00217             $changeable = true;
00218         }
00219         $gradehistories = new restore_grade_histories_setting('grade_histories', base_setting::IS_BOOLEAN, $defaultvalue);
00220         $gradehistories->set_ui(new backup_setting_ui_checkbox($gradehistories, get_string('rootsettinggradehistories', 'backup')));
00221         $gradehistories->get_ui()->set_changeable($changeable);
00222         $this->add_setting($gradehistories);
00223         $users->add_dependency($gradehistories);
00224     }
00225 }
 All Data Structures Namespaces Files Functions Variables Enumerations