2020-04-03 23:40:20 -07:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2020-04-03 23:40:20 -07:00
|
|
|
namespace Pterodactyl\Models;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Carbon\CarbonImmutable;
|
|
|
|
|
use Database\Factories\BackupFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
|
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2020-04-03 23:40:20 -07:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2026-02-14 11:21:57 -08:00
|
|
|
use Pterodactyl\Contracts\Models\Identifiable;
|
|
|
|
|
use Pterodactyl\Models\Traits\HasRealtimeIdentifier;
|
2020-04-03 23:40:20 -07:00
|
|
|
|
|
|
|
|
/**
|
2021-01-27 20:52:11 -08:00
|
|
|
* @property int $id
|
|
|
|
|
* @property int $server_id
|
|
|
|
|
* @property string $uuid
|
|
|
|
|
* @property bool $is_successful
|
2021-05-03 21:26:09 -07:00
|
|
|
* @property bool $is_locked
|
2021-01-27 20:52:11 -08:00
|
|
|
* @property string $name
|
|
|
|
|
* @property string[] $ignored_files
|
|
|
|
|
* @property string $disk
|
|
|
|
|
* @property string|null $checksum
|
|
|
|
|
* @property int $bytes
|
|
|
|
|
* @property string|null $upload_id
|
2026-10-05 18:10:18 -04:00
|
|
|
* @property CarbonImmutable|null $completed_at
|
|
|
|
|
* @property CarbonImmutable $created_at
|
|
|
|
|
* @property CarbonImmutable $updated_at
|
|
|
|
|
* @property CarbonImmutable|null $deleted_at
|
2024-10-21 19:18:20 -06:00
|
|
|
* @property Server $server
|
2026-10-05 18:10:18 -04:00
|
|
|
* @property AuditLog[] $audits
|
2020-04-03 23:40:20 -07:00
|
|
|
*/
|
2026-02-14 11:21:57 -08:00
|
|
|
#[Attributes\Identifiable('bkup')]
|
2026-10-05 18:10:18 -04:00
|
|
|
#[Guarded(['id', 'created_at', 'updated_at', 'deleted_at'])]
|
2026-02-14 11:21:57 -08:00
|
|
|
class Backup extends Model implements Identifiable
|
2020-04-03 23:40:20 -07:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
/** @use HasFactory<BackupFactory> */
|
2024-10-21 19:18:20 -06:00
|
|
|
use HasFactory;
|
2020-04-04 10:59:25 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use HasRealtimeIdentifier;
|
|
|
|
|
use SoftDeletes;
|
2020-04-04 19:54:59 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
public const string RESOURCE_NAME = 'backup';
|
2020-04-03 23:40:20 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
public const string ADAPTER_WINGS = 'wings';
|
2020-04-03 23:40:20 -07:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
public const string ADAPTER_AWS_S3 = 's3';
|
2020-04-03 23:40:20 -07:00
|
|
|
|
2020-04-04 12:26:39 -07:00
|
|
|
protected $attributes = [
|
2021-08-03 20:45:25 -06:00
|
|
|
'is_successful' => false,
|
2021-05-03 21:26:09 -07:00
|
|
|
'is_locked' => false,
|
2020-08-23 18:06:47 -07:00
|
|
|
'checksum' => null,
|
2020-04-04 12:26:39 -07:00
|
|
|
'bytes' => 0,
|
2020-12-26 11:59:21 -07:00
|
|
|
'upload_id' => null,
|
2020-04-04 12:26:39 -07:00
|
|
|
];
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'id' => 'integer',
|
|
|
|
|
'is_successful' => 'boolean',
|
|
|
|
|
'is_locked' => 'boolean',
|
|
|
|
|
'ignored_files' => 'array',
|
|
|
|
|
'bytes' => 'integer',
|
|
|
|
|
'completed_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
}
|
2020-04-04 10:59:25 -07:00
|
|
|
|
2025-12-20 15:55:13 -08:00
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* @return BelongsTo<Server, $this>
|
2025-12-20 15:55:13 -08:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function server(): BelongsTo
|
2020-04-04 10:59:25 -07:00
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Server::class);
|
|
|
|
|
}
|
2026-10-05 18:10:18 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Backups still running or completed successfully.
|
|
|
|
|
*
|
|
|
|
|
* @param Builder<self> $query
|
|
|
|
|
*/
|
|
|
|
|
#[Scope]
|
|
|
|
|
protected function nonFailed(Builder $query): void
|
|
|
|
|
{
|
|
|
|
|
$query->where(fn (Builder $inner) => $inner->whereNull('completed_at')->orWhere('is_successful', true));
|
|
|
|
|
}
|
2020-04-03 23:40:20 -07:00
|
|
|
}
|