Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/imsenterprise/db/install.php
Go to the documentation of this file.
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_install() {
00029     global $CFG, $DB;
00030 
00031     // NOTE: this file is executed during upgrade from 1.9.x!
00032 
00033 
00034     // this plugin does not use the new file api - lets undo the migration
00035     $fs = get_file_storage();
00036 
00037     if ($DB->record_exists('course', array('id'=>1))) { //course 1 is hardcoded here intentionally!
00038         if ($context = get_context_instance(CONTEXT_COURSE, 1)) {
00039             if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, '/', 'imsenterprise-enrol.xml')) {
00040                 if (!file_exists("$CFG->dataroot/1/imsenterprise-enrol.xml")) {
00041                     check_dir_exists($CFG->dataroot.'/');
00042                     $file->copy_content_to("$CFG->dataroot/1/imsenterprise-enrol.xml");
00043                 }
00044                 $file->delete();
00045             }
00046         }
00047     }
00048 
00049     if (!empty($CFG->enrol_imsfilelocation)) {
00050         if (strpos($CFG->enrol_imsfilelocation, "$CFG->dataroot/") === 0) {
00051             $location = str_replace("$CFG->dataroot/", '', $CFG->enrol_imsfilelocation);
00052             $location = str_replace('\\', '/', $location);
00053             $parts = explode('/', $location);
00054             $courseid = array_shift($parts);
00055             if (is_number($courseid) and $DB->record_exists('course', array('id'=>$courseid))) {
00056                 if ($context = get_context_instance(CONTEXT_COURSE, $courseid)) {
00057                     $file = array_pop($parts);
00058                     if ($parts) {
00059                         $dir = '/'.implode('/', $parts).'/';
00060                     } else {
00061                         $dir = '/';
00062                     }
00063                     if ($file = $fs->get_file($context->id, 'course', 'legacy', 0, $dir, $file)) {
00064                         if (!file_exists($CFG->enrol_imsfilelocation)) {
00065                             check_dir_exists($CFG->dataroot.'/'.$courseid.$dir);
00066                             $file->copy_content_to($CFG->enrol_imsfilelocation);
00067                         }
00068                         $file->delete();
00069                     }
00070                 }
00071             }
00072         }
00073     }
00074 
00075 
00076     // TODO: migrate old config settings
00077 
00078 }
 All Data Structures Namespaces Files Functions Variables Enumerations