refactor(backups): centralize storage deletion guard

This commit is contained in:
Andras Bacsai committed 2026-07-19 23:20:46 +02:00
1 parent 4e03be755d
commit bf72fd5d88
6 files changed
+38 -21

No files matched your search

@@ -4910,13 +4910,7 @@ class ApplicationsController extends Controller
], 422);
}
if ($storage->scheduledBackups()->exists()) {
return response()->json([
'message' => $storage instanceof LocalFileVolume
? 'Delete this directory backup schedule and its archives before deleting the directory.'
: 'Delete this volume backup schedule and its archives before deleting the volume.',
], 422);
}
$storage->abortIfScheduledBackupsExist();
if ($storage instanceof LocalFileVolume) {
$storage->deleteStorageOnServer();
@@ -4484,13 +4484,7 @@ class DatabasesController extends Controller
], 422);
}
if ($storage->scheduledBackups()->exists()) {
return response()->json([
'message' => $storage instanceof LocalFileVolume
? 'Delete this directory backup schedule and its archives before deleting the directory.'
: 'Delete this volume backup schedule and its archives before deleting the volume.',
], 422);
}
$storage->abortIfScheduledBackupsExist();
if ($storage instanceof LocalFileVolume) {
$storage->deleteStorageOnServer();
@@ -2911,13 +2911,7 @@ class ServicesController extends Controller
], 422);
}
if ($storage->scheduledBackups()->exists()) {
return response()->json([
'message' => $storage instanceof LocalFileVolume
? 'Delete this directory backup schedule and its archives before deleting the directory.'
: 'Delete this volume backup schedule and its archives before deleting the volume.',
], 422);
}
$storage->abortIfScheduledBackupsExist();
if ($storage instanceof LocalFileVolume) {
$storage->deleteStorageOnServer();
+7
View File
@@ -96,6 +96,13 @@ class LocalFileVolume extends BaseModel
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) {
+7
View File
@@ -56,6 +56,13 @@ class LocalPersistentVolume extends BaseModel
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;