From 2081ab724db67942645edaf84f002112d571140f Mon Sep 17 00:00:00 2001 From: xypp <2952795729@qq.com> Date: Fri, 18 Oct 2024 00:38:16 +0800 Subject: [PATCH 1/2] fix: Ignore isLiked when post is not comment post. --- extensions/likes/src/Listener/SaveLikesToDatabase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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']; From 90641ae856684d6e42a2e28553128e96f2b1bc17 Mon Sep 17 00:00:00 2001 From: xypp <2952795729@qq.com> Date: Fri, 18 Oct 2024 01:59:17 +0800 Subject: [PATCH 2/2] detach all likes on non-comment posts. --- ...00_detach_likes_from_non_comment_posts.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 extensions/likes/migrations/2024_10_18_000000_detach_likes_from_non_comment_posts.php 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) { + } +];