X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/712ccd23c4738e6a59a10f31ff654743fbc61879..refs/pull/2393/head:/app/Actions/ActivityService.php diff --git a/app/Actions/ActivityService.php b/app/Actions/ActivityService.php index fb4a739cd..b2a35fd2a 100644 --- a/app/Actions/ActivityService.php +++ b/app/Actions/ActivityService.php @@ -2,9 +2,10 @@ use BookStack\Auth\Permissions\PermissionService; use BookStack\Auth\User; -use BookStack\Entities\Chapter; -use BookStack\Entities\Entity; -use BookStack\Entities\Page; +use BookStack\Entities\Models\Chapter; +use BookStack\Entities\Models\Entity; +use BookStack\Entities\Models\Page; +use BookStack\Interfaces\Loggable; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Facades\Log; @@ -30,6 +31,22 @@ class ActivityService $this->setNotification($type); } + /** + * Add a generic activity event to the database. + * @param string|Loggable $detail + */ + public function add(string $type, $detail = '') + { + if ($detail instanceof Loggable) { + $detail = $detail->logDescriptor(); + } + + $activity = $this->newActivityForUser($type); + $activity->detail = $detail; + $activity->save(); + $this->setNotification($type); + } + /** * Get a new activity instance for the current user. */