|
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/backup_root_task.class.php'); 00028 require_once($CFG->dirroot . '/backup/moodle2/backup_activity_task.class.php'); 00029 require_once($CFG->dirroot . '/backup/moodle2/backup_section_task.class.php'); 00030 require_once($CFG->dirroot . '/backup/moodle2/backup_course_task.class.php'); 00031 require_once($CFG->dirroot . '/backup/moodle2/backup_final_task.class.php'); 00032 require_once($CFG->dirroot . '/backup/moodle2/backup_block_task.class.php'); 00033 require_once($CFG->dirroot . '/backup/moodle2/backup_default_block_task.class.php'); 00034 require_once($CFG->dirroot . '/backup/moodle2/backup_xml_transformer.class.php'); 00035 require_once($CFG->dirroot . '/backup/moodle2/backup_plugin.class.php'); 00036 require_once($CFG->dirroot . '/backup/moodle2/backup_qtype_plugin.class.php'); 00037 require_once($CFG->dirroot . '/backup/moodle2/backup_gradingform_plugin.class.php'); 00038 require_once($CFG->dirroot . '/backup/moodle2/backup_format_plugin.class.php'); 00039 require_once($CFG->dirroot . '/backup/moodle2/backup_theme_plugin.class.php'); 00040 require_once($CFG->dirroot . '/backup/moodle2/backup_report_plugin.class.php'); 00041 require_once($CFG->dirroot . '/backup/moodle2/backup_coursereport_plugin.class.php'); 00042 require_once($CFG->dirroot . '/backup/moodle2/backup_plagiarism_plugin.class.php'); 00043 require_once($CFG->dirroot . '/backup/moodle2/backup_subplugin.class.php'); 00044 require_once($CFG->dirroot . '/backup/moodle2/backup_settingslib.php'); 00045 require_once($CFG->dirroot . '/backup/moodle2/backup_stepslib.php'); 00046 require_once($CFG->dirroot . '/backup/moodle2/backup_custom_fields.php'); 00047 00048 // Load all the activity tasks for moodle2 format 00049 $mods = get_plugin_list('mod'); 00050 foreach ($mods as $mod => $moddir) { 00051 $taskpath = $moddir . '/backup/moodle2/backup_' . $mod . '_activity_task.class.php'; 00052 if (plugin_supports('mod', $mod, FEATURE_BACKUP_MOODLE2)) { 00053 if (file_exists($taskpath)) { 00054 require_once($taskpath); 00055 } 00056 } 00057 } 00058 00059 // Load all the block tasks for moodle2 format 00060 $blocks = get_plugin_list('block'); 00061 foreach ($blocks as $block => $blockdir) { 00062 $taskpath = $blockdir . '/backup/moodle2/backup_' . $block . '_block_task.class.php'; 00063 if (file_exists($taskpath)) { 00064 require_once($taskpath); 00065 } 00066 } 00067 00074 abstract class backup_plan_builder { 00075 00079 static public function build_plan($controller) { 00080 00081 $plan = $controller->get_plan(); 00082 00083 // Add the root task, responsible for storing global settings 00084 // and some init tasks 00085 $plan->add_task(new backup_root_task('root_task')); 00086 00087 switch ($controller->get_type()) { 00088 case backup::TYPE_1ACTIVITY: 00089 self::build_activity_plan($controller, $controller->get_id()); 00090 break; 00091 case backup::TYPE_1SECTION: 00092 self::build_section_plan($controller, $controller->get_id()); 00093 break; 00094 case backup::TYPE_1COURSE: 00095 self::build_course_plan($controller, $controller->get_id()); 00096 break; 00097 } 00098 00099 // Add the final task, responsible for outputting 00100 // all the global xml files (groups, users, 00101 // gradebook, questions, roles, files...) and 00102 // the main moodle_backup.xml file 00103 // and perform other various final actions. 00104 $plan->add_task(new backup_final_task('final_task')); 00105 } 00106 00107 00111 static public function supported_backup_types() { 00112 return array(backup::TYPE_1COURSE, backup::TYPE_1SECTION, backup::TYPE_1ACTIVITY); 00113 } 00114 00115 // Protected API starts here 00116 00120 static protected function build_activity_plan($controller, $id) { 00121 00122 $plan = $controller->get_plan(); 00123 00124 // Add the activity task, responsible for outputting 00125 // all the module related information 00126 try { 00127 $plan->add_task(backup_factory::get_backup_activity_task($controller->get_format(), $id)); 00128 00129 // For the given activity, add as many block tasks as necessary 00130 $blockids = backup_plan_dbops::get_blockids_from_moduleid($id); 00131 foreach ($blockids as $blockid) { 00132 try { 00133 $plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid, $id)); 00134 } catch (backup_task_exception $e) { 00135 $a = stdClass(); 00136 $a->mid = $id; 00137 $a->bid = $blockid; 00138 $controller->log(get_string('error_block_for_module_not_found', 'backup', $a), backup::LOG_WARNING); 00139 } 00140 } 00141 } catch (backup_task_exception $e) { 00142 $controller->log(get_string('error_course_module_not_found', 'backup', $id), backup::LOG_WARNING); 00143 } 00144 } 00145 00149 static protected function build_section_plan($controller, $id) { 00150 00151 $plan = $controller->get_plan(); 00152 00153 // Add the section task, responsible for outputting 00154 // all the section related information 00155 $plan->add_task(backup_factory::get_backup_section_task($controller->get_format(), $id)); 00156 00157 // For the given section, add as many activity tasks as necessary 00158 $coursemodules = backup_plan_dbops::get_modules_from_sectionid($id); 00159 foreach ($coursemodules as $coursemodule) { 00160 if (plugin_supports('mod', $coursemodule->modname, FEATURE_BACKUP_MOODLE2)) { // Check we support the format 00161 self::build_activity_plan($controller, $coursemodule->id); 00162 } else { 00163 // TODO: Debug information about module not supported 00164 } 00165 } 00166 } 00167 00171 static protected function build_course_plan($controller, $id) { 00172 00173 $plan = $controller->get_plan(); 00174 00175 // Add the course task, responsible for outputting 00176 // all the course related information 00177 $plan->add_task(backup_factory::get_backup_course_task($controller->get_format(), $id)); 00178 00179 // For the given course, add as many section tasks as necessary 00180 $sections = backup_plan_dbops::get_sections_from_courseid($id); 00181 foreach ($sections as $section) { 00182 self::build_section_plan($controller, $section); 00183 } 00184 00185 // For the given course, add as many block tasks as necessary 00186 $blockids = backup_plan_dbops::get_blockids_from_courseid($id); 00187 foreach ($blockids as $blockid) { 00188 $plan->add_task(backup_factory::get_backup_block_task($controller->get_format(), $blockid)); 00189 } 00190 } 00191 }