|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00035 function lesson_20_migrate_moddata_mixture($courseid, $path) { 00036 global $CFG, $DB, $OUTPUT; 00037 00038 $fullpathname = "$CFG->dataroot/$courseid".$path; 00039 00040 if (!file_exists($fullpathname)) { 00041 return; 00042 } 00043 00044 $context = get_context_instance(CONTEXT_COURSE, $courseid); 00045 $items = new DirectoryIterator($fullpathname); 00046 $fs = get_file_storage(); 00047 00048 foreach ($items as $item) { 00049 if ($item->isDot()) { 00050 // skip 00051 continue; 00052 } 00053 00054 if ($item->isFile()) { 00055 if (!$item->isReadable()) { 00056 echo $OUTPUT->notification(" File not readable, skipping: ".$courseid.$path.$item->getFilename()); 00057 continue; 00058 } 00059 00060 $filepath = clean_param($path, PARAM_PATH); 00061 $filename = clean_param($item->getFilename(), PARAM_FILE); 00062 00063 if ($filename === '') { 00064 //unsupported chars, sorry 00065 continue; 00066 } 00067 00068 if (!$fs->file_exists($context->id, 'course', 'legacy', '0', $filepath, $filename)) { 00069 $file_record = array('contextid'=>$context->id, 'component'=>'course', 'filearea'=>'legacy', 'itemid'=>0, 'filepath'=>$filepath, 'filename'=>$filename, 00070 'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime()); 00071 $fs->create_file_from_pathname($file_record, $fullpathname.$item->getFilename()); 00072 @unlink($fullpathname.$item->getFilename()); 00073 } 00074 00075 } else { 00076 //migrate recursively all subdirectories 00077 lesson_20_migrate_moddata_mixture($courseid, $path.$item->getFilename().'/'); 00078 } 00079 } 00080 00081 unset($item); //release file handles 00082 unset($items); //release file handles 00083 00084 // delete dir if empty 00085 @rmdir($fullpathname); 00086 }