1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
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.
|
|
|
14 |
//
|
|
|
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/>.
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* @package moodlecore
|
|
|
20 |
* @subpackage backup-plan
|
|
|
21 |
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Abstract class defining the needed stuf for one restore task (a collection of steps)
|
|
|
27 |
*
|
|
|
28 |
* TODO: Finish phpdocs
|
|
|
29 |
*/
|
|
|
30 |
abstract class restore_task extends base_task {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Constructor - instantiates one object of this class
|
|
|
34 |
*/
|
|
|
35 |
public function __construct($name, $plan = null) {
|
|
|
36 |
if (!is_null($plan) && !($plan instanceof restore_plan)) {
|
|
|
37 |
throw new restore_task_exception('wrong_restore_plan_specified');
|
|
|
38 |
}
|
|
|
39 |
parent::__construct($name, $plan);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public function get_restoreid() {
|
|
|
43 |
return $this->plan->get_restoreid();
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public function get_info() {
|
|
|
47 |
return $this->plan->get_info();
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public function get_target() {
|
|
|
51 |
return $this->plan->get_target();
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
public function get_userid() {
|
|
|
55 |
return $this->plan->get_userid();
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public function get_decoder() {
|
|
|
59 |
return $this->plan->get_decoder();
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public function is_samesite() {
|
|
|
63 |
return $this->plan->is_samesite();
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
public function is_missing_modules() {
|
|
|
67 |
return $this->plan->is_missing_modules();
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public function is_excluding_activities() {
|
|
|
71 |
return $this->plan->is_excluding_activities();
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
public function set_preloaded_information() {
|
|
|
75 |
$this->plan->set_preloaded_information();
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
public function get_preloaded_information() {
|
|
|
79 |
return $this->plan->get_preloaded_information();
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public function get_tempdir() {
|
|
|
83 |
return $this->plan->get_tempdir();
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
public function get_old_courseid() {
|
|
|
87 |
return $this->plan->get_info()->original_course_id;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
public function get_old_contextid() {
|
|
|
91 |
return $this->plan->get_info()->original_course_contextid;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
public function get_old_system_contextid() {
|
|
|
95 |
return $this->plan->get_info()->original_system_contextid;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
/**
|
|
|
99 |
* Given a commment area, return the itemname that contains the itemid mappings
|
|
|
100 |
*
|
|
|
101 |
* By default, both are the same (commentarea = itemname), so return it. If some
|
|
|
102 |
* plugins use a different approach, this method can be overriden in its task.
|
|
|
103 |
*
|
|
|
104 |
* @param string $commentarea area defined for this comment
|
|
|
105 |
* @return string itemname that contains the related itemid mapping
|
|
|
106 |
*/
|
|
|
107 |
public function get_comment_mapping_itemname($commentarea) {
|
|
|
108 |
return $commentarea;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* If the task has been executed, launch its after_restore()
|
|
|
113 |
* method if available
|
|
|
114 |
*/
|
|
|
115 |
public function execute_after_restore() {
|
|
|
116 |
if ($this->executed) {
|
|
|
117 |
foreach ($this->steps as $step) {
|
|
|
118 |
if (method_exists($step, 'launch_after_restore_methods')) {
|
|
|
119 |
$step->launch_after_restore_methods();
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
if ($this->executed && method_exists($this, 'after_restore')) {
|
|
|
124 |
$this->after_restore();
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
/**
|
|
|
129 |
* Compares the provided moodle version with the one the backup was taken from.
|
|
|
130 |
*
|
|
|
131 |
* @param int $version Moodle version number (YYYYMMDD or YYYYMMDDXX)
|
|
|
132 |
* @param string $operator Operator to compare the provided version to the backup version. {@see version_compare()}
|
|
|
133 |
* @return bool True if the comparison passes.
|
|
|
134 |
*/
|
|
|
135 |
public function backup_version_compare(int $version, string $operator) {
|
|
|
136 |
return $this->plan->backup_version_compare($version, $operator);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
/**
|
|
|
140 |
* Compares the provided moodle release with the one the backup was taken from.
|
|
|
141 |
*
|
|
|
142 |
* @param string $release Moodle release (X.Y or X.Y.Z)
|
|
|
143 |
* @param string $operator Operator to compare the provided release to the backup release. {@see version_compare()}
|
|
|
144 |
* @return bool True if the comparison passes.
|
|
|
145 |
*/
|
|
|
146 |
public function backup_release_compare(string $release, string $operator) {
|
|
|
147 |
return $this->plan->backup_release_compare($release, $operator);
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
/*
|
|
|
152 |
* Exception class used by all the @restore_task stuff
|
|
|
153 |
*/
|
|
|
154 |
class restore_task_exception extends base_task_exception {
|
|
|
155 |
|
|
|
156 |
public function __construct($errorcode, $a=NULL, $debuginfo=null) {
|
|
|
157 |
parent::__construct($errorcode, $a, $debuginfo);
|
|
|
158 |
}
|
|
|
159 |
}
|