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

@ -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);
}
/**

View File

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

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