MDL-21432 backup - all sort of restore tasks
[moodle.git] / backup / util / plan / restore_plan.class.php
CommitLineData
b5d45a04
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 * Implementable class defining the needed stuf for one restore plan
27 *
28 * TODO: Finish phpdocs
29 */
30class restore_plan extends base_plan implements loggable {
31
32 protected $controller; // The restore controller building/executing this plan
33 protected $basepath; // Fullpath to dir where backup is available
34
35 /**
36 * Constructor - instantiates one object of this class
37 */
38 public function __construct($controller) {
39 global $CFG;
40
41 if (! $controller instanceof restore_controller) {
42 throw new restore_plan_exception('wrong_restore_controller_specified');
43 }
44 $this->controller = $controller;
45 $this->basepath = $CFG->dataroot . '/temp/backup/' . $controller->get_restoreid();
46 parent::__construct('restore_plan');
47 }
48
49 public function build() {
50 restore_plan_builder::build_plan($this->controller); // We are moodle2 always, go straight to builder
51 $this->built = true;
52 }
53
54 public function get_restoreid() {
55 return $this->controller->get_restoreid();
56 }
57
58 public function get_courseid() {
59 return $this->controller->get_courseid();
60 }
61
62 public function get_basepath() {
63 return $this->basepath;
64 }
65
66 public function get_logger() {
67 return $this->controller->get_logger();
68 }
69
70 public function log($message, $level, $a = null, $depth = null, $display = false) {
71 backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
72 }
73
74 /**
75 * Function responsible for executing the tasks of any plan
76 */
77 public function execute() {
78 if ($this->controller->get_status() != backup::STATUS_AWAITING) {
79 throw new restore_controller_exception('restore_not_executable_awaiting_required', $this->controller->get_status());
80 }
81 $this->controller->set_status(backup::STATUS_EXECUTING);
82 parent::execute();
83 $this->controller->set_status(backup::STATUS_FINISHED_OK);
84 }
85}
86
87/*
88 * Exception class used by all the @restore_plan stuff
89 */
90class restore_plan_exception extends base_plan_exception {
91
92 public function __construct($errorcode, $a=NULL, $debuginfo=null) {
93 parent::__construct($errorcode, $a, $debuginfo);
94 }
95}