Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

   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 permission.
 103          if ($this->plan->get_mode() == backup::MODE_IMPORT) {
 104              $permissions = new backup_permissions_setting('permissions', base_setting::IS_BOOLEAN, false);
 105              $permissions->set_ui(new backup_setting_ui_checkbox($permissions, get_string('rootsettingpermissions', 'backup')));
 106              $this->add_setting($permissions);
 107          }
 108  
 109          // Define activities
 110          $activities = new backup_activities_setting('activities', base_setting::IS_BOOLEAN, true);
 111          $activities->set_ui(new backup_setting_ui_checkbox($activities, get_string('rootsettingactivities', 'backup')));
 112          $this->add_setting($activities);
 113  
 114          // Define blocks
 115          $blocks = new backup_generic_setting('blocks', base_setting::IS_BOOLEAN, true);
 116          $blocks->set_ui(new backup_setting_ui_checkbox($blocks, get_string('rootsettingblocks', 'backup')));
 117          $this->add_setting($blocks);
 118          $this->converter_deps($blocks, $converters);
 119  
 120          // Define files.
 121          $files = new backup_generic_setting('files', base_setting::IS_BOOLEAN, true);
 122          $files->set_ui(new backup_setting_ui_checkbox($files, get_string('rootsettingfiles', 'backup')));
 123          $this->add_setting($files);
 124          $this->converter_deps($files, $converters);
 125  
 126          // Define filters
 127          $filters = new backup_generic_setting('filters', base_setting::IS_BOOLEAN, true);
 128          $filters->set_ui(new backup_setting_ui_checkbox($filters, get_string('rootsettingfilters', 'backup')));
 129          $this->add_setting($filters);
 130          $this->converter_deps($filters, $converters);
 131  
 132          // Define comments (dependent of users)
 133          $comments = new backup_comments_setting('comments', base_setting::IS_BOOLEAN, true);
 134          $comments->set_ui(new backup_setting_ui_checkbox($comments, get_string('rootsettingcomments', 'backup')));
 135          $this->add_setting($comments);
 136          $users->add_dependency($comments);
 137  
 138          // Define badges (dependent of activities).
 139          $badges = new backup_badges_setting('badges', base_setting::IS_BOOLEAN, true);
 140          $badges->set_ui(new backup_setting_ui_checkbox($badges, get_string('rootsettingbadges', 'backup')));
 141          $this->add_setting($badges);
 142          $activities->add_dependency($badges);
 143          $users->add_dependency($badges);
 144  
 145          // Define calendar events.
 146          $events = new backup_calendarevents_setting('calendarevents', base_setting::IS_BOOLEAN, true);
 147          $events->set_ui(new backup_setting_ui_checkbox($events, get_string('rootsettingcalendarevents', 'backup')));
 148          $this->add_setting($events);
 149  
 150          // Define completion (dependent of users)
 151          $completion = new backup_userscompletion_setting('userscompletion', base_setting::IS_BOOLEAN, true);
 152          $completion->set_ui(new backup_setting_ui_checkbox($completion, get_string('rootsettinguserscompletion', 'backup')));
 153          $this->add_setting($completion);
 154          $users->add_dependency($completion);
 155  
 156          // Define logs (dependent of users)
 157          $logs = new backup_logs_setting('logs', base_setting::IS_BOOLEAN, true);
 158          $logs->set_ui(new backup_setting_ui_checkbox($logs, get_string('rootsettinglogs', 'backup')));
 159          $this->add_setting($logs);
 160          $users->add_dependency($logs);
 161  
 162          // Define grade_histories (dependent of users)
 163          $gradehistories = new backup_generic_setting('grade_histories', base_setting::IS_BOOLEAN, true);
 164          $gradehistories->set_ui(new backup_setting_ui_checkbox($gradehistories, get_string('rootsettinggradehistories', 'backup')));
 165          $this->add_setting($gradehistories);
 166          $users->add_dependency($gradehistories);
 167          // The restore does not process the grade histories when some activities are ignored.
 168          // So let's define a dependency to prevent false expectations from our users.
 169          $activities->add_dependency($gradehistories);
 170  
 171          // Define question bank inclusion setting.
 172          $questionbank = new backup_generic_setting('questionbank', base_setting::IS_BOOLEAN, true);
 173          $questionbank->set_ui(new backup_setting_ui_checkbox($questionbank, get_string('rootsettingquestionbank', 'backup')));
 174          $this->add_setting($questionbank);
 175  
 176          $groups = new backup_groups_setting('groups', base_setting::IS_BOOLEAN, true);
 177          $groups->set_ui(new backup_setting_ui_checkbox($groups, get_string('rootsettinggroups', 'backup')));
 178          $this->add_setting($groups);
 179  
 180          // Define competencies inclusion setting if competencies are enabled.
 181          $competencies = new backup_competencies_setting();
 182          $competencies->set_ui(new backup_setting_ui_checkbox($competencies, get_string('rootsettingcompetencies', 'backup')));
 183          $this->add_setting($competencies);
 184  
 185          // Define custom fields inclusion setting if custom fields are used.
 186          $customfields = new backup_customfield_setting('customfield', base_setting::IS_BOOLEAN, true);
 187          $customfields->set_ui(new backup_setting_ui_checkbox($customfields, get_string('rootsettingcustomfield', 'backup')));
 188          $this->add_setting($customfields);
 189  
 190          // Define content bank content inclusion setting.
 191          $contentbank = new backup_contentbankcontent_setting('contentbankcontent', base_setting::IS_BOOLEAN, true);
 192          $contentbank->set_ui(new backup_setting_ui_checkbox($contentbank, get_string('rootsettingcontentbankcontent', 'backup')));
 193          $this->add_setting($contentbank);
 194  
 195          // Define xAPI state inclusion setting.
 196          $xapistate = new backup_xapistate_setting('xapistate', base_setting::IS_BOOLEAN, true);
 197          $xapistate->set_ui(new backup_setting_ui_checkbox($xapistate, get_string('rootsettingxapistate', 'backup')));
 198          $this->add_setting($xapistate);
 199          $users->add_dependency($xapistate);
 200  
 201          // Define legacy file inclusion setting.
 202          $legacyfiles = new backup_generic_setting('legacyfiles', base_setting::IS_BOOLEAN, true);
 203          $legacyfiles->set_ui(new backup_setting_ui_checkbox($legacyfiles, get_string('rootsettinglegacyfiles', 'backup')));
 204          $this->add_setting($legacyfiles);
 205      }
 206  }