|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 defined('MOODLE_INTERNAL') || die(); 00027 00028 function xmldb_enrol_imsenterprise_upgrade($oldversion) { 00029 global $CFG, $DB, $OUTPUT; 00030 00031 $dbman = $DB->get_manager(); 00032 00033 00034 //NOTE: this file is not executed during upgrade from 1.9.x! 00035 00036 00037 if ($oldversion < 2011013000) { 00038 // this plugin does not use the new file api - lets undo the migration 00039 00040 $fs = get_file_storage(); 00041 00042 if ($DB->record_exists('course', array('id'=>1))) { //course 1 is hardcoded here intentionally! 00043 if ($context = get_context_instance(CONTEXT_COURSE, 1)) { 00044 if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, '/', 'imsenterprise-enrol.xml')) { 00045 if (!file_exists("$CFG->dataroot/1/imsenterprise-enrol.xml")) { 00046 check_dir_exists($CFG->dataroot.'/'); 00047 $file->copy_content_to("$CFG->dataroot/1/imsenterprise-enrol.xml"); 00048 } 00049 $file->delete(); 00050 } 00051 } 00052 } 00053 00054 if (!empty($CFG->enrol_imsfilelocation)) { 00055 if (strpos($CFG->enrol_imsfilelocation, "$CFG->dataroot/") === 0) { 00056 $location = str_replace("$CFG->dataroot/", '', $CFG->enrol_imsfilelocation); 00057 $location = str_replace('\\', '/', $location); 00058 $parts = explode('/', $location); 00059 $courseid = array_shift($parts); 00060 if (is_number($courseid) and $DB->record_exists('course', array('id'=>$courseid))) { 00061 if ($context = get_context_instance(CONTEXT_COURSE, $courseid)) { 00062 $file = array_pop($parts); 00063 if ($parts) { 00064 $dir = '/'.implode('/', $parts).'/'; 00065 } else { 00066 $dir = '/'; 00067 } 00068 if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, $dir, $file)) { 00069 if (!file_exists($CFG->enrol_imsfilelocation)) { 00070 check_dir_exists($CFG->dataroot.'/'.$courseid.$dir); 00071 $file->copy_content_to($CFG->enrol_imsfilelocation); 00072 } 00073 $file->delete(); 00074 } 00075 } 00076 } 00077 } 00078 } 00079 00080 upgrade_plugin_savepoint(true, 2011013000, 'enrol', 'imsenterprise'); 00081 } 00082 00083 // Moodle v2.1.0 release upgrade line 00084 // Put any upgrade step following this 00085 00086 // Moodle v2.2.0 release upgrade line 00087 // Put any upgrade step following this 00088 00089 return true; 00090 } 00091 00092