mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
restore_plan.class.php
206 lines (173 loc) · 6.63 KB
/
restore_plan.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package moodlecore
* @subpackage backup-plan
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Implementable class defining the needed stuf for one restore plan
*
* TODO: Finish phpdocs
*/
class restore_plan extends base_plan implements loggable {
/**
*
* @var restore_controller
*/
protected $controller; // The restore controller building/executing this plan
protected $basepath; // Fullpath to dir where backup is available
protected $preloaded; // When executing the plan, do we have preloaded (from checks) info
protected $decoder; // restore_decode_processor in charge of decoding all the interlinks
protected $missingmodules; // to flag if restore has detected some missing module
protected $excludingdactivities; // to flag if restore settings are excluding any activity
/**
* Constructor - instantiates one object of this class
*/
public function __construct($controller) {
global $CFG;
if (! $controller instanceof restore_controller) {
throw new restore_plan_exception('wrong_restore_controller_specified');
}
$this->controller = $controller;
$this->basepath = $CFG->tempdir . '/backup/' . $controller->get_tempdir();
$this->preloaded = false;
$this->decoder = new restore_decode_processor($this->get_restoreid(), $this->get_info()->original_wwwroot, $CFG->wwwroot);
$this->missingmodules = false;
$this->excludingdactivities = false;
parent::__construct('restore_plan');
}
/**
* Destroy all circular references. It helps PHP 5.2 a lot!
*/
public function destroy() {
// No need to destroy anything recursively here, direct reset
$this->controller = null;
// Delegate to base plan the rest
parent::destroy();
}
public function build() {
restore_plan_builder::build_plan($this->controller); // We are moodle2 always, go straight to builder
$this->built = true;
}
public function get_restoreid() {
return $this->controller->get_restoreid();
}
public function get_courseid() {
return $this->controller->get_courseid();
}
public function get_mode() {
return $this->controller->get_mode();
}
public function get_basepath() {
return $this->basepath;
}
public function get_logger() {
return $this->controller->get_logger();
}
/**
* Gets the progress reporter, which can be used to report progress within
* the backup or restore process.
*
* @return \core\progress\base Progress reporting object
*/
public function get_progress() {
return $this->controller->get_progress();
}
public function get_info() {
return $this->controller->get_info();
}
public function get_target() {
return $this->controller->get_target();
}
public function get_userid() {
return $this->controller->get_userid();
}
public function get_decoder() {
return $this->decoder;
}
public function is_samesite() {
return $this->controller->is_samesite();
}
public function is_missing_modules() {
return $this->missingmodules;
}
public function is_excluding_activities() {
return $this->excludingdactivities;
}
public function set_preloaded_information() {
$this->preloaded = true;
}
public function get_preloaded_information() {
return $this->preloaded;
}
public function get_tempdir() {
return $this->controller->get_tempdir();
}
public function set_missing_modules() {
$this->missingmodules = true;
}
public function set_excluding_activities() {
$this->excludingdactivities = true;
}
public function log($message, $level, $a = null, $depth = null, $display = false) {
backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
}
/**
* Function responsible for executing the tasks of any plan
*/
public function execute() {
if ($this->controller->get_status() != backup::STATUS_AWAITING) {
throw new restore_controller_exception('restore_not_executable_awaiting_required', $this->controller->get_status());
}
$this->controller->set_status(backup::STATUS_EXECUTING);
parent::execute();
$this->controller->set_status(backup::STATUS_FINISHED_OK);
// Check if we are restoring a course.
if ($this->controller->get_type() === backup::TYPE_1COURSE) {
// Trigger a course restored event.
$event = \core\event\course_restored::create(array(
'objectid' => $this->get_courseid(),
'userid' => $this->get_userid(),
'context' => context_course::instance($this->get_courseid()),
'other' => array('type' => $this->controller->get_type(),
'target' => $this->controller->get_target(),
'mode' => $this->controller->get_mode(),
'operation' => $this->controller->get_operation(),
'samesite' => $this->controller->is_samesite())
));
$event->trigger();
}
}
/**
* Execute the after_restore methods of all the executed tasks in the plan
*/
public function execute_after_restore() {
// Simply iterate over each task in the plan and delegate to them the execution
foreach ($this->tasks as $task) {
$task->execute_after_restore();
}
}
}
/*
* Exception class used by all the @restore_plan stuff
*/
class restore_plan_exception extends base_plan_exception {
public function __construct($errorcode, $a=NULL, $debuginfo=null) {
parent::__construct($errorcode, $a, $debuginfo);
}
}