]> BookStack Code Mirror - bookstack/commitdiff
Organised activity types and moved most to repos
authorDan Brown <redacted>
Sat, 7 Nov 2020 22:37:27 +0000 (22:37 +0000)
committerDan Brown <redacted>
Sat, 7 Nov 2020 22:37:27 +0000 (22:37 +0000)
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.

19 files changed:
app/Actions/ActivityService.php
app/Actions/ActivityType.php [new file with mode: 0644]
app/Actions/CommentRepo.php
app/Entities/Repos/BookRepo.php
app/Entities/Repos/BookshelfRepo.php
app/Entities/Repos/ChapterRepo.php
app/Entities/Repos/PageRepo.php
app/Http/Controllers/Api/BookApiController.php
app/Http/Controllers/Api/BookshelfApiController.php
app/Http/Controllers/Api/ChapterApiController.php
app/Http/Controllers/BookController.php
app/Http/Controllers/BookSortController.php
app/Http/Controllers/BookshelfController.php
app/Http/Controllers/ChapterController.php
app/Http/Controllers/CommentController.php
app/Http/Controllers/PageController.php
app/Http/Controllers/PageRevisionController.php
tests/CommandsTest.php
tests/User/UserProfileTest.php

index 4e5b1f36575ff74c5439fe1518c372d94ae448f6..e1046db88e3bdf65e251b23d088d82e1398130d0 100644 (file)
@@ -13,9 +13,6 @@ class ActivityService
     protected $user;
     protected $permissionService;
 
-    /**
-     * ActivityService constructor.
-     */
     public function __construct(Activity $activity, PermissionService $permissionService)
     {
         $this->activity = $activity;
@@ -26,23 +23,11 @@ class ActivityService
     /**
      * Add activity data to database.
      */
-    public function add(Entity $entity, string $activityKey, ?int $bookId = null)
+    public function add(Entity $entity, string $type, ?int $bookId = null)
     {
-        $activity = $this->newActivityForUser($activityKey, $bookId);
+        $activity = $this->newActivityForUser($type, $bookId);
         $entity->activity()->save($activity);
-        $this->setNotification($activityKey);
-    }
-
-    /**
-     * Adds a activity history with a message, without binding to a entity.
-     */
-    public function addMessage(string $activityKey, string $message, ?int $bookId = null)
-    {
-        $this->newActivityForUser($activityKey, $bookId)->forceFill([
-            'extra' => $message
-        ])->save();
-
-        $this->setNotification($activityKey);
+        $this->setNotification($type);
     }
 
     /**
diff --git a/app/Actions/ActivityType.php b/app/Actions/ActivityType.php
new file mode 100644 (file)
index 0000000..5404d88
--- /dev/null
@@ -0,0 +1,22 @@
+<?php namespace BookStack\Actions;
+
+class ActivityType
+{
+    const PAGE_CREATE = 'page_create';
+    const PAGE_UPDATE = 'page_update';
+    const PAGE_DELETE = 'page_delete';
+    const PAGE_RESTORE = 'page_restore';
+    const PAGE_MOVE = 'page_move';
+    const COMMENTED_ON = 'commented_on';
+    const CHAPTER_CREATE = 'chapter_create';
+    const CHAPTER_UPDATE = 'chapter_update';
+    const CHAPTER_DELETE = 'chapter_delete';
+    const CHAPTER_MOVE = 'chapter_move';
+    const BOOK_CREATE = 'book_create';
+    const BOOK_UPDATE = 'book_update';
+    const BOOK_DELETE = 'book_delete';
+    const BOOK_SORT = 'book_sort';
+    const BOOKSHELF_CREATE = 'bookshelf_create';
+    const BOOKSHELF_UPDATE = 'bookshelf_update';
+    const BOOKSHELF_DELETE = 'bookshelf_delete';
+}
\ No newline at end of file
index 4dfe3ddb64f86f3252418b3b83d04ef6367d39b6..c0f008137c87bac251ea8f8637c3cea68e302161 100644 (file)
@@ -44,6 +44,7 @@ class CommentRepo
         $comment->parent_id = $parent_id;
 
         $entity->comments()->save($comment);
+        Activity::add($entity, ActivityType::COMMENTED_ON, $entity->book->id);
         return $comment;
     }
 
index b0ea7cb87f1bd612c068f591af23ccef8906c793..c2a613f716f7145eed758b846446860f91ab2532 100644 (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();
     }
 }
index 49fb75f4cfebd47d3cd70701c45a8061027ee009..2c80b2a7d2bf58c6ab8e5cf8c9323ade856c92e9 100644 (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();
     }
 }
index 60599eac8231017fb85fb49cd2c029a6abb1bd53..581da1fa3e06614101a12aa58d782979f024ab0f 100644 (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;
     }
 }
index 80c8afe9813e873ac835516d9785aa3ba8fa64bc..065f1606f8b1ea9b14cb54743e2489de9f2b6b05 100644 (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;
     }
 
     /**
index 8333eba3a1d3779431dbbffa39e4e9abd49837d2..8ec9fdc066ff36eeecaf078c7c762f839560ec65 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace BookStack\Http\Controllers\Api;
 
+use BookStack\Actions\ActivityType;
 use BookStack\Entities\Book;
 use BookStack\Entities\Repos\BookRepo;
 use BookStack\Exceptions\NotifyException;
@@ -55,8 +56,6 @@ class BookApiController extends ApiController
         $requestData = $this->validate($request, $this->rules['create']);
 
         $book = $this->bookRepo->create($requestData);
-        Activity::add($book, 'book_create', $book->id);
-
         return response()->json($book);
     }
 
@@ -80,7 +79,6 @@ class BookApiController extends ApiController
 
         $requestData = $this->validate($request, $this->rules['update']);
         $book = $this->bookRepo->update($book, $requestData);
-        Activity::add($book, 'book_update', $book->id);
 
         return response()->json($book);
     }
@@ -96,8 +94,6 @@ class BookApiController extends ApiController
         $this->checkOwnablePermission('book-delete', $book);
 
         $this->bookRepo->destroy($book);
-        Activity::addMessage('book_delete', $book->name);
-
         return response('', 204);
     }
 }
\ No newline at end of file
index 14b5e053b9ec42b8fc9c18dc0c40119be5dcbabf..4650e1dde16fd9a46c2e436de74b26df4b7fcf57 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace BookStack\Http\Controllers\Api;
 
+use BookStack\Actions\ActivityType;
 use BookStack\Facades\Activity;
 use BookStack\Entities\Repos\BookshelfRepo;
 use BookStack\Entities\Bookshelf;
@@ -63,7 +64,6 @@ class BookshelfApiController extends ApiController
         $bookIds = $request->get('books', []);
         $shelf = $this->bookshelfRepo->create($requestData, $bookIds);
 
-        Activity::add($shelf, 'bookshelf_create', $shelf->id);
         return response()->json($shelf);
     }
 
@@ -94,12 +94,9 @@ class BookshelfApiController extends ApiController
         $this->checkOwnablePermission('bookshelf-update', $shelf);
 
         $requestData = $this->validate($request, $this->rules['update']);
-
         $bookIds = $request->get('books', null);
 
         $shelf = $this->bookshelfRepo->update($shelf, $requestData, $bookIds);
-        Activity::add($shelf, 'bookshelf_update', $shelf->id);
-
         return response()->json($shelf);
     }
 
@@ -115,8 +112,6 @@ class BookshelfApiController extends ApiController
         $this->checkOwnablePermission('bookshelf-delete', $shelf);
 
         $this->bookshelfRepo->destroy($shelf);
-        Activity::addMessage('bookshelf_delete', $shelf->name);
-
         return response('', 204);
     }
 }
\ No newline at end of file
index 50aa8834ec13ea7cc23bbf158a740f7dc16e8fb0..60e0f01312f9bb1047e88a556e158b75fc1ef8f7 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace BookStack\Http\Controllers\Api;
 
+use BookStack\Actions\ActivityType;
 use BookStack\Entities\Book;
 use BookStack\Entities\Chapter;
 use BookStack\Entities\Repos\ChapterRepo;
@@ -58,8 +59,6 @@ class ChapterApiController extends ApiController
         $this->checkOwnablePermission('chapter-create', $book);
 
         $chapter = $this->chapterRepo->create($request->all(), $book);
-        Activity::add($chapter, 'chapter_create', $book->id);
-
         return response()->json($chapter->load(['tags']));
     }
 
@@ -83,8 +82,6 @@ class ChapterApiController extends ApiController
         $this->checkOwnablePermission('chapter-update', $chapter);
 
         $updatedChapter = $this->chapterRepo->update($chapter, $request->all());
-        Activity::add($chapter, 'chapter_update', $chapter->book->id);
-
         return response()->json($updatedChapter->load(['tags']));
     }
 
@@ -97,8 +94,6 @@ class ChapterApiController extends ApiController
         $this->checkOwnablePermission('chapter-delete', $chapter);
 
         $this->chapterRepo->destroy($chapter);
-        Activity::addMessage('chapter_delete', $chapter->name, $chapter->book->id);
-
         return response('', 204);
     }
 }
index 25dc651945363e38140609d54772f78957f684c0..5a42daddbe8b8dd2e9a4452b9659058ea1c3c660 100644 (file)
@@ -1,12 +1,12 @@
 <?php namespace BookStack\Http\Controllers;
 
 use Activity;
+use BookStack\Actions\ActivityType;
 use BookStack\Entities\Managers\BookContents;
 use BookStack\Entities\Bookshelf;
 use BookStack\Entities\Managers\EntityContext;
 use BookStack\Entities\Repos\BookRepo;
 use BookStack\Exceptions\ImageUploadException;
-use BookStack\Exceptions\NotifyException;
 use Illuminate\Http\Request;
 use Illuminate\Validation\ValidationException;
 use Throwable;
@@ -18,9 +18,6 @@ class BookController extends Controller
     protected $bookRepo;
     protected $entityContextManager;
 
-    /**
-     * BookController constructor.
-     */
     public function __construct(EntityContext $entityContextManager, BookRepo $bookRepo)
     {
         $this->bookRepo = $bookRepo;
@@ -97,11 +94,10 @@ class BookController extends Controller
 
         $book = $this->bookRepo->create($request->all());
         $this->bookRepo->updateCoverImage($book, $request->file('image', null));
-        Activity::add($book, 'book_create', $book->id);
 
         if ($bookshelf) {
             $bookshelf->appendBook($book);
-            Activity::add($bookshelf, 'bookshelf_update');
+            Activity::add($bookshelf, ActivityType::BOOKSHELF_UPDATE);
         }
 
         return redirect($book->getUrl());
@@ -162,8 +158,6 @@ class BookController extends Controller
         $resetCover = $request->has('image_reset');
         $this->bookRepo->updateCoverImage($book, $request->file('image', null), $resetCover);
 
-        Activity::add($book, 'book_update', $book->id);
-
         return redirect($book->getUrl());
     }
 
@@ -187,7 +181,6 @@ class BookController extends Controller
         $book = $this->bookRepo->getBySlug($bookSlug);
         $this->checkOwnablePermission('book-delete', $book);
 
-        Activity::add($book, 'book_delete', $book->id);
         $this->bookRepo->destroy($book);
 
         return redirect('/books');
index f5fb6f255537c2d16017f7365974863cc402260f..e94e4ecce8b3fe7a6cd4b9ca53a57fe88ac5a166 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace BookStack\Http\Controllers;
 
+use BookStack\Actions\ActivityType;
 use BookStack\Entities\Book;
 use BookStack\Entities\Managers\BookContents;
 use BookStack\Entities\Repos\BookRepo;
@@ -74,7 +75,7 @@ class BookSortController extends Controller
 
         // Rebuild permissions and add activity for involved books.
         $booksInvolved->each(function (Book $book) {
-            Activity::add($book, 'book_sort', $book->id);
+            Activity::add($book, ActivityType::BOOK_SORT, $book->id);
         });
 
         return redirect($book->getUrl());
index efe280235bad18e75249b7a58ac50ff25a205d62..8d2eec3487debf8bded49cfa51bc72060990cb11 100644 (file)
@@ -92,7 +92,6 @@ class BookshelfController extends Controller
         $shelf = $this->bookshelfRepo->create($request->all(), $bookIds);
         $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null));
 
-        Activity::add($shelf, 'bookshelf_create');
         return redirect($shelf->getUrl());
     }
 
@@ -156,7 +155,6 @@ class BookshelfController extends Controller
         $shelf = $this->bookshelfRepo->update($shelf, $request->all(), $bookIds);
         $resetCover = $request->has('image_reset');
         $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null), $resetCover);
-        Activity::add($shelf, 'bookshelf_update');
 
         return redirect($shelf->getUrl());
     }
@@ -182,7 +180,6 @@ class BookshelfController extends Controller
         $shelf = $this->bookshelfRepo->getBySlug($slug);
         $this->checkOwnablePermission('bookshelf-delete', $shelf);
 
-        Activity::add($shelf, 'bookshelf_delete');
         $this->bookshelfRepo->destroy($shelf);
 
         return redirect('/shelves');
index 5d8631154c3fddfebb9fbe3b44b09d65f8587558..8eba43e21778b2995bea0897f171919500d4b001 100644 (file)
@@ -1,6 +1,5 @@
 <?php namespace BookStack\Http\Controllers;
 
-use Activity;
 use BookStack\Entities\Book;
 use BookStack\Entities\Managers\BookContents;
 use BookStack\Entities\Repos\ChapterRepo;
@@ -51,7 +50,6 @@ class ChapterController extends Controller
         $this->checkOwnablePermission('chapter-create', $book);
 
         $chapter = $this->chapterRepo->create($request->all(), $book);
-        Activity::add($chapter, 'chapter_create', $book->id);
 
         return redirect($chapter->getUrl());
     }
@@ -100,7 +98,6 @@ class ChapterController extends Controller
         $this->checkOwnablePermission('chapter-update', $chapter);
 
         $this->chapterRepo->update($chapter, $request->all());
-        Activity::add($chapter, 'chapter_update', $chapter->book->id);
 
         return redirect($chapter->getUrl());
     }
@@ -128,7 +125,6 @@ class ChapterController extends Controller
         $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
         $this->checkOwnablePermission('chapter-delete', $chapter);
 
-        Activity::add($chapter, 'chapter_delete', $chapter->book->id);
         $this->chapterRepo->destroy($chapter);
 
         return redirect($chapter->book->getUrl());
@@ -173,8 +169,6 @@ class ChapterController extends Controller
             return redirect()->back();
         }
 
-        Activity::add($chapter, 'chapter_move', $newBook->id);
-
         $this->showSuccessNotification(trans('entities.chapter_move_success', ['bookName' => $newBook->name]));
         return redirect($chapter->getUrl());
     }
index 4eb56a4b0cd0720cfcc110e5c22662b958231f4b..2dc1a4de43ea0ea877d9c7107ddcd5f1ef6091cb 100644 (file)
@@ -1,6 +1,7 @@
 <?php namespace BookStack\Http\Controllers;
 
 use Activity;
+use BookStack\Actions\ActivityType;
 use BookStack\Actions\CommentRepo;
 use BookStack\Entities\Page;
 use Illuminate\Http\Request;
@@ -40,7 +41,6 @@ class CommentController extends Controller
         // Create a new comment.
         $this->checkPermission('comment-create-all');
         $comment = $this->commentRepo->create($page, $request->get('text'), $request->get('parent_id'));
-        Activity::add($page, 'commented_on', $page->book->id);
         return view('comments.comment', ['comment' => $comment]);
     }
 
index 6396da23ed15b7e414221065766b489e6a689135..862ba3d7ffe3822169cd9b51ad6b060945f6db80 100644 (file)
@@ -1,6 +1,7 @@
 <?php namespace BookStack\Http\Controllers;
 
 use Activity;
+use BookStack\Actions\ActivityType;
 use BookStack\Entities\Managers\BookContents;
 use BookStack\Entities\Managers\PageContent;
 use BookStack\Entities\Managers\PageEditActivity;
@@ -107,7 +108,6 @@ class PageController extends Controller
         $this->checkOwnablePermission('page-create', $draftPage->getParent());
 
         $page = $this->pageRepo->publishDraft($draftPage, $request->all());
-        Activity::add($page, 'page_create', $draftPage->book->id);
 
         return redirect($page->getUrl());
     }
@@ -224,7 +224,6 @@ class PageController extends Controller
         $this->checkOwnablePermission('page-update', $page);
 
         $this->pageRepo->update($page, $request->all());
-        Activity::add($page, 'page_update', $page->book->id);
 
         return redirect($page->getUrl());
     }
@@ -304,11 +303,9 @@ class PageController extends Controller
     {
         $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
         $this->checkOwnablePermission('page-delete', $page);
+        $parent = $page->getParent();
 
-        $book = $page->book;
-        $parent = $page->chapter ?? $book;
         $this->pageRepo->destroy($page);
-        Activity::add($page, 'page_delete', $page->book_id);
 
         return redirect($parent->getUrl());
     }
@@ -393,7 +390,6 @@ class PageController extends Controller
             return redirect()->back();
         }
 
-        Activity::add($page, 'page_move', $page->book->id);
         $this->showSuccessNotification(trans('entities.pages_move_success', ['parentName' => $parent->name]));
         return redirect($page->getUrl());
     }
@@ -438,8 +434,6 @@ class PageController extends Controller
             return redirect()->back();
         }
 
-        Activity::add($pageCopy, 'page_create', $pageCopy->book->id);
-
         $this->showSuccessNotification(trans('entities.pages_copy_success'));
         return redirect($pageCopy->getUrl());
     }
index 797f5db8f43ff1ca9f8f561e029b888cec7a662d..b56235d5b70d566d1928b0f8cf977945b8af56a1 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace BookStack\Http\Controllers;
 
+use BookStack\Actions\ActivityType;
 use BookStack\Entities\Managers\PageContent;
 use BookStack\Entities\Repos\PageRepo;
 use BookStack\Exceptions\NotFoundException;
@@ -101,7 +102,6 @@ class PageRevisionController extends Controller
 
         $page = $this->pageRepo->restoreRevision($page, $revisionId);
 
-        Activity::add($page, 'page_restore', $page->book->id);
         return redirect($page->getUrl());
     }
 
index bfc0ac0eb4bb1b8ab6ea9d0c1aae4b8cebcffd05..7e931ee96bc7be5db3b00933fc860cea7a2c2ba7 100644 (file)
@@ -1,5 +1,6 @@
 <?php namespace Tests;
 
+use BookStack\Actions\ActivityType;
 use BookStack\Actions\Comment;
 use BookStack\Actions\CommentRepo;
 use BookStack\Auth\Permissions\JointPermission;
@@ -37,7 +38,7 @@ class CommandsTest extends TestCase
     {
         $this->asEditor();
         $page = Page::first();
-        \Activity::add($page, 'page_update', $page->book->id);
+        \Activity::add($page, ActivityType::PAGE_UPDATE, $page->book->id);
 
         $this->assertDatabaseHas('activities', [
             'key' => 'page_update',
index b564ed8c235a55e42d19d06cef4b8f2e199038aa..cc39c0d8efbd58fb6f6b711ba78c316f390cdde2 100644 (file)
@@ -1,6 +1,7 @@
 <?php namespace Tests\User;
 
 use Activity;
+use BookStack\Actions\ActivityType;
 use BookStack\Auth\User;
 use BookStack\Entities\Bookshelf;
 use Tests\BrowserKitTest;
@@ -60,8 +61,8 @@ class UserProfileTest extends BrowserKitTest
         $newUser = $this->getNewBlankUser();
         $this->actingAs($newUser);
         $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
-        Activity::add($entities['book'], 'book_update', $entities['book']->id);
-        Activity::add($entities['page'], 'page_create', $entities['book']->id);
+        Activity::add($entities['book'], ActivityType::BOOK_UPDATE, $entities['book']->id);
+        Activity::add($entities['page'], ActivityType::PAGE_CREATE, $entities['book']->id);
 
         $this->asAdmin()->visit('/user/' . $newUser->id)
             ->seeInElement('#recent-user-activity', 'updated book')
@@ -74,8 +75,8 @@ class UserProfileTest extends BrowserKitTest
         $newUser = $this->getNewBlankUser();
         $this->actingAs($newUser);
         $entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
-        Activity::add($entities['book'], 'book_update', $entities['book']->id);
-        Activity::add($entities['page'], 'page_create', $entities['book']->id);
+        Activity::add($entities['book'], ActivityType::BOOK_UPDATE, $entities['book']->id);
+        Activity::add($entities['page'], ActivityType::PAGE_CREATE, $entities['book']->id);
 
         $this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
             ->seePageIs('/user/' . $newUser->id)