Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
   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   * @package    moodlecore
  20   * @subpackage backup-factories
  21   * @copyright  2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  /**
  26   * Non instantiable factory class providing different restore object instances
  27   *
  28   * This class contains various methods available in order to easily
  29   * create different parts of the restore architecture in an easy way
  30   *
  31   * TODO: Finish phpdocs
  32   */
  33  abstract class restore_factory {
  34  
  35      public static function get_restore_activity_task($info) {
  36  
  37          $classname = 'restore_' . $info->modulename . '_activity_task';
  38          if (class_exists($classname)) {
  39              return new $classname($info->title, $info);
  40          }
  41      }
  42  
  43      public static function get_restore_block_task($blockname, $basepath) {
  44  
  45          $classname = 'restore_default_block_task';
  46          $testname  = 'restore_' . $blockname . '_block_task';
  47          // If the block has custom backup/restore task class (testname), use it
  48          if (class_exists($testname)) {
  49              $classname = $testname;
  50          }
  51          return new $classname($blockname, $basepath);
  52      }
  53  
  54      public static function get_restore_section_task($info) {
  55  
  56          return new restore_section_task($info->title, $info);
  57      }
  58  
  59      public static function get_restore_course_task($info, $courseid) {
  60          global $DB;
  61  
  62          // Check course exists
  63          if (!$course = $DB->get_record('course', array('id' => $courseid))) {
  64              throw new restore_task_exception('course_task_course_not_found', $courseid);
  65          }
  66  
  67          return new restore_course_task($info->title, $info);
  68      }
  69  }