mirror of
https://github.com/flarum/core.git
synced 2025-08-04 07:27:39 +02:00
Some fixes to tag metadata calculations (#154)
* If a discussion doesn't exist, it can't be the last posted discussion This fixes some rare errors where deleting the only post in the last posted discussion of a tag triggers a DB integrity exception. * Decrement tag's discussion count when deleting a post deletes an unhidden discussion. Co-authored-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
committed by
GitHub
parent
13f5f3ff7f
commit
714a74518e
@@ -100,7 +100,9 @@ class UpdateTagMetadata
|
||||
*/
|
||||
public function whenPostIsDeleted(PostDeleted $event)
|
||||
{
|
||||
$this->updateTags($event->post->discussion);
|
||||
$discussion = $event->post->discussion;
|
||||
$delta = ! $discussion->exists && $discussion->hidden_at === null ? -1 : 0;
|
||||
$this->updateTags($discussion, $delta);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +147,7 @@ class UpdateTagMetadata
|
||||
|
||||
// If this is a new / restored discussion, it isn't private, it isn't null,
|
||||
// and it's more recent than what we have now, set it as last posted discussion.
|
||||
if ($delta >= 0 && ! $discussion->is_private && $discussion->hidden_at == null && ($discussion->last_posted_at >= $tag->last_posted_at)) {
|
||||
if ($delta >= 0 && ! $discussion->is_private && $discussion->hidden_at == null && ($discussion->last_posted_at >= $tag->last_posted_at) && $discussion->exists) {
|
||||
$tag->setLastPostedDiscussion($discussion);
|
||||
} elseif ($discussion->id == $tag->last_posted_discussion_id) {
|
||||
// This is to persist refreshLastPost above. It is here instead of there so that
|
||||
|
Reference in New Issue
Block a user