[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
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 * Defines restore_plan_builder class 20 * 21 * @package core_backup 22 * @subpackage moodle2 23 * @category backup 24 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 require_once($CFG->dirroot . '/backup/moodle2/restore_root_task.class.php'); 31 require_once($CFG->dirroot . '/backup/moodle2/restore_course_task.class.php'); 32 require_once($CFG->dirroot . '/backup/moodle2/restore_section_task.class.php'); 33 require_once($CFG->dirroot . '/backup/moodle2/restore_activity_task.class.php'); 34 require_once($CFG->dirroot . '/backup/moodle2/restore_final_task.class.php'); 35 require_once($CFG->dirroot . '/backup/moodle2/restore_block_task.class.php'); 36 require_once($CFG->dirroot . '/backup/moodle2/restore_default_block_task.class.php'); 37 require_once($CFG->dirroot . '/backup/moodle2/restore_plugin.class.php'); 38 require_once($CFG->dirroot . '/backup/moodle2/restore_qtype_plugin.class.php'); 39 require_once($CFG->dirroot . '/backup/moodle2/restore_format_plugin.class.php'); 40 require_once($CFG->dirroot . '/backup/moodle2/restore_local_plugin.class.php'); 41 require_once($CFG->dirroot . '/backup/moodle2/restore_theme_plugin.class.php'); 42 require_once($CFG->dirroot . '/backup/moodle2/restore_report_plugin.class.php'); 43 require_once($CFG->dirroot . '/backup/moodle2/restore_coursereport_plugin.class.php'); 44 require_once($CFG->dirroot . '/backup/moodle2/restore_plagiarism_plugin.class.php'); 45 require_once($CFG->dirroot . '/backup/moodle2/restore_gradingform_plugin.class.php'); 46 require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php'); 47 require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php'); 48 require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php'); 49 require_once($CFG->dirroot . '/backup/moodle2/backup_local_plugin.class.php'); 50 require_once($CFG->dirroot . '/backup/moodle2/backup_theme_plugin.class.php'); 51 require_once($CFG->dirroot . '/backup/moodle2/backup_report_plugin.class.php'); 52 require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php'); 53 require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php'); 54 require_once($CFG->dirroot . '/backup/moodle2/backup_gradingform_plugin.class.php'); 55 require_once($CFG->dirroot . '/backup/moodle2/restore_subplugin.class.php'); 56 require_once($CFG->dirroot . '/backup/moodle2/restore_settingslib.php'); 57 require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php'); 58 59 // Load all the activity tasks for moodle2 format 60 $mods = core_component::get_plugin_list('mod'); 61 foreach ($mods as $mod => $moddir) { 62 $taskpath = $moddir . '/backup/moodle2/restore_' . $mod . '_activity_task.class.php'; 63 if (plugin_supports('mod', $mod, FEATURE_BACKUP_MOODLE2)) { 64 if (file_exists($taskpath)) { 65 require_once($taskpath); 66 } 67 } 68 } 69 70 // Load all the block tasks for moodle2 format 71 $blocks = core_component::get_plugin_list('block'); 72 foreach ($blocks as $block => $blockdir) { 73 $taskpath = $blockdir . '/backup/moodle2/restore_' . $block . '_block_task.class.php'; 74 if (file_exists($taskpath)) { 75 require_once($taskpath); 76 } 77 } 78 79 /** 80 * Abstract class defining the static method in charge of building the whole 81 * restore plan, based in @restore_controller preferences. 82 * 83 * TODO: Finish phpdocs 84 */ 85 abstract class restore_plan_builder { 86 87 /** 88 * Dispatches, based on type to specialised builders 89 */ 90 static public function build_plan($controller) { 91 92 $plan = $controller->get_plan(); 93 94 // Add the root task, responsible for 95 // preparing everything, creating the 96 // needed structures (users, roles), 97 // preloading information to temp table 98 // and other init tasks 99 $plan->add_task(new restore_root_task('root_task')); 100 $controller->get_progress()->progress(); 101 102 switch ($controller->get_type()) { 103 case backup::TYPE_1ACTIVITY: 104 self::build_activity_plan($controller, key($controller->get_info()->activities)); 105 break; 106 case backup::TYPE_1SECTION: 107 self::build_section_plan($controller, key($controller->get_info()->sections)); 108 break; 109 case backup::TYPE_1COURSE: 110 self::build_course_plan($controller, $controller->get_courseid()); 111 break; 112 } 113 114 // Add the final task, responsible for closing 115 // all the pending bits (remapings, inter-links 116 // conversion...) 117 // and perform other various final actions. 118 $plan->add_task(new restore_final_task('final_task')); 119 $controller->get_progress()->progress(); 120 } 121 122 123 // Protected API starts here 124 125 /** 126 * Restore one 1-activity backup 127 */ 128 static protected function build_activity_plan($controller, $activityid) { 129 130 $plan = $controller->get_plan(); 131 $info = $controller->get_info(); 132 $infoactivity = $info->activities[$activityid]; 133 134 // Add the activity task, responsible for restoring 135 // all the module related information. So it conditionally 136 // as far as the module can be missing on restore 137 if ($task = restore_factory::get_restore_activity_task($infoactivity)) { // can be missing 138 $plan->add_task($task); 139 $controller->get_progress()->progress(); 140 141 // For the given activity path, add as many block tasks as necessary 142 // TODO: Add blocks, we need to introspect xml here 143 $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); 144 foreach ($blocks as $basepath => $name) { 145 if ($task = restore_factory::get_restore_block_task($name, $basepath)) { 146 $plan->add_task($task); 147 $controller->get_progress()->progress(); 148 } else { 149 // TODO: Debug information about block not supported 150 } 151 } 152 } else { // Activity is missing in target site, inform plan about that 153 $plan->set_missing_modules(); 154 } 155 156 } 157 158 /** 159 * Restore one 1-section backup 160 */ 161 static protected function build_section_plan($controller, $sectionid) { 162 163 $plan = $controller->get_plan(); 164 $info = $controller->get_info(); 165 $infosection = $info->sections[$sectionid]; 166 167 // Add the section task, responsible for restoring 168 // all the section related information 169 $plan->add_task(restore_factory::get_restore_section_task($infosection)); 170 $controller->get_progress()->progress(); 171 // For the given section, add as many activity tasks as necessary 172 foreach ($info->activities as $activityid => $activity) { 173 if ($activity->sectionid != $infosection->sectionid) { 174 continue; 175 } 176 if (plugin_supports('mod', $activity->modulename, FEATURE_BACKUP_MOODLE2)) { // Check we support the format 177 self::build_activity_plan($controller, $activityid); 178 } else { 179 // TODO: Debug information about module not supported 180 } 181 } 182 } 183 184 /** 185 * Restore one 1-course backup 186 */ 187 static protected function build_course_plan($controller, $courseid) { 188 189 $plan = $controller->get_plan(); 190 $info = $controller->get_info(); 191 192 // Add the course task, responsible for restoring 193 // all the course related information 194 $task = restore_factory::get_restore_course_task($info->course, $courseid); 195 $plan->add_task($task); 196 $controller->get_progress()->progress(); 197 198 // For the given course path, add as many block tasks as necessary 199 // TODO: Add blocks, we need to introspect xml here 200 $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); 201 foreach ($blocks as $basepath => $name) { 202 if ($task = restore_factory::get_restore_block_task($name, $basepath)) { 203 $plan->add_task($task); 204 $controller->get_progress()->progress(); 205 } else { 206 // TODO: Debug information about block not supported 207 } 208 } 209 210 // For the given course, add as many section tasks as necessary 211 foreach ($info->sections as $sectionid => $section) { 212 self::build_section_plan($controller, $sectionid); 213 } 214 } 215 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |