diff --git a/app/References/ModelResolvers/BookLinkModelResolver.php b/app/References/ModelResolvers/BookLinkModelResolver.php index f33d97b84..459b13644 100644 --- a/app/References/ModelResolvers/BookLinkModelResolver.php +++ b/app/References/ModelResolvers/BookLinkModelResolver.php @@ -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; } diff --git a/app/References/ModelResolvers/BookshelfLinkModelResolver.php b/app/References/ModelResolvers/BookshelfLinkModelResolver.php index ca5b8ca5f..7d1636689 100644 --- a/app/References/ModelResolvers/BookshelfLinkModelResolver.php +++ b/app/References/ModelResolvers/BookshelfLinkModelResolver.php @@ -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; } diff --git a/app/References/ModelResolvers/ChapterLinkModelResolver.php b/app/References/ModelResolvers/ChapterLinkModelResolver.php index e15dba258..fbe75c4f6 100644 --- a/app/References/ModelResolvers/ChapterLinkModelResolver.php +++ b/app/References/ModelResolvers/ChapterLinkModelResolver.php @@ -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; } diff --git a/app/References/ModelResolvers/PageLinkModelResolver.php b/app/References/ModelResolvers/PageLinkModelResolver.php index f22f2734b..ead17e0a9 100644 --- a/app/References/ModelResolvers/PageLinkModelResolver.php +++ b/app/References/ModelResolvers/PageLinkModelResolver.php @@ -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; } diff --git a/app/References/ModelResolvers/PagePermalinkModelResolver.php b/app/References/ModelResolvers/PagePermalinkModelResolver.php index 45396d54a..d59d41925 100644 --- a/app/References/ModelResolvers/PagePermalinkModelResolver.php +++ b/app/References/ModelResolvers/PagePermalinkModelResolver.php @@ -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; } diff --git a/app/References/ReferenceService.php b/app/References/ReferenceService.php index 7a1cf2fed..fd7f74ae1 100644 --- a/app/References/ReferenceService.php +++ b/app/References/ReferenceService.php @@ -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()); diff --git a/tests/Commands/RegenerateReferencesCommandTest.php b/tests/Commands/RegenerateReferencesCommandTest.php new file mode 100644 index 000000000..8906474af --- /dev/null +++ b/tests/Commands/RegenerateReferencesCommandTest.php @@ -0,0 +1,32 @@ +first(); + $book = $page->book; + + $page->html = 'Book Link'; + $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(), + ]); + } +}