[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/backup/moodle2/ -> restore_root_task.class.php (source)

   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 restore_root_task class
  20   * @package     core_backup
  21   * @subpackage  moodle2
  22   * @category    backup
  23   * @copyright   2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  24   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Start task that provides all the settings common to all restores and other initial steps
  31   *
  32   * TODO: Finish phpdocs
  33   */
  34  class restore_root_task extends restore_task {
  35  
  36      /**
  37       * Create all the steps that will be part of this task
  38       */
  39      public function build() {
  40  
  41          // Conditionally create the temp table (can exist from prechecks) and delete old stuff
  42          $this->add_step(new restore_create_and_clean_temp_stuff('create_and_clean_temp_stuff'));
  43  
  44          // Now make sure the user that is running the restore can actually access the course
  45          // before executing any other step (potentially performing permission checks)
  46          $this->add_step(new restore_fix_restorer_access_step('fix_restorer_access'));
  47  
  48          // If we haven't preloaded information, load all the included inforef records to temp_ids table
  49          $this->add_step(new restore_load_included_inforef_records('load_inforef_records'));
  50  
  51          // Load all the needed files to temp_ids table
  52          $this->add_step(new restore_load_included_files('load_file_records', 'files.xml'));
  53  
  54          // If we haven't preloaded information, load all the needed roles to temp_ids_table
  55          $this->add_step(new restore_load_and_map_roles('load_and_map_roles'));
  56  
  57          // If we haven't preloaded information and are restoring user info, load all the needed users to temp_ids table
  58          $this->add_step(new restore_load_included_users('load_user_records'));
  59  
  60          // If we haven't preloaded information and are restoring user info, process all those needed users
  61          // marking for create/map them as needed. Any problem here will cause exception as far as prechecks have
  62          // performed the same process so, it's not possible to have errors here
  63          $this->add_step(new restore_process_included_users('process_user_records'));
  64  
  65          // Unconditionally, create all the needed users calculated in the previous step
  66          $this->add_step(new restore_create_included_users('create_users'));
  67  
  68          // Unconditionally, load create all the needed groups and groupings
  69          $this->add_step(new restore_groups_structure_step('create_groups_and_groupings', 'groups.xml'));
  70  
  71          // Unconditionally, load create all the needed scales
  72          $this->add_step(new restore_scales_structure_step('create_scales', 'scales.xml'));
  73  
  74          // Unconditionally, load create all the needed outcomes
  75          $this->add_step(new restore_outcomes_structure_step('create_scales', 'outcomes.xml'));
  76  
  77          // If we haven't preloaded information, load all the needed categories and questions (reduced) to temp_ids_table
  78          $this->add_step(new restore_load_categories_and_questions('load_categories_and_questions'));
  79  
  80          // If we haven't preloaded information, process all the loaded categories and questions
  81          // marking them for creation/mapping as needed. Any problem here will cause exception
  82          // because this same process has been executed and reported by restore prechecks, so
  83          // it is not possible to have errors here.
  84          $this->add_step(new restore_process_categories_and_questions('process_categories_and_questions'));
  85  
  86          // Unconditionally, create and map all the categories and questions
  87          $this->add_step(new restore_create_categories_and_questions('create_categories_and_questions', 'questions.xml'));
  88  
  89          // At the end, mark it as built
  90          $this->built = true;
  91      }
  92  
  93  // Protected API starts here
  94  
  95      /**
  96       * Define the common setting that any restore type will have
  97       */
  98      protected function define_settings() {
  99  
 100          // Load all the root settings found in backup file from controller
 101          $rootsettings = $this->get_info()->root_settings;
 102  
 103          // Define users setting (keeping it on hand to define dependencies)
 104          $defaultvalue = false;                      // Safer default
 105          $changeable = false;
 106          if (isset($rootsettings['users']) && $rootsettings['users']) { // Only enabled when available
 107              $defaultvalue = true;
 108              $changeable = true;
 109          }
 110          $users = new restore_users_setting('users', base_setting::IS_BOOLEAN, $defaultvalue);
 111          $users->set_ui(new backup_setting_ui_checkbox($users, get_string('rootsettingusers', 'backup')));
 112          $users->get_ui()->set_changeable($changeable);
 113          $this->add_setting($users);
 114  
 115          $rootenrolmanual = new restore_users_setting('enrol_migratetomanual', base_setting::IS_BOOLEAN, false);
 116          $rootenrolmanual->set_ui(new backup_setting_ui_checkbox($rootenrolmanual, get_string('rootenrolmanual', 'backup')));
 117          $rootenrolmanual->get_ui()->set_changeable(enrol_is_enabled('manual'));
 118          $rootenrolmanual->get_ui()->set_changeable($changeable);
 119          $this->add_setting($rootenrolmanual);
 120          $users->add_dependency($rootenrolmanual);
 121  
 122          // Define role_assignments (dependent of users)
 123          $defaultvalue = false;                      // Safer default
 124          $changeable = false;
 125          if (isset($rootsettings['role_assignments']) && $rootsettings['role_assignments']) { // Only enabled when available
 126              $defaultvalue = true;
 127              $changeable = true;
 128          }
 129          $roleassignments = new restore_role_assignments_setting('role_assignments', base_setting::IS_BOOLEAN, $defaultvalue);
 130          $roleassignments->set_ui(new backup_setting_ui_checkbox($roleassignments,get_string('rootsettingroleassignments', 'backup')));
 131          $roleassignments->get_ui()->set_changeable($changeable);
 132          $this->add_setting($roleassignments);
 133          $users->add_dependency($roleassignments);
 134  
 135          // Define activitites
 136          $defaultvalue = false;                      // Safer default
 137          $changeable = false;
 138          if (isset($rootsettings['activities']) && $rootsettings['activities']) { // Only enabled when available
 139              $defaultvalue = true;
 140              $changeable = true;
 141          }
 142          $activities = new restore_activities_setting('activities', base_setting::IS_BOOLEAN, $defaultvalue);
 143          $activities->set_ui(new backup_setting_ui_checkbox($activities, get_string('rootsettingactivities', 'backup')));
 144          $activities->get_ui()->set_changeable($changeable);
 145          $this->add_setting($activities);
 146  
 147          // Define blocks
 148          $defaultvalue = false;                      // Safer default
 149          $changeable = false;
 150          if (isset($rootsettings['blocks']) && $rootsettings['blocks']) { // Only enabled when available
 151              $defaultvalue = true;
 152              $changeable = true;
 153          }
 154          $blocks = new restore_generic_setting('blocks', base_setting::IS_BOOLEAN, $defaultvalue);
 155          $blocks->set_ui(new backup_setting_ui_checkbox($blocks, get_string('rootsettingblocks', 'backup')));
 156          $blocks->get_ui()->set_changeable($changeable);
 157          $this->add_setting($blocks);
 158  
 159          // Define filters
 160          $defaultvalue = false;                      // Safer default
 161          $changeable = false;
 162          if (isset($rootsettings['filters']) && $rootsettings['filters']) { // Only enabled when available
 163              $defaultvalue = true;
 164              $changeable = true;
 165          }
 166          $filters = new restore_generic_setting('filters', base_setting::IS_BOOLEAN, $defaultvalue);
 167          $filters->set_ui(new backup_setting_ui_checkbox($filters, get_string('rootsettingfilters', 'backup')));
 168          $filters->get_ui()->set_changeable($changeable);
 169          $this->add_setting($filters);
 170  
 171          // Define comments (dependent of users)
 172          $defaultvalue = false;                      // Safer default
 173          $changeable = false;
 174          if (isset($rootsettings['comments']) && $rootsettings['comments']) { // Only enabled when available
 175              $defaultvalue = true;
 176              $changeable = true;
 177          }
 178          $comments = new restore_comments_setting('comments', base_setting::IS_BOOLEAN, $defaultvalue);
 179          $comments->set_ui(new backup_setting_ui_checkbox($comments, get_string('rootsettingcomments', 'backup')));
 180          $comments->get_ui()->set_changeable($changeable);
 181          $this->add_setting($comments);
 182          $users->add_dependency($comments);
 183  
 184          // Define badges (dependent of activities).
 185          $defaultvalue = false;                      // Safer default.
 186          $changeable = false;
 187          if (isset($rootsettings['badges']) && $rootsettings['badges']) { // Only enabled when available.
 188              $defaultvalue = true;
 189              $changeable = true;
 190          }
 191          $badges = new restore_badges_setting('badges', base_setting::IS_BOOLEAN, $defaultvalue);
 192          $badges->set_ui(new backup_setting_ui_checkbox($badges, get_string('rootsettingbadges', 'backup')));
 193          $badges->get_ui()->set_changeable($changeable);
 194          $this->add_setting($badges);
 195          $activities->add_dependency($badges);
 196          $users->add_dependency($badges);
 197  
 198          // Define Calendar events.
 199          $defaultvalue = false;                      // Safer default
 200          $changeable = false;
 201          if (isset($rootsettings['calendarevents']) && $rootsettings['calendarevents']) { // Only enabled when available
 202              $defaultvalue = true;
 203              $changeable = true;
 204          }
 205          $events = new restore_calendarevents_setting('calendarevents', base_setting::IS_BOOLEAN, $defaultvalue);
 206          $events->set_ui(new backup_setting_ui_checkbox($events, get_string('rootsettingcalendarevents', 'backup')));
 207          $events->get_ui()->set_changeable($changeable);
 208          $this->add_setting($events);
 209  
 210          // Define completion (dependent of users)
 211          $defaultvalue = false;                      // Safer default
 212          $changeable = false;
 213          if (isset($rootsettings['userscompletion']) && $rootsettings['userscompletion']) { // Only enabled when available
 214              $defaultvalue = true;
 215              $changeable = true;
 216          }
 217          $completion = new restore_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, $defaultvalue);
 218          $completion->set_ui(new backup_setting_ui_checkbox($completion, get_string('rootsettinguserscompletion', 'backup')));
 219          $completion->get_ui()->set_changeable($changeable);
 220          $this->add_setting($completion);
 221          $users->add_dependency($completion);
 222  
 223          // Define logs (dependent of users)
 224          $defaultvalue = false;                      // Safer default
 225          $changeable = false;
 226          if (isset($rootsettings['logs']) && $rootsettings['logs']) { // Only enabled when available
 227              $defaultvalue = true;
 228              $changeable = true;
 229          }
 230          $logs = new restore_logs_setting('logs', base_setting::IS_BOOLEAN, $defaultvalue);
 231          $logs->set_ui(new backup_setting_ui_checkbox($logs, get_string('rootsettinglogs', 'backup')));
 232          $logs->get_ui()->set_changeable($changeable);
 233          $this->add_setting($logs);
 234          $users->add_dependency($logs);
 235  
 236          // Define grade_histories (dependent of users)
 237          $defaultvalue = false;                      // Safer default
 238          $changeable = false;
 239          if (isset($rootsettings['grade_histories']) && $rootsettings['grade_histories']) { // Only enabled when available
 240              $defaultvalue = true;
 241              $changeable = true;
 242          }
 243          $gradehistories = new restore_grade_histories_setting('grade_histories', base_setting::IS_BOOLEAN, $defaultvalue);
 244          $gradehistories->set_ui(new backup_setting_ui_checkbox($gradehistories, get_string('rootsettinggradehistories', 'backup')));
 245          $gradehistories->get_ui()->set_changeable($changeable);
 246          $this->add_setting($gradehistories);
 247          $users->add_dependency($gradehistories);
 248  
 249          // The restore does not process the grade histories when some activities are ignored.
 250          // So let's define a dependency to prevent false expectations from our users.
 251          $activities->add_dependency($gradehistories);
 252  
 253          // Define groups and groupings.
 254          $defaultvalue = false;
 255          $changeable = false;
 256          if (isset($rootsettings['groups']) && $rootsettings['groups']) { // Only enabled when available.
 257              $defaultvalue = true;
 258              $changeable = true;
 259          } else if (!isset($rootsettings['groups'])) {
 260              // It is likely this is an older backup that does not contain information on the group setting,
 261              // in which case groups should be restored and this setting can be changed.
 262              $defaultvalue = true;
 263              $changeable = true;
 264          }
 265          $groups = new restore_groups_setting('groups', base_setting::IS_BOOLEAN, $defaultvalue);
 266          $groups->set_ui(new backup_setting_ui_checkbox($groups, get_string('rootsettinggroups', 'backup')));
 267          $groups->get_ui()->set_changeable($changeable);
 268          $this->add_setting($groups);
 269  
 270          // Competencies restore setting. Show when competencies is enabled and the setting is available.
 271          $hascompetencies = !empty($rootsettings['competencies']);
 272          $competencies = new restore_competencies_setting($hascompetencies);
 273          $competencies->set_ui(new backup_setting_ui_checkbox($competencies, get_string('rootsettingcompetencies', 'backup')));
 274          $this->add_setting($competencies);
 275      }
 276  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1