2017-03-19 13:48:44 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2018-09-25 13:30:50 +02:00
|
|
|
use BookStack\Entities\SearchService;
|
2017-03-19 13:48:44 +01:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
class RegenerateSearch extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-03-26 20:24:57 +02:00
|
|
|
protected $signature = 'bookstack:regenerate-search {--database= : The database connection to use.}';
|
2017-03-19 13:48:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-10-01 18:51:59 +02:00
|
|
|
protected $description = 'Re-index all content for searching';
|
2017-03-19 13:48:44 +01:00
|
|
|
|
|
|
|
protected $searchService;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
2018-09-25 13:30:50 +02:00
|
|
|
* @param \BookStack\Entities\SearchService $searchService
|
2017-03-19 13:48:44 +01:00
|
|
|
*/
|
|
|
|
public function __construct(SearchService $searchService)
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->searchService = $searchService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2017-03-26 20:24:57 +02:00
|
|
|
$connection = \DB::getDefaultConnection();
|
|
|
|
if ($this->option('database') !== null) {
|
|
|
|
\DB::setDefaultConnection($this->option('database'));
|
2017-04-30 12:38:58 +02:00
|
|
|
$this->searchService->setConnection(\DB::connection($this->option('database')));
|
2017-03-26 20:24:57 +02:00
|
|
|
}
|
|
|
|
|
2017-03-19 13:48:44 +01:00
|
|
|
$this->searchService->indexAllEntities();
|
2017-03-26 20:24:57 +02:00
|
|
|
\DB::setDefaultConnection($connection);
|
|
|
|
$this->comment('Search index regenerated');
|
2017-03-19 13:48:44 +01:00
|
|
|
}
|
|
|
|
}
|