X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8efaeb068b89de5181e38368fe592fbd555d07be..refs/pull/3072/head:/app/Actions/ActivityService.php diff --git a/app/Actions/ActivityService.php b/app/Actions/ActivityService.php index 87cb075ae..33ed44b32 100644 --- a/app/Actions/ActivityService.php +++ b/app/Actions/ActivityService.php @@ -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; @@ -11,7 +12,6 @@ use BookStack\Interfaces\Loggable; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Facades\Log; -use Illuminate\Support\Facades\Request; class ActivityService { @@ -56,10 +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' => Request::ip(), + 'ip' => config('app.env') === 'demo' ? '127.0.0.1' : $ip, ]); } @@ -99,13 +101,13 @@ class ActivityService */ public function entityActivity(Entity $entity, int $count = 20, int $page = 1): array { - /** @var [string => int[]] $queryIds */ + /** @var array $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'); }