[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Implementable class defining the needed stuf for one restore plan 27 * 28 * TODO: Finish phpdocs 29 */ 30 class restore_plan extends base_plan implements loggable { 31 32 /** 33 * 34 * @var restore_controller 35 */ 36 protected $controller; // The restore controller building/executing this plan 37 protected $basepath; // Fullpath to dir where backup is available 38 protected $preloaded; // When executing the plan, do we have preloaded (from checks) info 39 protected $decoder; // restore_decode_processor in charge of decoding all the interlinks 40 protected $missingmodules; // to flag if restore has detected some missing module 41 protected $excludingdactivities; // to flag if restore settings are excluding any activity 42 43 /** 44 * Constructor - instantiates one object of this class 45 */ 46 public function __construct($controller) { 47 global $CFG; 48 49 if (! $controller instanceof restore_controller) { 50 throw new restore_plan_exception('wrong_restore_controller_specified'); 51 } 52 $this->controller = $controller; 53 $this->basepath = $CFG->tempdir . '/backup/' . $controller->get_tempdir(); 54 $this->preloaded = false; 55 $this->decoder = new restore_decode_processor($this->get_restoreid(), $this->get_info()->original_wwwroot, $CFG->wwwroot); 56 $this->missingmodules = false; 57 $this->excludingdactivities = false; 58 59 parent::__construct('restore_plan'); 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->controller = null; 68 // Delegate to base plan the rest 69 parent::destroy(); 70 } 71 72 public function build() { 73 restore_plan_builder::build_plan($this->controller); // We are moodle2 always, go straight to builder 74 $this->built = true; 75 } 76 77 public function get_restoreid() { 78 return $this->controller->get_restoreid(); 79 } 80 81 public function get_courseid() { 82 return $this->controller->get_courseid(); 83 } 84 85 public function get_mode() { 86 return $this->controller->get_mode(); 87 } 88 89 public function get_basepath() { 90 return $this->basepath; 91 } 92 93 public function get_logger() { 94 return $this->controller->get_logger(); 95 } 96 97 /** 98 * Gets the progress reporter, which can be used to report progress within 99 * the backup or restore process. 100 * 101 * @return \core\progress\base Progress reporting object 102 */ 103 public function get_progress() { 104 return $this->controller->get_progress(); 105 } 106 107 public function get_info() { 108 return $this->controller->get_info(); 109 } 110 111 public function get_target() { 112 return $this->controller->get_target(); 113 } 114 115 public function get_userid() { 116 return $this->controller->get_userid(); 117 } 118 119 public function get_decoder() { 120 return $this->decoder; 121 } 122 123 public function is_samesite() { 124 return $this->controller->is_samesite(); 125 } 126 127 public function is_missing_modules() { 128 return $this->missingmodules; 129 } 130 131 public function is_excluding_activities() { 132 return $this->excludingdactivities; 133 } 134 135 public function set_preloaded_information() { 136 $this->preloaded = true; 137 } 138 139 public function get_preloaded_information() { 140 return $this->preloaded; 141 } 142 143 public function get_tempdir() { 144 return $this->controller->get_tempdir(); 145 } 146 147 public function set_missing_modules() { 148 $this->missingmodules = true; 149 } 150 151 public function set_excluding_activities() { 152 $this->excludingdactivities = true; 153 } 154 155 public function log($message, $level, $a = null, $depth = null, $display = false) { 156 backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger()); 157 } 158 159 /** 160 * Function responsible for executing the tasks of any plan 161 */ 162 public function execute() { 163 if ($this->controller->get_status() != backup::STATUS_AWAITING) { 164 throw new restore_controller_exception('restore_not_executable_awaiting_required', $this->controller->get_status()); 165 } 166 $this->controller->set_status(backup::STATUS_EXECUTING); 167 parent::execute(); 168 $this->controller->set_status(backup::STATUS_FINISHED_OK); 169 170 // Check if we are restoring a course. 171 if ($this->controller->get_type() === backup::TYPE_1COURSE) { 172 // Trigger a course restored event. 173 $event = \core\event\course_restored::create(array( 174 'objectid' => $this->get_courseid(), 175 'userid' => $this->get_userid(), 176 'context' => context_course::instance($this->get_courseid()), 177 'other' => array('type' => $this->controller->get_type(), 178 'target' => $this->controller->get_target(), 179 'mode' => $this->controller->get_mode(), 180 'operation' => $this->controller->get_operation(), 181 'samesite' => $this->controller->is_samesite()) 182 )); 183 $event->trigger(); 184 } 185 } 186 187 /** 188 * Execute the after_restore methods of all the executed tasks in the plan 189 */ 190 public function execute_after_restore() { 191 // Simply iterate over each task in the plan and delegate to them the execution 192 foreach ($this->tasks as $task) { 193 $task->execute_after_restore(); 194 } 195 } 196 } 197 198 /* 199 * Exception class used by all the @restore_plan stuff 200 */ 201 class restore_plan_exception extends base_plan_exception { 202 203 public function __construct($errorcode, $a=NULL, $debuginfo=null) { 204 parent::__construct($errorcode, $a, $debuginfo); 205 } 206 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |