Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/scorm/db/upgradelib.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 
00033 function scorm_migrate_moddata_files($scorm, $context) {
00034     global $CFG;
00035 
00036     // now migrate the extracted package
00037     $basepath = "$CFG->dataroot/$scorm->course/$CFG->moddata/scorm/$scorm->id";
00038     if (!is_dir($basepath)) {
00039         //no files?
00040         return;
00041     }
00042 
00043     scorm_migrate_moddata_subdir($context, $basepath, '/');
00044 }
00052 function scorm_migrate_moddata_subdir($context, $base, $path) {
00053     global $OUTPUT;
00054 
00055     $fullpathname = $base.$path;
00056     $fs           = get_file_storage();
00057     $filearea     = 'content';
00058     $items        = new DirectoryIterator($fullpathname);
00059 
00060     foreach ($items as $item) {
00061         if ($item->isDot()) {
00062             unset($item); // release file handle
00063             continue;
00064         }
00065 
00066         if ($item->isLink()) {
00067             // do not follow symlinks - they were never supported in moddata, sorry
00068             unset($item); // release file handle
00069             continue;
00070         }
00071 
00072         if ($item->isFile()) {
00073             if (!$item->isReadable()) {
00074                 echo $OUTPUT->notification(" File not readable, skipping: ".$fullpathname.$item->getFilename());
00075                 unset($item); // release file handle
00076                 continue;
00077             }
00078 
00079             $filepath    = clean_param($path, PARAM_PATH);
00080             $filename    = clean_param($item->getFilename(), PARAM_FILE);
00081             $oldpathname = $fullpathname.$item->getFilename();
00082 
00083             if ($filename === '') {
00084                 continue;
00085                 unset($item); // release file handle
00086             }
00087 
00088             if (!$fs->file_exists($context->id, 'mod_scorm', $filearea, '0', $filepath, $filename)) {
00089                 $file_record = array('contextid'=>$context->id, 'component'=>'mod_scorm', 'filearea'=>$filearea, 'itemid'=>0, 'filepath'=>$filepath, 'filename'=>$filename,
00090                                      'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime());
00091                 unset($item); // release file handle
00092                 if ($fs->create_file_from_pathname($file_record, $oldpathname)) {
00093                     @unlink($oldpathname);
00094                 }
00095             } else {
00096                 unset($item); // release file handle
00097             }
00098 
00099         } else {
00100             //migrate recursively all subdirectories
00101             $oldpathname = $fullpathname.$item->getFilename().'/';
00102             $subpath     = $path.$item->getFilename().'/';
00103             unset($item);  // release file handle
00104             scorm_migrate_moddata_subdir($context, $base, $subpath);
00105             @rmdir($oldpathname); // deletes dir if empty
00106         }
00107     }
00108     unset($items); //release file handles
00109 }
 All Data Structures Namespaces Files Functions Variables Enumerations