Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/plan/restore_plan.class.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00030 class restore_plan extends base_plan implements loggable {
00031 
00036     protected $controller; // The restore controller building/executing this plan
00037     protected $basepath;   // Fullpath to dir where backup is available
00038     protected $preloaded;  // When executing the plan, do we have preloaded (from checks) info
00039     protected $decoder;    // restore_decode_processor in charge of decoding all the interlinks
00040     protected $missingmodules; // to flag if restore has detected some missing module
00041     protected $excludingdactivities; // to flag if restore settings are excluding any activity
00042 
00046     public function __construct($controller) {
00047         global $CFG;
00048 
00049         if (! $controller instanceof restore_controller) {
00050             throw new restore_plan_exception('wrong_restore_controller_specified');
00051         }
00052         $this->controller = $controller;
00053         $this->basepath   = $CFG->tempdir . '/backup/' . $controller->get_tempdir();
00054         $this->preloaded  = false;
00055         $this->decoder    = new restore_decode_processor($this->get_restoreid(), $this->get_info()->original_wwwroot, $CFG->wwwroot);
00056         $this->missingmodules = false;
00057         $this->excludingdactivities = false;
00058 
00059         parent::__construct('restore_plan');
00060     }
00061 
00065     public function destroy() {
00066         // No need to destroy anything recursively here, direct reset
00067         $this->controller = null;
00068         // Delegate to base plan the rest
00069         parent::destroy();
00070     }
00071 
00072     public function build() {
00073         restore_plan_builder::build_plan($this->controller); // We are moodle2 always, go straight to builder
00074         $this->built = true;
00075     }
00076 
00077     public function get_restoreid() {
00078         return $this->controller->get_restoreid();
00079     }
00080 
00081     public function get_courseid() {
00082         return $this->controller->get_courseid();
00083     }
00084 
00085     public function get_mode() {
00086         return $this->controller->get_mode();
00087     }
00088 
00089     public function get_basepath() {
00090         return $this->basepath;
00091     }
00092 
00093     public function get_logger() {
00094         return $this->controller->get_logger();
00095     }
00096 
00097     public function get_info() {
00098         return $this->controller->get_info();
00099     }
00100 
00101     public function get_target() {
00102         return $this->controller->get_target();
00103     }
00104 
00105     public function get_userid() {
00106         return $this->controller->get_userid();
00107     }
00108 
00109     public function get_decoder() {
00110         return $this->decoder;
00111     }
00112 
00113     public function is_samesite() {
00114         return $this->controller->is_samesite();
00115     }
00116 
00117     public function is_missing_modules() {
00118         return $this->missingmodules;
00119     }
00120 
00121     public function is_excluding_activities() {
00122         return $this->excludingdactivities;
00123     }
00124 
00125     public function set_preloaded_information() {
00126         $this->preloaded = true;
00127     }
00128 
00129     public function get_preloaded_information() {
00130         return $this->preloaded;
00131     }
00132 
00133     public function get_tempdir() {
00134         return $this->controller->get_tempdir();
00135     }
00136 
00137     public function set_missing_modules() {
00138         $this->missingmodules = true;
00139     }
00140 
00141     public function set_excluding_activities() {
00142         $this->excludingdactivities = true;
00143     }
00144 
00145     public function log($message, $level, $a = null, $depth = null, $display = false) {
00146         backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
00147     }
00148 
00152     public function execute() {
00153         if ($this->controller->get_status() != backup::STATUS_AWAITING) {
00154             throw new restore_controller_exception('restore_not_executable_awaiting_required', $this->controller->get_status());
00155         }
00156         $this->controller->set_status(backup::STATUS_EXECUTING);
00157         parent::execute();
00158         $this->controller->set_status(backup::STATUS_FINISHED_OK);
00159     }
00160 
00164     public function execute_after_restore() {
00165         // Simply iterate over each task in the plan and delegate to them the execution
00166         foreach ($this->tasks as $task) {
00167             $task->execute_after_restore();
00168         }
00169     }
00170 }
00171 
00172 /*
00173  * Exception class used by all the @restore_plan stuff
00174  */
00175 class restore_plan_exception extends base_plan_exception {
00176 
00177     public function __construct($errorcode, $a=NULL, $debuginfo=null) {
00178         parent::__construct($errorcode, $a, $debuginfo);
00179     }
00180 }
 All Data Structures Namespaces Files Functions Variables Enumerations