2022-05-28 19:36:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
use Illuminate\Database\Eloquent\Model as IlluminateModel;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \Pterodactyl\Models\ActivityLog.
|
|
|
|
*
|
|
|
|
* @property int $id
|
|
|
|
* @property string|null $batch
|
|
|
|
* @property string $event
|
2022-05-29 17:56:39 +00:00
|
|
|
* @property string $ip
|
2022-05-28 19:36:26 +00:00
|
|
|
* @property string|null $description
|
|
|
|
* @property string|null $actor_type
|
|
|
|
* @property int|null $actor_id
|
|
|
|
* @property \Illuminate\Support\Collection $properties
|
|
|
|
* @property string $timestamp
|
2022-05-29 17:56:39 +00:00
|
|
|
* @property IlluminateModel|\Eloquent $actor
|
|
|
|
* @property IlluminateModel|\Eloquent $subject
|
2022-05-28 19:36:26 +00:00
|
|
|
*
|
2022-05-29 20:19:04 +00:00
|
|
|
* @method static Builder|ActivityLog forEvent(string $event)
|
2022-05-28 19:36:26 +00:00
|
|
|
* @method static Builder|ActivityLog forActor(\Illuminate\Database\Eloquent\Model $actor)
|
|
|
|
* @method static Builder|ActivityLog newModelQuery()
|
|
|
|
* @method static Builder|ActivityLog newQuery()
|
|
|
|
* @method static Builder|ActivityLog query()
|
|
|
|
* @method static Builder|ActivityLog whereActorId($value)
|
|
|
|
* @method static Builder|ActivityLog whereActorType($value)
|
|
|
|
* @method static Builder|ActivityLog whereBatch($value)
|
|
|
|
* @method static Builder|ActivityLog whereDescription($value)
|
2022-05-29 17:56:39 +00:00
|
|
|
* @method static Builder|ActivityLog whereEvent($value)
|
2022-05-28 19:36:26 +00:00
|
|
|
* @method static Builder|ActivityLog whereId($value)
|
|
|
|
* @method static Builder|ActivityLog whereIp($value)
|
|
|
|
* @method static Builder|ActivityLog whereProperties($value)
|
|
|
|
* @method static Builder|ActivityLog whereTimestamp($value)
|
|
|
|
* @mixin \Eloquent
|
|
|
|
*/
|
|
|
|
class ActivityLog extends Model
|
|
|
|
{
|
|
|
|
public $timestamps = false;
|
|
|
|
|
|
|
|
protected $guarded = [
|
|
|
|
'id',
|
|
|
|
'timestamp',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
'properties' => 'collection',
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $validationRules = [
|
|
|
|
'event' => ['required', 'string'],
|
|
|
|
'batch' => ['nullable', 'uuid'],
|
2022-05-29 17:56:39 +00:00
|
|
|
'ip' => ['required', 'string'],
|
2022-05-28 19:36:26 +00:00
|
|
|
'description' => ['nullable', 'string'],
|
2022-05-29 17:56:39 +00:00
|
|
|
'properties' => ['array'],
|
2022-05-28 19:36:26 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
public function actor(): MorphTo
|
|
|
|
{
|
|
|
|
return $this->morphTo();
|
|
|
|
}
|
|
|
|
|
2022-05-29 20:19:04 +00:00
|
|
|
public function scopeForEvent(Builder $builder, string $action): Builder
|
2022-05-28 19:36:26 +00:00
|
|
|
{
|
2022-05-29 20:19:04 +00:00
|
|
|
return $builder->where('event', $action);
|
2022-05-28 19:36:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scopes a query to only return results where the actor is a given model.
|
|
|
|
*/
|
|
|
|
public function scopeForActor(Builder $builder, IlluminateModel $actor): Builder
|
|
|
|
{
|
|
|
|
return $builder->whereMorphedTo('actor', $actor);
|
|
|
|
}
|
|
|
|
}
|