From 5a045b4dcd4e01186d2bc01ea3dbdf93d006d7a5 Mon Sep 17 00:00:00 2001 From: Samuel Stancl Date: Sun, 12 Apr 2026 19:41:12 +0200 Subject: [PATCH] Make skipping opt-out, add opt-in ignoreFailures logic --- src/Jobs/DeleteDatabase.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Jobs/DeleteDatabase.php b/src/Jobs/DeleteDatabase.php index 98f175fb..cc9ead66 100644 --- a/src/Jobs/DeleteDatabase.php +++ b/src/Jobs/DeleteDatabase.php @@ -22,18 +22,31 @@ class DeleteDatabase implements ShouldQueue protected TenantWithDatabase&Model $tenant, ) {} - public function handle(): bool + /** Skip database deletion if the create_database internal attribute is false. */ + public static bool $skipWhenCreateDatabaseIsFalse = true; + + /** Ignore exceptions thrown during database deletion and continue execution. */ + public static bool $ignoreFailures = false; + + public function handle(): void { event(new DeletingDatabase($this->tenant)); - if ($this->tenant->getInternal('create_database') === false) { - return false; + if (static::$skipWhenCreateDatabaseIsFalse && $this->tenant->getInternal('create_database') === false) { + // If database creation was skipped, we presume deletion should also be skipped. + // To avoid this skip, either unset the `create_database` attribute (or make it true), or + // set the $skipWhenCreateDatabaseIsFalse static property to false. + return; } - $this->tenant->database()->manager()->deleteDatabase($this->tenant); + try { + $this->tenant->database()->manager()->deleteDatabase($this->tenant); + } catch (\Throwable $e) { + if (! static::$ignoreFailures) { + throw $e; + } + } event(new DatabaseDeleted($this->tenant)); - - return true; } }