diff --git a/extensions/likes/migrations/2024_10_18_000000_detach_likes_from_non_comment_posts.php b/extensions/likes/migrations/2024_10_18_000000_detach_likes_from_non_comment_posts.php new file mode 100644 index 0000000000..a64cb10f33 --- /dev/null +++ b/extensions/likes/migrations/2024_10_18_000000_detach_likes_from_non_comment_posts.php @@ -0,0 +1,24 @@ + function (Builder $schema) { + // Detach likes on non-comment posts + $schema->getConnection() + ->table('post_likes') + ->whereNotExists(function ($query) { + $query->selectRaw(1)->from('posts')->whereColumn('id', 'post_id')->where('type', 'comment'); + }) + ->delete(); + }, + 'down' => function (Builder $schema) { + } +]; diff --git a/extensions/likes/src/Listener/SaveLikesToDatabase.php b/extensions/likes/src/Listener/SaveLikesToDatabase.php index 516b42f730..adce5495a4 100755 --- a/extensions/likes/src/Listener/SaveLikesToDatabase.php +++ b/extensions/likes/src/Listener/SaveLikesToDatabase.php @@ -34,7 +34,7 @@ public function whenPostIsSaving(Saving $event) $post = $event->post; $data = $event->data; - if ($post->exists && isset($data['attributes']['isLiked'])) { + if ($post->exists && isset($data['attributes']['isLiked']) && $post->type === 'comment') { $actor = $event->actor; $liked = (bool) $data['attributes']['isLiked'];