1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Added reference storage system, and command to re-index

Also re-named/orgranized some files for this, to make them "References"
specific instead of a subset of "Util".
This commit is contained in:
Dan Brown
2022-08-17 14:39:53 +01:00
parent 344b3a3615
commit 5d29d0cc7b
15 changed files with 253 additions and 23 deletions

View File

@ -5,6 +5,7 @@ namespace BookStack\Console\Commands;
use BookStack\Actions\Comment;
use BookStack\Actions\CommentRepo;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class RegenerateCommentContent extends Command
{
@ -43,9 +44,9 @@ class RegenerateCommentContent extends Command
*/
public function handle()
{
$connection = \DB::getDefaultConnection();
$connection = DB::getDefaultConnection();
if ($this->option('database') !== null) {
\DB::setDefaultConnection($this->option('database'));
DB::setDefaultConnection($this->option('database'));
}
Comment::query()->chunk(100, function ($comments) {
@ -55,7 +56,8 @@ class RegenerateCommentContent extends Command
}
});
\DB::setDefaultConnection($connection);
DB::setDefaultConnection($connection);
$this->comment('Comment HTML content has been regenerated');
return 0;
}
}

View File

@ -50,5 +50,6 @@ class RegeneratePermissions extends Command
DB::setDefaultConnection($connection);
$this->comment('Permissions regenerated');
return 0;
}
}

View File

@ -0,0 +1,58 @@
<?php
namespace BookStack\Console\Commands;
use BookStack\References\ReferenceService;
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 ReferenceService $references;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(ReferenceService $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;
}
}