X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/b1b8067cbe79d7ca2bca9021ab9d37465b0c44fe..refs/pull/5676/head:/app/Activity/Models/Activity.php diff --git a/app/Activity/Models/Activity.php b/app/Activity/Models/Activity.php index 9e4cb7858..ac9fec517 100644 --- a/app/Activity/Models/Activity.php +++ b/app/Activity/Models/Activity.php @@ -9,31 +9,30 @@ use BookStack\Users\Models\User; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphTo; +use Illuminate\Support\Carbon; use Illuminate\Support\Str; /** * @property string $type * @property User $user - * @property Entity $entity + * @property Entity $loggable * @property string $detail - * @property string $entity_type - * @property int $entity_id + * @property string $loggable_type + * @property int $loggable_id * @property int $user_id * @property Carbon $created_at - * @property Carbon $updated_at */ class Activity extends Model { /** - * Get the entity for this activity. + * Get the loggable model related to this activity. + * Currently only used for entities (previously entity_[id/type] columns). + * Could be used for others but will need an audit of uses where assumed + * to be entities. */ - public function entity(): MorphTo + public function loggable(): MorphTo { - if ($this->entity_type === '') { - $this->entity_type = null; - } - - return $this->morphTo('entity'); + return $this->morphTo('loggable'); } /** @@ -46,8 +45,8 @@ class Activity extends Model public function jointPermissions(): HasMany { - return $this->hasMany(JointPermission::class, 'entity_id', 'entity_id') - ->whereColumn('activities.entity_type', '=', 'joint_permissions.entity_type'); + return $this->hasMany(JointPermission::class, 'entity_id', 'loggable_id') + ->whereColumn('activities.loggable_type', '=', 'joint_permissions.entity_type'); } /** @@ -73,6 +72,6 @@ class Activity extends Model */ public function isSimilarTo(self $activityB): bool { - return [$this->type, $this->entity_type, $this->entity_id] === [$activityB->type, $activityB->entity_type, $activityB->entity_id]; + return [$this->type, $this->loggable_type, $this->loggable_id] === [$activityB->type, $activityB->loggable_type, $activityB->loggable_id]; } }