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 |
* Restoration 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 restore task for the multiblock block
|
|
|
27 |
*
|
|
|
28 |
* @package block_multiblock
|
|
|
29 |
* @copyright 2019 Peter Spicer <peter.spicer@catalyst-eu.net>
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class restore_multiblock_block_task extends restore_block_task {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Injects the restore plan into this task.
|
|
|
36 |
*
|
|
|
37 |
* While receiving the dependency of the restore_plan, rearrange
|
|
|
38 |
* the queue to make sure multiblock is processed first.
|
|
|
39 |
*
|
|
|
40 |
* @param restore_plan $plan The restore plan for this restore job.
|
|
|
41 |
*/
|
|
|
42 |
public function set_plan($plan) {
|
|
|
43 |
parent::set_plan($plan);
|
|
|
44 |
|
|
|
45 |
// So here we need to reorder the task list. Specifically, we need
|
|
|
46 |
// to rearrange all instances of restore_block_task to put
|
|
|
47 |
// instances of restore_multiblock_task_block first. And that means
|
|
|
48 |
// we first have to get the task list, it's a protected property.
|
|
|
49 |
$planclass = new ReflectionClass($plan);
|
|
|
50 |
$taskproperty = $planclass->getProperty('tasks');
|
|
|
51 |
$taskproperty->setAccessible(true);
|
|
|
52 |
|
|
|
53 |
// So, this task (a multiblock) is the last task added. We need to splice it in.
|
|
|
54 |
// First, break it off the list.
|
|
|
55 |
$tasks = $taskproperty->getValue($plan);
|
|
|
56 |
$thistask = array_pop($tasks);
|
|
|
57 |
|
|
|
58 |
// Now we need to find which index contains the first instance of a block task.
|
|
|
59 |
$index = null;
|
|
|
60 |
foreach ($tasks as $id => $task) {
|
|
|
61 |
if ($task instanceof restore_block_task) {
|
|
|
62 |
$index = $id;
|
|
|
63 |
break;
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
if ($index !== null) {
|
|
|
68 |
// Splice the item at the front of the queue. This should be fine in all backup cases
|
|
|
69 |
// because in all backup types, the blocks are after the root/course/activity tasks.
|
|
|
70 |
$tasks = array_merge(array_slice($tasks, 0, $index), [$thistask], array_slice($tasks, $index));
|
|
|
71 |
} else {
|
|
|
72 |
// Slightly bizarrely, there's no other blocks in the tasklist, just put this back.
|
|
|
73 |
$tasks[] = $thistask;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
// And put the queue back.
|
|
|
77 |
$taskproperty->setValue($plan, $tasks);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Mandatory function for defining processing settings on restore.
|
|
|
82 |
*/
|
|
|
83 |
protected function define_my_settings() {
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
/**
|
|
|
87 |
* Mandatory function for defining processing steps on restore.
|
|
|
88 |
*
|
|
|
89 |
* Moodle actually inadvertantly handles all the steps automatically.
|
|
|
90 |
*/
|
|
|
91 |
protected function define_my_steps() {
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Mandatory function for handling file areas on restoration.
|
|
|
96 |
*
|
|
|
97 |
* @return array A list of file areas handled by this plugin.
|
|
|
98 |
*/
|
|
|
99 |
public function get_fileareas() {
|
|
|
100 |
return [];
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
/**
|
|
|
104 |
* Return a list of attributes that requires decoding during restore.
|
|
|
105 |
*
|
|
|
106 |
* @return array A list of attributes ot be fixed.
|
|
|
107 |
*/
|
|
|
108 |
public function get_configdata_encoded_attributes() {
|
|
|
109 |
return [];
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
/**
|
|
|
113 |
* Return a list of contents for the plugin that will need to be decoded during restore.
|
|
|
114 |
*
|
|
|
115 |
* @return array A list of content items to be decoded.
|
|
|
116 |
*/
|
|
|
117 |
public static function define_decode_contents() {
|
|
|
118 |
return array();
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
/**
|
|
|
122 |
* Return a list of find/replace rules to decode content during restore.
|
|
|
123 |
*
|
|
|
124 |
* @return array A list of find/replace rules.
|
|
|
125 |
*/
|
|
|
126 |
public static function define_decode_rules() {
|
|
|
127 |
return array();
|
|
|
128 |
}
|
|
|
129 |
}
|