3 namespace BookStack\Console\Commands;
5 use BookStack\Actions\Comment;
6 use BookStack\Actions\CommentRepo;
7 use Illuminate\Console\Command;
9 class RegenerateCommentContent extends Command
12 * The name and signature of the console command.
16 protected $signature = 'bookstack:regenerate-comment-content {--database= : The database connection to use.}';
19 * The console command description.
23 protected $description = 'Regenerate the stored HTML of all comments';
28 protected $commentRepo;
31 * Create a new command instance.
33 public function __construct(CommentRepo $commentRepo)
35 $this->commentRepo = $commentRepo;
36 parent::__construct();
40 * Execute the console command.
44 public function handle()
46 $connection = \DB::getDefaultConnection();
47 if ($this->option('database') !== null) {
48 \DB::setDefaultConnection($this->option('database'));
51 Comment::query()->chunk(100, function ($comments) {
52 foreach ($comments as $comment) {
53 $comment->html = $this->commentRepo->commentToHtml($comment->text);
58 \DB::setDefaultConnection($connection);
59 $this->comment('Comment HTML content has been regenerated');