|
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 00033 abstract class backup_factory { 00034 00035 public static function get_destination_chain($type, $id, $mode, $execution) { 00036 return null; 00037 } 00038 00039 public static function get_logger_chain($interactive, $execution, $backupid) { 00040 global $CFG; 00041 00042 $dfltloglevel = backup::LOG_WARNING; // Default logging level 00043 if (debugging('', DEBUG_DEVELOPER)) { // Debug developer raises default logging level 00044 $dfltloglevel = backup::LOG_DEBUG; 00045 } 00046 00047 $enabledloggers = array(); // Array to store all enabled loggers 00048 00049 // Create error_log_logger, observing $CFG->backup_error_log_logger_level, 00050 // defaulting to $dfltloglevel 00051 $elllevel = isset($CFG->backup_error_log_logger_level) ? $CFG->backup_error_log_logger_level : $dfltloglevel; 00052 $enabledloggers[] = new error_log_logger($elllevel); 00053 00054 // Create output_indented_logger, observing $CFG->backup_output_indented_logger_level and $CFG->debugdisplay, 00055 // defaulting to LOG_ERROR. Only if interactive and inmediate 00056 if ($CFG->debugdisplay && $interactive == backup::INTERACTIVE_YES && $execution == backup::EXECUTION_INMEDIATE) { 00057 $oillevel = isset($CFG->backup_output_indented_logger_level) ? $CFG->backup_output_indented_logger_level : backup::LOG_ERROR; 00058 $enabledloggers[] = new output_indented_logger($oillevel, false, false); 00059 } 00060 00061 // Create file_logger, observing $CFG->backup_file_logger_level 00062 // defaulting to $dfltloglevel 00063 check_dir_exists($CFG->tempdir . '/backup', true, true); // need to ensure that temp/backup already exists 00064 $fllevel = isset($CFG->backup_file_logger_level) ? $CFG->backup_file_logger_level : $dfltloglevel; 00065 $enabledloggers[] = new file_logger($fllevel, true, true, $CFG->tempdir . '/backup/' . $backupid . '.log'); 00066 00067 // Create database_logger, observing $CFG->backup_database_logger_level and defaulting to LOG_WARNING 00068 // and pointing to the backup_logs table 00069 $dllevel = isset($CFG->backup_database_logger_level) ? $CFG->backup_database_logger_level : backup::LOG_WARNING; 00070 $columns = array('backupid' => $backupid); 00071 $enabledloggers[] = new database_logger($dllevel, 'timecreated', 'loglevel', 'message', 'backup_logs', $columns); 00072 00073 // Create extra file_logger, observing $CFG->backup_file_logger_extra and $CFG->backup_file_logger_extra_level 00074 // defaulting to $fllevel (normal file logger) 00075 if (isset($CFG->backup_file_logger_extra)) { 00076 $flelevel = isset($CFG->backup_file_logger_extra_level) ? $CFG->backup_file_logger_extra_level : $fllevel; 00077 $enabledloggers[] = new file_logger($flelevel, true, true, $CFG->backup_file_logger_extra); 00078 } 00079 00080 // Build the chain 00081 $loggers = null; 00082 foreach ($enabledloggers as $currentlogger) { 00083 if ($loggers == null) { 00084 $loggers = $currentlogger; 00085 } else { 00086 $lastlogger->set_next($currentlogger); 00087 } 00088 $lastlogger = $currentlogger; 00089 } 00090 00091 return $loggers; 00092 } 00093 00094 00099 public static function get_backup_activity_task($format, $moduleid) { 00100 global $CFG, $DB; 00101 00102 // Check moduleid exists 00103 if (!$coursemodule = get_coursemodule_from_id(false, $moduleid)) { 00104 throw new backup_task_exception('activity_task_coursemodule_not_found', $moduleid); 00105 } 00106 $classname = 'backup_' . $coursemodule->modname . '_activity_task'; 00107 return new $classname($coursemodule->name, $moduleid); 00108 } 00109 00113 public static function get_backup_block_task($format, $blockid, $moduleid = null) { 00114 global $CFG, $DB; 00115 00116 // Check blockid exists 00117 if (!$block = $DB->get_record('block_instances', array('id' => $blockid))) { 00118 throw new backup_task_exception('block_task_block_instance_not_found', $blockid); 00119 } 00120 00121 // Set default block backup task 00122 $classname = 'backup_default_block_task'; 00123 $testname = 'backup_' . $block->blockname . '_block_task'; 00124 // If the block has custom backup/restore task class (testname), use it 00125 if (class_exists($testname)) { 00126 $classname = $testname; 00127 } 00128 return new $classname($block->blockname, $blockid, $moduleid); 00129 } 00130 00134 public static function get_backup_section_task($format, $sectionid) { 00135 global $DB; 00136 00137 // Check section exists 00138 if (!$section = $DB->get_record('course_sections', array('id' => $sectionid))) { 00139 throw new backup_task_exception('section_task_section_not_found', $sectionid); 00140 } 00141 00142 return new backup_section_task(empty($section->name) ? $section->section : $section->name, $sectionid); 00143 } 00144 00148 public static function get_backup_course_task($format, $courseid) { 00149 global $DB; 00150 00151 // Check course exists 00152 if (!$course = $DB->get_record('course', array('id' => $courseid))) { 00153 throw new backup_task_exception('course_task_course_not_found', $courseid); 00154 } 00155 00156 return new backup_course_task($course->shortname, $courseid); 00157 } 00158 00162 static public function build_plan($controller) { 00163 backup_plan_builder::build_plan($controller); 00164 } 00165 }