From 0f729672be4c4dcb417a5e0b5aec7b2b0754c44e Mon Sep 17 00:00:00 2001 From: Dongsheng Cai Date: Tue, 24 Aug 2010 06:29:24 +0000 Subject: [PATCH] "MDL-23823 allow users pick same file multi times in html editor" --- repository/recent/lib.php | 15 ++++++++++----- repository/upload/lib.php | 6 +++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/repository/recent/lib.php b/repository/recent/lib.php index 754bfb96d27..e967aee6013 100755 --- a/repository/recent/lib.php +++ b/repository/recent/lib.php @@ -54,15 +54,15 @@ class repository_recent extends repository { } private function get_recent_files($limitfrom = 0, $limit = DEFAULT_RECENT_FILES_NUM) { - global $USER, $DB; - // TODO: should exclude user_draft area files? + // XXX: get current itemid + global $USER, $DB, $itemid; $sql = 'SELECT * FROM {files} files1 JOIN (SELECT contenthash, filename, MAX(id) AS id FROM {files} - WHERE userid = ? AND filename != ? AND filearea != ? + WHERE (userid = ? AND filename != ?) OR (filearea = ? AND itemid = ?) GROUP BY contenthash, filename) files2 ON files1.id = files2.id ORDER BY files1.timemodified DESC'; - $params = array('userid'=>$USER->id, 'filename'=>'.', 'filearea'=>'draft'); + $params = array('userid'=>$USER->id, 'filename'=>'.', 'filearea'=>'draft', 'itemid'=>$itemid); $rs = $DB->get_recordset_sql($sql, $params, $limitfrom, $limit); $result = array(); foreach ($rs as $file_record) { @@ -178,7 +178,12 @@ class repository_recent extends repository { $file_record = array('contextid'=>$user_context->id, 'component'=>'user', 'filearea'=>'draft', 'itemid'=>$draftitemid, 'filepath'=>$new_filepath, 'filename'=>$new_filename); if ($file = $fs->get_file($user_context->id, 'user', 'draft', $draftitemid, $new_filepath, $new_filename)) { - throw new moodle_exception('fileexists'); + $info = array(); + $info['title'] = $file->get_filename(); + $info['itemid'] = $file->get_itemid(); + $info['filesize'] = $file->get_filesize(); + $info['contextid'] = $file->get_contextid(); + return $info; } $fs->create_file_from_storedfile($file_record, $stored_file); } diff --git a/repository/upload/lib.php b/repository/upload/lib.php index a9181f3b680..b443b8cae02 100755 --- a/repository/upload/lib.php +++ b/repository/upload/lib.php @@ -104,7 +104,11 @@ class repository_upload extends repository { } if ($file = $fs->get_file($context->id, $record->component, $record->filearea, $record->itemid, $record->filepath, $record->filename)) { - throw new moodle_exception('fileexists'); + return array( + 'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(), + 'id'=>$file->get_itemid(), + 'file'=>$file->get_filename() + ); } $record->contextid = $context->id;