mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 08:39:25 +08:00
Make sure user activity is synced when whole discussions are deleted
We need to fire the PostWasDeleted event for every post when a discussion is deleted. This means deleting big discussions will be an intensive process, but that’s OK because it’s very rare.
This commit is contained in:
parent
1c359b1041
commit
7e69284661
@ -54,12 +54,14 @@ class DiscussionMetadataUpdater
|
||||
{
|
||||
$discussion = $post->discussion;
|
||||
|
||||
$discussion->refreshCommentsCount();
|
||||
if ($discussion->exists) {
|
||||
$discussion->refreshCommentsCount();
|
||||
|
||||
if ($discussion->last_post_id == $post->id) {
|
||||
$discussion->refreshLastPost();
|
||||
if ($discussion->last_post_id == $post->id) {
|
||||
$discussion->refreshLastPost();
|
||||
}
|
||||
|
||||
$discussion->save();
|
||||
}
|
||||
|
||||
$discussion->save();
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,6 @@ class UserActivitySyncer
|
||||
|
||||
protected function postedActivity(Post $post)
|
||||
{
|
||||
return $post->number === 1 ? new StartedDiscussionActivity($post) : new PostedActivity($post);
|
||||
return $post->number == 1 ? new StartedDiscussionActivity($post) : new PostedActivity($post);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use Flarum\Core\Support\VisibleScope;
|
||||
use Flarum\Core\Events\DiscussionWasDeleted;
|
||||
use Flarum\Core\Events\DiscussionWasStarted;
|
||||
use Flarum\Core\Events\DiscussionWasRenamed;
|
||||
use Flarum\Core\Events\PostWasDeleted;
|
||||
use Flarum\Core\Models\User;
|
||||
|
||||
class Discussion extends Model
|
||||
@ -79,7 +80,16 @@ class Discussion extends Model
|
||||
static::deleted(function ($discussion) {
|
||||
$discussion->raise(new DiscussionWasDeleted($discussion));
|
||||
|
||||
$discussion->posts()->allTypes()->delete();
|
||||
$posts = $discussion->posts()->allTypes();
|
||||
|
||||
foreach ($posts->get() as $post) {
|
||||
$post->setRelation('discussion', $discussion);
|
||||
|
||||
$discussion->raise(new PostWasDeleted($post));
|
||||
}
|
||||
|
||||
$posts->delete();
|
||||
|
||||
$discussion->readers()->detach();
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user