Merge remote-tracking branch 'origin/next' into v5-parallel-inertia-react

This commit is contained in:
Andras Bacsai committed 2026-07-20 12:09:17 +02:00
commit ee36124300
82 files changed
+8190 -463

No files matched your search

+26 -1
View File
@@ -6,6 +6,8 @@ use App\Events\FileStorageChanged;
use App\Jobs\ServerStorageSaveJob;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Symfony\Component\Yaml\Yaml;
class LocalFileVolume extends BaseModel
@@ -57,6 +59,12 @@ class LocalFileVolume extends BaseModel
$fileVolume->load(['service']);
dispatch(new ServerStorageSaveJob($fileVolume));
});
static::deleting(function (LocalFileVolume $fileVolume): void {
if ($fileVolume->scheduledBackups()->exists()) {
throw new \RuntimeException('Delete this directory backup schedule and its archives before deleting the directory.');
}
});
}
protected function isBinary(): Attribute
@@ -73,11 +81,28 @@ class LocalFileVolume extends BaseModel
);
}
public function service()
public function resource(): MorphTo
{
return $this->morphTo();
}
public function service(): MorphTo
{
return $this->morphTo('resource');
}
public function scheduledBackups(): MorphMany
{
return $this->morphMany(ScheduledVolumeBackup::class, 'backupable');
}
public function abortIfScheduledBackupsExist(): void
{
if ($this->scheduledBackups()->exists()) {
abort(422, 'Delete this directory backup schedule and its archives before deleting the directory.');
}
}
public function loadStorageOnServer()
{
if ($this->is_host_file) {
+22
View File
@@ -3,10 +3,20 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Symfony\Component\Yaml\Yaml;
class LocalPersistentVolume extends BaseModel
{
protected static function booted(): void
{
static::deleting(function (LocalPersistentVolume $volume): void {
if ($volume->scheduledBackups()->exists()) {
throw new \RuntimeException('Delete this volume backup schedule and its archives before deleting the volume.');
}
});
}
protected $fillable = [
'name',
'mount_path',
@@ -41,6 +51,18 @@ class LocalPersistentVolume extends BaseModel
return $this->morphTo('resource');
}
public function scheduledBackups(): MorphMany
{
return $this->morphMany(ScheduledVolumeBackup::class, 'backupable');
}
public function abortIfScheduledBackupsExist(): void
{
if ($this->scheduledBackups()->exists()) {
abort(422, 'Delete this volume backup schedule and its archives before deleting the volume.');
}
}
protected function customizeName($value)
{
return str($value)->trim()->value;
+14
View File
@@ -69,6 +69,15 @@ class S3Storage extends BaseModel
'save_s3' => false,
's3_storage_id' => null,
]);
ScheduledVolumeBackupExecution::where('s3_storage_id', $storage->id)
->update([
's3_storage_deleted' => true,
's3_cleanup_pending' => false,
]);
ScheduledVolumeBackup::where('s3_storage_id', $storage->id)->update([
'save_s3' => false,
's3_storage_id' => null,
]);
});
}
@@ -101,6 +110,11 @@ class S3Storage extends BaseModel
return $this->hasMany(ScheduledDatabaseBackup::class, 's3_storage_id');
}
public function scheduledVolumeBackups()
{
return $this->hasMany(ScheduledVolumeBackup::class, 's3_storage_id');
}
public function awsUrl()
{
return "{$this->endpoint}/{$this->bucket}";
+149
View File
@@ -0,0 +1,149 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphTo;
class ScheduledVolumeBackup extends BaseModel
{
protected $fillable = [
'uuid',
'backupable_type',
'backupable_id',
'team_id',
's3_storage_id',
'frequency',
'enabled',
'save_s3',
'disable_local_backup',
'stop_during_backup',
'retention_amount_locally',
'retention_days_locally',
'retention_max_storage_locally',
'retention_amount_s3',
'retention_days_s3',
'retention_max_storage_s3',
'timeout',
];
protected function casts(): array
{
return [
'enabled' => 'boolean',
'save_s3' => 'boolean',
'disable_local_backup' => 'boolean',
'stop_during_backup' => 'boolean',
'retention_amount_locally' => 'integer',
'retention_days_locally' => 'integer',
'retention_max_storage_locally' => 'float',
'retention_amount_s3' => 'integer',
'retention_days_s3' => 'integer',
'retention_max_storage_s3' => 'float',
'timeout' => 'integer',
];
}
public function scopeForApplication(Builder $query, Application $application): Builder
{
$volumeIds = $application->persistentStorages()->pluck('id');
$directoryIds = $application->fileStorages()
->where('is_directory', true)
->where('is_host_file', false)
->pluck('id');
return $query->where(function (Builder $query) use ($volumeIds, $directoryIds): void {
$query->where(function (Builder $query) use ($volumeIds): void {
$query->where('backupable_type', (new LocalPersistentVolume)->getMorphClass())
->whereIn('backupable_id', $volumeIds);
})->orWhere(function (Builder $query) use ($directoryIds): void {
$query->where('backupable_type', (new LocalFileVolume)->getMorphClass())
->whereIn('backupable_id', $directoryIds);
});
});
}
public function backupable(): MorphTo
{
return $this->morphTo();
}
public function team(): BelongsTo
{
return $this->belongsTo(Team::class);
}
public function s3(): BelongsTo
{
return $this->belongsTo(S3Storage::class, 's3_storage_id');
}
public function executions(): HasMany
{
return $this->hasMany(ScheduledVolumeBackupExecution::class)->latest();
}
public function latestExecution(): HasOne
{
return $this->hasOne(ScheduledVolumeBackupExecution::class)->latestOfMany();
}
public function server(): ?Server
{
$resource = $this->targetResource();
if ($resource instanceof ServiceApplication || $resource instanceof ServiceDatabase) {
return $resource->service?->server?->fresh();
}
return $resource?->destination?->server?->fresh();
}
public function targetResource(): ?Model
{
return $this->backupable?->resource;
}
public function targetType(): string
{
return $this->backupable instanceof LocalFileVolume ? 'Directory' : 'Volume';
}
public function targetName(): string
{
return match (true) {
$this->backupable instanceof LocalFileVolume => $this->backupable->fs_path,
$this->backupable instanceof LocalPersistentVolume => $this->backupable->name,
default => 'Unknown storage',
};
}
public function sourcePath(): string
{
$target = $this->backupable;
if ($target instanceof LocalPersistentVolume) {
return filled($target->host_path) ? $target->host_path : $target->name;
}
if (! $target instanceof LocalFileVolume || ! $target->is_directory) {
throw new \RuntimeException('The backup target is not a directory or persistent volume.');
}
$path = str($target->fs_path);
if ($path->startsWith('.')) {
$resource = $this->targetResource();
if (! $resource || ! method_exists($resource, 'workdir')) {
throw new \RuntimeException('The directory backup workdir is unavailable.');
}
return $resource->workdir().$path->after('.')->toString();
}
return $path->toString();
}
}
@@ -0,0 +1,49 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ScheduledVolumeBackupExecution extends BaseModel
{
protected $fillable = [
'uuid',
'scheduled_volume_backup_id',
's3_storage_id',
'status',
'message',
'size',
'filename',
'stop_container_ids',
'stop_recovery_pending',
's3_cleanup_pending',
'finished_at',
'local_storage_deleted',
's3_storage_deleted',
's3_uploaded',
];
protected function casts(): array
{
return [
'size' => 'integer',
'finished_at' => 'datetime',
'stop_container_ids' => 'array',
'stop_recovery_pending' => 'boolean',
's3_cleanup_pending' => 'boolean',
'local_storage_deleted' => 'boolean',
's3_storage_deleted' => 'boolean',
's3_uploaded' => 'boolean',
];
}
public function scheduledVolumeBackup(): BelongsTo
{
return $this->belongsTo(ScheduledVolumeBackup::class);
}
public function s3(): BelongsTo
{
return $this->belongsTo(S3Storage::class, 's3_storage_id');
}
}