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 RegenerateCommentContent extends Command
13 * The name and signature of the console command.
17 protected $signature = 'bookstack:regenerate-comment-content {--database= : The database connection to use.}';
20 * The console command description.
24 protected $description = 'Regenerate the stored HTML of all comments';
29 protected $commentRepo;
32 * Create a new command instance.
34 public function __construct(CommentRepo $commentRepo)
36 $this->commentRepo = $commentRepo;
37 parent::__construct();
41 * Execute the console command.
45 public function handle()
47 $connection = DB::getDefaultConnection();
48 if ($this->option('database') !== null) {
49 DB::setDefaultConnection($this->option('database'));
52 Comment::query()->chunk(100, function ($comments) {
53 foreach ($comments as $comment) {
54 $comment->html = $this->commentRepo->commentToHtml($comment->text);
59 DB::setDefaultConnection($connection);
60 $this->comment('Comment HTML content has been regenerated');