mirror of
https://github.com/flarum/core.git
synced 2025-07-25 18:51:40 +02: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:
@@ -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();
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user