Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/backup/util/plan/backup_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 backup_plan extends base_plan implements loggable {
00031 
00032     protected $controller; // The backup controller building/executing this plan
00033     protected $basepath;   // Fullpath to dir where backup is created
00034     protected $excludingdactivities;
00035 
00039     public function __construct($controller) {
00040         global $CFG;
00041 
00042         if (! $controller instanceof backup_controller) {
00043             throw new backup_plan_exception('wrong_backup_controller_specified');
00044         }
00045         $this->controller = $controller;
00046         $this->basepath   = $CFG->tempdir . '/backup/' . $controller->get_backupid();
00047         $this->excludingdactivities = false;
00048         parent::__construct('backup_plan');
00049     }
00050 
00054     public function destroy() {
00055         // No need to destroy anything recursively here, direct reset
00056         $this->controller = null;
00057         // Delegate to base plan the rest
00058         parent::destroy();
00059     }
00060 
00061     public function build() {
00062         backup_factory::build_plan($this->controller); // Dispatch to correct format
00063         $this->built = true;
00064     }
00065 
00066     public function get_backupid() {
00067         return $this->controller->get_backupid();
00068     }
00069 
00070     public function get_mode() {
00071         return $this->controller->get_mode();
00072     }
00073 
00074     public function get_courseid() {
00075         return $this->controller->get_courseid();
00076     }
00077 
00078     public function get_basepath() {
00079         return $this->basepath;
00080     }
00081 
00082     public function get_logger() {
00083         return $this->controller->get_logger();
00084     }
00085 
00086     public function is_excluding_activities() {
00087         return $this->excludingdactivities;
00088     }
00089 
00090     public function set_excluding_activities() {
00091         $this->excludingdactivities = true;
00092     }
00093 
00094     public function log($message, $level, $a = null, $depth = null, $display = false) {
00095         backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
00096     }
00097 
00101     public function execute() {
00102         if ($this->controller->get_status() != backup::STATUS_AWAITING) {
00103             throw new backup_controller_exception('backup_not_executable_awaiting_required', $this->controller->get_status());
00104         }
00105         $this->controller->set_status(backup::STATUS_EXECUTING);
00106         parent::execute();
00107         $this->controller->set_status(backup::STATUS_FINISHED_OK);
00108     }
00109 }
00110 
00111 /*
00112  * Exception class used by all the @backup_plan stuff
00113  */
00114 class backup_plan_exception extends base_plan_exception {
00115 
00116     public function __construct($errorcode, $a=NULL, $debuginfo=null) {
00117         parent::__construct($errorcode, $a, $debuginfo);
00118     }
00119 }
 All Data Structures Namespaces Files Functions Variables Enumerations