Update counter on delete

This commit is contained in:
Michael 2023-12-31 08:56:05 +00:00
parent 72f5a64cf3
commit dfc96af2cd
2 changed files with 7 additions and 2 deletions

View file

@ -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;

View file

@ -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;
}