improved legacy file migration - now processing default directory indexes too
authorPetr Skoda <skodak@moodle.org>
Mon, 18 Oct 2010 11:44:14 +0000 (11:44 +0000)
committerPetr Skoda <skodak@moodle.org>
Mon, 18 Oct 2010 11:44:14 +0000 (11:44 +0000)
lib/resourcelib.php

index 709e8c0..82c5eb6 100644 (file)
@@ -74,10 +74,23 @@ function resourcelib_try_file_migration($filepath, $cmid, $courseid, $component,
         return false;
     }
 
         return false;
     }
 
-    $pathnamehash = sha1("/$coursecontext->id/course/legacy/0".$filepath);
-    if (!$file = $fs->get_file_by_hash($pathnamehash)) {
-        return false;
-    }
+    $fullpath = rtrim("/$coursecontext->id/course/legacy/0".$filepath, '/');
+    do {
+        if (!$file = $fs->get_file_by_hash(sha1($fullpath))) {
+            if ($file = $fs->get_file_by_hash(sha1("$fullpath/.")) and $file->is_directory()) {
+                if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.htm"))) {
+                    break;
+                }
+                if ($file = $fs->get_file_by_hash(sha1("$fullpath/index.html"))) {
+                    break;
+                }
+                if ($file = $fs->get_file_by_hash(sha1("$fullpath/Default.htm"))) {
+                    break;
+                }
+            }
+            return false;
+        }
+    } while (false);
 
     // copy and keep the same path, name, etc.
     $file_record = array('contextid'=>$context->id, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid);
 
     // copy and keep the same path, name, etc.
     $file_record = array('contextid'=>$context->id, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid);