From dfc96af2cd99c9625698eaabb522d63714f405cb Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 31 Dec 2023 08:56:05 +0000 Subject: [PATCH] Update counter on delete --- src/Model/Item.php | 6 +++++- src/Model/Post/Counts.php | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 1c29716129..3a613d6180 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -338,7 +338,7 @@ class Item // locate item to be deleted $fields = [ 'id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri-id', 'origin', - 'deleted', 'resource-id', 'event-id', + 'thr-parent-id', 'deleted', 'resource-id', 'event-id', 'vid', 'body', 'verb', 'object-type', 'object', 'target', 'contact-id', 'psid', 'gravity' ]; $item = Post::selectFirst($fields, ['id' => $item_id]); @@ -418,6 +418,10 @@ class Item DI::notify()->deleteForItem($item['uri-id']); DI::notification()->deleteForItem($item['uri-id']); + if (in_array($item['gravity'], [self::GRAVITY_ACTIVITY, self::GRAVITY_COMMENT])) { + Post\Counts::update($item['thr-parent-id'], $item['parent-uri-id'], $item['vid'], $item['verb'], $item['body']); + } + Logger::info('Item has been marked for deletion.', ['id' => $item_id]); return true; diff --git a/src/Model/Post/Counts.php b/src/Model/Post/Counts.php index 230b41f5cb..865b3bdb4c 100644 --- a/src/Model/Post/Counts.php +++ b/src/Model/Post/Counts.php @@ -44,7 +44,7 @@ class Counts return true; } - $condition = ['thr-parent-id' => $uri_id, 'vid' => $vid]; + $condition = ['thr-parent-id' => $uri_id, 'vid' => $vid, 'deleted' => false]; if ($body == $verb) { $condition['body'] = null; @@ -67,6 +67,7 @@ class Counts ]; if ($fields['count'] == 0) { + DBA::delete('post-counts', ['uri-id' => $uri_id, 'vid' => $vid, 'reaction' => $body]); return true; }