|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00025 defined('MOODLE_INTERNAL') || die(); 00026 00027 require_once($CFG->dirroot . '/backup/moodle2/restore_root_task.class.php'); 00028 require_once($CFG->dirroot . '/backup/moodle2/restore_course_task.class.php'); 00029 require_once($CFG->dirroot . '/backup/moodle2/restore_section_task.class.php'); 00030 require_once($CFG->dirroot . '/backup/moodle2/restore_activity_task.class.php'); 00031 require_once($CFG->dirroot . '/backup/moodle2/restore_final_task.class.php'); 00032 require_once($CFG->dirroot . '/backup/moodle2/restore_block_task.class.php'); 00033 require_once($CFG->dirroot . '/backup/moodle2/restore_default_block_task.class.php'); 00034 require_once($CFG->dirroot . '/backup/moodle2/restore_plugin.class.php'); 00035 require_once($CFG->dirroot . '/backup/moodle2/restore_qtype_plugin.class.php'); 00036 require_once($CFG->dirroot . '/backup/moodle2/restore_format_plugin.class.php'); 00037 require_once($CFG->dirroot . '/backup/moodle2/restore_theme_plugin.class.php'); 00038 require_once($CFG->dirroot . '/backup/moodle2/restore_report_plugin.class.php'); 00039 require_once($CFG->dirroot . '/backup/moodle2/restore_coursereport_plugin.class.php'); 00040 require_once($CFG->dirroot . '/backup/moodle2/restore_plagiarism_plugin.class.php'); 00041 require_once($CFG->dirroot . '/backup/moodle2/restore_gradingform_plugin.class.php'); 00042 require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php'); 00043 require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php'); 00044 require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php'); 00045 require_once($CFG->dirroot . '/backup/moodle2/backup_theme_plugin.class.php'); 00046 require_once($CFG->dirroot . '/backup/moodle2/backup_report_plugin.class.php'); 00047 require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php'); 00048 require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php'); 00049 require_once($CFG->dirroot . '/backup/moodle2/backup_gradingform_plugin.class.php'); 00050 require_once($CFG->dirroot . '/backup/moodle2/restore_subplugin.class.php'); 00051 require_once($CFG->dirroot . '/backup/moodle2/restore_settingslib.php'); 00052 require_once($CFG->dirroot . '/backup/moodle2/restore_stepslib.php'); 00053 00054 // Load all the activity tasks for moodle2 format 00055 $mods = get_plugin_list('mod'); 00056 foreach ($mods as $mod => $moddir) { 00057 $taskpath = $moddir . '/backup/moodle2/restore_' . $mod . '_activity_task.class.php'; 00058 if (plugin_supports('mod', $mod, FEATURE_BACKUP_MOODLE2)) { 00059 if (file_exists($taskpath)) { 00060 require_once($taskpath); 00061 } 00062 } 00063 } 00064 00065 // Load all the block tasks for moodle2 format 00066 $blocks = get_plugin_list('block'); 00067 foreach ($blocks as $block => $blockdir) { 00068 $taskpath = $blockdir . '/backup/moodle2/restore_' . $block . '_block_task.class.php'; 00069 if (file_exists($taskpath)) { 00070 require_once($taskpath); 00071 } 00072 } 00073 00080 abstract class restore_plan_builder { 00081 00085 static public function build_plan($controller) { 00086 00087 $plan = $controller->get_plan(); 00088 00089 // Add the root task, responsible for 00090 // preparing everything, creating the 00091 // needed structures (users, roles), 00092 // preloading information to temp table 00093 // and other init tasks 00094 $plan->add_task(new restore_root_task('root_task')); 00095 00096 switch ($controller->get_type()) { 00097 case backup::TYPE_1ACTIVITY: 00098 self::build_activity_plan($controller, key($controller->get_info()->activities)); 00099 break; 00100 case backup::TYPE_1SECTION: 00101 self::build_section_plan($controller, key($controller->get_info()->sections)); 00102 break; 00103 case backup::TYPE_1COURSE: 00104 self::build_course_plan($controller, $controller->get_courseid()); 00105 break; 00106 } 00107 00108 // Add the final task, responsible for closing 00109 // all the pending bits (remapings, inter-links 00110 // conversion...) 00111 // and perform other various final actions. 00112 $plan->add_task(new restore_final_task('final_task')); 00113 } 00114 00115 00116 // Protected API starts here 00117 00121 static protected function build_activity_plan($controller, $activityid) { 00122 00123 $plan = $controller->get_plan(); 00124 $info = $controller->get_info(); 00125 $infoactivity = $info->activities[$activityid]; 00126 00127 // Add the activity task, responsible for restoring 00128 // all the module related information. So it conditionally 00129 // as far as the module can be missing on restore 00130 if ($task = restore_factory::get_restore_activity_task($infoactivity)) { // can be missing 00131 $plan->add_task($task); 00132 00133 // For the given activity path, add as many block tasks as necessary 00134 // TODO: Add blocks, we need to introspect xml here 00135 $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); 00136 foreach ($blocks as $basepath => $name) { 00137 if ($task = restore_factory::get_restore_block_task($name, $basepath)) { 00138 $plan->add_task($task); 00139 } else { 00140 // TODO: Debug information about block not supported 00141 } 00142 } 00143 } else { // Activity is missing in target site, inform plan about that 00144 $plan->set_missing_modules(); 00145 } 00146 00147 } 00148 00152 static protected function build_section_plan($controller, $sectionid) { 00153 00154 $plan = $controller->get_plan(); 00155 $info = $controller->get_info(); 00156 $infosection = $info->sections[$sectionid]; 00157 00158 // Add the section task, responsible for restoring 00159 // all the section related information 00160 $plan->add_task(restore_factory::get_restore_section_task($infosection)); 00161 // For the given section, add as many activity tasks as necessary 00162 foreach ($info->activities as $activityid => $activity) { 00163 if ($activity->sectionid != $infosection->sectionid) { 00164 continue; 00165 } 00166 if (plugin_supports('mod', $activity->modulename, FEATURE_BACKUP_MOODLE2)) { // Check we support the format 00167 self::build_activity_plan($controller, $activityid); 00168 } else { 00169 // TODO: Debug information about module not supported 00170 } 00171 } 00172 } 00173 00177 static protected function build_course_plan($controller, $courseid) { 00178 00179 $plan = $controller->get_plan(); 00180 $info = $controller->get_info(); 00181 00182 // Add the course task, responsible for restoring 00183 // all the course related information 00184 $task = restore_factory::get_restore_course_task($info->course, $courseid); 00185 $plan->add_task($task); 00186 00187 // For the given course path, add as many block tasks as necessary 00188 // TODO: Add blocks, we need to introspect xml here 00189 $blocks = backup_general_helper::get_blocks_from_path($task->get_taskbasepath()); 00190 foreach ($blocks as $basepath => $name) { 00191 if ($task = restore_factory::get_restore_block_task($name, $basepath)) { 00192 $plan->add_task($task); 00193 } else { 00194 // TODO: Debug information about block not supported 00195 } 00196 } 00197 00198 // For the given course, add as many section tasks as necessary 00199 foreach ($info->sections as $sectionid => $section) { 00200 self::build_section_plan($controller, $sectionid); 00201 } 00202 } 00203 }