use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListingResponseBuilder
{
- protected $query;
- protected $request;
- protected $fields;
+ protected Builder $query;
+ protected Request $request;
+
+ /**
+ * @var string[]
+ */
+ protected array $fields;
/**
* @var array<callable>
*/
- protected $resultModifiers = [];
+ protected array $resultModifiers = [];
- protected $filterOperators = [
+ /**
+ * @var array<string, string>
+ */
+ protected array $filterOperators = [
'eq' => '=',
'ne' => '!=',
'gt' => '>',
/**
* Add a callback to modify each element of the results.
*
- * @param (callable(Model)) $modifier
+ * @param (callable(Model): void) $modifier
*/
- public function modifyResults($modifier): void
+ public function modifyResults(callable $modifier): void
{
$this->resultModifiers[] = $modifier;
}
/**
* @var array<string, array<int, SimpleEntityData>>
*/
- protected $entityCache;
+ protected array $entityCache;
/**
* Re-generate all entity permission from scratch.
/**
* Create & Save entity jointPermissions for many entities and roles.
*
- * @param Entity[] $entities
+ * @param Entity[] $originalEntities
* @param Role[] $roles
*/
protected function createManyJointPermissions(array $originalEntities, array $roles)
/**
* Get the current revision for the page if existing.
- *
- * @return PageRevision|null
*/
public function currentRevision(): HasOne
{
{
if ($coverImage) {
$imageType = $entity->coverImageTypeKey();
- $this->imageRepo->destroyImage($entity->cover);
+ $this->imageRepo->destroyImage($entity->cover()->first());
$image = $this->imageRepo->saveNew($coverImage, $imageType, $entity->id, 512, 512, true);
$entity->cover()->associate($image);
$entity->save();
}
if ($removeImage) {
- $this->imageRepo->destroyImage($entity->cover);
+ $this->imageRepo->destroyImage($entity->cover()->first());
$entity->image_id = 0;
$entity->save();
}
$model->changeBook($newBook->id);
}
- if ($chapterChanged) {
+ if ($model instanceof Page && $chapterChanged) {
$model->chapter_id = $newChapter->id ?? 0;
}
}
$hasPageEditPermission = userCan('page-update', $model);
- $newParentInRightLocation = ($newParent instanceof Book || $newParent->book_id === $newBook->id);
+ $newParentInRightLocation = ($newParent instanceof Book || ($newParent instanceof Chapter && $newParent->book_id === $newBook->id));
$newParentPermission = ($newParent instanceof Chapter) ? 'chapter-update' : 'book-update';
$hasNewParentPermission = userCan($newParentPermission, $newParent);
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Entity;
+use BookStack\Entities\Models\HasCoverImage;
use BookStack\Entities\Models\Page;
use BookStack\Entities\Repos\BookRepo;
use BookStack\Entities\Repos\ChapterRepo;
$inputData['tags'] = $this->entityTagsToInputArray($entity);
// Add a cover to the data if existing on the original entity
- if ($entity->cover instanceof Image) {
- $uploadedFile = $this->imageToUploadedFile($entity->cover);
- $inputData['image'] = $uploadedFile;
+ if ($entity instanceof HasCoverImage) {
+ $cover = $entity->cover()->first();
+ if ($cover) {
+ $inputData['image'] = $this->imageToUploadedFile($cover);
+ }
}
return $inputData;
namespace BookStack\Http\Controllers;
use BookStack\Actions\ActivityType;
+use BookStack\Entities\Models\PageRevision;
use BookStack\Entities\Repos\PageRepo;
use BookStack\Entities\Tools\PageContent;
use BookStack\Exceptions\NotFoundException;
public function show(string $bookSlug, string $pageSlug, int $revisionId)
{
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
+ /** @var ?PageRevision $revision */
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
if ($revision === null) {
throw new NotFoundException();
public function changes(string $bookSlug, string $pageSlug, int $revisionId)
{
$page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
+ /** @var ?PageRevision $revision */
$revision = $page->revisions()->where('id', '=', $revisionId)->first();
if ($revision === null) {
throw new NotFoundException();
*/
public const HOME = '/';
- /**
- * This namespace is applied to the controller routes in your routes file.
- *
- * In addition, it is set as the URL generator's root namespace.
- *
- * @var string
- */
-
/**
* Define your route model bindings, pattern filters, etc.
*
* The provided count is for each entity to search,
* Total returned could be larger and not guaranteed.
*
- * @return array{total: int, count: int, has_more: bool, results: Entity[]}
+ * @return array{total: int, count: int, has_more: bool, results: Collection<Entity>}
*/
public function searchEntities(SearchOptions $searchOpts, string $entityType = 'all', int $page = 1, int $count = 20): array
{