Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/GroupObserver.php
Show All 30 Lines | class GroupObserver | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function created(Group $group) | public function created(Group $group) | ||||
{ | { | ||||
\App\Jobs\Group\CreateJob::dispatch($group->id); | \App\Jobs\Group\CreateJob::dispatch($group->id); | ||||
} | } | ||||
/** | /** | ||||
* Handle the group "deleting" event. | |||||
* | |||||
* @param \App\Group $group The group | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function deleting(Group $group) | |||||
{ | |||||
// Entitlements do not have referential integrity on the entitled object, so this is our | |||||
// way of doing an onDelete('cascade') without the foreign key. | |||||
\App\Entitlement::where('entitleable_id', $group->id) | |||||
->where('entitleable_type', Group::class) | |||||
->delete(); | |||||
} | |||||
/** | |||||
* Handle the group "deleted" event. | * Handle the group "deleted" event. | ||||
* | * | ||||
* @param \App\Group $group The group | * @param \App\Group $group The group | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function deleted(Group $group) | public function deleted(Group $group) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | class GroupObserver | ||||
* Handle the group "restored" event. | * Handle the group "restored" event. | ||||
* | * | ||||
* @param \App\Group $group The group | * @param \App\Group $group The group | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function restored(Group $group) | public function restored(Group $group) | ||||
{ | { | ||||
// Restore group entitlements | |||||
\App\Entitlement::restoreEntitlementsFor($group); | |||||
\App\Jobs\Group\CreateJob::dispatch($group->id); | \App\Jobs\Group\CreateJob::dispatch($group->id); | ||||
} | } | ||||
/** | |||||
* Handle the group "force deleting" event. | |||||
* | |||||
* @param \App\Group $group The group | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function forceDeleted(Group $group) | |||||
{ | |||||
// A group can be force-deleted separately from the owner | |||||
// we have to force-delete entitlements | |||||
\App\Entitlement::where('entitleable_id', $group->id) | |||||
->where('entitleable_type', Group::class) | |||||
->forceDelete(); | |||||
} | |||||
} | } |