]> BookStack Code Mirror - bookstack/blob - app/Console/Commands/RegenerateReferencesCommand.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Console / Commands / RegenerateReferencesCommand.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 RegenerateReferencesCommand extends Command
10 {
11     /**
12      * The name and signature of the console command.
13      *
14      * @var string
15      */
16     protected $signature = 'bookstack:regenerate-references
17                             {--database= : The database connection to use}';
18
19     /**
20      * The console command description.
21      *
22      * @var string
23      */
24     protected $description = 'Regenerate all the cross-item model reference index';
25
26     /**
27      * Execute the console command.
28      */
29     public function handle(ReferenceStore $references): int
30     {
31         $connection = DB::getDefaultConnection();
32
33         if ($this->option('database')) {
34             DB::setDefaultConnection($this->option('database'));
35         }
36
37         $references->updateForAll();
38
39         DB::setDefaultConnection($connection);
40
41         $this->comment('References have been regenerated');
42
43         return 0;
44     }
45 }