MDL-21432 backup - access to userid is done across task
[moodle.git] / backup / util / plan / base_step.class.php
CommitLineData
69dd0c8c
EL
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 */
30abstract class base_step implements executable, loggable {
31
32 protected $name; // One simple name for identification purposes
33 protected $task; // Task this is part of
34
35 /**
36 * Constructor - instantiates one object of this class
37 */
38 public function __construct($name, $task = null) {
39 if (!is_null($task) && !($task instanceof base_task)) {
40 throw new base_step_exception('wrong_base_task_specified');
41 }
42 $this->name = $name;
43 $this->task = $task;
44 if (!is_null($task)) { // Add the step to the task if specified
45 $task->add_step($this);
46 }
47 }
48
49 public function get_name() {
50 return $this->name;
51 }
52
53 public function set_task($task) {
54 if (! $task instanceof base_task) {
55 throw new base_step_exception('wrong_base_task_specified');
56 }
57 $this->task = $task;
58 }
59
60 public function log($message, $level, $a = null, $depth = null, $display = false) {
61 if (is_null($this->task)) {
62 throw new base_step_exception('not_specified_base_task');
63 }
64 backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
65 }
66
67/// Protected API starts here
68
69 protected function get_settings() {
70 if (is_null($this->task)) {
71 throw new base_step_exception('not_specified_base_task');
72 }
73 return $this->task->get_settings();
74 }
75
76 protected function get_setting($name) {
77 if (is_null($this->task)) {
78 throw new base_step_exception('not_specified_base_task');
79 }
80 return $this->task->get_setting($name);
81 }
82
83 protected function get_setting_value($name) {
84 if (is_null($this->task)) {
85 throw new base_step_exception('not_specified_base_task');
86 }
87 return $this->task->get_setting_value($name);
88 }
89
69dd0c8c
EL
90 protected function get_courseid() {
91 if (is_null($this->task)) {
92 throw new base_step_exception('not_specified_base_task');
93 }
94 return $this->task->get_courseid();
95 }
96
97 protected function get_basepath() {
98 return $this->task->get_basepath();
99 }
100
101 protected function get_logger() {
102 return $this->task->get_logger();
103 }
104}
105
106
107/*
108 * Exception class used by all the @base_step stuff
109 */
110class base_step_exception extends moodle_exception {
111
112 public function __construct($errorcode, $a=NULL, $debuginfo=null) {
113 parent::__construct($errorcode, '', '', $a, $debuginfo);
114 }
115}