1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 18:04:03 +00:00

Make skipping opt-out, add opt-in ignoreFailures logic

This commit is contained in:
Samuel Stancl 2026-04-12 19:41:12 +02:00
parent 41e6e7c9c8
commit 5a045b4dcd
No known key found for this signature in database
GPG key ID: BA146259A1E16C57

View file

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