50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class RestoreRun extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $casts = [
|
|
'is_dry_run' => 'boolean',
|
|
'requested_items' => 'array',
|
|
'preview' => 'array',
|
|
'results' => 'array',
|
|
'metadata' => 'array',
|
|
'started_at' => 'datetime',
|
|
'completed_at' => 'datetime',
|
|
];
|
|
|
|
public function tenant(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tenant::class);
|
|
}
|
|
|
|
public function backupSet(): BelongsTo
|
|
{
|
|
return $this->belongsTo(BackupSet::class);
|
|
}
|
|
|
|
public function scopeDeletable($query)
|
|
{
|
|
return $query->whereIn('status', ['completed', 'failed', 'aborted', 'completed_with_errors', 'partial', 'previewed']);
|
|
}
|
|
|
|
public function isDeletable(): bool
|
|
{
|
|
$status = strtolower(trim((string) $this->status));
|
|
$status = str_replace([' ', '-'], '_', $status);
|
|
|
|
return in_array($status, ['completed', 'failed', 'aborted', 'completed_with_errors', 'partial', 'previewed'], true);
|
|
}
|
|
}
|