2022-08-17 21:39:53 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2022-08-20 19:07:38 +08:00
|
|
|
use BookStack\References\ReferenceStore;
|
2022-08-17 21:39:53 +08:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class RegenerateReferences extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'bookstack:regenerate-references {--database= : The database connection to use.}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Regenerate all the cross-item model reference index';
|
|
|
|
|
2022-08-20 19:07:38 +08:00
|
|
|
protected ReferenceStore $references;
|
2022-08-17 21:39:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-08-20 19:07:38 +08:00
|
|
|
public function __construct(ReferenceStore $references)
|
2022-08-17 21:39:53 +08:00
|
|
|
{
|
|
|
|
$this->references = $references;
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$connection = DB::getDefaultConnection();
|
|
|
|
|
|
|
|
if ($this->option('database')) {
|
|
|
|
DB::setDefaultConnection($this->option('database'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->references->updateForAllPages();
|
|
|
|
|
|
|
|
DB::setDefaultConnection($connection);
|
|
|
|
|
|
|
|
$this->comment('References have been regenerated');
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|