MDL-29793 Advanced grading forms attached to activity modules are included in the...
[moodle.git] / backup / moodle2 / backup_plan_builder.class.php
CommitLineData
77547b46
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-moodle2
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
ca2ba065
EL
25defined('MOODLE_INTERNAL') || die();
26
77547b46
EL
27require_once($CFG->dirroot . '/backup/moodle2/backup_root_task.class.php');
28require_once($CFG->dirroot . '/backup/moodle2/backup_activity_task.class.php');
29require_once($CFG->dirroot . '/backup/moodle2/backup_section_task.class.php');
30require_once($CFG->dirroot . '/backup/moodle2/backup_course_task.class.php');
31require_once($CFG->dirroot . '/backup/moodle2/backup_final_task.class.php');
32require_once($CFG->dirroot . '/backup/moodle2/backup_block_task.class.php');
33require_once($CFG->dirroot . '/backup/moodle2/backup_default_block_task.class.php');
34require_once($CFG->dirroot . '/backup/moodle2/backup_xml_transformer.class.php');
767cb7f0
EL
35require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php');
36require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php');
9b553d47 37require_once($CFG->dirroot . '/backup/moodle2/backup_gradingform_plugin.class.php');
4fda584f 38require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php');
89213d00 39require_once($CFG->dirroot . '/backup/moodle2/backup_theme_plugin.class.php');
5e0dae12 40require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php');
571ae252 41require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php');
060df4c8 42require_once($CFG->dirroot . '/backup/moodle2/backup_subplugin.class.php');
77547b46
EL
43require_once($CFG->dirroot . '/backup/moodle2/backup_settingslib.php');
44require_once($CFG->dirroot . '/backup/moodle2/backup_stepslib.php');
45require_once($CFG->dirroot . '/backup/moodle2/backup_custom_fields.php');
46
47// Load all the activity tasks for moodle2 format
48$mods = get_plugin_list('mod');
49foreach ($mods as $mod => $moddir) {
ca2ba065 50 $taskpath = $moddir . '/backup/moodle2/backup_' . $mod . '_activity_task.class.php';
77547b46 51 if (plugin_supports('mod', $mod, FEATURE_BACKUP_MOODLE2)) {
ca2ba065
EL
52 if (file_exists($taskpath)) {
53 require_once($taskpath);
54 }
77547b46
EL
55 }
56}
57
58// Load all the block tasks for moodle2 format
59$blocks = get_plugin_list('block');
60foreach ($blocks as $block => $blockdir) {
61 $taskpath = $blockdir . '/backup/moodle2/backup_' . $block . '_block_task.class.php';
62 if (file_exists($taskpath)) {
63 require_once($taskpath);
64 }
65}
66
67/**
68 * Abstract class defining the static method in charge of building the whole
69 * backup plan, based in @backup_controller preferences.
70 *
71 * TODO: Finish phpdocs
72 */
73abstract class backup_plan_builder {
74
75 /**
76 * Dispatches, based on type to specialised builders
77 */
78 static public function build_plan($controller) {
79
80 $plan = $controller->get_plan();
81
82 // Add the root task, responsible for storing global settings
83 // and some init tasks
84 $plan->add_task(new backup_root_task('root_task'));
85
86 switch ($controller->get_type()) {
87 case backup::TYPE_1ACTIVITY:
88 self::build_activity_plan($controller, $controller->get_id());
89 break;
90 case backup::TYPE_1SECTION:
91 self::build_section_plan($controller, $controller->get_id());
92 break;
93 case backup::TYPE_1COURSE:
94 self::build_course_plan($controller, $controller->get_id());
95 break;
96 }
97
39b5371c 98 // Add the final task, responsible for outputting
77547b46
EL
99 // all the global xml files (groups, users,
100 // gradebook, questions, roles, files...) and
101 // the main moodle_backup.xml file
102 // and perform other various final actions.
103 $plan->add_task(new backup_final_task('final_task'));
104 }
105
106
107 /**
108 * Return one array of supported backup types
109 */
110 static public function supported_backup_types() {
111 return array(backup::TYPE_1COURSE, backup::TYPE_1SECTION, backup::TYPE_1ACTIVITY);
112 }
113
114// Protected API starts here
115
116 /**
117 * Build one 1-activity backup
118 */
119 static protected function build_activity_plan($controller, $id) {
120
121 $plan = $controller->get_plan();
122
39b5371c 123 // Add the activity task, responsible for outputting
77547b46
EL
124 // all the module related information
125 $plan->add_task(backup_factory::get_backup_activity_task($controller->get_format(), $id));
126
127 // For the given activity, add as many block tasks as necessary
128 $blockids = backup_plan_dbops::get_blockids_from_moduleid($id);
129 foreach ($blockids as $blockid) {
130 $plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid, $id));
131 }
132 }
133
134 /**
135 * Build one 1-section backup
136 */
137 static protected function build_section_plan($controller, $id) {
138
139 $plan = $controller->get_plan();
140
39b5371c 141 // Add the section task, responsible for outputting
77547b46
EL
142 // all the section related information
143 $plan->add_task(backup_factory::get_backup_section_task($controller->get_format(), $id));
144
145 // For the given section, add as many activity tasks as necessary
146 $coursemodules = backup_plan_dbops::get_modules_from_sectionid($id);
147 foreach ($coursemodules as $coursemodule) {
57a535cd 148 if (plugin_supports('mod', $coursemodule->modname, FEATURE_BACKUP_MOODLE2)) { // Check we support the format
77547b46
EL
149 self::build_activity_plan($controller, $coursemodule->id);
150 } else {
151 // TODO: Debug information about module not supported
152 }
153 }
154 }
155
156 /**
157 * Build one 1-course backup
158 */
159 static protected function build_course_plan($controller, $id) {
160
161 $plan = $controller->get_plan();
162
39b5371c 163 // Add the course task, responsible for outputting
77547b46
EL
164 // all the course related information
165 $plan->add_task(backup_factory::get_backup_course_task($controller->get_format(), $id));
166
167 // For the given course, add as many section tasks as necessary
168 $sections = backup_plan_dbops::get_sections_from_courseid($id);
169 foreach ($sections as $section) {
170 self::build_section_plan($controller, $section);
171 }
172
173 // For the given course, add as many block tasks as necessary
174 $blockids = backup_plan_dbops::get_blockids_from_courseid($id);
175 foreach ($blockids as $blockid) {
176 $plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid));
177 }
178 }
179}