]> BookStack Code Mirror - bookstack/blob - app/Console/Commands/RegenerateSearch.php
move zip export into exportservice
[bookstack] / app / Console / Commands / RegenerateSearch.php
1 <?php
2
3 namespace BookStack\Console\Commands;
4
5 use BookStack\Entities\SearchService;
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 $searchService;
26
27     /**
28      * Create a new command instance.
29      *
30      * @param SearchService $searchService
31      */
32     public function __construct(SearchService $searchService)
33     {
34         parent::__construct();
35         $this->searchService = $searchService;
36     }
37
38     /**
39      * Execute the console command.
40      *
41      * @return mixed
42      */
43     public function handle()
44     {
45         $connection = DB::getDefaultConnection();
46         if ($this->option('database') !== null) {
47             DB::setDefaultConnection($this->option('database'));
48             $this->searchService->setConnection(DB::connection($this->option('database')));
49         }
50
51         $this->searchService->indexAllEntities();
52         DB::setDefaultConnection($connection);
53         $this->comment('Search index regenerated');
54     }
55 }