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.
   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_subplugin class
  20   * @package     core_backup
  21   * @subpackage  moodle2
  22   * @category    backup
  23   * @copyright   2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
  24   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  /**
  30   * Class implementing the subplugins support for moodle2 backups
  31   *
  32   * TODO: Finish phpdocs
  33   * TODO: Make this subclass of backup_plugin
  34   */
  35  abstract class backup_subplugin {
  36  
  37      protected $subplugintype;
  38      protected $subpluginname;
  39      protected $connectionpoint;
  40      protected $optigroup; // Optigroup, parent of all optigroup elements
  41      protected $step;
  42      protected $task;
  43  
  44      public function __construct($subplugintype, $subpluginname, $optigroup, $step) {
  45          $this->subplugintype = $subplugintype;
  46          $this->subpluginname = $subpluginname;
  47          $this->optigroup     = $optigroup;
  48          $this->connectionpoint = '';
  49          $this->step          = $step;
  50          $this->task          = $step->get_task();
  51      }
  52  
  53      public function define_subplugin_structure($connectionpoint) {
  54  
  55          $this->connectionpoint = $connectionpoint;
  56  
  57          $methodname = 'define_' . $connectionpoint . '_subplugin_structure';
  58  
  59          if (method_exists($this, $methodname)) {
  60              $this->$methodname();
  61          }
  62      }
  63  
  64  // Protected API starts here
  65  
  66  // backup_step/structure_step/task wrappers
  67  
  68      /**
  69       * Returns the value of one (task/plan) setting
  70       */
  71      protected function get_setting_value($name) {
  72          if (is_null($this->task)) {
  73              throw new backup_step_exception('not_specified_backup_task');
  74          }
  75          return $this->task->get_setting_value($name);
  76      }
  77  
  78  // end of backup_step/structure_step/task wrappers
  79  
  80      /**
  81       * Factory method that will return one backup_subplugin_element (backup_optigroup_element)
  82       * with its name automatically calculated, based one the subplugin being handled (type, name)
  83       */
  84      protected function get_subplugin_element($final_elements = null, $conditionparam = null, $conditionvalue = null) {
  85          // Something exclusive for this backup_subplugin_element (backup_optigroup_element)
  86          // because it hasn't XML representation
  87          $name = 'optigroup_' . $this->subplugintype . '_' . $this->subpluginname . '_' . $this->connectionpoint;
  88          $optigroup_element = new backup_subplugin_element($name, $final_elements, $conditionparam, $conditionvalue);
  89          $this->optigroup->add_child($optigroup_element);  // Add optigroup_element to stay connected since beginning
  90          return $optigroup_element;
  91      }
  92  
  93      /**
  94       * Simple helper function that suggests one name for the main nested element in subplugins
  95       * It's not mandatory to use it but recommended ;-)
  96       */
  97      protected function get_recommended_name() {
  98          return 'subplugin_' . $this->subplugintype . '_' . $this->subpluginname . '_' . $this->connectionpoint;
  99      }
 100  
 101  }