Files
panel/app/Models/Backup.php
Dane Everitt a81c3b4d52 Add support for stripe-style identifiers on existing models with UUIDs (#5548)
This is a partial implementation to begin moving towards stripe-style
identifiers for resources in the system. Any models with an existing
`uuid` column can easily be updated to return an identifier in the
format of `prfx_xyz` where `prfx` is a four character prefix, and `xyz`
is the UUID, encoded using base-32.

These are quite easy to use within the API layer because we just need to
do one quick transformation to extract the UUID for those models. This
PR implements that logic for servers in the `SubstituteClientBindings`
logic.

A future PR will need to come through and handle identifiers for models
that _don't_ currently use UUIDs for reference that we want to expose to
clients. In those cases it is easier to just generate base-32 encoded
UUID7s that get stored in the database and indexed. They follow the same
base approach, but you don't need to do any transformations in the code
(other than stripping the prefix, unless we decide to store the prefix).

There is also now a `PTERODACTYL_USE_SERVER_IDENTIFIERS` environment
variable, that when set to true, updates the front-end and API response
to use this new identifier in place of the `uuidShort` value.
2026-02-14 11:21:57 -08:00

87 lines
2.4 KiB
PHP

<?php
namespace Pterodactyl\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Pterodactyl\Contracts\Models\Identifiable;
use Pterodactyl\Models\Traits\HasRealtimeIdentifier;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* @property int $id
* @property int $server_id
* @property string $uuid
* @property bool $is_successful
* @property bool $is_locked
* @property string $name
* @property string[] $ignored_files
* @property string $disk
* @property string|null $checksum
* @property int $bytes
* @property string|null $upload_id
* @property \Carbon\CarbonImmutable|null $completed_at
* @property \Carbon\CarbonImmutable $created_at
* @property \Carbon\CarbonImmutable $updated_at
* @property \Carbon\CarbonImmutable|null $deleted_at
* @property Server $server
* @property \Pterodactyl\Models\AuditLog[] $audits
*/
#[Attributes\Identifiable('bkup')]
class Backup extends Model implements Identifiable
{
/** @use HasFactory<\Database\Factories\BackupFactory> */
use HasFactory;
use SoftDeletes;
use HasRealtimeIdentifier;
public const RESOURCE_NAME = 'backup';
public const ADAPTER_WINGS = 'wings';
public const ADAPTER_AWS_S3 = 's3';
protected $table = 'backups';
protected bool $immutableDates = true;
protected $casts = [
'id' => 'int',
'is_successful' => 'bool',
'is_locked' => 'bool',
'ignored_files' => 'array',
'bytes' => 'int',
'completed_at' => 'datetime',
];
protected $attributes = [
'is_successful' => false,
'is_locked' => false,
'checksum' => null,
'bytes' => 0,
'upload_id' => null,
];
protected $guarded = ['id', 'created_at', 'updated_at', 'deleted_at'];
public static array $validationRules = [
'server_id' => 'bail|required|numeric|exists:servers,id',
'uuid' => 'required|uuid',
'is_successful' => 'boolean',
'is_locked' => 'boolean',
'name' => 'required|string',
'ignored_files' => 'array',
'disk' => 'required|string',
'checksum' => 'nullable|string',
'bytes' => 'numeric',
'upload_id' => 'nullable|string',
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\Pterodactyl\Models\Server, $this>
*/
public function server(): BelongsTo
{
return $this->belongsTo(Server::class);
}
}