|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file keeps track of upgrades to 00004 // the assignment module 00005 // 00006 // Sometimes, changes between versions involve 00007 // alterations to database structures and other 00008 // major things that may break installations. 00009 // 00010 // The upgrade function in this file will attempt 00011 // to perform all the necessary actions to upgrade 00012 // your older installation to the current version. 00013 // 00014 // If there's something it cannot do itself, it 00015 // will tell you what you need to do. 00016 // 00017 // The commands in here will all be database-neutral, 00018 // using the methods of database_manager class 00019 // 00020 // Please do not forget to use upgrade_set_timeout() 00021 // before any action that may take longer time to finish. 00022 00023 function xmldb_assignment_upgrade($oldversion) { 00024 global $CFG, $DB, $OUTPUT; 00025 00026 $dbman = $DB->get_manager(); 00027 00028 //===== 1.9.0 upgrade line ======// 00029 00030 if ($oldversion < 2007101511) { 00031 // change grade typo to text if no grades MDL-13920 00032 require_once $CFG->dirroot.'/mod/assignment/lib.php'; 00033 assignment_upgrade_grades(); 00034 upgrade_mod_savepoint(true, 2007101511, 'assignment'); 00035 } 00036 00037 if ($oldversion < 2008081900) { 00038 00042 00043 $fs = get_file_storage(); 00044 00045 $sqlfrom = "FROM {assignment_submissions} s 00046 JOIN {assignment} a ON a.id = s.assignment 00047 JOIN {modules} m ON m.name = 'assignment' 00048 JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = a.id)"; 00049 00050 $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom"); 00051 00052 $rs = $DB->get_recordset_sql("SELECT s.id, s.userid, s.teacher, s.assignment, a.course, cm.id AS cmid $sqlfrom ORDER BY a.course, s.assignment"); 00053 00054 if ($rs->valid()) { 00055 $pbar = new progress_bar('migrateassignmentfiles', 500, true); 00056 $i = 0; 00057 foreach ($rs as $submission) { 00058 $i++; 00059 upgrade_set_timeout(180); // set up timeout, may also abort execution 00060 $pbar->update($i, $count, "Migrating assignment submissions - $i/$count."); 00061 00062 $basepath = "$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->userid/"; 00063 if (!file_exists($basepath)) { 00064 //no files 00065 continue; 00066 } 00067 $context = get_context_instance(CONTEXT_MODULE, $submission->cmid); 00068 00069 // migrate submitted files first 00070 $path = $basepath; 00071 $items = new DirectoryIterator($path); 00072 foreach ($items as $item) { 00073 if (!$item->isFile()) { 00074 continue; 00075 } 00076 if (!$item->isReadable()) { 00077 echo $OUTPUT->notification(" File not readable, skipping: ".$path.$item->getFilename()); 00078 continue; 00079 } 00080 $filename = clean_param($item->getFilename(), PARAM_FILE); 00081 if ($filename === '') { 00082 continue; 00083 } 00084 if (!$fs->file_exists($context->id, 'mod_assignment', 'submission', $submission->id, '/', $filename)) { 00085 $file_record = array('contextid'=>$context->id, 'component'=>'mod_assignment', 'filearea'=>'submission', 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$submission->userid); 00086 if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) { 00087 unlink($path.$item->getFilename()); 00088 } 00089 } 00090 } 00091 unset($items); //release file handles 00092 00093 // migrate teacher response files for "upload" subtype, unfortunately we do not 00094 $path = $basepath.'responses/'; 00095 if (file_exists($path)) { 00096 $items = new DirectoryIterator($path); 00097 foreach ($items as $item) { 00098 if (!$item->isFile()) { 00099 continue; 00100 } 00101 $filename = clean_param($item->getFilename(), PARAM_FILE); 00102 if ($filename === '') { 00103 continue; 00104 } 00105 if (!$fs->file_exists($context->id, 'mod_assignment', 'response', $submission->id, '/', $filename)) { 00106 $file_record = array('contextid'=>$context->id, 'component'=>'mod_assignment', 'filearea'=>'response', 'itemid'=>$submission->id, 'filepath'=>'/', 'filename'=>$filename, 00107 'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime()); 00108 if ($submission->teacher) { 00109 $file_record['userid'] = $submission->teacher; 00110 } 00111 if ($fs->create_file_from_pathname($file_record, $path.$item->getFilename())) { 00112 unlink($path.$item->getFilename()); 00113 } 00114 } 00115 } 00116 unset($items); //release file handles 00117 @rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->userid/responses"); 00118 } 00119 00120 // remove dirs if empty 00121 @rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->userid"); 00122 @rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment"); 00123 @rmdir("$CFG->dataroot/$submission->course/$CFG->moddata/assignment"); 00124 } 00125 } 00126 $rs->close(); 00127 00128 upgrade_mod_savepoint(true, 2008081900, 'assignment'); 00129 } 00130 00131 if ($oldversion < 2009042000) { 00132 00134 $table = new xmldb_table('assignment'); 00135 $field = new xmldb_field('description', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'name'); 00136 00138 $dbman->rename_field($table, $field, 'intro'); 00139 00141 upgrade_mod_savepoint(true, 2009042000, 'assignment'); 00142 } 00143 00144 if ($oldversion < 2009042001) { 00145 00147 $table = new xmldb_table('assignment'); 00148 $field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro'); 00149 00151 $dbman->rename_field($table, $field, 'introformat'); 00152 00154 upgrade_mod_savepoint(true, 2009042001, 'assignment'); 00155 } 00156 00157 // Moodle v2.1.0 release upgrade line 00158 // Put any upgrade step following this 00159 00160 // Moodle v2.2.0 release upgrade line 00161 // Put any upgrade step following this 00162 00163 return true; 00164 } 00165 00166