Skip to content

Commit daf0b84

Browse files
committed
Entities: Got most queries back to working order
1 parent 1bd0dda commit daf0b84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+148
-142
lines changed

app/Console/Commands/UpdateUrlCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ public function handle(Connection $db): int
4545

4646
$columnsToUpdateByTable = [
4747
'attachments' => ['path'],
48-
'pages' => ['html', 'text', 'markdown'],
49-
'chapters' => ['description_html'],
50-
'books' => ['description_html'],
51-
'bookshelves' => ['description_html'],
48+
'entity_page_contents' => ['html', 'text', 'markdown'],
49+
'entity_container_contents' => ['description_html'],
5250
'page_revisions' => ['html', 'text', 'markdown'],
5351
'images' => ['url'],
5452
'settings' => ['value'],

app/Entities/Controllers/BookApiController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ protected function forJsonDisplay(Book $book): Book
124124

125125
$book->load(['tags']);
126126
$book->makeVisible(['cover', 'description_html'])
127-
->setAttribute('description_html', $book->description()->getHtml())
128-
->setAttribute('cover', $book->cover()->getImage());
127+
->setAttribute('description_html', $book->descriptionInfo()->getHtml())
128+
->setAttribute('cover', $book->coverInfo()->getImage());
129129

130130
return $book;
131131
}

app/Entities/Controllers/BookshelfApiController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ protected function forJsonDisplay(Bookshelf $shelf): Bookshelf
118118

119119
$shelf->load(['tags']);
120120
$shelf->makeVisible(['cover', 'description_html'])
121-
->setAttribute('description_html', $shelf->description()->getHtml())
122-
->setAttribute('cover', $shelf->cover()->getImage());
121+
->setAttribute('description_html', $shelf->descriptionInfo()->getHtml())
122+
->setAttribute('cover', $shelf->coverInfo()->getImage());
123123

124124
return $shelf;
125125
}

app/Entities/Controllers/BookshelfController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ public function show(Request $request, ActivityQueries $activities, string $slug
116116
]);
117117

118118
$sort = $listOptions->getSort();
119+
119120
$sortedVisibleShelfBooks = $shelf->visibleBooks()
120121
->reorder($sort === 'default' ? 'order' : $sort, $listOptions->getOrder())
121122
->get()

app/Entities/Controllers/ChapterApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ protected function forJsonDisplay(Chapter $chapter): Chapter
144144

145145
$chapter->load(['tags']);
146146
$chapter->makeVisible('description_html');
147-
$chapter->setAttribute('description_html', $chapter->description()->getHtml());
147+
$chapter->setAttribute('description_html', $chapter->descriptionInfo()->getHtml());
148148

149149
/** @var Book $book */
150150
$book = $chapter->book()->first();

app/Entities/Models/Book.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use BookStack\Entities\Tools\EntityCover;
66
use BookStack\Entities\Tools\EntityDefaultTemplate;
77
use BookStack\Sorting\SortRule;
8+
use BookStack\Uploads\Image;
89
use Illuminate\Database\Eloquent\Factories\HasFactory;
910
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1011
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
@@ -42,11 +43,6 @@ public function getUrl(string $path = ''): string
4243
return url('/books/' . implode('/', [urlencode($this->slug), trim($path, '/')]));
4344
}
4445

45-
public function cover(): EntityCover
46-
{
47-
return new EntityCover($this);
48-
}
49-
5046
/**
5147
* Get all pages within this book.
5248
* @return HasMany<Page, $this>
@@ -97,6 +93,16 @@ public function defaultTemplate(): EntityDefaultTemplate
9793
return new EntityDefaultTemplate($this);
9894
}
9995

96+
public function cover(): BelongsTo
97+
{
98+
return $this->belongsTo(Image::class, 'image_id');
99+
}
100+
101+
public function coverInfo(): EntityCover
102+
{
103+
return new EntityCover($this);
104+
}
105+
100106
/**
101107
* Get the sort rule assigned to this container, if existing.
102108
*/

app/Entities/Models/Bookshelf.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace BookStack\Entities\Models;
44

55
use BookStack\Entities\Tools\EntityCover;
6+
use BookStack\Uploads\Image;
67
use Illuminate\Database\Eloquent\Factories\HasFactory;
8+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
79
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
810

911
/**
@@ -26,6 +28,7 @@ class Bookshelf extends Entity implements HasDescriptionInterface, HasCoverInter
2628
public function books(): BelongsToMany
2729
{
2830
return $this->belongsToMany(Book::class, 'bookshelves_books', 'bookshelf_id', 'book_id')
31+
->select(['entities.*', 'entity_container_contents.*'])
2932
->withPivot('order')
3033
->orderBy('order', 'asc');
3134
}
@@ -67,8 +70,13 @@ public function appendBook(Book $book): void
6770
$this->books()->attach($book->id, ['order' => $maxOrder + 1]);
6871
}
6972

70-
public function cover(): EntityCover
73+
public function coverInfo(): EntityCover
7174
{
7275
return new EntityCover($this);
7376
}
77+
78+
public function cover(): BelongsTo
79+
{
80+
return $this->belongsTo(Image::class, 'image_id');
81+
}
7482
}

app/Entities/Models/ContainerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
trait ContainerTrait
1212
{
13-
public function description(): EntityHtmlDescription
13+
public function descriptionInfo(): EntityHtmlDescription
1414
{
1515
return new EntityHtmlDescription($this);
1616
}

app/Entities/Models/Entity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public function getParent(): ?self
373373
{
374374
if ($this instanceof Page) {
375375
/** @var BelongsTo<Chapter|Book, Page> $builder */
376-
$builder = $this->pageData->chapter_id ? $this->chapter() : $this->book();
376+
$builder = $this->chapter_id ? $this->chapter() : $this->book();
377377
return $builder->withTrashed()->first();
378378
}
379379
if ($this instanceof Chapter) {

app/Entities/Models/HasCoverInterface.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33
namespace BookStack\Entities\Models;
44

55
use BookStack\Entities\Tools\EntityCover;
6+
use BookStack\Uploads\Image;
7+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
68

79
interface HasCoverInterface
810
{
9-
public function cover(): EntityCover;
11+
public function coverInfo(): EntityCover;
12+
13+
/**
14+
* The cover image of this entity.
15+
* @return BelongsTo<Image, $this>
16+
*/
17+
public function cover(): BelongsTo;
1018
}

0 commit comments

Comments
 (0)