From 0ca28dc630c659a3bf6db822a47212f0670a4a6a Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 26 Jun 2025 17:30:34 -0400 Subject: [PATCH] Fix Document API to not insert a new document upon update as we changed the way documents and document versions are handled --- api/v1/documents/update.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/api/v1/documents/update.php b/api/v1/documents/update.php index 9ff03ca6..14308218 100644 --- a/api/v1/documents/update.php +++ b/api/v1/documents/update.php @@ -17,20 +17,14 @@ if (!empty($document_id)) { // Variable assignment from POST - assigning the current database value if a value is not provided require_once 'document_model.php'; - // Documents are a little weird as we update them by *inserting* a new document row - $update_insert_sql = mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$name', document_description = '$description', document_content = '$content', document_content_raw = '$content_raw', document_folder_id = $folder, document_created_by = 0, document_client_id = $client_id"); + $update_insert_sql = mysqli_query($mysqli,"UPDATE documents SET document_name = '$name', document_description = '$description', document_content = '$content', document_content_raw = '$content_raw', document_folder_id = $folder, document_updated_by = 0, document_client_id = $client_id"); - // Check insert & get insert ID - if ($update_insert_sql) { - $insert_id = $new_document_id = mysqli_insert_id($mysqli); + // Logging + logAction("Document", "Edit", "$name via API ($api_key_name)", $client_id, $document_id); + logAction("API", "Success", "Edited document $name via API ($api_key_name)", $client_id); - // Logging - logAction("Document", "Edit", "$name via API ($api_key_name) previous version kept", $client_id, $insert_id); - logAction("API", "Success", "Edited document $name via API ($api_key_name)", $client_id); - - // Override update count to 1 for API to report a success (as we inserted a document, not "updated" an existing row) - $update_count = 1; - } + // Override update count to 1 for API to report a success (as we inserted a document, not "updated" an existing row) + $update_count = 1; }