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