Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-31515 Allow for subsequent files to overwrite old files in databa…

…se activity records
  • Loading branch information...
commit 08b213beeae456f9910c781418671c33b29c68d8 1 parent 2787eeb
@andrewnicols andrewnicols authored samhemelryk committed
Showing with 12 additions and 10 deletions.
  1. +12 −10 mod/data/field/file/field.class.php
View
22 mod/data/field/file/field.class.php
@@ -167,27 +167,29 @@ function update_content($recordid, $value, $name) {
$fs->delete_area_files($this->context->id, 'mod_data', 'content', $content->id);
$usercontext = get_context_instance(CONTEXT_USER, $USER->id);
- $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $value);
+ $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $value, 'timecreated DESC');
if (count($files)<2) {
// no file
} else {
- $count = 0;
foreach ($files as $draftfile) {
- $file_record = array('contextid'=>$this->context->id, 'component'=>'mod_data', 'filearea'=>'content', 'itemid'=>$content->id, 'filepath'=>'/');
if (!$draftfile->is_directory()) {
- $file_record['filename'] = $draftfile->get_filename();
+ $file_record = array(
+ 'contextid' => $this->context->id,
+ 'component' => 'mod_data',
+ 'filearea' => 'content',
+ 'itemid' => $content->id,
+ 'filepath' => '/',
+ 'filename' => $draftfile->get_filename(),
+ );
- $content->content = $draftfile->get_filename();
+ $content->content = $file_record['filename'];
$fs->create_file_from_storedfile($file_record, $draftfile);
$DB->update_record('data_content', $content);
- if ($count > 0) {
- break;
- } else {
- $count++;
- }
+ // Break from the loop now to avoid overwriting the uploaded file record
+ break;
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.