mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 18:24:04 +00:00
Make skipping opt-out, add opt-in ignoreFailures logic
This commit is contained in:
parent
41e6e7c9c8
commit
5a045b4dcd
1 changed files with 19 additions and 6 deletions
|
|
@ -22,18 +22,31 @@ class DeleteDatabase implements ShouldQueue
|
||||||
protected TenantWithDatabase&Model $tenant,
|
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));
|
event(new DeletingDatabase($this->tenant));
|
||||||
|
|
||||||
if ($this->tenant->getInternal('create_database') === false) {
|
if (static::$skipWhenCreateDatabaseIsFalse && $this->tenant->getInternal('create_database') === false) {
|
||||||
return 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
$this->tenant->database()->manager()->deleteDatabase($this->tenant);
|
$this->tenant->database()->manager()->deleteDatabase($this->tenant);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
if (! static::$ignoreFailures) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
event(new DatabaseDeleted($this->tenant));
|
event(new DatabaseDeleted($this->tenant));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue