improved legacy file migration - now processing default directory indexes too

This commit is contained in:
Petr Skoda
2010-10-18 11:44:14 +00:00
parent 9815cceee8
commit aa0dd423f7
+17 -4
View File
@@ -74,10 +74,23 @@ function resourcelib_try_file_migration($filepath, $cmid, $courseid, $component,
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);