wiki MDL-24130 fixed editing errors when editing is turned on when creating a first...
[moodle.git] / backup / util / plan / backup_plan.class.php
CommitLineData
69dd0c8c
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 backup plan
27 *
28 * TODO: Finish phpdocs
29 */
30class backup_plan extends base_plan implements loggable {
31
32 protected $controller; // The backup controller building/executing this plan
33 protected $basepath; // Fullpath to dir where backup is created
bd39b6f2 34 protected $excludingdactivities;
69dd0c8c
EL
35
36 /**
37 * Constructor - instantiates one object of this class
38 */
39 public function __construct($controller) {
40 global $CFG;
41
42 if (! $controller instanceof backup_controller) {
43 throw new backup_plan_exception('wrong_backup_controller_specified');
44 }
45 $this->controller = $controller;
46 $this->basepath = $CFG->dataroot . '/temp/backup/' . $controller->get_backupid();
47 parent::__construct('backup_plan');
48 }
49
50 public function build() {
51 backup_factory::build_plan($this->controller); // Dispatch to correct format
52 $this->built = true;
53 }
54
55 public function get_backupid() {
56 return $this->controller->get_backupid();
57 }
58
59 public function get_courseid() {
60 return $this->controller->get_courseid();
61 }
62
63 public function get_basepath() {
64 return $this->basepath;
65 }
66
67 public function get_logger() {
68 return $this->controller->get_logger();
69 }
70
bd39b6f2
SH
71 public function is_excluding_activities() {
72 return $this->excludingdactivities;
73 }
74
75 public function set_excluding_activities() {
76 $this->excludingdactivities = true;
77 }
78
69dd0c8c
EL
79 public function log($message, $level, $a = null, $depth = null, $display = false) {
80 backup_helper::log($message, $level, $a, $depth, $display, $this->get_logger());
81 }
82
83 /**
84 * Function responsible for executing the tasks of any plan
85 */
86 public function execute() {
87 if ($this->controller->get_status() != backup::STATUS_AWAITING) {
88 throw new backup_controller_exception('backup_not_executable_awaiting_required', $this->controller->get_status());
89 }
90 $this->controller->set_status(backup::STATUS_EXECUTING);
91 parent::execute();
92 $this->controller->set_status(backup::STATUS_FINISHED_OK);
93 }
94}
95
96/*
97 * Exception class used by all the @backup_plan stuff
98 */
99class backup_plan_exception extends base_plan_exception {
100
101 public function __construct($errorcode, $a=NULL, $debuginfo=null) {
102 parent::__construct($errorcode, $a, $debuginfo);
103 }
104}