mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 15:24:03 +00:00
Give pending_since to pending tenants during creation
Instead of creating pending tenants without pending_since, letting job pipelines (e.g. TenantCreated) run, and only after that, setting the tenant's pending_since, set it while creating. This allows checking tenant's pending status accurately e.g. in the CreateDatabase job pipeline.
This commit is contained in:
parent
6b4d22bb92
commit
b592d3dad4
1 changed files with 8 additions and 11 deletions
|
|
@ -49,18 +49,15 @@ trait HasPending
|
||||||
*/
|
*/
|
||||||
public static function createPending(array $attributes = []): Model&Tenant
|
public static function createPending(array $attributes = []): Model&Tenant
|
||||||
{
|
{
|
||||||
$tenant = null;
|
$tenant = static::make(array_merge(
|
||||||
|
['pending_since' => now()->timestamp],
|
||||||
|
static::getPendingAttributes($attributes),
|
||||||
|
$attributes
|
||||||
|
));
|
||||||
|
|
||||||
try {
|
event(new CreatingPendingTenant($tenant));
|
||||||
$tenant = static::create(array_merge(static::getPendingAttributes($attributes), $attributes));
|
|
||||||
event(new CreatingPendingTenant($tenant));
|
$tenant->save();
|
||||||
} finally {
|
|
||||||
// Update the pending_since value only after the tenant is created so it's
|
|
||||||
// not marked as pending until after migrations, seeders, etc are run.
|
|
||||||
$tenant?->update([
|
|
||||||
'pending_since' => now()->timestamp,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
event(new PendingTenantCreated($tenant));
|
event(new PendingTenantCreated($tenant));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue