Upgrade to Laravel 9 (#4413)

Co-authored-by: DaneEveritt <dane@daneeveritt.com>
This commit is contained in:
Matthew Penner 2022-10-14 10:59:20 -06:00 committed by GitHub
parent 95e15d2c8a
commit cbcf62086f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
573 changed files with 4387 additions and 9411 deletions

View file

@ -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');
}