MDL-30459 when one filename already exist we bypass the execution and continue. We...
authorJerome Mouneyrac <jerome@moodle.com>
Thu, 1 Dec 2011 02:33:37 +0000 (10:33 +0800)
committerSam Hemelryk <sam@moodle.com>
Thu, 1 Dec 2011 02:56:15 +0000 (15:56 +1300)
webservice/upload.php

index 43ddb39..037a573 100644 (file)
@@ -130,10 +130,14 @@ foreach ($files as $file) {
                 $file_record->itemid, $file_record->filepath, $file_record->filename);
     if ($existingfile) {
         //if allow automatic rename (avoid)
                 $file_record->itemid, $file_record->filepath, $file_record->filename);
     if ($existingfile) {
         //if allow automatic rename (avoid)
-        throw new moodle_exception('filenameexist', 'webservice', '', $file->filename);
+        $fileerror = new stdClass();
+        $fileerror->filename = $file->filename;
+        $fileerror->errortype = 'filenameexist';
+        $fileerror->errormsg = get_string('filenameexist', 'webservice', $file->filename);
+        $results[] = $fileerror;
+    } else {
+        $stored_file = $fs->create_file_from_pathname($file_record, $file->filepath);
+        $results[] = $file_record;
     }
     }
-
-    $stored_file = $fs->create_file_from_pathname($file_record, $file->filepath);
-    $results[] = $file_record;
 }
 echo json_encode($results);
 }
 echo json_encode($results);