Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 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 classes used to handle restore settings
  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  // TODO: Reduce these to the minimum because ui/dependencies are 100% separated
  31  
  32  // Root restore settings
  33  
  34  /**
  35   * root generic setting to store different things without dependencies
  36   */
  37  class restore_generic_setting extends root_backup_setting {}
  38  
  39  /**
  40   * root setting to control if restore will create user information
  41   * A lot of other settings are dependent of this (module's user info,
  42   * grades user info, messages, blogs...
  43   */
  44  class restore_users_setting extends restore_generic_setting {}
  45  
  46  /**
  47   * root setting to control if restore will create groups/grouping information. Depends on @restore_users_setting
  48   *
  49   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  50   * @copyright 2014 Matt Sammarco
  51   */
  52  class restore_groups_setting extends restore_generic_setting {
  53  }
  54  
  55  /**
  56   * root setting to control if restore will include custom field information
  57   *
  58   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  59   * @copyright 2018 Daniel Neis Araujo
  60   */
  61  class restore_customfield_setting extends restore_generic_setting {
  62  }
  63  
  64  /**
  65   * root setting to control if restore will create role assignments
  66   * or no (any level), depends of @restore_users_setting
  67   */
  68  class restore_role_assignments_setting extends root_backup_setting {}
  69  
  70  /**
  71   * root setting to control if restore will create activities
  72   * A lot of other settings (_included at activity levels)
  73   * are dependent of this setting
  74   */
  75  class restore_activities_setting extends restore_generic_setting {}
  76  
  77  /**
  78   * root setting to control if restore will create
  79   * comments or no, depends of @restore_users_setting
  80   * exactly in the same way than @restore_role_assignments_setting so we extend from it
  81   */
  82  class restore_comments_setting extends restore_role_assignments_setting {}
  83  
  84  /**
  85   * root setting to control if restore will create badges or not,
  86   * depends on @restore_activities_setting
  87   */
  88  class restore_badges_setting extends restore_generic_setting {}
  89  
  90  /**
  91   * root setting to control if competencies will also be restored.
  92   */
  93  class restore_competencies_setting extends restore_generic_setting {
  94  
  95      /**
  96       * restore_competencies_setting constructor.
  97       * @param bool $hascompetencies Flag whether to set the restore setting as checked and unlocked.
  98       */
  99      public function __construct($hascompetencies) {
 100          $defaultvalue = false;
 101          $visibility = base_setting::HIDDEN;
 102          $status = base_setting::LOCKED_BY_CONFIG;
 103          if (\core_competency\api::is_enabled()) {
 104              $visibility = base_setting::VISIBLE;
 105              if ($hascompetencies) {
 106                  $defaultvalue = true;
 107                  $status = base_setting::NOT_LOCKED;
 108              }
 109          }
 110          parent::__construct('competencies', base_setting::IS_BOOLEAN, $defaultvalue, $visibility, $status);
 111      }
 112  }
 113  
 114  /**
 115   * root setting to control if restore will create
 116   * events or no, depends of @restore_users_setting
 117   * exactly in the same way than @restore_role_assignments_setting so we extend from it
 118   */
 119  class restore_calendarevents_setting extends restore_role_assignments_setting {}
 120  
 121  /**
 122   * root setting to control if restore will create
 123   * completion info or no, depends of @restore_users_setting
 124   * exactly in the same way than @restore_role_assignments_setting so we extend from it
 125   */
 126  class restore_userscompletion_setting extends restore_role_assignments_setting {}
 127  
 128  /**
 129   * root setting to control if restore will create
 130   * logs or no, depends of @restore_users_setting
 131   * exactly in the same way than @restore_role_assignments_setting so we extend from it
 132   */
 133  class restore_logs_setting extends restore_role_assignments_setting {}
 134  
 135  /**
 136   * root setting to control if restore will create
 137   * grade_histories or no, depends of @restore_users_setting
 138   * exactly in the same way than @restore_role_assignments_setting so we extend from it
 139   */
 140  class restore_grade_histories_setting extends restore_role_assignments_setting {}
 141  
 142  
 143  // Course restore settings
 144  
 145  /**
 146   * generic course setting to pass various settings between tasks and steps
 147   */
 148  class restore_course_generic_setting extends course_backup_setting {}
 149  
 150  /**
 151   * Setting to define is we are going to overwrite course configuration
 152   */
 153  class restore_course_overwrite_conf_setting extends restore_course_generic_setting {}
 154  
 155  /**
 156   * Setting to switch between current and new course name/startdate
 157   *
 158   * @copyright   2017 Marina Glancy
 159   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 160   */
 161  class restore_course_defaultcustom_setting extends restore_course_generic_setting {
 162      /**
 163       * Validates that the value $value has type $vtype
 164       * @param int $vtype
 165       * @param mixed $value
 166       * @return mixed
 167       */
 168      public function validate_value($vtype, $value) {
 169          if ($value === false) {
 170              // Value "false" means default and is allowed for this setting type even if it does not match $vtype.
 171              return $value;
 172          }
 173          return parent::validate_value($vtype, $value);
 174      }
 175  
 176      /**
 177       * Special method for this element only. When value is "false" returns the default value.
 178       * @return mixed
 179       */
 180      public function get_normalized_value() {
 181          $value = $this->get_value();
 182          if ($value === false && $this->get_ui() instanceof backup_setting_ui_defaultcustom) {
 183              $attributes = $this->get_ui()->get_attributes();
 184              return $attributes['defaultvalue'];
 185          }
 186          return $value;
 187      }
 188  }
 189  
 190  
 191  class restore_course_generic_text_setting extends restore_course_generic_setting {
 192  
 193      public function __construct($name, $vtype, $value = null, $visibility = self::VISIBLE, $status = self::NOT_LOCKED) {
 194          parent::__construct($name, $vtype, $value, $visibility, $status);
 195          $this->set_ui(new backup_setting_ui_text($this, $name));
 196      }
 197  
 198  }
 199  
 200  // Section restore settings
 201  
 202  /**
 203   * generic section setting to pass various settings between tasks and steps
 204   */
 205  class restore_section_generic_setting extends section_backup_setting {}
 206  
 207  /**
 208   * Setting to define if one section is included or no. Activities _included
 209   * settings depend of them if available
 210   */
 211  class restore_section_included_setting extends restore_section_generic_setting {}
 212  
 213  /**
 214   * section backup setting to control if section will include
 215   * user information or no, depends of @restore_users_setting
 216   */
 217  class restore_section_userinfo_setting extends restore_section_generic_setting {}
 218  
 219  
 220  // Activity backup settings
 221  
 222  /**
 223   * generic activity setting to pass various settings between tasks and steps
 224   */
 225  class restore_activity_generic_setting extends activity_backup_setting {}
 226  
 227  /**
 228   * activity backup setting to control if activity will
 229   * be included or no, depends of @restore_activities_setting and
 230   * optionally parent section included setting
 231   */
 232  class restore_activity_included_setting extends restore_activity_generic_setting {}
 233  
 234  /**
 235   * activity backup setting to control if activity will include
 236   * user information or no, depends of @restore_users_setting
 237   */
 238  class restore_activity_userinfo_setting extends restore_activity_generic_setting {}
 239  
 240  /**
 241   * root setting to control if restore will create content bank content or no
 242   */
 243  class restore_contentbankcontent_setting extends restore_generic_setting {
 244  }