Differences Between: [Versions 311 and 402] [Versions 311 and 403]
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 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 /** 61 * Destroy all circular references. It helps PHP 5.2 a lot! 62 */ 63 public function destroy() { 64 // No need to destroy anything recursively here, direct reset 65 $this->task = null; 66 } 67 68 public function log($message, $level, $a = null, $depth = null, $display = false) { 69 if (is_null($this->task)) { 70 throw new base_step_exception('not_specified_base_task'); 71 } 72 backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger()); 73 } 74 75 /// Protected API starts here 76 77 protected function get_settings() { 78 if (is_null($this->task)) { 79 throw new base_step_exception('not_specified_base_task'); 80 } 81 return $this->task->get_settings(); 82 } 83 84 protected function get_setting($name) { 85 if (is_null($this->task)) { 86 throw new base_step_exception('not_specified_base_task'); 87 } 88 return $this->task->get_setting($name); 89 } 90 91 protected function setting_exists($name) { 92 if (is_null($this->task)) { 93 throw new base_step_exception('not_specified_base_task'); 94 } 95 return $this->task->setting_exists($name); 96 } 97 98 protected function get_setting_value($name) { 99 if (is_null($this->task)) { 100 throw new base_step_exception('not_specified_base_task'); 101 } 102 return $this->task->get_setting_value($name); 103 } 104 105 protected function get_courseid() { 106 if (is_null($this->task)) { 107 throw new base_step_exception('not_specified_base_task'); 108 } 109 return $this->task->get_courseid(); 110 } 111 112 protected function get_basepath() { 113 return $this->task->get_basepath(); 114 } 115 116 protected function get_logger() { 117 return $this->task->get_logger(); 118 } 119 } 120 121 122 /* 123 * Exception class used by all the @base_step stuff 124 */ 125 class base_step_exception extends moodle_exception { 126 127 public function __construct($errorcode, $a=NULL, $debuginfo=null) { 128 parent::__construct($errorcode, '', '', $a, $debuginfo); 129 } 130 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body