Merge branch 'MDL-81456-main' of https://github.com/andrewnicols/moodle
[moodle.git] / backup / moodle2 / backup_subplugin.class.php
blob7cb30e3896c03a7edce6de9cc786768b46214218
1 <?php
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.
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/>.
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
27 defined('MOODLE_INTERNAL') || die();
29 /**
30 * Class implementing the subplugins support for moodle2 backups
32 * TODO: Finish phpdocs
33 * TODO: Make this subclass of backup_plugin
35 abstract class backup_subplugin {
37 protected $subplugintype;
38 protected $subpluginname;
39 protected $connectionpoint;
40 protected $optigroup; // Optigroup, parent of all optigroup elements
41 protected $step;
42 protected $task;
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();
53 public function define_subplugin_structure($connectionpoint) {
55 $this->connectionpoint = $connectionpoint;
57 $methodname = 'define_' . $connectionpoint . '_subplugin_structure';
59 if (method_exists($this, $methodname)) {
60 $this->$methodname();
64 // Protected API starts here
66 // backup_step/structure_step/task wrappers
68 /**
69 * Returns the value of one (task/plan) setting
71 protected function get_setting_value($name) {
72 if (is_null($this->task)) {
73 throw new backup_step_exception('not_specified_backup_task');
75 return $this->task->get_setting_value($name);
78 // end of backup_step/structure_step/task wrappers
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)
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;
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 ;-)
97 protected function get_recommended_name() {
98 return 'subplugin_' . $this->subplugintype . '_' . $this->subpluginname . '_' . $this->connectionpoint;