Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Console/PruneHiddenContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
Expand All @@ -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, [])));
}
}