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; } }