2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * This file keeps track of upgrades to the imsenterprise enrolment plugin
21 * @subpackage imsenterprise
22 * @copyright 2011 Petr Skoda {@link http://skodak.org
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 defined('MOODLE_INTERNAL') ||
die();
28 function xmldb_enrol_imsenterprise_upgrade($oldversion) {
29 global $CFG, $DB, $OUTPUT;
31 $dbman = $DB->get_manager();
34 //NOTE: this file is not executed during upgrade from 1.9.x!
37 if ($oldversion < 2011013000) {
38 // this plugin does not use the new file api - lets undo the migration
40 $fs = get_file_storage();
42 if ($DB->record_exists('course', array('id'=>1))) { //course 1 is hardcoded here intentionally!
43 if ($context = get_context_instance(CONTEXT_COURSE
, 1)) {
44 if ($file = $fs->get_file($context->id
, 'course', 'legacy', 0, '/', 'imsenterprise-enrol.xml')) {
45 if (!file_exists("$CFG->dataroot/1/imsenterprise-enrol.xml")) {
46 check_dir_exists($CFG->dataroot
.'/');
47 $file->copy_content_to("$CFG->dataroot/1/imsenterprise-enrol.xml");
54 if (!empty($CFG->enrol_imsfilelocation
)) {
55 if (strpos($CFG->enrol_imsfilelocation
, "$CFG->dataroot/") === 0) {
56 $location = str_replace("$CFG->dataroot/", '', $CFG->enrol_imsfilelocation
);
57 $location = str_replace('\\', '/', $location);
58 $parts = explode('/', $location);
59 $courseid = array_shift($parts);
60 if (is_number($courseid) and $DB->record_exists('course', array('id'=>$courseid))) {
61 if ($context = get_context_instance(CONTEXT_COURSE
, $courseid)) {
62 $file = array_pop($parts);
64 $dir = '/'.implode('/', $parts).'/';
68 if ($file = $fs->get_file($context->id
, 'course', 'legacy', 0, $dir, $file)) {
69 if (!file_exists($CFG->enrol_imsfilelocation
)) {
70 check_dir_exists($CFG->dataroot
.'/'.$courseid.$dir);
71 $file->copy_content_to($CFG->enrol_imsfilelocation
);
80 upgrade_plugin_savepoint(true, 2011013000, 'enrol', 'imsenterprise');