From fefa189e87d79c3dbbd97ae3570cbaf3717c7ce3 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Tue, 17 Dec 2013 21:54:32 -0500 Subject: [PATCH] Add case for document upload where the document exists on disk but there is no database record - refs BT#7218 If upload is in overwrite mode (default), then overwrite the file and create the db record. This goes through the secure files filter first, so no worry there. --- main/inc/lib/fileUpload.lib.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main/inc/lib/fileUpload.lib.php b/main/inc/lib/fileUpload.lib.php index 77f25e7285..1925e2018d 100644 --- a/main/inc/lib/fileUpload.lib.php +++ b/main/inc/lib/fileUpload.lib.php @@ -256,6 +256,7 @@ function handle_uploaded_document( $files_perm = api_get_permissions_for_new_files(); // What to do if the target file exists + error_log($what_if_file_exists); switch ($what_if_file_exists) { // Overwrite the file if it exists case 'overwrite': @@ -276,7 +277,18 @@ function handle_uploaded_document( // Redo visibility api_set_default_visibility(TOOL_DOCUMENT, $document_id); - } + } else { + // There might be cases where the file exists on disk but there is no registration of that in the database + // In this case, and if we are in overwrite mode, overwrite and create the db record + $document_id = add_document($_course, $file_path, 'file', $file_size, $document_name, null, 0, true, null, $current_session_id); + if ($document_id) { + // Put the document in item_property update + api_item_property_update($_course, TOOL_DOCUMENT, $document_id, 'DocumentAdded', $user_id, $to_group_id, $to_user_id, null, null, $current_session_id); + + // Redo visibility + api_set_default_visibility(TOOL_DOCUMENT, $document_id); + } + } // If the file is in a folder, we need to update all parent folders item_property_update_on_folder($_course, $upload_path, $user_id); // Display success message with extra info to user