docs spellchecker fixes
[moodle.git] / backup / moodle2 / restore_plan_builder.class.php
CommitLineData
c9d8234a
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
25require_once($CFG->dirroot . '/backup/moodle2/restore_root_task.class.php');
26require_once($CFG->dirroot . '/backup/moodle2/restore_course_task.class.php');
27require_once($CFG->dirroot . '/backup/moodle2/restore_section_task.class.php');
28require_once($CFG->dirroot . '/backup/moodle2/restore_activity_task.class.php');
29require_once($CFG->dirroot . '/backup/moodle2/restore_final_task.class.php');
30//require_once($CFG->dirroot . '/backup/moodle2/restore_block_task.class.php');
31//require_once($CFG->dirroot . '/backup/moodle2/restore_default_block_task.class.php');
32//require_once($CFG->dirroot . '/backup/moodle2/restore_subplugin.class.php');
33require_once($CFG->dirroot . '/backup/moodle2/restore_settingslib.php');
34//require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php');
35
36// Load all the activity tasks for moodle2 format
37$mods = get_plugin_list('mod');
38foreach ($mods as $mod => $moddir) {
39 $taskpath = $moddir . '/backup/moodle2/restore_' . $mod . '_activity_task.class.php';
40 if (plugin_supports('mod', $mod, FEATURE_BACKUP_MOODLE2)) {
41 if (file_exists($taskpath)) {
42 require_once($taskpath);
43 }
44 }
45}
46
47// Load all the block tasks for moodle2 format
48$blocks = get_plugin_list('block');
49foreach ($blocks as $block => $blockdir) {
50 $taskpath = $blockdir . '/backup/moodle2/restore_' . $block . '_block_task.class.php';
51 if (file_exists($taskpath)) {
52 require_once($taskpath);
53 }
54}
55
56/**
57 * Abstract class defining the static method in charge of building the whole
58 * restore plan, based in @restore_controller preferences.
59 *
60 * TODO: Finish phpdocs
61 */
62abstract class restore_plan_builder {
63
64 /**
65 * Dispatches, based on type to specialised builders
66 */
67 static public function build_plan($controller) {
68
69 $plan = $controller->get_plan();
70
71 // Add the root task, responsible for
72 // preparing everything, creating the
73 // needed structures (users, roles),
74 // preloading information to temp table
75 // and other init tasks
76 $plan->add_task(new restore_root_task('root_task'));
77
78 switch ($controller->get_type()) {
79 case backup::TYPE_1ACTIVITY:
80 self::build_activity_plan($controller, $controller->get_courseid());
81 break;
82 case backup::TYPE_1SECTION:
83 self::build_section_plan($controller, $controller->get_courseid());
84 break;
85 case backup::TYPE_1COURSE:
86 self::build_course_plan($controller, $controller->get_courseid());
87 break;
88 }
89
90 // Add the final task, responsible for closing
91 // all the pending bits (remapings, inter-links
92 // conversion...)
93 // and perform other various final actions.
94 $plan->add_task(new restore_final_task('final_task'));
95 }
96
97
98// Protected API starts here
99
100 /**
101 * Restore one 1-activity backup
102 */
103 static protected function build_activity_plan($controller, $activityid) {
104
105 $plan = $controller->get_plan();
106 $info = $controller->get_info();
107 $infoactivity = $info->activities[$activityid];
108
109 // Add the activity task, responsible for restoring
110 // all the module related information. So it conditionally
111 // as far as the module can be missing on restore
112 if ($task = restore_factory::get_restore_activity_task($infoactivity)) { // can be missing
113 $plan->add_task($task);
114 }
115
116 // For the given activity, add as many block tasks as necessary
117 // TODO: Add blocks, we need to introspect xml here
118 //$blockids = backup_plan_dbops::get_blockids_from_moduleid($id);
119 //foreach ($blockids as $blockid) {
120 // $plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid, $id));
121 //}
122 }
123
124 /**
125 * Restore one 1-section backup
126 */
127 static protected function build_section_plan($controller, $sectionid) {
128
129 $plan = $controller->get_plan();
130 $info = $controller->get_info();
131 $infosection = $info->sections[$sectionid];
132
133 // Add the section task, responsible for restoring
134 // all the section related information
135 $plan->add_task(restore_factory::get_restore_section_task($infosection));
136 // For the given section, add as many activity tasks as necessary
137 foreach ($info->activities as $activityid => $activity) {
138 if ($activity->sectionid != $infosection->sectionid) {
139 continue;
140 }
141 if (plugin_supports('mod', $activity->modulename, FEATURE_BACKUP_MOODLE2)) { // Check we support the format
142 self::build_activity_plan($controller, $activityid);
143 } else {
144 // TODO: Debug information about module not supported
145 }
146 }
147 }
148
149 /**
150 * Restore one 1-course backup
151 */
152 static protected function build_course_plan($controller, $courseid) {
153
154 $plan = $controller->get_plan();
155 $info = $controller->get_info();
156
157 // Add the course task, responsible for restoring
158 // all the course related information
159 $plan->add_task(restore_factory::get_restore_course_task($info->course, $courseid));
160
161 // For the given course, add as many section tasks as necessary
162 foreach ($info->sections as $sectionid => $section) {
163 self::build_section_plan($controller, $sectionid);
164 }
165
166 // For the given course, add as many block tasks as necessary
167 // TODO: Add blocks, we need to introspect xml here
168 //$blockids = backup_plan_dbops::get_blockids_from_courseid($id);
169 //foreach ($blockids as $blockid) {
170 // $plan->add_task(restore_factory::get_restore_block_task($controller->get_format(), $blockid));
171 //}
172 }
173}