mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-01-22 21:22:00 +08:00
f634b4ea57
Not totally happy with implementation as is requires extra service to be injected to core controllers, but does the job. Included test to cover. Updated some controller properties to be typed while there.
59 lines
1.3 KiB
PHP
59 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
use BookStack\References\ReferenceStore;
|
|
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';
|
|
|
|
protected ReferenceStore $references;
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(ReferenceStore $references)
|
|
{
|
|
$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;
|
|
}
|
|
}
|