diff --git a/src/Console/PruneHiddenContent.php b/src/Console/PruneHiddenContent.php index e3045c0..816d88b 100644 --- a/src/Console/PruneHiddenContent.php +++ b/src/Console/PruneHiddenContent.php @@ -6,8 +6,11 @@ use Flarum\Discussion\Discussion; use Flarum\Discussion\Event\Deleting; use Flarum\Group\Group; +use Flarum\Post\Command\DeletePost; +use Flarum\Post\Post; use Flarum\User\User; use Illuminate\Console\Command; +use Illuminate\Contracts\Bus\Dispatcher as Bus; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\Eloquent\Builder; @@ -16,9 +19,9 @@ class PruneHiddenContent extends Command private const int HIDDEN_DAYS = 30; protected $signature = 'app:prune-hidden'; - protected $description = 'Permanently delete hidden discussions older than 30 days.'; + protected $description = 'Permanently delete hidden content older than 30 days.'; - public function handle(Dispatcher $events): void + public function handle(Dispatcher $events, Bus $bus): void { /** @var User $actor */ $actor = User::query() @@ -37,5 +40,10 @@ public function handle(Dispatcher $events): void $events->dispatch(new Deleting($discussion, $actor, [])); $discussion->delete(); }); + + Post::query() + ->whereNotNull('hidden_at') + ->where('hidden_at', '<', $threshold) + ->eachById(fn (Post $post) => $bus->dispatch(new DeletePost($post->id, $actor, []))); } }