Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/DomainObserver.php
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | class DomainObserver | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function updated(Domain $domain) | public function updated(Domain $domain) | ||||
{ | { | ||||
\App\Jobs\Domain\UpdateJob::dispatch($domain->id); | \App\Jobs\Domain\UpdateJob::dispatch($domain->id); | ||||
} | } | ||||
/** | /** | ||||
* Handle the domain "restoring" event. | |||||
* | |||||
* @param \App\Domain $domain The domain. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function restoring(Domain $domain) | |||||
{ | |||||
// Make sure it's not DELETED/LDAP_READY/SUSPENDED | |||||
if ($domain->isDeleted()) { | |||||
$domain->status ^= Domain::STATUS_DELETED; | |||||
} | |||||
if ($domain->isLdapReady()) { | |||||
$domain->status ^= Domain::STATUS_LDAP_READY; | |||||
} | |||||
if ($domain->isSuspended()) { | |||||
$domain->status ^= Domain::STATUS_SUSPENDED; | |||||
} | |||||
if ($domain->isConfirmed() && $domain->isVerified()) { | |||||
$domain->status |= Domain::STATUS_ACTIVE; | |||||
} | |||||
// Note: $domain->save() is invoked between 'restoring' and 'restored' events | |||||
} | |||||
/** | |||||
* Handle the domain "restored" event. | * Handle the domain "restored" event. | ||||
* | * | ||||
* @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 | ||||
// We'll restore only these that were deleted last. So, first we get | |||||
// 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) { | |||||
vanmeeuwen: When a domain is restored, we don't update the `updated_at` column of the entitlements table… | |||||
\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 | |||||
\App\Jobs\Domain\CreateJob::dispatch($domain->id); | |||||
} | } | ||||
/** | /** | ||||
* Handle the domain "force deleted" event. | * Handle the domain "force deleted" event. | ||||
* | * | ||||
* @param \App\Domain $domain The domain. | * @param \App\Domain $domain The domain. | ||||
* | * | ||||
Not Done Inline ActionsI believe created_at will remain what it was, which would be the expected result. I also believe $domain->save() will automatically update updated_at. vanmeeuwen: I believe `created_at` will remain what it was, which would be the expected result.
I also… | |||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function forceDeleted(Domain $domain) | public function forceDeleted(Domain $domain) | ||||
{ | { | ||||
// | // | ||||
} | } | ||||
} | } |
When a domain is restored, we don't update the updated_at column of the entitlements table because it's used to track payment status / due dates for new charges.