1 |
efrain |
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 |
* Backup steps for the multiblock plugin.
|
|
|
19 |
*
|
|
|
20 |
* @package block_multiblock
|
|
|
21 |
* @copyright 2019 Peter Spicer <peter.spicer@catalyst-eu.net>
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Specialised backup task for the multiblock block.
|
|
|
27 |
*
|
|
|
28 |
* This is primarily about backing up the child blocks.
|
|
|
29 |
*
|
|
|
30 |
* @package block_multiblock
|
|
|
31 |
* @copyright 2019 Peter Spicer <peter.spicer@catalyst-eu.net>
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class backup_multiblock_block_task extends backup_block_task {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Mandatory function for defining specific settings for this task.
|
|
|
38 |
*/
|
|
|
39 |
protected function define_my_settings() {
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Mandatory function for defining steps carried out by this backup process.
|
|
|
44 |
*
|
|
|
45 |
* Specifically when run, queue the sub-blocks to the backup plan and execute them.
|
|
|
46 |
*/
|
|
|
47 |
protected function define_my_steps() {
|
|
|
48 |
global $DB;
|
|
|
49 |
|
|
|
50 |
// Find all the sub-blocks so we can add them to the backup plan.
|
|
|
51 |
$subblocks = $DB->get_records('block_instances', ['parentcontextid' => $this->get_contextid()]);
|
|
|
52 |
|
|
|
53 |
// Before we add anything to the plan, we need to sort out the progress meter.
|
|
|
54 |
// The issue is, we're adding tasks to the progress queue but the size of the queue
|
|
|
55 |
// for the progress meter was set up before we started the queue, so we have to fit it.
|
|
|
56 |
// Unfortunately, it's a protected array inside the progress instance, so better
|
|
|
57 |
// pop the lid and get ourselves access to it with Reflection.
|
|
|
58 |
$progress = $this->get_progress();
|
|
|
59 |
$progressclass = new ReflectionClass($progress);
|
|
|
60 |
$progressproperty = $progressclass->getProperty('maxes');
|
|
|
61 |
$progressproperty->setAccessible(true);
|
|
|
62 |
$maxes = $progressproperty->getValue($progress);
|
|
|
63 |
$maxes[count($maxes) - 1] += count($subblocks);
|
|
|
64 |
$progressproperty->setValue($progress, $maxes);
|
|
|
65 |
|
|
|
66 |
foreach (array_keys($subblocks) as $blockid) {
|
|
|
67 |
// Only Moodle2 format backups support blocks, not that the backup block task cares anyway.
|
|
|
68 |
$task = backup_factory::get_backup_block_task(backup::FORMAT_MOODLE, $blockid);
|
|
|
69 |
|
|
|
70 |
// Add it to the plan, then run the task for each sub-block.
|
|
|
71 |
$this->plan->add_task($task);
|
|
|
72 |
$task->build();
|
|
|
73 |
$task->execute();
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Return fileareas attached to this block.
|
|
|
79 |
* Multiblock itself has no fileareas, it leverages those of its children.
|
|
|
80 |
*
|
|
|
81 |
* @return array List of fileareas.
|
|
|
82 |
*/
|
|
|
83 |
public function get_fileareas() {
|
|
|
84 |
return [];
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* Return a list of configuration items that need to be safely encoded to
|
|
|
89 |
* successfully be handled during backup/restore.
|
|
|
90 |
*
|
|
|
91 |
* Multiblock itself has minimal configuration, it leverages its children.
|
|
|
92 |
*
|
|
|
93 |
* @return array List of attributes that need encoding.
|
|
|
94 |
*/
|
|
|
95 |
public function get_configdata_encoded_attributes() {
|
|
|
96 |
return [];
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* Re-encode content links inside the block's content when backing up
|
|
|
101 |
* or restoring.
|
|
|
102 |
*
|
|
|
103 |
* Multiblock has no content itself for this to be processed.
|
|
|
104 |
*
|
|
|
105 |
* @param string $content The content to be processed.
|
|
|
106 |
* @return string The processed content.
|
|
|
107 |
*/
|
|
|
108 |
public static function encode_content_links($content) {
|
|
|
109 |
return $content;
|
|
|
110 |
}
|
|
|
111 |
}
|