|
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 00032 class backup_final_task extends backup_task { 00033 00037 public function build() { 00038 global $CFG; 00039 00040 // Set the backup::VAR_CONTEXTID setting to course context as far as next steps require that 00041 $coursectxid = get_context_instance(CONTEXT_COURSE, $this->get_courseid())->id; 00042 $this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $coursectxid)); 00043 00044 // Set the backup::VAR_COURSEID setting to course, we'll need that in some steps 00045 $courseid = $this->get_courseid(); 00046 $this->add_setting(new backup_activity_generic_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $courseid)); 00047 00048 // Generate the groups file with the final annotated groups and groupings 00049 // including membership based on setting 00050 $this->add_step(new backup_groups_structure_step('groups', 'groups.xml')); 00051 00052 // Generate the questions file with the final annotated question_categories 00053 $this->add_step(new backup_questions_structure_step('questions', 'questions.xml')); 00054 00055 // Annotate all the question files for the already annotated question 00056 // categories (this is performed here and not in the structure step because 00057 // it involves multiple contexts and as far as we are always backup-ing 00058 // complete question banks we don't need to restrict at all and can be 00059 // done in a single pass 00060 $this->add_step(new backup_annotate_all_question_files('question_files')); 00061 00062 // Annotate all the user files (conditionally) (private, profile and icon files) 00063 // Because each user has its own context, we need a separate/specialised step here 00064 // This step also ensures that the contexts for all the users exist, so next 00065 // step can be safely executed (join between users and contexts) 00066 // Not executed if backup is without users of anonymized 00067 if ($this->get_setting_value('users') && !$this->get_setting_value('anonymize')) { 00068 $this->add_step(new backup_annotate_all_user_files('user_files')); 00069 } 00070 00071 // Generate the users file (conditionally) with the final annotated users 00072 // including custom profile fields, preferences, tags, role assignments and 00073 // overrides 00074 if ($this->get_setting_value('users')) { 00075 $this->add_step(new backup_users_structure_step('users', 'users.xml')); 00076 } 00077 00078 // Generate the top roles file with all the final annotated roles 00079 // that have been detected along the whole process. It's just 00080 // the list of role definitions (no assignments nor permissions) 00081 $this->add_step(new backup_final_roles_structure_step('roleslist', 'roles.xml')); 00082 00083 // Generate the gradebook file with categories and course grade items. Do it conditionally, using 00084 // execute_condition() so only will be excuted if ALL module grade_items in course have been exported 00085 $this->add_step(new backup_gradebook_structure_step('course_gradebook','gradebook.xml')); 00086 00087 // Generate the course completion 00088 $this->add_step(new backup_course_completion_structure_step('course_completion', 'completion.xml')); 00089 00090 // Generate the scales file with all the (final) annotated scales 00091 $this->add_step(new backup_final_scales_structure_step('scaleslist', 'scales.xml')); 00092 00093 // Generate the outcomes file with all the (final) annotated outcomes 00094 $this->add_step(new backup_final_outcomes_structure_step('outcomeslist', 'outcomes.xml')); 00095 00096 // Migrate the pending annotations to final (prev steps may have added some files) 00097 // This must be executed before backup files 00098 $this->add_step(new move_inforef_annotations_to_final('migrate_inforef')); 00099 00100 // Generate the files.xml file with all the (final) annotated files. At the same 00101 // time copy all the files from moodle storage to backup storage (uses custom 00102 // backup_nested_element for that) 00103 $this->add_step(new backup_final_files_structure_step('fileslist', 'files.xml')); 00104 00105 // Write the main moodle_backup.xml file, with all the information related 00106 // to the backup, settings, license, versions and other useful information 00107 $this->add_step(new backup_main_structure_step('mainfile', 'moodle_backup.xml')); 00108 00109 require_once($CFG->dirroot . '/backup/util/helper/convert_helper.class.php'); 00110 00111 //Checking if we have some converter involved in the process 00112 $converters = convert_helper::available_converters(false); 00113 //Conversion status 00114 $conversion = false; 00115 foreach ($converters as $value) { 00116 if ($this->get_setting_value($value)) { 00117 //zip class 00118 $zip_contents = "{$value}_zip_contents"; 00119 $store_backup_file = "{$value}_store_backup_file"; 00120 $convert = "{$value}_backup_convert"; 00121 00122 $this->add_step(new $convert("package_convert_{$value}")); 00123 $this->add_step(new $zip_contents("zip_contents_{$value}")); 00124 $this->add_step(new $store_backup_file("save_backupfile_{$value}")); 00125 if (!$conversion) { 00126 $conversion = true; 00127 } 00128 } 00129 } 00130 00131 00132 // On backup::MODE_IMPORT, we don't have to zip nor store the the file, skip these steps 00133 if (($this->plan->get_mode() != backup::MODE_IMPORT) && !$conversion) { 00134 // Generate the zip file (mbz extension) 00135 $this->add_step(new backup_zip_contents('zip_contents')); 00136 00137 // Copy the generated zip (.mbz) file to final destination 00138 $this->add_step(new backup_store_backup_file('save_backupfile')); 00139 } 00140 00141 // Clean the temp dir (conditionally) and drop temp tables 00142 $cleanstep = new drop_and_clean_temp_stuff('drop_and_clean_temp_stuff'); 00143 // Decide about to delete the temp dir (based on backup::MODE_IMPORT) 00144 $cleanstep->skip_cleaning_temp_dir($this->plan->get_mode() == backup::MODE_IMPORT); 00145 $this->add_step($cleanstep); 00146 00147 $this->built = true; 00148 } 00149 00150 // Protected API starts here 00151 00155 protected function define_settings() { 00156 // This task has not settings (could have them, like destination or so in the future, let's see) 00157 } 00158 }