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:
@@ -54,12 +54,14 @@ class DiscussionMetadataUpdater
|
|||||||
{
|
{
|
||||||
$discussion = $post->discussion;
|
$discussion = $post->discussion;
|
||||||
|
|
||||||
$discussion->refreshCommentsCount();
|
if ($discussion->exists) {
|
||||||
|
$discussion->refreshCommentsCount();
|
||||||
|
|
||||||
if ($discussion->last_post_id == $post->id) {
|
if ($discussion->last_post_id == $post->id) {
|
||||||
$discussion->refreshLastPost();
|
$discussion->refreshLastPost();
|
||||||
|
}
|
||||||
|
|
||||||
|
$discussion->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
$discussion->save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -71,6 +71,6 @@ class UserActivitySyncer
|
|||||||
|
|
||||||
protected function postedActivity(Post $post)
|
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\DiscussionWasDeleted;
|
||||||
use Flarum\Core\Events\DiscussionWasStarted;
|
use Flarum\Core\Events\DiscussionWasStarted;
|
||||||
use Flarum\Core\Events\DiscussionWasRenamed;
|
use Flarum\Core\Events\DiscussionWasRenamed;
|
||||||
|
use Flarum\Core\Events\PostWasDeleted;
|
||||||
use Flarum\Core\Models\User;
|
use Flarum\Core\Models\User;
|
||||||
|
|
||||||
class Discussion extends Model
|
class Discussion extends Model
|
||||||
@@ -79,7 +80,16 @@ class Discussion extends Model
|
|||||||
static::deleted(function ($discussion) {
|
static::deleted(function ($discussion) {
|
||||||
$discussion->raise(new DiscussionWasDeleted($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();
|
$discussion->readers()->detach();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user