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;
|
|
|
|
|
2023-05-24 20:21:46 +08:00
|
|
|
class RegenerateReferencesCommand extends Command
|
2022-08-17 21:39:53 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-05-24 19:59:50 +08:00
|
|
|
protected $signature = 'bookstack:regenerate-references
|
|
|
|
{--database= : The database connection to use}';
|
2022-08-17 21:39:53 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Regenerate all the cross-item model reference index';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*/
|
2023-05-24 19:59:50 +08:00
|
|
|
public function handle(ReferenceStore $references): int
|
2022-08-17 21:39:53 +08:00
|
|
|
{
|
|
|
|
$connection = DB::getDefaultConnection();
|
|
|
|
|
|
|
|
if ($this->option('database')) {
|
|
|
|
DB::setDefaultConnection($this->option('database'));
|
|
|
|
}
|
|
|
|
|
2023-12-19 00:23:40 +08:00
|
|
|
$references->updateForAll();
|
2022-08-17 21:39:53 +08:00
|
|
|
|
|
|
|
DB::setDefaultConnection($connection);
|
|
|
|
|
|
|
|
$this->comment('References have been regenerated');
|
2022-08-30 00:46:41 +08:00
|
|
|
|
2022-08-17 21:39:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|