MDL-22584 detect file paths that are too long to fit into 255 char db field
authorPetr Skoda <skodak@moodle.org>
Tue, 26 Oct 2010 19:14:22 +0000 (19:14 +0000)
committerPetr Skoda <skodak@moodle.org>
Tue, 26 Oct 2010 19:14:22 +0000 (19:14 +0000)
lib/db/upgradelib.php

index da8d78b..17ac87d 100644 (file)
@@ -287,6 +287,8 @@ function upgrade_migrate_files_course($context, $path, $delete) {
     $items = new DirectoryIterator($fullpathname);
     $fs = get_file_storage();
 
+    $textlib = textlib_get_instance();
+
     foreach ($items as $item) {
         if ($item->isDot()) {
             continue;
@@ -323,6 +325,11 @@ function upgrade_migrate_files_course($context, $path, $delete) {
                 continue;
             }
 
+            if ($textlib->strlen($filepath) > 255) {
+                echo $OUTPUT->notification(" File path longer than 255 chars, skipping: ".$fullpathname.$item->getFilename());
+                continue;
+            }
+
             if (!$fs->file_exists($context->id, $component, $filearea, '0', $filepath, $filename)) {
                 $file_record = array('contextid'=>$context->id, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>0, 'filepath'=>$filepath, 'filename'=>$filename,
                                      'timecreated'=>$item->getCTime(), 'timemodified'=>$item->getMTime());