]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Repos/ChapterRepo.php
Add unit test for ip addess searching
[bookstack] / app / Entities / Repos / ChapterRepo.php
index 581da1fa3e06614101a12aa58d782979f024ab0f..68330dd57bf5a02135db0765280fccd730e09bbe 100644 (file)
@@ -1,19 +1,19 @@
-<?php namespace BookStack\Entities\Repos;
+<?php
+
+namespace BookStack\Entities\Repos;
 
 use BookStack\Actions\ActivityType;
-use BookStack\Entities\Book;
-use BookStack\Entities\Chapter;
-use BookStack\Entities\Managers\BookContents;
-use BookStack\Entities\Managers\TrashCan;
+use BookStack\Entities\Models\Book;
+use BookStack\Entities\Models\Chapter;
+use BookStack\Entities\Tools\BookContents;
+use BookStack\Entities\Tools\TrashCan;
 use BookStack\Exceptions\MoveOperationException;
 use BookStack\Exceptions\NotFoundException;
 use BookStack\Facades\Activity;
 use Exception;
-use Illuminate\Support\Collection;
 
 class ChapterRepo
 {
-
     protected $baseRepo;
 
     /**
@@ -26,6 +26,7 @@ class ChapterRepo
 
     /**
      * Get a chapter via the slug.
+     *
      * @throws NotFoundException
      */
     public function getBySlug(string $bookSlug, string $chapterSlug): Chapter
@@ -48,7 +49,8 @@ class ChapterRepo
         $chapter->book_id = $parentBook->id;
         $chapter->priority = (new BookContents($parentBook))->getLastPriority() + 1;
         $this->baseRepo->create($chapter, $input);
-        Activity::add($chapter, ActivityType::CHAPTER_CREATE, $parentBook->id);
+        Activity::addForEntity($chapter, ActivityType::CHAPTER_CREATE);
+
         return $chapter;
     }
 
@@ -58,34 +60,29 @@ class ChapterRepo
     public function update(Chapter $chapter, array $input): Chapter
     {
         $this->baseRepo->update($chapter, $input);
-        Activity::add($chapter, ActivityType::CHAPTER_UPDATE, $chapter->book->id);
-        return $chapter;
-    }
+        Activity::addForEntity($chapter, ActivityType::CHAPTER_UPDATE);
 
-    /**
-     * Update the permissions of a chapter.
-     */
-    public function updatePermissions(Chapter $chapter, bool $restricted, Collection $permissions = null)
-    {
-        $this->baseRepo->updatePermissions($chapter, $restricted, $permissions);
+        return $chapter;
     }
 
     /**
      * Remove a chapter from the system.
+     *
      * @throws Exception
      */
     public function destroy(Chapter $chapter)
     {
         $trashCan = new TrashCan();
         $trashCan->softDestroyChapter($chapter);
-        Activity::add($chapter, ActivityType::CHAPTER_DELETE, $chapter->book->id);
+        Activity::addForEntity($chapter, ActivityType::CHAPTER_DELETE);
         $trashCan->autoClearOld();
     }
 
     /**
      * Move the given chapter into a new parent book.
      * The $parentIdentifier must be a string of the following format:
-     * 'book:<id>' (book:5)
+     * 'book:<id>' (book:5).
+     *
      * @throws MoveOperationException
      */
     public function move(Chapter $chapter, string $parentIdentifier): Book
@@ -106,7 +103,7 @@ class ChapterRepo
 
         $chapter->changeBook($parent->id);
         $chapter->rebuildPermissions();
-        Activity::add($chapter, ActivityType::CHAPTER_MOVE, $parent->id);
+        Activity::addForEntity($chapter, ActivityType::CHAPTER_MOVE);
 
         return $parent;
     }