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 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   * @package moodlecore
  20   * @subpackage backup-plan
  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   * Abstract class defining the needed stuf for one restore task (a collection of steps)
  27   *
  28   * TODO: Finish phpdocs
  29   */
  30  abstract class restore_task extends base_task {
  31  
  32      /**
  33       * Constructor - instantiates one object of this class
  34       */
  35      public function __construct($name, $plan = null) {
  36          if (!is_null($plan) && !($plan instanceof restore_plan)) {
  37              throw new restore_task_exception('wrong_restore_plan_specified');
  38          }
  39          parent::__construct($name, $plan);
  40      }
  41  
  42      public function get_restoreid() {
  43          return $this->plan->get_restoreid();
  44      }
  45  
  46      public function get_info() {
  47          return $this->plan->get_info();
  48      }
  49  
  50      public function get_target() {
  51          return $this->plan->get_target();
  52      }
  53  
  54      public function get_userid() {
  55          return $this->plan->get_userid();
  56      }
  57  
  58      public function get_decoder() {
  59          return $this->plan->get_decoder();
  60      }
  61  
  62      public function is_samesite() {
  63          return $this->plan->is_samesite();
  64      }
  65  
  66      public function is_missing_modules() {
  67          return $this->plan->is_missing_modules();
  68      }
  69  
  70      public function is_excluding_activities() {
  71          return $this->plan->is_excluding_activities();
  72      }
  73  
  74      public function set_preloaded_information() {
  75          $this->plan->set_preloaded_information();
  76      }
  77  
  78      public function get_preloaded_information() {
  79          return $this->plan->get_preloaded_information();
  80      }
  81  
  82      public function get_tempdir() {
  83          return $this->plan->get_tempdir();
  84      }
  85  
  86      public function get_old_courseid() {
  87          return $this->plan->get_info()->original_course_id;
  88      }
  89  
  90      public function get_old_contextid() {
  91          return $this->plan->get_info()->original_course_contextid;
  92      }
  93  
  94      public function get_old_system_contextid() {
  95          return $this->plan->get_info()->original_system_contextid;
  96      }
  97  
  98      /**
  99       * If the task has been executed, launch its after_restore()
 100       * method if available
 101       */
 102      public function execute_after_restore() {
 103          if ($this->executed) {
 104              foreach ($this->steps as $step) {
 105                  if (method_exists($step, 'launch_after_restore_methods')) {
 106                      $step->launch_after_restore_methods();
 107                  }
 108              }
 109          }
 110          if ($this->executed && method_exists($this, 'after_restore')) {
 111              $this->after_restore();
 112          }
 113      }
 114  }
 115  
 116  /*
 117   * Exception class used by all the @restore_task stuff
 118   */
 119  class restore_task_exception extends base_task_exception {
 120  
 121      public function __construct($errorcode, $a=NULL, $debuginfo=null) {
 122          parent::__construct($errorcode, $a, $debuginfo);
 123      }
 124  }