2017-03-19 08:48:44 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2020-11-21 19:17:45 -05:00
|
|
|
use BookStack\Entities\Tools\SearchIndex;
|
2017-03-19 08:48:44 -04:00
|
|
|
use Illuminate\Console\Command;
|
2021-09-26 10:48:22 -04:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2017-03-19 08:48:44 -04:00
|
|
|
|
|
|
|
class RegenerateSearch extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-03-26 14:24:57 -04:00
|
|
|
protected $signature = 'bookstack:regenerate-search {--database= : The database connection to use.}';
|
2017-03-19 08:48:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2017-10-01 12:51:59 -04:00
|
|
|
protected $description = 'Re-index all content for searching';
|
2017-03-19 08:48:44 -04:00
|
|
|
|
2020-11-21 19:17:45 -05:00
|
|
|
protected $searchIndex;
|
2017-03-19 08:48:44 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*/
|
2020-11-21 19:17:45 -05:00
|
|
|
public function __construct(SearchIndex $searchIndex)
|
2017-03-19 08:48:44 -04:00
|
|
|
{
|
|
|
|
parent::__construct();
|
2020-11-21 19:17:45 -05:00
|
|
|
$this->searchIndex = $searchIndex;
|
2017-03-19 08:48:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2020-04-09 11:58:40 -04:00
|
|
|
$connection = DB::getDefaultConnection();
|
2017-03-26 14:24:57 -04:00
|
|
|
if ($this->option('database') !== null) {
|
2020-04-09 11:58:40 -04:00
|
|
|
DB::setDefaultConnection($this->option('database'));
|
2017-03-26 14:24:57 -04:00
|
|
|
}
|
|
|
|
|
2020-11-21 19:17:45 -05:00
|
|
|
$this->searchIndex->indexAllEntities();
|
2020-04-09 11:58:40 -04:00
|
|
|
DB::setDefaultConnection($connection);
|
2017-03-26 14:24:57 -04:00
|
|
|
$this->comment('Search index regenerated');
|
2017-03-19 08:48:44 -04:00
|
|
|
}
|
|
|
|
}
|