Merge branch 'MDL-33136_dndfilemanager_replace_file' of git://github.com/davosmith...
authorDan Poltawski <dan@moodle.com>
Mon, 18 Jun 2012 09:36:03 +0000 (17:36 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 18 Jun 2012 09:36:03 +0000 (17:36 +0800)
1  2 
lang/en/moodle.php
lang/en/repository.php
lib/outputrequirementslib.php
repository/upload/lib.php

Simple merge
Simple merge
Simple merge
@@@ -189,34 -188,40 +191,39 @@@ class repository_upload extends reposit
          }
          $record->contextid = $context->id;
          $record->userid    = $USER->id;
 -        $record->source    = '';
  
          if (repository::draftfile_exists($record->itemid, $record->filepath, $record->filename)) {
-             $existingfilename = $record->filename;
-             $unused_filename = repository::get_unused_filename($record->itemid, $record->filepath, $record->filename);
-             $record->filename = $unused_filename;
-             $stored_file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']);
-             $event = array();
-             $event['event'] = 'fileexists';
-             $event['newfile'] = new stdClass;
-             $event['newfile']->filepath = $record->filepath;
-             $event['newfile']->filename = $unused_filename;
-             $event['newfile']->url = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $unused_filename)->out(false);
-             $event['existingfile'] = new stdClass;
-             $event['existingfile']->filepath = $record->filepath;
-             $event['existingfile']->filename = $existingfilename;
-             $event['existingfile']->url      = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $existingfilename)->out(false);
-             return $event;
-         } else {
-             $stored_file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']);
-             return array(
-                 'url'=>moodle_url::make_draftfile_url($record->itemid, $record->filepath, $record->filename)->out(false),
-                 'id'=>$record->itemid,
-                 'file'=>$record->filename);
+             if ($overwriteexisting) {
+                 repository::delete_tempfile_from_draft($record->itemid, $record->filepath, $record->filename);
+             } else {
+                 $existingfilename = $record->filename;
+                 $unused_filename = repository::get_unused_filename($record->itemid, $record->filepath, $record->filename);
+                 $record->filename = $unused_filename;
+                 $stored_file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']);
+                 $event = array();
+                 $event['event'] = 'fileexists';
+                 $event['newfile'] = new stdClass;
+                 $event['newfile']->filepath = $record->filepath;
+                 $event['newfile']->filename = $unused_filename;
+                 $event['newfile']->url = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $unused_filename)->out(false);
+                 $event['existingfile'] = new stdClass;
+                 $event['existingfile']->filepath = $record->filepath;
+                 $event['existingfile']->filename = $existingfilename;
+                 $event['existingfile']->url      = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $existingfilename)->out(false);
+                 return $event;
+             }
          }
+         $stored_file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']);
+         return array(
+             'url'=>moodle_url::make_draftfile_url($record->itemid, $record->filepath, $record->filename)->out(false),
+             'id'=>$record->itemid,
+             'file'=>$record->filename);
      }
  
      /**
       * Checks the contents of the given file is not completely NULL - this can happen if a
       * user drags & drops a folder onto a filemanager / filepicker element