Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

use Illuminate\Database\Schema\Builder;

return [
'up' => 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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it no need to delete?

just keep it in database for rolling back.

},
'down' => function (Builder $schema) {
}
];
2 changes: 1 addition & 1 deletion extensions/likes/src/Listener/SaveLikesToDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
Loading