Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/DomainObserver.php
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | class DomainObserver | ||||
* | * | ||||
* @param \App\Domain $domain The domain. | * @param \App\Domain $domain The domain. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function restored(Domain $domain) | public function restored(Domain $domain) | ||||
{ | { | ||||
// Restore domain entitlements | // Restore domain entitlements | ||||
// We'll restore only these that were deleted last. So, first we get | \App\Entitlement::restoreEntitlementsFor($domain); | ||||
// the maximum deleted_at timestamp and then use it to select | |||||
// domain entitlements for restore | |||||
$deleted_at = \App\Entitlement::withTrashed() | |||||
->where('entitleable_id', $domain->id) | |||||
->where('entitleable_type', Domain::class) | |||||
->max('deleted_at'); | |||||
if ($deleted_at) { | |||||
\App\Entitlement::withTrashed() | |||||
->where('entitleable_id', $domain->id) | |||||
->where('entitleable_type', Domain::class) | |||||
->where('deleted_at', '>=', (new \Carbon\Carbon($deleted_at))->subMinute()) | |||||
->update(['updated_at' => now(), 'deleted_at' => null]); | |||||
} | |||||
// Create the domain in LDAP again | // Create the domain in LDAP again | ||||
\App\Jobs\Domain\CreateJob::dispatch($domain->id); | \App\Jobs\Domain\CreateJob::dispatch($domain->id); | ||||
} | } | ||||
/** | /** | ||||
* Handle the domain "force deleted" event. | * Handle the domain "force deleted" event. | ||||
* | * | ||||
Show All 9 Lines |