Use new method, property is deprecated

This commit is contained in:
Lance Pioch 2024-03-19 21:08:49 -04:00
parent 899b8836fb
commit 6d3da18bf6
22 changed files with 250 additions and 247 deletions

View File

@ -21,10 +21,10 @@ class APILog extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Cast values to correct type.
*/
protected $casts = [
'authorized' => 'boolean',
];
protected function casts(): array
{
return [
'authorized' => 'boolean',
];
}
}

View File

@ -67,11 +67,6 @@ class ActivityLog extends Model
'timestamp',
];
protected $casts = [
'properties' => 'collection',
'timestamp' => 'datetime',
];
protected $with = ['subjects'];
public static array $validationRules = [
@ -82,6 +77,14 @@ class ActivityLog extends Model
'properties' => ['array'],
];
protected function casts(): array
{
return [
'properties' => 'collection',
'timestamp' => 'datetime',
];
}
public function actor(): MorphTo
{
$morph = $this->morphTo();

View File

@ -57,15 +57,6 @@ class Allocation extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Cast values to correct type.
*/
protected $casts = [
'node_id' => 'integer',
'port' => 'integer',
'server_id' => 'integer',
];
public static array $validationRules = [
'node_id' => 'required|exists:nodes,id',
'ip' => 'required|ip',
@ -82,9 +73,15 @@ class Allocation extends Model
});
}
/**
* {@inheritDoc}
*/
protected function casts(): array
{
return [
'node_id' => 'integer',
'port' => 'integer',
'server_id' => 'integer',
];
}
public function getRouteKeyName(): string
{
return $this->getKeyName();

View File

@ -88,25 +88,6 @@ class ApiKey extends Model
*/
protected $table = 'api_keys';
/**
* Cast values to correct type.
*/
protected $casts = [
'allowed_ips' => 'array',
'user_id' => 'int',
'last_used_at' => 'datetime',
'expires_at' => 'datetime',
self::CREATED_AT => 'datetime',
self::UPDATED_AT => 'datetime',
'r_' . AdminAcl::RESOURCE_USERS => 'int',
'r_' . AdminAcl::RESOURCE_ALLOCATIONS => 'int',
'r_' . AdminAcl::RESOURCE_DATABASE_HOSTS => 'int',
'r_' . AdminAcl::RESOURCE_SERVER_DATABASES => 'int',
'r_' . AdminAcl::RESOURCE_EGGS => 'int',
'r_' . AdminAcl::RESOURCE_NODES => 'int',
'r_' . AdminAcl::RESOURCE_SERVERS => 'int',
];
/**
* Fields that are mass assignable.
*/
@ -147,6 +128,25 @@ class ApiKey extends Model
'r_' . AdminAcl::RESOURCE_SERVERS => 'integer|min:0|max:3',
];
protected function casts(): array
{
return [
'allowed_ips' => 'array',
'user_id' => 'int',
'last_used_at' => 'datetime',
'expires_at' => 'datetime',
self::CREATED_AT => 'datetime',
self::UPDATED_AT => 'datetime',
'r_' . AdminAcl::RESOURCE_USERS => 'int',
'r_' . AdminAcl::RESOURCE_ALLOCATIONS => 'int',
'r_' . AdminAcl::RESOURCE_DATABASE_HOSTS => 'int',
'r_' . AdminAcl::RESOURCE_SERVER_DATABASES => 'int',
'r_' . AdminAcl::RESOURCE_EGGS => 'int',
'r_' . AdminAcl::RESOURCE_NODES => 'int',
'r_' . AdminAcl::RESOURCE_SERVERS => 'int',
];
}
/**
* Returns the user this token is assigned to.
*/

View File

@ -26,18 +26,21 @@ class AuditLog extends Model
protected $table = 'audit_logs';
protected $casts = [
'is_system' => 'bool',
'device' => 'array',
'metadata' => 'array',
'created_at' => 'immutable_datetime',
];
protected $guarded = [
'id',
'created_at',
];
protected function casts(): array
{
return [
'is_system' => 'bool',
'device' => 'array',
'metadata' => 'array',
'created_at' => 'immutable_datetime',
];
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);

View File

@ -36,18 +36,6 @@ class Backup extends Model
protected $table = 'backups';
protected $casts = [
'id' => 'int',
'is_successful' => 'bool',
'is_locked' => 'bool',
'ignored_files' => 'array',
'bytes' => 'int',
'completed_at' => 'immutable_datetime',
'created_at' => 'immutable_datetime',
'updated_at' => 'immutable_datetime',
'deleted_at' => 'immutable_datetime',
];
protected $attributes = [
'is_successful' => false,
'is_locked' => false,
@ -71,6 +59,21 @@ class Backup extends Model
'upload_id' => 'nullable|string',
];
protected function casts(): array
{
return [
'id' => 'int',
'is_successful' => 'bool',
'is_locked' => 'bool',
'ignored_files' => 'array',
'bytes' => 'int',
'completed_at' => 'immutable_datetime',
'created_at' => 'immutable_datetime',
'updated_at' => 'immutable_datetime',
'deleted_at' => 'immutable_datetime',
];
}
public function server(): BelongsTo
{
return $this->belongsTo(Server::class);

View File

@ -48,15 +48,6 @@ class Database extends Model
'server_id', 'database_host_id', 'database', 'username', 'password', 'remote', 'max_connections',
];
/**
* Cast values to correct type.
*/
protected $casts = [
'server_id' => 'integer',
'database_host_id' => 'integer',
'max_connections' => 'integer',
];
public static array $validationRules = [
'server_id' => 'required|numeric|exists:servers,id',
'database_host_id' => 'required|exists:database_hosts,id',
@ -67,9 +58,15 @@ class Database extends Model
'password' => 'string',
];
/**
* {@inheritDoc}
*/
protected function casts(): array
{
return [
'server_id' => 'integer',
'database_host_id' => 'integer',
'max_connections' => 'integer',
];
}
public function getRouteKeyName(): string
{
return $this->getKeyName();

View File

@ -42,17 +42,6 @@ class DatabaseHost extends Model
'name', 'host', 'port', 'username', 'password', 'max_databases', 'node_id',
];
/**
* Cast values to correct type.
*/
protected $casts = [
'id' => 'integer',
'max_databases' => 'integer',
'node_id' => 'integer',
'created_at' => 'immutable_datetime',
'updated_at' => 'immutable_datetime',
];
/**
* Validation rules to assign to this model.
*/
@ -65,6 +54,17 @@ class DatabaseHost extends Model
'node_id' => 'sometimes|nullable|integer|exists:nodes,id',
];
protected function casts(): array
{
return [
'id' => 'integer',
'max_databases' => 'integer',
'node_id' => 'integer',
'created_at' => 'immutable_datetime',
'updated_at' => 'immutable_datetime',
];
}
/**
* Gets the node associated with a database host.
*/

View File

@ -99,19 +99,6 @@ class Egg extends Model
'copy_script_from',
];
/**
* Cast values to correct type.
*/
protected $casts = [
'config_from' => 'integer',
'script_is_privileged' => 'boolean',
'force_outgoing_ip' => 'boolean',
'copy_script_from' => 'integer',
'features' => 'array',
'docker_images' => 'array',
'file_denylist' => 'array',
];
public static array $validationRules = [
'uuid' => 'required|string|size:36',
'name' => 'required|string|max:191',
@ -142,6 +129,19 @@ class Egg extends Model
'update_url' => null,
];
protected function casts(): array
{
return [
'config_from' => 'integer',
'script_is_privileged' => 'boolean',
'force_outgoing_ip' => 'boolean',
'copy_script_from' => 'integer',
'features' => 'array',
'docker_images' => 'array',
'file_denylist' => 'array',
];
}
protected static function booted(): void
{
static::deleting(function (self $egg) {

View File

@ -48,17 +48,6 @@ class EggVariable extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Cast values to correct type.
*/
protected $casts = [
'egg_id' => 'integer',
'user_viewable' => 'bool',
'user_editable' => 'bool',
'created_at' => 'immutable_datetime',
'updated_at' => 'immutable_datetime',
];
public static array $validationRules = [
'egg_id' => 'exists:eggs,id',
'name' => 'required|string|between:1,191',
@ -75,6 +64,17 @@ class EggVariable extends Model
'user_viewable' => 0,
];
protected function casts(): array
{
return [
'egg_id' => 'integer',
'user_viewable' => 'bool',
'user_editable' => 'bool',
'created_at' => 'immutable_datetime',
'updated_at' => 'immutable_datetime',
];
}
public function getRequiredAttribute(): bool
{
return in_array('required', explode('|', $this->rules));

View File

@ -36,15 +36,6 @@ class Mount extends Model
*/
protected $guarded = ['id', 'uuid'];
/**
* Default values for specific fields in the database.
*/
protected $casts = [
'id' => 'int',
'read_only' => 'bool',
'user_mountable' => 'bool',
];
/**
* Rules verifying that the data being stored matches the expectations of the database.
*/
@ -92,6 +83,15 @@ class Mount extends Model
'/home/container',
];
protected function casts(): array
{
return [
'id' => 'int',
'read_only' => 'bool',
'user_mountable' => 'bool',
];
}
/**
* Returns all eggs that have this mount assigned.
*/

View File

@ -60,19 +60,6 @@ class Node extends Model
public int $sum_memory;
public int $sum_disk;
/**
* Cast values to correct type.
*/
protected $casts = [
'memory' => 'integer',
'disk' => 'integer',
'daemonListen' => 'integer',
'daemonSFTP' => 'integer',
'behind_proxy' => 'boolean',
'public' => 'boolean',
'maintenance_mode' => 'boolean',
];
/**
* Fields that are mass assignable.
*/
@ -117,6 +104,19 @@ class Node extends Model
'maintenance_mode' => false,
];
protected function casts(): array
{
return [
'memory' => 'integer',
'disk' => 'integer',
'daemonListen' => 'integer',
'daemonSFTP' => 'integer',
'behind_proxy' => 'boolean',
'public' => 'boolean',
'maintenance_mode' => 'boolean',
];
}
/**
* Get the connection address to use when making calls to this node.
*/

View File

@ -80,13 +80,6 @@ class Permission extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Cast values to correct type.
*/
protected $casts = [
'subuser_id' => 'integer',
];
public static array $validationRules = [
'subuser_id' => 'required|numeric|min:1',
'permission' => 'required|string',
@ -208,6 +201,13 @@ class Permission extends Model
],
];
protected function casts(): array
{
return [
'subuser_id' => 'integer',
];
}
/**
* Returns all the permissions available on the system for a user to
* have when controlling a server.

View File

@ -65,16 +65,6 @@ class Schedule extends Model
'next_run_at',
];
protected $casts = [
'id' => 'integer',
'server_id' => 'integer',
'is_active' => 'boolean',
'is_processing' => 'boolean',
'only_when_online' => 'boolean',
'last_run_at' => 'datetime',
'next_run_at' => 'datetime',
];
protected $attributes = [
'name' => null,
'cron_day_of_week' => '*',
@ -102,9 +92,19 @@ class Schedule extends Model
'next_run_at' => 'nullable|date',
];
/**
* {@inheritDoc}
*/
protected function casts(): array
{
return [
'id' => 'integer',
'server_id' => 'integer',
'is_active' => 'boolean',
'is_processing' => 'boolean',
'only_when_online' => 'boolean',
'last_run_at' => 'datetime',
'next_run_at' => 'datetime',
];
}
public function getRouteKeyName(): string
{
return $this->getKeyName();

View File

@ -170,29 +170,29 @@ class Server extends Model
'backup_limit' => 'present|nullable|integer|min:0',
];
/**
* Cast values to correct type.
*/
protected $casts = [
'node_id' => 'integer',
'skip_scripts' => 'boolean',
'owner_id' => 'integer',
'memory' => 'integer',
'swap' => 'integer',
'disk' => 'integer',
'io' => 'integer',
'cpu' => 'integer',
'oom_disabled' => 'boolean',
'allocation_id' => 'integer',
'egg_id' => 'integer',
'database_limit' => 'integer',
'allocation_limit' => 'integer',
'backup_limit' => 'integer',
self::CREATED_AT => 'datetime',
self::UPDATED_AT => 'datetime',
'deleted_at' => 'datetime',
'installed_at' => 'datetime',
];
protected function casts(): array
{
return [
'node_id' => 'integer',
'skip_scripts' => 'boolean',
'owner_id' => 'integer',
'memory' => 'integer',
'swap' => 'integer',
'disk' => 'integer',
'io' => 'integer',
'cpu' => 'integer',
'oom_disabled' => 'boolean',
'allocation_id' => 'integer',
'egg_id' => 'integer',
'database_limit' => 'integer',
'allocation_limit' => 'integer',
'backup_limit' => 'integer',
self::CREATED_AT => 'datetime',
self::UPDATED_AT => 'datetime',
'deleted_at' => 'datetime',
'installed_at' => 'datetime',
];
}
/**
* Returns the format for server allocations when communicating with the Daemon.

View File

@ -40,21 +40,6 @@ class ServerTransfer extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Cast values to correct type.
*/
protected $casts = [
'server_id' => 'int',
'old_node' => 'int',
'new_node' => 'int',
'old_allocation' => 'int',
'new_allocation' => 'int',
'old_additional_allocations' => 'array',
'new_additional_allocations' => 'array',
'successful' => 'bool',
'archived' => 'bool',
];
public static array $validationRules = [
'server_id' => 'required|numeric|exists:servers,id',
'old_node' => 'required|numeric',
@ -68,6 +53,21 @@ class ServerTransfer extends Model
'successful' => 'sometimes|nullable|boolean',
];
protected function casts(): array
{
return [
'server_id' => 'int',
'old_node' => 'int',
'new_node' => 'int',
'old_allocation' => 'int',
'new_allocation' => 'int',
'old_additional_allocations' => 'array',
'new_additional_allocations' => 'array',
'successful' => 'bool',
'archived' => 'bool',
];
}
/**
* Gets the server associated with a server transfer.
*/

View File

@ -26,19 +26,22 @@ class ServerVariable extends Model
protected $guarded = ['id', 'created_at', 'updated_at'];
protected $casts = [
'server_id' => 'integer',
'variable_id' => 'integer',
'created_at' => 'immutable_datetime',
'updated_at' => 'immutable_datetime',
];
public static array $validationRules = [
'server_id' => 'required|int',
'variable_id' => 'required|int',
'variable_value' => 'string',
];
protected function casts(): array
{
return [
'server_id' => 'integer',
'variable_id' => 'integer',
'created_at' => 'immutable_datetime',
'updated_at' => 'immutable_datetime',
];
}
/**
* Returns the server this variable is associated with.
*/

View File

@ -11,11 +11,11 @@ class Session extends Model
*/
protected $table = 'sessions';
/**
* Cast values to correct type.
*/
protected $casts = [
'id' => 'string',
'user_id' => 'integer',
];
protected function casts(): array
{
return [
'id' => 'string',
'user_id' => 'integer',
];
}
}

View File

@ -36,15 +36,6 @@ class Subuser extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Cast values to correct type.
*/
protected $casts = [
'user_id' => 'int',
'server_id' => 'int',
'permissions' => 'array',
];
public static array $validationRules = [
'user_id' => 'required|numeric|exists:users,id',
'server_id' => 'required|numeric|exists:servers,id',
@ -52,6 +43,15 @@ class Subuser extends Model
'permissions.*' => 'string',
];
protected function casts(): array
{
return [
'user_id' => 'int',
'server_id' => 'int',
'permissions' => 'array',
];
}
/**
* Return a hashid encoded string to represent the ID of the subuser.
*/

View File

@ -62,18 +62,6 @@ class Task extends Model
'continue_on_failure',
];
/**
* Cast values to correct type.
*/
protected $casts = [
'id' => 'integer',
'schedule_id' => 'integer',
'sequence_id' => 'integer',
'time_offset' => 'integer',
'is_queued' => 'boolean',
'continue_on_failure' => 'boolean',
];
/**
* Default attributes when creating a new model.
*/
@ -93,9 +81,18 @@ class Task extends Model
'continue_on_failure' => 'boolean',
];
/**
* {@inheritDoc}
*/
protected function casts(): array
{
return [
'id' => 'integer',
'schedule_id' => 'integer',
'sequence_id' => 'integer',
'time_offset' => 'integer',
'is_queued' => 'boolean',
'continue_on_failure' => 'boolean',
];
}
public function getRouteKeyName(): string
{
return $this->getKeyName();

View File

@ -16,15 +16,15 @@ class TaskLog extends Model
*/
protected $guarded = ['id', 'created_at', 'updated_at'];
/**
* Cast values to correct type.
*/
protected $casts = [
'id' => 'integer',
'task_id' => 'integer',
'run_status' => 'integer',
'run_time' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
protected function casts(): array
{
return [
'id' => 'integer',
'task_id' => 'integer',
'run_status' => 'integer',
'run_time' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
}
}

View File

@ -125,16 +125,6 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
'root_admin',
];
/**
* Cast values to correct type.
*/
protected $casts = [
'root_admin' => 'boolean',
'use_totp' => 'boolean',
'gravatar' => 'boolean',
'totp_authenticated_at' => 'datetime',
];
/**
* The attributes excluded from the model's JSON form.
*/
@ -168,6 +158,16 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
'totp_secret' => 'nullable|string',
];
protected function casts(): array
{
return [
'root_admin' => 'boolean',
'use_totp' => 'boolean',
'gravatar' => 'boolean',
'totp_authenticated_at' => 'datetime',
];
}
protected static function booted(): void
{
static::deleting(function (self $user) {