mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-29 23:22:34 +01:00
Added regenerate-references command test
Also updated model resolvers to only fetch model ID, to prevent bringing back way more data from database than desired.
This commit is contained in:
parent
5d29d0cc7b
commit
3290ab3ac9
@ -19,7 +19,7 @@ class BookLinkModelResolver implements CrossLinkModelResolver
|
||||
$bookSlug = $matches[1];
|
||||
|
||||
/** @var ?Book $model */
|
||||
$model = Book::query()->where('slug', '=', $bookSlug)->first();
|
||||
$model = Book::query()->where('slug', '=', $bookSlug)->first(['id']);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class BookshelfLinkModelResolver implements CrossLinkModelResolver
|
||||
$shelfSlug = $matches[1];
|
||||
|
||||
/** @var ?Bookshelf $model */
|
||||
$model = Bookshelf::query()->where('slug', '=', $shelfSlug)->first();
|
||||
$model = Bookshelf::query()->where('slug', '=', $shelfSlug)->first(['id']);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class ChapterLinkModelResolver implements CrossLinkModelResolver
|
||||
$chapterSlug = $matches[2];
|
||||
|
||||
/** @var ?Chapter $model */
|
||||
$model = Chapter::query()->whereSlugs($bookSlug, $chapterSlug)->first();
|
||||
$model = Chapter::query()->whereSlugs($bookSlug, $chapterSlug)->first(['id']);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class PageLinkModelResolver implements CrossLinkModelResolver
|
||||
$pageSlug = $matches[2];
|
||||
|
||||
/** @var ?Page $model */
|
||||
$model = Page::query()->whereSlugs($bookSlug, $pageSlug)->first();
|
||||
$model = Page::query()->whereSlugs($bookSlug, $pageSlug)->first(['id']);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ class PagePermalinkModelResolver implements CrossLinkModelResolver
|
||||
|
||||
$id = intval($matches[1]);
|
||||
/** @var ?Page $model */
|
||||
$model = Page::query()->find($id);
|
||||
$model = Page::query()->find($id, ['id']);
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class ReferenceService
|
||||
{
|
||||
Reference::query()
|
||||
->where('from_type', '=', (new Page())->getMorphClass())
|
||||
->truncate();
|
||||
->delete();
|
||||
|
||||
Page::query()->select(['id', 'html'])->chunk(100, function(Collection $pages) {
|
||||
$this->updateForPages($pages->all());
|
||||
|
32
tests/Commands/RegenerateReferencesCommandTest.php
Normal file
32
tests/Commands/RegenerateReferencesCommandTest.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Commands;
|
||||
|
||||
use BookStack\Entities\Models\Page;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RegenerateReferencesCommandTest extends TestCase
|
||||
{
|
||||
public function test_regenerate_references_command()
|
||||
{
|
||||
/** @var Page $page */
|
||||
$page = Page::query()->first();
|
||||
$book = $page->book;
|
||||
|
||||
$page->html = '<a href="' . $book->getUrl() . '">Book Link</a>';
|
||||
$page->save();
|
||||
|
||||
DB::table('references')->delete();
|
||||
|
||||
$this->artisan('bookstack:regenerate-references')
|
||||
->assertExitCode(0);
|
||||
|
||||
$this->assertDatabaseHas('references', [
|
||||
'from_id' => $page->id,
|
||||
'from_type' => $page->getMorphClass(),
|
||||
'to_id' => $book->id,
|
||||
'to_type' => $book->getMorphClass(),
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user