Upgrade to Laravel 9 (#4413)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
parent
95e15d2c8a
commit
cbcf62086f
573 changed files with 4387 additions and 9411 deletions
|
@ -8,29 +8,21 @@ class APILog extends Model
|
|||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'api_logs';
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [];
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'authorized' => 'boolean',
|
||||
|
|
|
@ -9,6 +9,7 @@ use Pterodactyl\Events\ActivityLogged;
|
|||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\MassPrunable;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Database\Eloquent\Model as IlluminateModel;
|
||||
|
||||
|
@ -45,6 +46,7 @@ use Illuminate\Database\Eloquent\Model as IlluminateModel;
|
|||
* @method static Builder|ActivityLog whereIp($value)
|
||||
* @method static Builder|ActivityLog whereProperties($value)
|
||||
* @method static Builder|ActivityLog whereTimestamp($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class ActivityLog extends Model
|
||||
|
@ -54,7 +56,7 @@ class ActivityLog extends Model
|
|||
public const RESOURCE_NAME = 'activity_log';
|
||||
|
||||
/**
|
||||
* Tracks all of the events we no longer wish to display to users. These are either legacy
|
||||
* Tracks all the events we no longer wish to display to users. These are either legacy
|
||||
* events or just events where we never ended up using the associated data.
|
||||
*/
|
||||
public const DISABLED_EVENTS = ['server:file.upload'];
|
||||
|
@ -73,7 +75,7 @@ class ActivityLog extends Model
|
|||
|
||||
protected $with = ['subjects'];
|
||||
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'event' => ['required', 'string'],
|
||||
'batch' => ['nullable', 'uuid'],
|
||||
'ip' => ['required', 'string'],
|
||||
|
@ -91,7 +93,7 @@ class ActivityLog extends Model
|
|||
return $morph;
|
||||
}
|
||||
|
||||
public function subjects()
|
||||
public function subjects(): HasMany
|
||||
{
|
||||
return $this->hasMany(ActivityLogSubject::class);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|ActivityLogSubject newModelQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ActivityLogSubject newQuery()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ActivityLogSubject query()
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class ActivityLogSubject extends Pivot
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* Pterodactyl\Models\Allocation.
|
||||
*
|
||||
|
@ -33,6 +35,7 @@ namespace Pterodactyl\Models;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|Allocation wherePort($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereServerId($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Allocation whereUpdatedAt($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Allocation extends Model
|
||||
|
@ -45,22 +48,16 @@ class Allocation extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'allocations';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'node_id' => 'integer',
|
||||
|
@ -68,10 +65,7 @@ class Allocation extends Model
|
|||
'server_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'node_id' => 'required|exists:nodes,id',
|
||||
'ip' => 'required|ip',
|
||||
'port' => 'required|numeric|between:1024,65535',
|
||||
|
@ -90,34 +84,24 @@ class Allocation extends Model
|
|||
|
||||
/**
|
||||
* Return a hashid encoded string to represent the ID of the allocation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHashidAttribute()
|
||||
public function getHashidAttribute(): string
|
||||
{
|
||||
return app()->make('hashids')->encode($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to automatically provide the IP alias if defined.
|
||||
*
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAliasAttribute($value)
|
||||
public function getAliasAttribute(?string $value): string
|
||||
{
|
||||
return (is_null($this->ip_alias)) ? $this->ip : $this->ip_alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to quickly determine if this allocation has an alias.
|
||||
*
|
||||
* @param string|null $value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getHasAliasAttribute($value)
|
||||
public function getHasAliasAttribute(?string $value): bool
|
||||
{
|
||||
return !is_null($this->ip_alias);
|
||||
}
|
||||
|
@ -129,20 +113,16 @@ class Allocation extends Model
|
|||
|
||||
/**
|
||||
* Gets information for the server associated with this allocation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Node model associated with this allocation.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function node()
|
||||
public function node(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Node::class);
|
||||
}
|
||||
|
|
|
@ -55,6 +55,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|ApiKey whereToken($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ApiKey whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|ApiKey whereUserId($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class ApiKey extends Model
|
||||
|
@ -87,15 +88,11 @@ class ApiKey extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'api_keys';
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'allowed_ips' => 'array',
|
||||
|
@ -113,8 +110,6 @@ class ApiKey extends Model
|
|||
|
||||
/**
|
||||
* Fields that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'identifier',
|
||||
|
@ -127,17 +122,13 @@ class ApiKey extends Model
|
|||
/**
|
||||
* Fields that should not be included when calling toArray() or toJson()
|
||||
* on this model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['token'];
|
||||
|
||||
/**
|
||||
* Rules to protect against invalid data entry to DB.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'user_id' => 'required|exists:users,id',
|
||||
'key_type' => 'present|integer|min:0|max:4',
|
||||
'identifier' => 'required|string|size:16|unique:api_keys,identifier',
|
||||
|
@ -157,9 +148,6 @@ class ApiKey extends Model
|
|||
'r_' . AdminAcl::RESOURCE_SERVERS => 'integer|min:0|max:3',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = [
|
||||
self::CREATED_AT,
|
||||
self::UPDATED_AT,
|
||||
|
@ -177,23 +165,17 @@ class ApiKey extends Model
|
|||
/**
|
||||
* Required for support with Laravel Sanctum.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*
|
||||
* @see \Laravel\Sanctum\Guard::supportsTokens()
|
||||
*/
|
||||
public function tokenable()
|
||||
public function tokenable(): BelongsTo
|
||||
{
|
||||
return $this->user();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the model matching the provided token.
|
||||
*
|
||||
* @param string $token
|
||||
*
|
||||
* @return self|null
|
||||
*/
|
||||
public static function findToken($token)
|
||||
public static function findToken(string $token): ?self
|
||||
{
|
||||
$identifier = substr($token, 0, self::IDENTIFIER_LENGTH);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Pterodactyl\Models;
|
|||
use Ramsey\Uuid\Uuid;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @deprecated — this class will be dropped in a future version, use the activity log
|
||||
|
@ -13,10 +14,7 @@ class AuditLog extends Model
|
|||
{
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'uuid' => 'required|uuid',
|
||||
'action' => 'required|string|max:191',
|
||||
'subaction' => 'nullable|string|max:191',
|
||||
|
@ -26,45 +24,27 @@ class AuditLog extends Model
|
|||
'metadata' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'audit_logs';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $immutableDates = true;
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $casts = [
|
||||
'is_system' => 'bool',
|
||||
'device' => 'array',
|
||||
'metadata' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $guarded = [
|
||||
'id',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
@ -74,11 +54,9 @@ class AuditLog extends Model
|
|||
* currently authenticated user if available. This model is not saved at this point, so
|
||||
* you can always make modifications to it as needed before saving.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public static function instance(string $action, array $metadata, bool $isSystem = false)
|
||||
public static function instance(string $action, array $metadata, bool $isSystem = false): self
|
||||
{
|
||||
/** @var \Illuminate\Http\Request $request */
|
||||
$request = Container::getInstance()->make('request');
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
|
@ -32,19 +33,10 @@ class Backup extends Model
|
|||
public const ADAPTER_WINGS = 'wings';
|
||||
public const ADAPTER_AWS_S3 = 's3';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'backups';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $immutableDates = true;
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
'is_successful' => 'bool',
|
||||
|
@ -53,16 +45,10 @@ class Backup extends Model
|
|||
'bytes' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = [
|
||||
'completed_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'is_successful' => false,
|
||||
'is_locked' => false,
|
||||
|
@ -71,15 +57,9 @@ class Backup extends Model
|
|||
'upload_id' => null,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'deleted_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'server_id' => 'bail|required|numeric|exists:servers,id',
|
||||
'uuid' => 'required|uuid',
|
||||
'is_successful' => 'boolean',
|
||||
|
@ -92,10 +72,7 @@ class Backup extends Model
|
|||
'upload_id' => 'nullable|string',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
||||
|
||||
/**
|
||||
|
@ -29,22 +30,16 @@ class Database extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'databases';
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['password'];
|
||||
|
||||
/**
|
||||
* Fields that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'server_id', 'database_host_id', 'database', 'username', 'password', 'remote', 'max_connections',
|
||||
|
@ -52,8 +47,6 @@ class Database extends Model
|
|||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'server_id' => 'integer',
|
||||
|
@ -61,10 +54,7 @@ class Database extends Model
|
|||
'max_connections' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'server_id' => 'required|numeric|exists:servers,id',
|
||||
'database_host_id' => 'required|exists:database_hosts,id',
|
||||
'database' => 'required|string|alpha_dash|between:3,48',
|
||||
|
@ -89,11 +79,9 @@ class Database extends Model
|
|||
* @param mixed $value
|
||||
* @param string|null $field
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function resolveRouteBinding($value, $field = null)
|
||||
public function resolveRouteBinding($value, $field = null): ?\Illuminate\Database\Eloquent\Model
|
||||
{
|
||||
if (is_scalar($value) && ($field ?? $this->getRouteKeyName()) === 'id') {
|
||||
$value = ctype_digit((string) $value)
|
||||
|
@ -106,20 +94,16 @@ class Database extends Model
|
|||
|
||||
/**
|
||||
* Gets the host database server associated with a database.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function host()
|
||||
public function host(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DatabaseHost::class, 'database_host_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server associated with a database.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
|
@ -22,29 +25,20 @@ class DatabaseHost extends Model
|
|||
*/
|
||||
public const RESOURCE_NAME = 'database_host';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $immutableDates = true;
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'database_hosts';
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['password'];
|
||||
|
||||
/**
|
||||
* Fields that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'host', 'port', 'username', 'password', 'max_databases', 'node_id',
|
||||
|
@ -52,8 +46,6 @@ class DatabaseHost extends Model
|
|||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
|
@ -63,10 +55,8 @@ class DatabaseHost extends Model
|
|||
|
||||
/**
|
||||
* Validation rules to assign to this model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'name' => 'required|string|max:191',
|
||||
'host' => 'required|string',
|
||||
'port' => 'required|numeric|between:1,65535',
|
||||
|
@ -77,20 +67,16 @@ class DatabaseHost extends Model
|
|||
|
||||
/**
|
||||
* Gets the node associated with a database host.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function node()
|
||||
public function node(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Node::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the databases associated with this host.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function databases()
|
||||
public function databases(): HasMany
|
||||
{
|
||||
return $this->hasMany(Database::class);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $uuid
|
||||
|
@ -70,15 +73,11 @@ class Egg extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'eggs';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
|
@ -102,8 +101,6 @@ class Egg extends Model
|
|||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'nest_id' => 'integer',
|
||||
|
@ -116,10 +113,7 @@ class Egg extends Model
|
|||
'file_denylist' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'nest_id' => 'required|bail|numeric|exists:nests,id',
|
||||
'uuid' => 'required|string|size:36',
|
||||
'name' => 'required|string|max:191',
|
||||
|
@ -140,9 +134,6 @@ class Egg extends Model
|
|||
'force_outgoing_ip' => 'sometimes|boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'features' => null,
|
||||
'file_denylist' => null,
|
||||
|
@ -156,10 +147,8 @@ class Egg extends Model
|
|||
/**
|
||||
* Returns the install script for the egg; if egg is copying from another
|
||||
* it will return the copied script.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCopyScriptInstallAttribute()
|
||||
public function getCopyScriptInstallAttribute(): ?string
|
||||
{
|
||||
if (!is_null($this->script_install) || is_null($this->copy_script_from)) {
|
||||
return $this->script_install;
|
||||
|
@ -171,10 +160,8 @@ class Egg extends Model
|
|||
/**
|
||||
* Returns the entry command for the egg; if egg is copying from another
|
||||
* it will return the copied entry command.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCopyScriptEntryAttribute()
|
||||
public function getCopyScriptEntryAttribute(): string
|
||||
{
|
||||
if (!is_null($this->script_entry) || is_null($this->copy_script_from)) {
|
||||
return $this->script_entry;
|
||||
|
@ -186,10 +173,8 @@ class Egg extends Model
|
|||
/**
|
||||
* Returns the install container for the egg; if egg is copying from another
|
||||
* it will return the copied install container.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCopyScriptContainerAttribute()
|
||||
public function getCopyScriptContainerAttribute(): string
|
||||
{
|
||||
if (!is_null($this->script_container) || is_null($this->copy_script_from)) {
|
||||
return $this->script_container;
|
||||
|
@ -200,10 +185,8 @@ class Egg extends Model
|
|||
|
||||
/**
|
||||
* Return the file configuration for an egg.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInheritConfigFilesAttribute()
|
||||
public function getInheritConfigFilesAttribute(): ?string
|
||||
{
|
||||
if (!is_null($this->config_files) || is_null($this->config_from)) {
|
||||
return $this->config_files;
|
||||
|
@ -214,10 +197,8 @@ class Egg extends Model
|
|||
|
||||
/**
|
||||
* Return the startup configuration for an egg.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInheritConfigStartupAttribute()
|
||||
public function getInheritConfigStartupAttribute(): ?string
|
||||
{
|
||||
if (!is_null($this->config_startup) || is_null($this->config_from)) {
|
||||
return $this->config_startup;
|
||||
|
@ -228,10 +209,8 @@ class Egg extends Model
|
|||
|
||||
/**
|
||||
* Return the log reading configuration for an egg.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInheritConfigLogsAttribute()
|
||||
public function getInheritConfigLogsAttribute(): ?string
|
||||
{
|
||||
if (!is_null($this->config_logs) || is_null($this->config_from)) {
|
||||
return $this->config_logs;
|
||||
|
@ -242,10 +221,8 @@ class Egg extends Model
|
|||
|
||||
/**
|
||||
* Return the stop command configuration for an egg.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInheritConfigStopAttribute()
|
||||
public function getInheritConfigStopAttribute(): ?string
|
||||
{
|
||||
if (!is_null($this->config_stop) || is_null($this->config_from)) {
|
||||
return $this->config_stop;
|
||||
|
@ -257,10 +234,8 @@ class Egg extends Model
|
|||
/**
|
||||
* Returns the features available to this egg from the parent configuration if there are
|
||||
* no features defined for this egg specifically and there is a parent egg configured.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getInheritFeaturesAttribute()
|
||||
public function getInheritFeaturesAttribute(): ?array
|
||||
{
|
||||
if (!is_null($this->features) || is_null($this->config_from)) {
|
||||
return $this->features;
|
||||
|
@ -272,10 +247,8 @@ class Egg extends Model
|
|||
/**
|
||||
* Returns the features available to this egg from the parent configuration if there are
|
||||
* no features defined for this egg specifically and there is a parent egg configured.
|
||||
*
|
||||
* @return string[]|null
|
||||
*/
|
||||
public function getInheritFileDenylistAttribute()
|
||||
public function getInheritFileDenylistAttribute(): ?array
|
||||
{
|
||||
if (is_null($this->config_from)) {
|
||||
return $this->file_denylist;
|
||||
|
@ -286,50 +259,40 @@ class Egg extends Model
|
|||
|
||||
/**
|
||||
* Gets nest associated with an egg.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function nest()
|
||||
public function nest(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Nest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all servers associated with this egg.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servers()
|
||||
public function servers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Server::class, 'egg_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all variables associated with this egg.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function variables()
|
||||
public function variables(): HasMany
|
||||
{
|
||||
return $this->hasMany(EggVariable::class, 'egg_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent egg from which to copy scripts.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function scriptFrom()
|
||||
public function scriptFrom(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(self::class, 'copy_script_from');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parent egg from which to copy configuration settings.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function configFrom()
|
||||
public function configFrom(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(self::class, 'config_from');
|
||||
}
|
||||
|
|
|
@ -4,18 +4,9 @@ namespace Pterodactyl\Models;
|
|||
|
||||
class EggMount extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'egg_mount';
|
||||
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
protected $primaryKey = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $egg_id
|
||||
|
@ -32,34 +35,23 @@ class EggVariable extends Model
|
|||
|
||||
/**
|
||||
* Reserved environment variable names.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const RESERVED_ENV_NAMES = 'SERVER_MEMORY,SERVER_IP,SERVER_PORT,ENV,HOME,USER,STARTUP,SERVER_UUID,UUID';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $immutableDates = true;
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'egg_variables';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'egg_id' => 'integer',
|
||||
|
@ -67,10 +59,7 @@ class EggVariable extends Model
|
|||
'user_editable' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'egg_id' => 'exists:eggs,id',
|
||||
'name' => 'required|string|between:1,191',
|
||||
'description' => 'string',
|
||||
|
@ -81,36 +70,25 @@ class EggVariable extends Model
|
|||
'rules' => 'required|string',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'user_editable' => 0,
|
||||
'user_viewable' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getRequiredAttribute()
|
||||
public function getRequiredAttribute(): bool
|
||||
{
|
||||
return in_array('required', explode('|', $this->rules));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function egg()
|
||||
public function egg(): HasOne
|
||||
{
|
||||
return $this->hasOne(Egg::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return server variables associated with this variable.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function serverVariable()
|
||||
public function serverVariable(): HasMany
|
||||
{
|
||||
return $this->hasMany(ServerVariable::class, 'variable_id');
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $short
|
||||
|
@ -21,24 +24,18 @@ class Location extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'locations';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Rules ensuring that the raw data stored in the database meets expectations.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'short' => 'required|string|between:1,60|unique:locations,short',
|
||||
'long' => 'string|nullable|between:1,191',
|
||||
];
|
||||
|
@ -53,20 +50,16 @@ class Location extends Model
|
|||
|
||||
/**
|
||||
* Gets the nodes in a specified location.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function nodes()
|
||||
public function nodes(): HasMany
|
||||
{
|
||||
return $this->hasMany(Node::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the servers within a given location.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
*/
|
||||
public function servers()
|
||||
public function servers(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Server::class, Node::class);
|
||||
}
|
||||
|
|
|
@ -4,13 +4,16 @@ namespace Pterodactyl\Models;
|
|||
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Pterodactyl\Exceptions\Model\DataValidationException;
|
||||
use Illuminate\Database\Eloquent\Model as IlluminateModel;
|
||||
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
|
||||
|
||||
abstract class Model extends IlluminateModel
|
||||
{
|
||||
|
@ -18,28 +21,18 @@ abstract class Model extends IlluminateModel
|
|||
|
||||
/**
|
||||
* Set to true to return immutable Carbon date instances from the model.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $immutableDates = false;
|
||||
protected bool $immutableDates = false;
|
||||
|
||||
/**
|
||||
* Determines if the model should undergo data validation before it is saved
|
||||
* to the database.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $skipValidation = false;
|
||||
protected bool $skipValidation = false;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Validation\Factory
|
||||
*/
|
||||
protected static $validatorFactory;
|
||||
protected static ValidationFactory $validatorFactory;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [];
|
||||
public static array $validationRules = [];
|
||||
|
||||
/**
|
||||
* Listen for the model saving event and fire off the validation
|
||||
|
@ -51,7 +44,7 @@ abstract class Model extends IlluminateModel
|
|||
{
|
||||
parent::boot();
|
||||
|
||||
static::$validatorFactory = Container::getInstance()->make(Factory::class);
|
||||
static::$validatorFactory = Container::getInstance()->make(ValidationFactory::class);
|
||||
|
||||
static::saving(function (Model $model) {
|
||||
try {
|
||||
|
@ -65,7 +58,7 @@ abstract class Model extends IlluminateModel
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the model key to use for route model binding. By default we'll
|
||||
* Returns the model key to use for route model binding. By default, we'll
|
||||
* assume every model uses a UUID field for this. If the model does not have
|
||||
* a UUID and is using a different key it should be specified on the model
|
||||
* itself.
|
||||
|
@ -80,10 +73,8 @@ abstract class Model extends IlluminateModel
|
|||
|
||||
/**
|
||||
* Set the model to skip validation when saving.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function skipValidation()
|
||||
public function skipValidation(): self
|
||||
{
|
||||
$this->skipValidation = true;
|
||||
|
||||
|
@ -92,10 +83,8 @@ abstract class Model extends IlluminateModel
|
|||
|
||||
/**
|
||||
* Returns the validator instance used by this model.
|
||||
*
|
||||
* @return \Illuminate\Validation\Validator|\Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
public function getValidator()
|
||||
public function getValidator(): Validator
|
||||
{
|
||||
$rules = $this->exists ? static::getRulesForUpdate($this) : static::getRules();
|
||||
|
||||
|
@ -104,10 +93,8 @@ abstract class Model extends IlluminateModel
|
|||
|
||||
/**
|
||||
* Returns the rules associated with this model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRules()
|
||||
public static function getRules(): array
|
||||
{
|
||||
$rules = static::$validationRules;
|
||||
foreach ($rules as $key => &$rule) {
|
||||
|
@ -129,12 +116,8 @@ abstract class Model extends IlluminateModel
|
|||
/**
|
||||
* Returns the rules associated with the model, specifically for updating the given model
|
||||
* rather than just creating it.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model|int|string $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getRulesForUpdate($model, string $column = 'id')
|
||||
public static function getRulesForUpdate(IlluminateModel|int|string $model, string $column = 'id'): array
|
||||
{
|
||||
if ($model instanceof Model) {
|
||||
[$id, $column] = [$model->getKey(), $model->getKeyName()];
|
||||
|
@ -144,7 +127,7 @@ abstract class Model extends IlluminateModel
|
|||
foreach ($rules as $key => &$data) {
|
||||
// For each rule in a given field, iterate over it and confirm if the rule
|
||||
// is one for a unique field. If that is the case, append the ID of the current
|
||||
// working model so we don't run into errors due to the way that field validation
|
||||
// working model, so we don't run into errors due to the way that field validation
|
||||
// works.
|
||||
foreach ($data as &$datum) {
|
||||
if (!is_string($datum) || !Str::startsWith($datum, 'unique')) {
|
||||
|
@ -163,6 +146,8 @@ abstract class Model extends IlluminateModel
|
|||
|
||||
/**
|
||||
* Determines if the model is in a valid state or not.
|
||||
*
|
||||
* @throws \Illuminate\Validation\ValidationException
|
||||
*/
|
||||
public function validate(): void
|
||||
{
|
||||
|
@ -172,9 +157,9 @@ abstract class Model extends IlluminateModel
|
|||
|
||||
$validator = $this->getValidator();
|
||||
$validator->setData(
|
||||
// Trying to do self::toArray() here will leave out keys based on the whitelist/blacklist
|
||||
// for that model. Doing this will return all of the attributes in a format that can
|
||||
// properly be validated.
|
||||
// Trying to do self::toArray() here will leave out keys based on the whitelist/blacklist
|
||||
// for that model. Doing this will return all the attributes in a format that can
|
||||
// properly be validated.
|
||||
$this->addCastAttributesToArray(
|
||||
$this->getAttributes(),
|
||||
$this->getMutatedAttributes()
|
||||
|
@ -190,10 +175,8 @@ abstract class Model extends IlluminateModel
|
|||
* Return a timestamp as DateTime object.
|
||||
*
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return \Illuminate\Support\Carbon|\Carbon\CarbonImmutable
|
||||
*/
|
||||
protected function asDateTime($value)
|
||||
protected function asDateTime($value): Carbon|CarbonImmutable
|
||||
{
|
||||
if (!$this->immutableDates) {
|
||||
return parent::asDateTime($value);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Validation\Rules\NotIn;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
|
@ -27,22 +28,16 @@ class Mount extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'mounts';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'uuid'];
|
||||
|
||||
/**
|
||||
* Default values for specific fields in the database.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'int',
|
||||
|
@ -52,10 +47,8 @@ class Mount extends Model
|
|||
|
||||
/**
|
||||
* Rules verifying that the data being stored matches the expectations of the database.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'name' => 'required|string|min:2|max:64|unique:mounts,name',
|
||||
'description' => 'nullable|string|max:191',
|
||||
'source' => 'required|string',
|
||||
|
@ -68,7 +61,7 @@ class Mount extends Model
|
|||
* Implement language verification by overriding Eloquence's gather
|
||||
* rules function.
|
||||
*/
|
||||
public static function getRules()
|
||||
public static function getRules(): array
|
||||
{
|
||||
$rules = parent::getRules();
|
||||
|
||||
|
@ -80,15 +73,11 @@ class Mount extends Model
|
|||
|
||||
/**
|
||||
* Disable timestamps on this model.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Blacklisted source paths.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $invalidSourcePaths = [
|
||||
'/etc/pterodactyl',
|
||||
|
@ -98,8 +87,6 @@ class Mount extends Model
|
|||
|
||||
/**
|
||||
* Blacklisted target paths.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
public static $invalidTargetPaths = [
|
||||
'/home/container',
|
||||
|
@ -107,30 +94,24 @@ class Mount extends Model
|
|||
|
||||
/**
|
||||
* Returns all eggs that have this mount assigned.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function eggs()
|
||||
public function eggs(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Egg::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all nodes that have this mount assigned.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function nodes()
|
||||
public function nodes(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Node::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all servers that have this mount assigned.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function servers()
|
||||
public function servers(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Server::class);
|
||||
}
|
||||
|
|
|
@ -6,18 +6,9 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class MountNode extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'mount_node';
|
||||
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
protected $primaryKey = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
}
|
||||
|
|
|
@ -6,23 +6,11 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class MountServer extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'mount_server';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var null
|
||||
*/
|
||||
protected $primaryKey = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $incrementing = false;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $uuid
|
||||
|
@ -23,25 +25,18 @@ class Nest extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'nests';
|
||||
|
||||
/**
|
||||
* Fields that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'author' => 'required|string|email',
|
||||
'name' => 'required|string|max:191',
|
||||
'description' => 'nullable|string',
|
||||
|
@ -49,20 +44,16 @@ class Nest extends Model
|
|||
|
||||
/**
|
||||
* Gets all eggs associated with this service.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function eggs()
|
||||
public function eggs(): HasMany
|
||||
{
|
||||
return $this->hasMany(Egg::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all servers associated with this nest.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servers()
|
||||
public function servers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Server::class);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ use Symfony\Component\Yaml\Yaml;
|
|||
use Illuminate\Container\Container;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Contracts\Encryption\Encrypter;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
|
@ -51,22 +54,16 @@ class Node extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'nodes';
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['daemon_token_id', 'daemon_token'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'location_id' => 'integer',
|
||||
|
@ -81,8 +78,6 @@ class Node extends Model
|
|||
|
||||
/**
|
||||
* Fields that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'public', 'name', 'location_id',
|
||||
|
@ -93,10 +88,7 @@ class Node extends Model
|
|||
'description', 'maintenance_mode',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'name' => 'required|regex:/^([\w .-]{1,100})$/',
|
||||
'description' => 'string|nullable',
|
||||
'location_id' => 'required|exists:locations,id',
|
||||
|
@ -117,8 +109,6 @@ class Node extends Model
|
|||
|
||||
/**
|
||||
* Default values for specific columns that are generally not changed on base installs.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'public' => true,
|
||||
|
@ -141,10 +131,8 @@ class Node extends Model
|
|||
|
||||
/**
|
||||
* Returns the configuration as an array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getConfiguration()
|
||||
public function getConfiguration(): array
|
||||
{
|
||||
return [
|
||||
'debug' => false,
|
||||
|
@ -174,20 +162,16 @@ class Node extends Model
|
|||
|
||||
/**
|
||||
* Returns the configuration in Yaml format.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getYamlConfiguration()
|
||||
public function getYamlConfiguration(): string
|
||||
{
|
||||
return Yaml::dump($this->getConfiguration(), 4, 2, Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration in JSON format.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getJsonConfiguration(bool $pretty = false)
|
||||
public function getJsonConfiguration(bool $pretty = false): string
|
||||
{
|
||||
return json_encode($this->getConfiguration(), $pretty ? JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT : JSON_UNESCAPED_SLASHES);
|
||||
}
|
||||
|
@ -202,40 +186,31 @@ class Node extends Model
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
*/
|
||||
public function mounts()
|
||||
public function mounts(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Mount::class, MountNode::class, 'node_id', 'id', 'id', 'mount_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location associated with a node.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function location()
|
||||
public function location(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Location::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the servers associated with a node.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servers()
|
||||
public function servers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Server::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the allocations associated with a node.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function allocations()
|
||||
public function allocations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Allocation::class);
|
||||
}
|
||||
|
|
|
@ -4,30 +4,18 @@ namespace Pterodactyl\Models\Objects;
|
|||
|
||||
class DeploymentObject
|
||||
{
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $dedicated = false;
|
||||
private bool $dedicated = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $locations = [];
|
||||
private array $locations = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $ports = [];
|
||||
private array $ports = [];
|
||||
|
||||
public function isDedicated(): bool
|
||||
{
|
||||
return $this->dedicated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setDedicated(bool $dedicated)
|
||||
public function setDedicated(bool $dedicated): self
|
||||
{
|
||||
$this->dedicated = $dedicated;
|
||||
|
||||
|
@ -39,10 +27,7 @@ class DeploymentObject
|
|||
return $this->locations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setLocations(array $locations)
|
||||
public function setLocations(array $locations): self
|
||||
{
|
||||
$this->locations = $locations;
|
||||
|
||||
|
@ -54,10 +39,7 @@ class DeploymentObject
|
|||
return $this->ports;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function setPorts(array $ports)
|
||||
public function setPorts(array $ports): self
|
||||
{
|
||||
$this->ports = $ports;
|
||||
|
||||
|
|
|
@ -67,51 +67,38 @@ class Permission extends Model
|
|||
|
||||
/**
|
||||
* Should timestamps be used on this model.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'permissions';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'subuser_id' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'subuser_id' => 'required|numeric|min:1',
|
||||
'permission' => 'required|string',
|
||||
];
|
||||
|
||||
/**
|
||||
* All of the permissions available on the system. You should use self::permissions()
|
||||
* All the permissions available on the system. You should use self::permissions()
|
||||
* to retrieve them, and not directly access this array as it is subject to change.
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @see \Pterodactyl\Models\Permission::permissions()
|
||||
*/
|
||||
protected static $permissions = [
|
||||
protected static array $permissions = [
|
||||
'websocket' => [
|
||||
'description' => 'Allows the user to connect to the server websocket, giving them access to view console output and realtime server stats.',
|
||||
'keys' => [
|
||||
|
@ -222,10 +209,8 @@ class Permission extends Model
|
|||
];
|
||||
|
||||
/**
|
||||
* Returns all of the permissions available on the system for a user to
|
||||
* Returns all the permissions available on the system for a user to
|
||||
* have when controlling a server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public static function permissions(): Collection
|
||||
{
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
|
@ -16,27 +18,15 @@ class RecoveryToken extends Model
|
|||
*/
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $immutableDates = true;
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'token' => 'required|string',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ namespace Pterodactyl\Models;
|
|||
use Cron\CronExpression;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
||||
|
||||
/**
|
||||
|
@ -37,22 +39,16 @@ class Schedule extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'schedules';
|
||||
|
||||
/**
|
||||
* Always return the tasks associated with this schedule.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = ['tasks'];
|
||||
|
||||
/**
|
||||
* Mass assignable attributes on this model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'server_id',
|
||||
|
@ -69,9 +65,6 @@ class Schedule extends Model
|
|||
'next_run_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
'server_id' => 'integer',
|
||||
|
@ -82,17 +75,12 @@ class Schedule extends Model
|
|||
|
||||
/**
|
||||
* Columns to mutate to a date.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = [
|
||||
'last_run_at',
|
||||
'next_run_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'name' => null,
|
||||
'cron_day_of_week' => '*',
|
||||
|
@ -105,10 +93,7 @@ class Schedule extends Model
|
|||
'only_when_online' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'server_id' => 'required|exists:servers,id',
|
||||
'name' => 'required|string|max:191',
|
||||
'cron_day_of_week' => 'required|string',
|
||||
|
@ -134,11 +119,9 @@ class Schedule extends Model
|
|||
/**
|
||||
* Returns the schedule's execution crontab entry as a string.
|
||||
*
|
||||
* @return \Carbon\CarbonImmutable
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getNextRunDate()
|
||||
public function getNextRunDate(): CarbonImmutable
|
||||
{
|
||||
$formatted = sprintf('%s %s %s %s %s', $this->cron_minute, $this->cron_hour, $this->cron_day_of_month, $this->cron_month, $this->cron_day_of_week);
|
||||
|
||||
|
@ -149,30 +132,24 @@ class Schedule extends Model
|
|||
|
||||
/**
|
||||
* Return a hashid encoded string to represent the ID of the schedule.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHashidAttribute()
|
||||
public function getHashidAttribute(): string
|
||||
{
|
||||
return Container::getInstance()->make(HashidsInterface::class)->encode($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return tasks belonging to a schedule.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function tasks()
|
||||
public function tasks(): HasMany
|
||||
{
|
||||
return $this->hasMany(Task::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the server model that a schedule belongs to.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,11 @@ namespace Pterodactyl\Models;
|
|||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Pterodactyl\Exceptions\Http\Server\ServerStateConflictException;
|
||||
|
||||
/**
|
||||
|
@ -95,6 +99,7 @@ use Pterodactyl\Exceptions\Http\Server\ServerStateConflictException;
|
|||
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUuid($value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|Server whereUuidShort($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class Server extends Model
|
||||
|
@ -115,16 +120,12 @@ class Server extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'servers';
|
||||
|
||||
/**
|
||||
* Default values when creating the model. We want to switch to disabling OOM killer
|
||||
* on server instances unless the user specifies otherwise in the request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'status' => self::STATUS_INSTALLING,
|
||||
|
@ -134,29 +135,20 @@ class Server extends Model
|
|||
|
||||
/**
|
||||
* The default relationships to load for all server models.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $with = ['allocation'];
|
||||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = [self::CREATED_AT, self::UPDATED_AT, 'deleted_at', 'installed_at'];
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', self::CREATED_AT, self::UPDATED_AT, 'deleted_at', 'installed_at'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'external_id' => 'sometimes|nullable|string|between:1,191|unique:servers',
|
||||
'owner_id' => 'required|integer|exists:users,id',
|
||||
'name' => 'required|string|min:1|max:191',
|
||||
|
@ -183,8 +175,6 @@ class Server extends Model
|
|||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'node_id' => 'integer',
|
||||
|
@ -226,76 +216,62 @@ class Server extends Model
|
|||
|
||||
/**
|
||||
* Gets the user who owns the server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'owner_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the subusers associated with a server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function subusers()
|
||||
public function subusers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Subuser::class, 'server_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default allocation for a server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function allocation()
|
||||
public function allocation(): HasOne
|
||||
{
|
||||
return $this->hasOne(Allocation::class, 'id', 'allocation_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all allocations associated with this server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function allocations()
|
||||
public function allocations(): HasMany
|
||||
{
|
||||
return $this->hasMany(Allocation::class, 'server_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information for the nest associated with this server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function nest()
|
||||
public function nest(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Nest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information for the egg associated with this server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function egg()
|
||||
public function egg(): HasOne
|
||||
{
|
||||
return $this->hasOne(Egg::class, 'id', 'egg_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information for the service variables associated with this server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function variables()
|
||||
public function variables(): HasMany
|
||||
{
|
||||
return $this->hasMany(EggVariable::class, 'egg_id', 'egg_id')
|
||||
->select(['egg_variables.*', 'server_variables.variable_value as server_value'])
|
||||
->leftJoin('server_variables', function (JoinClause $join) {
|
||||
// Don't forget to join against the server ID as well since the way we're using this relationship
|
||||
// would actually return all of the variables and their values for _all_ servers using that egg,\
|
||||
// would actually return all the variables and their values for _all_ servers using that egg,
|
||||
// rather than only the server for this model.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/issues/2250
|
||||
|
@ -306,30 +282,24 @@ class Server extends Model
|
|||
|
||||
/**
|
||||
* Gets information for the node associated with this server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function node()
|
||||
public function node(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Node::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets information for the tasks associated with this server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function schedules()
|
||||
public function schedules(): HasMany
|
||||
{
|
||||
return $this->hasMany(Schedule::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all databases associated with a server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function databases()
|
||||
public function databases(): HasMany
|
||||
{
|
||||
return $this->hasMany(Database::class);
|
||||
}
|
||||
|
@ -337,39 +307,30 @@ class Server extends Model
|
|||
/**
|
||||
* Returns the location that a server belongs to.
|
||||
*
|
||||
* @return \Znck\Eloquent\Relations\BelongsToThrough
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function location()
|
||||
public function location(): \Znck\Eloquent\Relations\BelongsToThrough
|
||||
{
|
||||
return $this->belongsToThrough(Location::class, Node::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the associated server transfer.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function transfer()
|
||||
public function transfer(): HasOne
|
||||
{
|
||||
return $this->hasOne(ServerTransfer::class)->whereNull('successful')->orderByDesc('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function backups()
|
||||
public function backups(): HasMany
|
||||
{
|
||||
return $this->hasMany(Backup::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all mounts that have this server has mounted.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
|
||||
*/
|
||||
public function mounts()
|
||||
public function mounts(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Mount::class, MountServer::class, 'server_id', 'id', 'id', 'mount_id');
|
||||
}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $server_id
|
||||
|
@ -29,22 +32,16 @@ class ServerTransfer extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'server_transfers';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'server_id' => 'int',
|
||||
|
@ -58,10 +55,7 @@ class ServerTransfer extends Model
|
|||
'archived' => 'bool',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'server_id' => 'required|numeric|exists:servers,id',
|
||||
'old_node' => 'required|numeric',
|
||||
'new_node' => 'required|numeric',
|
||||
|
@ -76,30 +70,24 @@ class ServerTransfer extends Model
|
|||
|
||||
/**
|
||||
* Gets the server associated with a server transfer.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source node associated with a server transfer.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function oldNode()
|
||||
public function oldNode(): HasOne
|
||||
{
|
||||
return $this->hasOne(Node::class, 'id', 'old_node');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the target node associated with a server transfer.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function newNode()
|
||||
public function newNode(): HasOne
|
||||
{
|
||||
return $this->hasOne(Node::class, 'id', 'new_node');
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $server_id
|
||||
|
@ -20,23 +22,18 @@ class ServerVariable extends Model
|
|||
*/
|
||||
public const RESOURCE_NAME = 'server_variable';
|
||||
|
||||
/** @var bool */
|
||||
protected $immutableDates = true;
|
||||
protected bool $immutableDates = true;
|
||||
|
||||
/** @var string */
|
||||
protected $table = 'server_variables';
|
||||
|
||||
/** @var string[] */
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/** @var string[] */
|
||||
protected $casts = [
|
||||
'server_id' => 'integer',
|
||||
'variable_id' => 'integer',
|
||||
];
|
||||
|
||||
/** @var string[] */
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'server_id' => 'required|int',
|
||||
'variable_id' => 'required|int',
|
||||
'variable_value' => 'string',
|
||||
|
@ -44,20 +41,16 @@ class ServerVariable extends Model
|
|||
|
||||
/**
|
||||
* Returns the server this variable is associated with.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about a given variables parent.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function variable()
|
||||
public function variable(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(EggVariable::class, 'variable_id');
|
||||
}
|
||||
|
|
|
@ -8,15 +8,11 @@ class Session extends Model
|
|||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sessions';
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'string',
|
||||
|
|
|
@ -6,25 +6,14 @@ class Setting extends Model
|
|||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'settings';
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['key', 'value'];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'key' => 'required|string|between:1,191',
|
||||
'value' => 'string',
|
||||
];
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
namespace Pterodactyl\Models;
|
||||
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
|
@ -26,22 +28,16 @@ class Subuser extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'subusers';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'user_id' => 'int',
|
||||
|
@ -49,10 +45,7 @@ class Subuser extends Model
|
|||
'permissions' => 'array',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'user_id' => 'required|numeric|exists:users,id',
|
||||
'server_id' => 'required|numeric|exists:servers,id',
|
||||
'permissions' => 'nullable|array',
|
||||
|
@ -61,40 +54,32 @@ class Subuser extends Model
|
|||
|
||||
/**
|
||||
* Return a hashid encoded string to represent the ID of the subuser.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHashidAttribute()
|
||||
public function getHashidAttribute(): string
|
||||
{
|
||||
return app()->make('hashids')->encode($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server associated with a subuser.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function server()
|
||||
public function server(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Server::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the user associated with a subuser.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the permissions associated with a subuser.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function permissions()
|
||||
public function permissions(): HasMany
|
||||
{
|
||||
return $this->hasMany(Permission::class);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Pterodactyl\Models;
|
|||
|
||||
use Illuminate\Container\Container;
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Pterodactyl\Contracts\Extensions\HashidsInterface;
|
||||
|
||||
/**
|
||||
|
@ -40,22 +41,16 @@ class Task extends Model
|
|||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'tasks';
|
||||
|
||||
/**
|
||||
* Relationships to be updated when this model is updated.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $touches = ['schedule'];
|
||||
|
||||
/**
|
||||
* Fields that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'schedule_id',
|
||||
|
@ -69,8 +64,6 @@ class Task extends Model
|
|||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
|
@ -83,8 +76,6 @@ class Task extends Model
|
|||
|
||||
/**
|
||||
* Default attributes when creating a new model.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'time_offset' => 0,
|
||||
|
@ -92,10 +83,7 @@ class Task extends Model
|
|||
'continue_on_failure' => false,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'schedule_id' => 'required|numeric|exists:schedules,id',
|
||||
'sequence_id' => 'required|numeric|min:1',
|
||||
'action' => 'required|string',
|
||||
|
@ -115,32 +103,24 @@ class Task extends Model
|
|||
|
||||
/**
|
||||
* Return a hashid encoded string to represent the ID of the task.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHashidAttribute()
|
||||
public function getHashidAttribute(): string
|
||||
{
|
||||
return Container::getInstance()->make(HashidsInterface::class)->encode($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the schedule that a task belongs to.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function schedule()
|
||||
public function schedule(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Schedule::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the server a task is assigned to, acts as a belongsToThrough.
|
||||
*
|
||||
* @return \Znck\Eloquent\Relations\BelongsToThrough
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function server()
|
||||
public function server(): \Znck\Eloquent\Relations\BelongsToThrough
|
||||
{
|
||||
return $this->belongsToThrough(Server::class, Schedule::class);
|
||||
}
|
||||
|
|
|
@ -8,22 +8,16 @@ class TaskLog extends Model
|
|||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'tasks_log';
|
||||
|
||||
/**
|
||||
* Fields that are not mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'id' => 'integer',
|
||||
|
@ -33,8 +27,6 @@ class TaskLog extends Model
|
|||
|
||||
/**
|
||||
* The attributes that should be mutated to dates.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['run_time', 'created_at', 'updated_at'];
|
||||
}
|
||||
|
|
|
@ -75,6 +75,7 @@ use Pterodactyl\Notifications\SendPasswordReset as ResetPasswordNotification;
|
|||
* @method static Builder|User whereUseTotp($value)
|
||||
* @method static Builder|User whereUsername($value)
|
||||
* @method static Builder|User whereUuid($value)
|
||||
*
|
||||
* @mixin \Eloquent
|
||||
*/
|
||||
class User extends Model implements
|
||||
|
@ -100,22 +101,16 @@ class User extends Model implements
|
|||
|
||||
/**
|
||||
* Level of servers to display when using access() on a user.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $accessLevel = 'all';
|
||||
protected string $accessLevel = 'all';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'users';
|
||||
|
||||
/**
|
||||
* A list of mass-assignable variables.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'external_id',
|
||||
|
@ -134,8 +129,6 @@ class User extends Model implements
|
|||
|
||||
/**
|
||||
* Cast values to correct type.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'root_admin' => 'boolean',
|
||||
|
@ -143,22 +136,15 @@ class User extends Model implements
|
|||
'gravatar' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $dates = ['totp_authenticated_at'];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['password', 'remember_token', 'totp_secret', 'totp_authenticated_at'];
|
||||
|
||||
/**
|
||||
* Default values for specific fields in the database.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $attributes = [
|
||||
'external_id' => null,
|
||||
|
@ -170,10 +156,8 @@ class User extends Model implements
|
|||
|
||||
/**
|
||||
* Rules verifying that the data being stored matches the expectations of the database.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'uuid' => 'required|string|size:36|unique:users,uuid',
|
||||
'email' => 'required|email|between:1,191|unique:users,email',
|
||||
'external_id' => 'sometimes|nullable|string|max:191|unique:users,external_id',
|
||||
|
@ -191,7 +175,7 @@ class User extends Model implements
|
|||
* Implement language verification by overriding Eloquence's gather
|
||||
* rules function.
|
||||
*/
|
||||
public static function getRules()
|
||||
public static function getRules(): array
|
||||
{
|
||||
$rules = parent::getRules();
|
||||
|
||||
|
@ -234,37 +218,27 @@ class User extends Model implements
|
|||
|
||||
/**
|
||||
* Return a concatenated result for the accounts full name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute()
|
||||
public function getNameAttribute(): string
|
||||
{
|
||||
return trim($this->name_first . ' ' . $this->name_last);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all servers that a user owns.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function servers()
|
||||
public function servers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Server::class, 'owner_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function apiKeys()
|
||||
public function apiKeys(): HasMany
|
||||
{
|
||||
return $this->hasMany(ApiKey::class)
|
||||
->where('key_type', ApiKey::TYPE_ACCOUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function recoveryTokens()
|
||||
public function recoveryTokens(): HasMany
|
||||
{
|
||||
return $this->hasMany(RecoveryToken::class);
|
||||
}
|
||||
|
@ -275,7 +249,7 @@ class User extends Model implements
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all of the activity logs where this user is the subject — not to
|
||||
* Returns all the activity logs where this user is the subject — not to
|
||||
* be confused by activity logs where this user is the _actor_.
|
||||
*/
|
||||
public function activity(): MorphToMany
|
||||
|
@ -284,12 +258,10 @@ class User extends Model implements
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all of the servers that a user can access by way of being the owner of the
|
||||
* Returns all the servers that a user can access by way of being the owner of the
|
||||
* server, or because they are assigned as a subuser for that server.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function accessibleServers()
|
||||
public function accessibleServers(): Builder
|
||||
{
|
||||
return Server::query()
|
||||
->select('servers.*')
|
||||
|
|
|
@ -50,7 +50,7 @@ class UserSSHKey extends Model
|
|||
'fingerprint',
|
||||
];
|
||||
|
||||
public static $validationRules = [
|
||||
public static array $validationRules = [
|
||||
'name' => ['required', 'string'],
|
||||
'fingerprint' => ['required', 'string'],
|
||||
'public_key' => ['required', 'string'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue