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 basis for one execution (backup/restore) step
|
|
|
27 |
*
|
|
|
28 |
* TODO: Finish phpdocs
|
|
|
29 |
*/
|
|
|
30 |
abstract class base_step implements executable, loggable {
|
|
|
31 |
|
|
|
32 |
/** @var string One simple name for identification purposes */
|
|
|
33 |
protected $name;
|
|
|
34 |
/** @var base_task|null Task this is part of */
|
|
|
35 |
protected $task;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Constructor - instantiates one object of this class
|
|
|
39 |
*/
|
|
|
40 |
public function __construct($name, $task = null) {
|
|
|
41 |
if (!is_null($task) && !($task instanceof base_task)) {
|
|
|
42 |
throw new base_step_exception('wrong_base_task_specified');
|
|
|
43 |
}
|
|
|
44 |
$this->name = $name;
|
|
|
45 |
$this->task = $task;
|
|
|
46 |
if (!is_null($task)) { // Add the step to the task if specified
|
|
|
47 |
$task->add_step($this);
|
|
|
48 |
}
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
public function get_name() {
|
|
|
52 |
return $this->name;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public function set_task($task) {
|
|
|
56 |
if (! $task instanceof base_task) {
|
|
|
57 |
throw new base_step_exception('wrong_base_task_specified');
|
|
|
58 |
}
|
|
|
59 |
$this->task = $task;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Destroy all circular references. It helps PHP 5.2 a lot!
|
|
|
64 |
*/
|
|
|
65 |
public function destroy() {
|
|
|
66 |
// No need to destroy anything recursively here, direct reset
|
|
|
67 |
$this->task = null;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public function log($message, $level, $a = null, $depth = null, $display = false) {
|
|
|
71 |
if (is_null($this->task)) {
|
|
|
72 |
throw new base_step_exception('not_specified_base_task');
|
|
|
73 |
}
|
|
|
74 |
backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
/// Protected API starts here
|
|
|
78 |
|
|
|
79 |
protected function get_settings() {
|
|
|
80 |
if (is_null($this->task)) {
|
|
|
81 |
throw new base_step_exception('not_specified_base_task');
|
|
|
82 |
}
|
|
|
83 |
return $this->task->get_settings();
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
protected function get_setting($name) {
|
|
|
87 |
if (is_null($this->task)) {
|
|
|
88 |
throw new base_step_exception('not_specified_base_task');
|
|
|
89 |
}
|
|
|
90 |
return $this->task->get_setting($name);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
protected function setting_exists($name) {
|
|
|
94 |
if (is_null($this->task)) {
|
|
|
95 |
throw new base_step_exception('not_specified_base_task');
|
|
|
96 |
}
|
|
|
97 |
return $this->task->setting_exists($name);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
protected function get_setting_value($name) {
|
|
|
101 |
if (is_null($this->task)) {
|
|
|
102 |
throw new base_step_exception('not_specified_base_task');
|
|
|
103 |
}
|
|
|
104 |
return $this->task->get_setting_value($name);
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
protected function get_courseid() {
|
|
|
108 |
if (is_null($this->task)) {
|
|
|
109 |
throw new base_step_exception('not_specified_base_task');
|
|
|
110 |
}
|
|
|
111 |
return $this->task->get_courseid();
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
protected function get_basepath() {
|
|
|
115 |
return $this->task->get_basepath();
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
protected function get_logger() {
|
|
|
119 |
return $this->task->get_logger();
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
/*
|
|
|
125 |
* Exception class used by all the @base_step stuff
|
|
|
126 |
*/
|
|
|
127 |
class base_step_exception extends moodle_exception {
|
|
|
128 |
|
|
|
129 |
public function __construct($errorcode, $a=NULL, $debuginfo=null) {
|
|
|
130 |
parent::__construct($errorcode, '', '', $a, $debuginfo);
|
|
|
131 |
}
|
|
|
132 |
}
|