Search moodle.org's
Developer Documentation

See Release Notes

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

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

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Base class with shared stuff between backup controller and restore
  19   * controller.
  20   *
  21   * @package core_backup
  22   * @copyright 2013 The Open University
  23   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  abstract class base_controller extends backup implements loggable {
  26      /**
  27       * @var \core\progress\base Progress reporting object.
  28       */
  29      protected $progress;
  30  
  31      /**
  32       * @var base_logger Logging chain object (moodle, inline, fs, db, syslog)
  33       */
  34      protected $logger;
  35  
  36      /** @var bool Whether this backup should release the session. */
  37      protected $releasesession = backup::RELEASESESSION_NO;
  38  
  39      /**
  40       * Holds the relevant destination information for course copy operations.
  41       *
  42       * @var \stdClass.
  43       */
  44      protected $copy;
  45  
  46      /** @var int Backup mode. */
  47      protected $mode;
  48  
  49      /**
  50       * Gets the progress reporter, which can be used to report progress within
  51       * the backup or restore process.
  52       *
  53       * @return \core\progress\base Progress reporting object
  54       */
  55      public function get_progress() {
  56          return $this->progress;
  57      }
  58  
  59      /**
  60       * Sets the progress reporter.
  61       *
  62       * @param \core\progress\base $progress Progress reporting object
  63       */
  64      public function set_progress(\core\progress\base $progress) {
  65          $this->progress = $progress;
  66      }
  67  
  68      /**
  69       * Gets first logger in logging chain.
  70       *
  71       * @return base_logger Logger
  72       */
  73      public function get_logger() {
  74          return $this->logger;
  75      }
  76  
  77      /**
  78       * Inserts a new logger at end of logging chain.
  79       *
  80       * @param base_logger $logger New logger to add
  81       */
  82      public function add_logger(base_logger $logger) {
  83          $existing = $this->logger;
  84          while ($existing->get_next()) {
  85              $existing = $existing->get_next();
  86          }
  87          $existing->set_next($logger);
  88      }
  89  
  90      /**
  91       * Logs data to the logger chain.
  92       *
  93       * @see loggable::log()
  94       */
  95      public function log($message, $level, $a = null, $depth = null, $display = false) {
  96          backup_helper::log($message, $level, $a, $depth, $display, $this->logger);
  97      }
  98  
  99      /**
 100       * Returns the set value of releasesession.
 101       * This is used to indicate if the session should be closed during the backup/restore.
 102       *
 103       * @return bool Indicates whether the session should be released.
 104       */
 105      public function get_releasesession() {
 106          return $this->releasesession;
 107      }
 108  
 109      /**
 110       * Store extra data for course copy operations.
 111       *
 112       * For a course copying these is data required to be passed to the restore step.
 113       * We store this data in its own section of the backup controller
 114       *
 115       * @param \stdClass $data The course copy data.
 116       * @throws backup_controller_exception
 117       * @deprecated since Moodle 4.1 MDL-74548 - please do not use this method anymore.
 118       * @todo MDL-75025 This method will be deleted in Moodle 4.5
 119       * @see restore_controller::__construct()
 120       */
 121      public function set_copy(\stdClass $data): void {
 122          debugging('The method base_controller::set_copy() is deprecated.
 123              Please use the restore_controller class instead.', DEBUG_DEVELOPER);
 124          // Only allow setting of copy data when controller is in copy mode.
 125          if ($this->mode != backup::MODE_COPY) {
 126              throw new backup_controller_exception('cannot_set_copy_vars_wrong_mode');
 127          }
 128          $this->copy = $data;
 129      }
 130  
 131      /**
 132       * Get the course copy data.
 133       *
 134       * @return \stdClass
 135       * @deprecated since Moodle 4.1 MDL-74548 - please do not use this method anymore.
 136       * @todo MDL-75026 This method will be deleted in Moodle 4.5
 137       * @see restore_controller::get_copy()
 138       */
 139      public function get_copy(): \stdClass {
 140          debugging('The method base_controller::get_copy() is deprecated.
 141             Please use restore_controller::get_copy() instead.', DEBUG_DEVELOPER);
 142          return $this->copy;
 143      }
 144  }