2022-08-17 09:39:53 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2022-08-20 07:07:38 -04:00
|
|
|
use BookStack\References\ReferenceStore;
|
2022-08-17 09:39:53 -04:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
2023-05-24 08:21:46 -04:00
|
|
|
class RegenerateReferencesCommand extends Command
|
2022-08-17 09:39:53 -04:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-05-24 07:59:50 -04:00
|
|
|
protected $signature = 'bookstack:regenerate-references
|
|
|
|
{--database= : The database connection to use}';
|
2022-08-17 09:39:53 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Regenerate all the cross-item model reference index';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*/
|
2023-05-24 07:59:50 -04:00
|
|
|
public function handle(ReferenceStore $references): int
|
2022-08-17 09:39:53 -04:00
|
|
|
{
|
|
|
|
$connection = DB::getDefaultConnection();
|
|
|
|
|
|
|
|
if ($this->option('database')) {
|
|
|
|
DB::setDefaultConnection($this->option('database'));
|
|
|
|
}
|
|
|
|
|
2023-05-24 07:59:50 -04:00
|
|
|
$references->updateForAllPages();
|
2022-08-17 09:39:53 -04:00
|
|
|
|
|
|
|
DB::setDefaultConnection($connection);
|
|
|
|
|
|
|
|
$this->comment('References have been regenerated');
|
2022-08-29 12:46:41 -04:00
|
|
|
|
2022-08-17 09:39:53 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|