MDL-22634 fixed exception when adding files with the same name via file browser
This commit is contained in:
@@ -344,6 +344,8 @@ class file_info_stored extends file_info {
|
||||
return null;
|
||||
}
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
$now = time();
|
||||
|
||||
$newrecord = new object();
|
||||
@@ -353,13 +355,16 @@ class file_info_stored extends file_info {
|
||||
$newrecord->filepath = $this->lf->get_filepath();
|
||||
$newrecord->filename = $newfilename;
|
||||
|
||||
if ($fs->file_exists($newrecord->contextid, $newrecord->filearea, $newrecord->itemid, $newrecord->filepath, $newrecord->filename)) {
|
||||
// file already exists, sorry
|
||||
return null;
|
||||
}
|
||||
|
||||
$newrecord->timecreated = $now;
|
||||
$newrecord->timemodified = $now;
|
||||
$newrecord->mimetype = mimeinfo('type', $newfilename);
|
||||
$newrecord->userid = $userid;
|
||||
|
||||
$fs = get_file_storage();
|
||||
|
||||
if ($file = $fs->create_file_from_pathname($newrecord, $pathname)) {
|
||||
return $this->browser->get_file_info($this->context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user