mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-07 23:03:00 +03:00
Organised activity types and moved most to repos
Repos are generally better since otherwise we end up duplicating things between front-end and API. Types moved to by CONST values within a class for better visibilty of usage and listing of types.
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
<?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\Exceptions\MoveOperationException;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
use BookStack\Facades\Activity;
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -46,6 +48,7 @@ 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);
|
||||
return $chapter;
|
||||
}
|
||||
|
||||
@@ -55,6 +58,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -74,6 +78,7 @@ class ChapterRepo
|
||||
{
|
||||
$trashCan = new TrashCan();
|
||||
$trashCan->softDestroyChapter($chapter);
|
||||
Activity::add($chapter, ActivityType::CHAPTER_DELETE, $chapter->book->id);
|
||||
$trashCan->autoClearOld();
|
||||
}
|
||||
|
||||
@@ -93,6 +98,7 @@ class ChapterRepo
|
||||
throw new MoveOperationException('Chapters can only be moved into books');
|
||||
}
|
||||
|
||||
/** @var Book $parent */
|
||||
$parent = Book::visible()->where('id', '=', $entityId)->first();
|
||||
if ($parent === null) {
|
||||
throw new MoveOperationException('Book to move chapter into not found');
|
||||
@@ -100,6 +106,8 @@ class ChapterRepo
|
||||
|
||||
$chapter->changeBook($parent->id);
|
||||
$chapter->rebuildPermissions();
|
||||
Activity::add($chapter, ActivityType::CHAPTER_MOVE, $parent->id);
|
||||
|
||||
return $parent;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user