From 02ba53724ee1f4b8a55d7f019f38111ed3489b33 Mon Sep 17 00:00:00 2001 From: luptmoor Date: Tue, 28 Apr 2026 10:04:51 +0200 Subject: [PATCH] prepared comment counting --- migrations/006_comments_and_photos.sql | 1 + public/api/contributions.php | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/migrations/006_comments_and_photos.sql b/migrations/006_comments_and_photos.sql index 97366f6..31e08de 100644 --- a/migrations/006_comments_and_photos.sql +++ b/migrations/006_comments_and_photos.sql @@ -31,5 +31,6 @@ CREATE INDEX idx_comments_browser ON comments(browser_id); -- --------------------------------------------------------------------- ALTER TABLE contributions ADD COLUMN photo_path VARCHAR(255) DEFAULT NULL; + ADD COLUMN comment_count INTEGER NOT NULL DEFAULT 0; COMMENT ON COLUMN contributions.photo_path IS 'Relative Path to uploaded Photo. NULL = no Photo.'; \ No newline at end of file diff --git a/public/api/contributions.php b/public/api/contributions.php index 2c1620f..1a0f27e 100644 --- a/public/api/contributions.php +++ b/public/api/contributions.php @@ -629,6 +629,14 @@ function handle_create_comment($input) { ':content' => $input['content'] ]); + $stmt2 = $pdo->prepare(" + UPDATE contributions + SET comment_count = comment_count + 1 + WHERE id = :cid; + "); + + $stmt2->execute([':cid' => $input['contribution_id']]); + json_response([ 'message' => 'Comment created successfully.', 'comment_id' => (int) $pdo->lastInsertId()