Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/url/db/upgradelib.php
Go to the documentation of this file.
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 
00027 defined('MOODLE_INTERNAL') || die;
00028 
00033 function url_20_migrate() {
00034     global $CFG, $DB;
00035 
00036     require_once("$CFG->libdir/filelib.php");
00037     require_once("$CFG->libdir/resourcelib.php");
00038     require_once("$CFG->dirroot/course/lib.php");
00039 
00040     if (!file_exists("$CFG->dirroot/mod/resource/db/upgradelib.php")) {
00041         // bad luck, somebody deleted resource module
00042         return;
00043     }
00044 
00045     require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
00046 
00047     // create resource_old table and copy resource table there if needed
00048     if (!resource_20_prepare_migration()) {
00049         // no modules or fresh install
00050         return;
00051     }
00052 
00053     $candidates = $DB->get_recordset('resource_old', array('type'=>'file', 'migrated'=>0));
00054     if (!$candidates->valid()) {
00055         $candidates->close(); // Not going to iterate (but exit), close rs
00056         return;
00057     }
00058 
00059     foreach ($candidates as $candidate) {
00060         $path = $candidate->reference;
00061         $siteid = get_site()->id;
00062 
00063         if (strpos($path, 'LOCALPATH') === 0) {
00064             // ignore not maintained local files - sorry
00065             continue;
00066         } else if (!strpos($path, '://')) {
00067             // not URL
00068             continue;
00069         } else if (preg_match("|$CFG->wwwroot/file.php(\?file=)?/$siteid(/[^\s'\"&\?#]+)|", $path, $matches)) {
00070             // handled by resource module
00071             continue;
00072         } else if (preg_match("|$CFG->wwwroot/file.php(\?file=)?/$candidate->course(/[^\s'\"&\?#]+)|", $path, $matches)) {
00073             // handled by resource module
00074             continue;
00075         }
00076 
00077         upgrade_set_timeout();
00078 
00079         if ($CFG->texteditors !== 'textarea') {
00080             $intro       = text_to_html($candidate->intro, false, false, true);
00081             $introformat = FORMAT_HTML;
00082         } else {
00083             $intro       = $candidate->intro;
00084             $introformat = FORMAT_MOODLE;
00085         }
00086 
00087         $url = new stdClass();
00088         $url->course       = $candidate->course;
00089         $url->name         = $candidate->name;
00090         $url->intro        = $intro;
00091         $url->introformat  = $introformat;
00092         $url->externalurl  = $path;
00093         $url->timemodified = time();
00094 
00095         $options    = array('printheading'=>0, 'printintro'=>1);
00096         $parameters = array();
00097         if ($candidate->options == 'frame') {
00098             $url->display = RESOURCELIB_DISPLAY_FRAME;
00099 
00100         } else if ($candidate->options == 'objectframe') {
00101             $url->display = RESOURCELIB_DISPLAY_EMBED;
00102 
00103         } else if ($candidate->popup) {
00104             $url->display = RESOURCELIB_DISPLAY_POPUP;
00105             if ($candidate->popup) {
00106                 $rawoptions = explode(',', $candidate->popup);
00107                 foreach ($rawoptions as $rawoption) {
00108                     list($name, $value) = explode('=', trim($rawoption), 2);
00109                     if ($value > 0 and ($name == 'width' or $name == 'height')) {
00110                         $options['popup'.$name] = $value;
00111                         continue;
00112                     }
00113                 }
00114             }
00115 
00116         } else {
00117             $url->display = RESOURCELIB_DISPLAY_AUTO;
00118         }
00119         $url->displayoptions = serialize($options);
00120 
00121         if ($candidate->alltext) {
00122             $rawoptions = explode(',', $candidate->alltext);
00123             foreach ($rawoptions as $rawoption) {
00124                 list($variable, $parameter) = explode('=', trim($rawoption), 2);
00125                 $parameters[$parameter] = $variable;
00126             }
00127         }
00128 
00129         $url->parameters = serialize($parameters);
00130 
00131         if (!$url = resource_migrate_to_module('url', $candidate, $url)) {
00132             continue;
00133         }
00134     }
00135 
00136     $candidates->close();
00137 
00138     // clear all course modinfo caches
00139     rebuild_course_cache(0, true);
00140 }
 All Data Structures Namespaces Files Functions Variables Enumerations