]> BookStack Code Mirror - bookstack/blob - app/Entities/Repos/BookRepo.php
Fix Book form (create) returning to the full books list on cancel
[bookstack] / app / Entities / Repos / BookRepo.php
1 <?php
2
3
4 namespace BookStack\Entities\Repos;
5
6 use BookStack\Entities\Book;
7 use BookStack\Exceptions\NotFoundException;
8 use BookStack\Exceptions\NotifyException;
9
10 class BookRepo extends EntityRepo
11 {
12
13     /**
14      * Fetch a book by its slug.
15      * @param string $slug
16      * @return Book
17      * @throws NotFoundException
18      */
19     public function getBySlug(string $slug): Book
20     {
21         /** @var Book $book */
22         $book = $this->getEntityBySlug('book', $slug);
23         return $book;
24     }
25
26     /**
27      * Destroy the provided book and all its child entities.
28      * @param Book $book
29      * @throws NotifyException
30      * @throws \Throwable
31      */
32     public function destroyBook(Book $book)
33     {
34         foreach ($book->pages as $page) {
35             $this->destroyPage($page);
36         }
37
38         foreach ($book->chapters as $chapter) {
39             $this->destroyChapter($chapter);
40         }
41
42         $this->destroyEntityCommonRelations($book);
43         $book->delete();
44     }
45
46 }