]> BookStack Code Mirror - bookstack/blob - app/Console/Commands/RegenerateSearch.php
Fixes for CodeStyle vol.2
[bookstack] / app / Console / Commands / RegenerateSearch.php
1 <?php
2
3 namespace BookStack\Console\Commands;
4
5 use BookStack\Entities\Tools\SearchIndex;
6 use DB;
7 use Illuminate\Console\Command;
8
9 class RegenerateSearch extends Command
10 {
11     /**
12      * The name and signature of the console command.
13      *
14      * @var string
15      */
16     protected $signature = 'bookstack:regenerate-search {--database= : The database connection to use.}';
17
18     /**
19      * The console command description.
20      *
21      * @var string
22      */
23     protected $description = 'Re-index all content for searching';
24
25     protected $searchIndex;
26
27     /**
28      * Create a new command instance.
29      */
30     public function __construct(SearchIndex $searchIndex)
31     {
32         parent::__construct();
33         $this->searchIndex = $searchIndex;
34     }
35
36     /**
37      * Execute the console command.
38      *
39      * @return mixed
40      */
41     public function handle()
42     {
43         $connection = DB::getDefaultConnection();
44         if ($this->option('database') !== null) {
45             DB::setDefaultConnection($this->option('database'));
46         }
47
48         $this->searchIndex->indexAllEntities();
49         DB::setDefaultConnection($connection);
50         $this->comment('Search index regenerated');
51     }
52 }