]> BookStack Code Mirror - bookstack/blob - app/Console/Commands/RegenerateReferences.php
Extracted shortcut text to language files
[bookstack] / app / Console / Commands / RegenerateReferences.php
1 <?php
2
3 namespace BookStack\Console\Commands;
4
5 use BookStack\References\ReferenceStore;
6 use Illuminate\Console\Command;
7 use Illuminate\Support\Facades\DB;
8
9 class RegenerateReferences extends Command
10 {
11     /**
12      * The name and signature of the console command.
13      *
14      * @var string
15      */
16     protected $signature = 'bookstack:regenerate-references {--database= : The database connection to use.}';
17
18     /**
19      * The console command description.
20      *
21      * @var string
22      */
23     protected $description = 'Regenerate all the cross-item model reference index';
24
25     protected ReferenceStore $references;
26
27     /**
28      * Create a new command instance.
29      *
30      * @return void
31      */
32     public function __construct(ReferenceStore $references)
33     {
34         $this->references = $references;
35         parent::__construct();
36     }
37
38     /**
39      * Execute the console command.
40      *
41      * @return int
42      */
43     public function handle()
44     {
45         $connection = DB::getDefaultConnection();
46
47         if ($this->option('database')) {
48             DB::setDefaultConnection($this->option('database'));
49         }
50
51         $this->references->updateForAllPages();
52
53         DB::setDefaultConnection($connection);
54
55         $this->comment('References have been regenerated');
56
57         return 0;
58     }
59 }