3 namespace BookStack\Console\Commands;
5 use BookStack\Activity\CommentRepo;
6 use BookStack\Activity\Models\Comment;
7 use Illuminate\Console\Command;
8 use Illuminate\Support\Facades\DB;
10 class RegenerateCommentContentCommand extends Command
13 * The name and signature of the console command.
17 protected $signature = 'bookstack:regenerate-comment-content
18 {--database= : The database connection to use}';
21 * The console command description.
25 protected $description = 'Regenerate the stored HTML of all comments';
28 * Execute the console command.
30 public function handle(CommentRepo $commentRepo): int
32 $connection = DB::getDefaultConnection();
33 if ($this->option('database') !== null) {
34 DB::setDefaultConnection($this->option('database'));
37 Comment::query()->chunk(100, function ($comments) use ($commentRepo) {
38 foreach ($comments as $comment) {
39 $comment->html = $commentRepo->commentToHtml($comment->text);
44 DB::setDefaultConnection($connection);
45 $this->comment('Comment HTML content has been regenerated');