]> BookStack Code Mirror - bookstack/blobdiff - app/Actions/ActivityService.php
Added test for logical-theme-system command registration
[bookstack] / app / Actions / ActivityService.php
index dce7dc7b2595df00a1652bcfbcce7124de811b62..33ed44b32efa0dd64715af5a227e90a642cc0574 100644 (file)
@@ -4,6 +4,7 @@ namespace BookStack\Actions;
 
 use BookStack\Auth\Permissions\PermissionService;
 use BookStack\Auth\User;
+use BookStack\Entities\Models\Book;
 use BookStack\Entities\Models\Chapter;
 use BookStack\Entities\Models\Entity;
 use BookStack\Entities\Models\Page;
@@ -55,9 +56,12 @@ class ActivityService
      */
     protected function newActivityForUser(string $type): Activity
     {
+        $ip = request()->ip() ?? '';
+
         return $this->activity->newInstance()->forceFill([
             'type'     => strtolower($type),
             'user_id'  => user()->id,
+            'ip'       => config('app.env') === 'demo' ? '127.0.0.1' : $ip,
         ]);
     }
 
@@ -97,13 +101,13 @@ class ActivityService
      */
     public function entityActivity(Entity $entity, int $count = 20, int $page = 1): array
     {
-        /** @var [string => int[]] $queryIds */
+        /** @var array<string, int[]> $queryIds */
         $queryIds = [$entity->getMorphClass() => [$entity->id]];
 
-        if ($entity->isA('book')) {
+        if ($entity instanceof Book) {
             $queryIds[(new Chapter())->getMorphClass()] = $entity->chapters()->visible()->pluck('id');
         }
-        if ($entity->isA('book') || $entity->isA('chapter')) {
+        if ($entity instanceof Book || $entity instanceof Chapter) {
             $queryIds[(new Page())->getMorphClass()] = $entity->pages()->visible()->pluck('id');
         }