3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * Defines restore_block_task class
21 * @package core_backup
24 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') ||
die();
31 * abstract block task that provides all the properties and common steps to be performed
32 * when one block is being restored
34 * TODO: Finish phpdocs
36 abstract class restore_block_task
extends restore_task
{
38 protected $taskbasepath; // To store the basepath of this block
39 protected $blockname; // Name of the block
40 protected $contextid; // new (target) context of the block
41 protected $oldcontextid;// old (original) context of the block
42 protected $blockid; // new (target) id of the block
43 protected $oldblockid; // old (original) id of the block
46 * Constructor - instantiates one object of this class
48 public function __construct($name, $taskbasepath, $plan = null) {
49 $this->taskbasepath
= $taskbasepath;
50 $this->blockname
= '';
52 $this->oldcontextid
= 0;
54 $this->oldblockid
= 0;
55 parent
::__construct($name, $plan);
59 * Block tasks have their own directory to write files
61 public function get_taskbasepath() {
62 return $this->taskbasepath
;
66 * Create all the steps that will be part of this task
68 public function build() {
70 // If we have decided not to backup blocks, prevent anything to be built
71 if (!$this->get_setting_value('blocks')) {
76 // If "child" of activity task and it has been excluded, nothing to do
77 $parent = basename(dirname(dirname($this->taskbasepath
)));
78 if ($parent != 'course') {
79 $includedsetting = $parent . '_included';
80 if (!$this->get_setting_value($includedsetting)) {
86 // Process the block.xml common file (instance + positions)
87 $this->add_step(new restore_block_instance_structure_step('block_commons', 'block.xml'));
89 // Here we add all the common steps for any block and, in the point of interest
90 // we call to define_my_steps() in order to get the particular ones inserted in place.
91 $this->define_my_steps();
93 // Restore block role assignments and overrides (internally will observe the role_assignments setting)
94 $this->add_step(new restore_ras_and_caps_structure_step('block_ras_and_caps', 'roles.xml'));
96 // Restore block comments (conditionally)
97 if ($this->get_setting_value('comments')) {
98 $this->add_step(new restore_comments_structure_step('block_comments', 'comments.xml'));
101 // At the end, mark it as built
105 public function set_blockname($blockname) {
106 $this->blockname
= $blockname;
109 public function get_blockname() {
110 return $this->blockname
;
113 public function set_blockid($blockid) {
114 $this->blockid
= $blockid;
117 public function get_blockid() {
118 return $this->blockid
;
121 public function set_old_blockid($blockid) {
122 $this->oldblockid
= $blockid;
125 public function get_old_blockid() {
126 return $this->oldblockid
;
129 public function set_contextid($contextid) {
130 $this->contextid
= $contextid;
133 public function get_contextid() {
134 return $this->contextid
;
137 public function set_old_contextid($contextid) {
138 $this->oldcontextid
= $contextid;
141 public function get_old_contextid() {
142 return $this->oldcontextid
;
146 * Define one array() of fileareas that each block controls
148 abstract public function get_fileareas();
151 * Define one array() of configdata attributes
152 * that need to be decoded
154 abstract public function get_configdata_encoded_attributes();
157 * Define the contents in the activity that must be
158 * processed by the link decoder
160 static public function define_decode_contents() {
161 throw new coding_exception('define_decode_contents() method needs to be overridden in each subclass of restore_block_task');
165 * Define the decoding rules for links belonging
166 * to the activity to be executed by the link decoder
168 static public function define_decode_rules() {
169 throw new coding_exception('define_decode_rules() method needs to be overridden in each subclass of restore_block_task');
172 // Protected API starts here
175 * Define the common setting that any backup block will have
177 protected function define_settings() {
179 // Nothing to add, blocks doesn't have common settings (for now)
181 // End of common activity settings, let's add the particular ones
182 $this->define_my_settings();
186 * Define (add) particular settings that each block can have
188 abstract protected function define_my_settings();
191 * Define (add) particular steps that each block can have
193 abstract protected function define_my_steps();