1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-09 10:22:51 +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:
Dan Brown
2020-11-07 22:37:27 +00:00
parent 4824ef2760
commit c157dc3490
19 changed files with 76 additions and 73 deletions

View File

@@ -1,11 +1,13 @@
<?php namespace BookStack\Entities\Repos;
use BookStack\Actions\ActivityType;
use BookStack\Actions\TagRepo;
use BookStack\Entities\Book;
use BookStack\Entities\Managers\TrashCan;
use BookStack\Exceptions\ImageUploadException;
use BookStack\Exceptions\NotFoundException;
use BookStack\Exceptions\NotifyException;
use BookStack\Facades\Activity;
use BookStack\Uploads\ImageRepo;
use Exception;
use Illuminate\Contracts\Container\BindingResolutionException;
@@ -91,6 +93,7 @@ class BookRepo
{
$book = new Book();
$this->baseRepo->create($book, $input);
Activity::add($book, ActivityType::BOOK_CREATE, $book->id);
return $book;
}
@@ -100,6 +103,7 @@ class BookRepo
public function update(Book $book, array $input): Book
{
$this->baseRepo->update($book, $input);
Activity::add($book, ActivityType::BOOK_UPDATE, $book->id);
return $book;
}
@@ -129,6 +133,8 @@ class BookRepo
{
$trashCan = new TrashCan();
$trashCan->softDestroyBook($book);
Activity::add($book, ActivityType::BOOK_DELETE, $book->id);
$trashCan->autoClearOld();
}
}

View File

@@ -1,10 +1,12 @@
<?php namespace BookStack\Entities\Repos;
use BookStack\Actions\ActivityType;
use BookStack\Entities\Book;
use BookStack\Entities\Bookshelf;
use BookStack\Entities\Managers\TrashCan;
use BookStack\Exceptions\ImageUploadException;
use BookStack\Exceptions\NotFoundException;
use BookStack\Facades\Activity;
use Exception;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\UploadedFile;
@@ -87,11 +89,12 @@ class BookshelfRepo
$shelf = new Bookshelf();
$this->baseRepo->create($shelf, $input);
$this->updateBooks($shelf, $bookIds);
Activity::add($shelf, ActivityType::BOOKSHELF_CREATE);
return $shelf;
}
/**
* Create a new shelf in the system.
* Update an existing shelf in the system using the given input.
*/
public function update(Bookshelf $shelf, array $input, ?array $bookIds): Bookshelf
{
@@ -101,6 +104,7 @@ class BookshelfRepo
$this->updateBooks($shelf, $bookIds);
}
Activity::add($shelf, ActivityType::BOOKSHELF_UPDATE);
return $shelf;
}
@@ -175,6 +179,7 @@ class BookshelfRepo
{
$trashCan = new TrashCan();
$trashCan->softDestroyShelf($shelf);
Activity::add($shelf, ActivityType::BOOKSHELF_DELETE);
$trashCan->autoClearOld();
}
}

View File

@@ -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;
}
}

View File

@@ -1,5 +1,6 @@
<?php namespace BookStack\Entities\Repos;
use BookStack\Actions\ActivityType;
use BookStack\Entities\Book;
use BookStack\Entities\Chapter;
use BookStack\Entities\Entity;
@@ -12,6 +13,7 @@ use BookStack\Exceptions\MoveOperationException;
use BookStack\Exceptions\NotFoundException;
use BookStack\Exceptions\NotifyException;
use BookStack\Exceptions\PermissionsException;
use BookStack\Facades\Activity;
use Exception;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\LengthAwarePaginator;
@@ -165,7 +167,10 @@ class PageRepo
$this->savePageRevision($draft, trans('entities.pages_initial_revision'));
$draft->indexForSearch();
return $draft->refresh();
$draft->refresh();
Activity::add($draft, ActivityType::PAGE_CREATE, $draft->book->id);
return $draft;
}
/**
@@ -203,6 +208,7 @@ class PageRepo
$this->savePageRevision($page, $summary);
}
Activity::add($page, ActivityType::PAGE_UPDATE, $page->book->id);
return $page;
}
@@ -266,6 +272,7 @@ class PageRepo
{
$trashCan = new TrashCan();
$trashCan->softDestroyPage($page);
Activity::add($page, ActivityType::PAGE_DELETE, $page->book_id);
$trashCan->autoClearOld();
}
@@ -286,6 +293,7 @@ class PageRepo
$page->save();
$page->indexForSearch();
Activity::add($page, ActivityType::PAGE_RESTORE, $page->book->id);
return $page;
}
@@ -296,7 +304,7 @@ class PageRepo
* @throws MoveOperationException
* @throws PermissionsException
*/
public function move(Page $page, string $parentIdentifier): Book
public function move(Page $page, string $parentIdentifier): Entity
{
$parent = $this->findParentByIdentifier($parentIdentifier);
if ($parent === null) {
@@ -311,7 +319,8 @@ class PageRepo
$page->changeBook($parent instanceof Book ? $parent->id : $parent->book->id);
$page->rebuildPermissions();
return ($parent instanceof Book ? $parent : $parent->book);
Activity::add($page, ActivityType::PAGE_MOVE, $page->book->id);
return $parent;
}
/**