MDL-17491 fixed notice typo
[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
785d6603
SH
32 /**
33 *
34 * @var restore_controller
35 */
b5d45a04
EL
36 protected $controller; // The restore controller building/executing this plan
37 protected $basepath; // Fullpath to dir where backup is available
482aac65 38 protected $preloaded; // When executing the plan, do we have preloaded (from checks) info
03307846 39 protected $decoder; // restore_decode_processor in charge of decoding all the interlinks
b5d45a04
EL
40
41 /**
42 * Constructor - instantiates one object of this class
43 */
44 public function __construct($controller) {
45 global $CFG;
46
47 if (! $controller instanceof restore_controller) {
48 throw new restore_plan_exception('wrong_restore_controller_specified');
49 }
50 $this->controller = $controller;
c9d8234a 51 $this->basepath = $CFG->dataroot . '/temp/backup/' . $controller->get_tempdir();
482aac65 52 $this->preloaded = false;
03307846 53 $this->decoder = new restore_decode_processor($this->get_restoreid(), $this->get_info()->original_wwwroot, $CFG->wwwroot);
b5d45a04
EL
54 parent::__construct('restore_plan');
55 }
56
57 public function build() {
58 restore_plan_builder::build_plan($this->controller); // We are moodle2 always, go straight to builder
03307846 59 restore_decode_processor::register_link_decoders($this->decoder); // Add decoder contents and rules
b5d45a04
EL
60 $this->built = true;
61 }
62
63 public function get_restoreid() {
64 return $this->controller->get_restoreid();
65 }
66
67 public function get_courseid() {
68 return $this->controller->get_courseid();
69 }
70
71 public function get_basepath() {
72 return $this->basepath;
73 }
74
75 public function get_logger() {
76 return $this->controller->get_logger();
77 }
78
c9d8234a
EL
79 public function get_info() {
80 return $this->controller->get_info();
81 }
82
a4e13312
EL
83 public function get_target() {
84 return $this->controller->get_target();
85 }
86
482aac65
EL
87 public function get_userid() {
88 return $this->controller->get_userid();
89 }
90
03307846
EL
91 public function get_decoder() {
92 return $this->decoder;
93 }
94
482aac65
EL
95 public function is_samesite() {
96 return $this->controller->is_samesite();
97 }
98
99 public function set_preloaded_information() {
100 $this->preloaded = true;
101 }
102
103 public function get_preloaded_information() {
104 return $this->preloaded;
105 }
106
b1eaf633
EL
107 public function get_tempdir() {
108 return $this->controller->get_tempdir();
109 }
110
b5d45a04
EL
111 public function log($message, $level, $a = null, $depth = null, $display = false) {
112 backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
113 }
114
115 /**
116 * Function responsible for executing the tasks of any plan
117 */
118 public function execute() {
119 if ($this->controller->get_status() != backup::STATUS_AWAITING) {
120 throw new restore_controller_exception('restore_not_executable_awaiting_required', $this->controller->get_status());
121 }
122 $this->controller->set_status(backup::STATUS_EXECUTING);
123 parent::execute();
124 $this->controller->set_status(backup::STATUS_FINISHED_OK);
125 }
126}
127
128/*
129 * Exception class used by all the @restore_plan stuff
130 */
131class restore_plan_exception extends base_plan_exception {
132
133 public function __construct($errorcode, $a=NULL, $debuginfo=null) {
134 parent::__construct($errorcode, $a, $debuginfo);
135 }
136}