- // Loop through contents of provided map and update entities accordingly
- foreach ($sortMap as $bookChild) {
- $priority = $bookChild->sort;
- $id = intval($bookChild->id);
- $isPage = $bookChild->type == 'page';
- $bookId = $defaultBookId;
- $targetBook = $this->entityRepo->getById('book', $bookChild->book);
+ // Get the books involved in the sort
+ $bookIdsInvolved = $bookIdsInvolved->unique()->toArray();
+ $booksInvolved = $this->entityRepo->book->newQuery()->whereIn('id', $bookIdsInvolved)->get();
+ // Throw permission error if invalid ids or inaccessible books given.
+ if (count($bookIdsInvolved) !== count($booksInvolved)) {
+ $this->showPermissionError();
+ }
+ // Check permissions of involved books
+ $booksInvolved->each(function (Book $book) {
+ $this->checkOwnablePermission('book-update', $book);
+ });