]> BookStack Code Mirror - bookstack/commitdiff
Moved shelf book append logic
authorDan Brown <redacted>
Thu, 19 Sep 2019 17:20:09 +0000 (18:20 +0100)
committerDan Brown <redacted>
Thu, 19 Sep 2019 17:20:09 +0000 (18:20 +0100)
app/Entities/Bookshelf.php
app/Entities/Repos/BookRepo.php
app/Http/Controllers/BookController.php

index 745611ba782704adc4bd30831081699e4cb6685c..1db348b6bc3c830ba306e6b71ed2f8d4ea4f6279 100644 (file)
@@ -104,4 +104,18 @@ class Bookshelf extends Entity
     {
         return $this->books()->where('id', '=', $book->id)->count() > 0;
     }
+
+    /**
+     * Add a book to the end of this shelf.
+     * @param Book $book
+     */
+    public function appendBook(Book $book)
+    {
+       if (!$this->contains($book)) {
+           return;
+       }
+
+       $maxOrder = $this->books()->max('order');
+       $this->books()->attach($book->id, ['order' => $maxOrder + 1]);
+    }
 }
index c82780fea39d4399b24034fd9f7deaf78e401863..91bc9a1b41eebafb74cfe8aeaae1ff0344528d86 100644 (file)
@@ -3,9 +3,7 @@
 
 namespace BookStack\Entities\Repos;
 
-
 use BookStack\Entities\Book;
-use BookStack\Entities\Bookshelf;
 use BookStack\Exceptions\NotFoundException;
 use BookStack\Exceptions\NotifyException;
 
@@ -25,21 +23,6 @@ class BookRepo extends EntityRepo
         return $book;
     }
 
-    /**
-     * Append a Book to a BookShelf.
-     * @param Bookshelf $shelf
-     * @param Book $book
-     */
-    public function appendBookToShelf(Bookshelf $shelf, Book $book)
-    {
-        if ($shelf->contains($book)) {
-            return;
-        }
-
-        $maxOrder = $shelf->books()->max('order');
-        $shelf->books()->attach($book->id, ['order' => $maxOrder + 1]);
-    }
-
     /**
      * Destroy the provided book and all its child entities.
      * @param Book $book
index 1f9caf75641aa6c885b975946f1dcd51ec3d91f2..1a787203034153f650a5d267113e0a2cc068670b 100644 (file)
@@ -3,10 +3,9 @@
 use Activity;
 use BookStack\Auth\UserRepo;
 use BookStack\Entities\Book;
+use BookStack\Entities\Bookshelf;
 use BookStack\Entities\EntityContextManager;
 use BookStack\Entities\Repos\BookRepo;
-use BookStack\Entities\Repos\EntityRepo;
-use BookStack\Entities\ExportService;
 use BookStack\Exceptions\ImageUploadException;
 use BookStack\Exceptions\NotFoundException;
 use BookStack\Exceptions\NotifyException;
@@ -121,16 +120,18 @@ class BookController extends Controller
 
         $bookshelf = null;
         if ($shelfSlug !== null) {
+            /** @var Bookshelf $bookshelf */
             $bookshelf = $this->bookRepo->getEntityBySlug('bookshelf', $shelfSlug);
             $this->checkOwnablePermission('bookshelf-update', $bookshelf);
         }
 
+        /** @var Book $book */
         $book = $this->bookRepo->createFromInput('book', $request->all());
         $this->bookUpdateActions($book, $request);
         Activity::add($book, 'book_create', $book->id);
 
         if ($bookshelf) {
-            $this->bookRepo->appendBookToShelf($bookshelf, $book);
+            $bookshelf->appendBook($book);
             Activity::add($bookshelf, 'bookshelf_update');
         }