Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/folder/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 folder_20_migrate() {
00034     global $CFG, $DB;
00035     require_once("$CFG->libdir/filelib.php");
00036     require_once("$CFG->dirroot/course/lib.php");
00037 
00038     if (!file_exists("$CFG->dirroot/mod/resource/db/upgradelib.php")) {
00039         // bad luck, somebody deleted resource module
00040         return;
00041     }
00042 
00043     require_once("$CFG->dirroot/mod/resource/db/upgradelib.php");
00044 
00045     // create resource_old table and copy resource table there if needed
00046     if (!resource_20_prepare_migration()) {
00047         // no modules or fresh install
00048         return;
00049     }
00050 
00051     $candidates = $DB->get_recordset('resource_old', array('type'=>'directory', 'migrated'=>0));
00052 
00053     if (!$candidates->valid()) {
00054         $candidates->close(); // Not going to iterate (but exit), close rs
00055         return;
00056     }
00057 
00058     $fs = get_file_storage();
00059 
00060     foreach ($candidates as $candidate) {
00061         upgrade_set_timeout();
00062 
00063         $directory = '/'.trim($candidate->reference, '/').'/';
00064         $directory = str_replace('//', '/', $directory);
00065 
00066         if ($CFG->texteditors !== 'textarea') {
00067             $intro       = text_to_html($candidate->intro, false, false, true);
00068             $introformat = FORMAT_HTML;
00069         } else {
00070             $intro       = $candidate->intro;
00071             $introformat = FORMAT_MOODLE;
00072         }
00073 
00074         $folder = new stdClass();
00075         $folder->course       = $candidate->course;
00076         $folder->name         = $candidate->name;
00077         $folder->intro        = $intro;
00078         $folder->introformat  = $introformat;
00079         $folder->revision     = 1;
00080         $folder->timemodified = time();
00081 
00082         if (!$folder = resource_migrate_to_module('folder', $candidate, $folder)) {
00083             continue;
00084         }
00085 
00086         // copy files in given directory, skip moddata and backups!
00087         $context       = get_context_instance(CONTEXT_MODULE, $candidate->cmid);
00088         $coursecontext = get_context_instance(CONTEXT_COURSE, $candidate->course);
00089         $files = $fs->get_directory_files($coursecontext->id, 'course', 'legacy', 0, $directory, true, true);
00090         $file_record = array('contextid'=>$context->id, 'component'=>'mod_folder', 'filearea'=>'content', 'itemid'=>0);
00091         foreach ($files as $file) {
00092             $path = $file->get_filepath();
00093             if (stripos($path, '/backupdata/') === 0 or stripos($path, '/moddata/') === 0) {
00094                 // do not publish protected data!
00095                 continue;
00096             }
00097             $relpath = substr($path, strlen($directory) - 1); // keep only subfolder paths
00098             $file_record['filepath'] = $relpath;
00099             $fs->create_file_from_storedfile($file_record, $file);
00100         }
00101     }
00102 
00103     $candidates->close();
00104 
00105     // clear all course modinfo caches
00106     rebuild_course_cache(0, true);
00107 }
 All Data Structures Namespaces Files Functions Variables Enumerations