diff --git a/app/Events/Common/ContactCreated.php b/app/Events/Common/ContactCreated.php new file mode 100644 index 00000000000..c9817cd7dbc --- /dev/null +++ b/app/Events/Common/ContactCreated.php @@ -0,0 +1,21 @@ +contact = $contact; + } +} diff --git a/app/Events/Common/ContactCreating.php b/app/Events/Common/ContactCreating.php new file mode 100644 index 00000000000..9db77275d8c --- /dev/null +++ b/app/Events/Common/ContactCreating.php @@ -0,0 +1,20 @@ +request = $request; + } +} diff --git a/app/Events/Common/ContactDeleted.php b/app/Events/Common/ContactDeleted.php new file mode 100644 index 00000000000..fbcef3f291f --- /dev/null +++ b/app/Events/Common/ContactDeleted.php @@ -0,0 +1,20 @@ +contact = $contact; + } +} diff --git a/app/Events/Common/ContactDeleting.php b/app/Events/Common/ContactDeleting.php new file mode 100644 index 00000000000..db68ea39bf0 --- /dev/null +++ b/app/Events/Common/ContactDeleting.php @@ -0,0 +1,20 @@ +contact = $contact; + } +} diff --git a/app/Events/Common/ContactUpdated.php b/app/Events/Common/ContactUpdated.php new file mode 100644 index 00000000000..6fd28e977dc --- /dev/null +++ b/app/Events/Common/ContactUpdated.php @@ -0,0 +1,25 @@ +contact = $contact; + $this->request = $request; + } +} diff --git a/app/Events/Common/ContactUpdating.php b/app/Events/Common/ContactUpdating.php new file mode 100644 index 00000000000..0866a935140 --- /dev/null +++ b/app/Events/Common/ContactUpdating.php @@ -0,0 +1,25 @@ +contact = $contact; + $this->request = $request; + } +} diff --git a/app/Jobs/Common/CreateContact.php b/app/Jobs/Common/CreateContact.php index c580b412bd2..b87c9b38b3b 100644 --- a/app/Jobs/Common/CreateContact.php +++ b/app/Jobs/Common/CreateContact.php @@ -3,6 +3,8 @@ namespace App\Jobs\Common; use App\Abstracts\Job; +use App\Events\Common\ContactCreated; +use App\Events\Common\ContactCreating; use App\Interfaces\Job\HasOwner; use App\Interfaces\Job\HasSource; use App\Interfaces\Job\ShouldCreate; @@ -15,6 +17,8 @@ class CreateContact extends Job implements HasOwner, HasSource, ShouldCreate { public function handle(): Contact { + event(new ContactCreating($this->request)); + \DB::transaction(function () { if ($this->request->get('create_user', 'false') === 'true') { $this->createUser(); @@ -32,6 +36,8 @@ public function handle(): Contact $this->dispatch(new CreateContactPersons($this->model, $this->request)); }); + event(new ContactCreated($this->model, $this->request)); + return $this->model; } diff --git a/app/Jobs/Common/DeleteContact.php b/app/Jobs/Common/DeleteContact.php index 43601dccaf5..7783f62708c 100644 --- a/app/Jobs/Common/DeleteContact.php +++ b/app/Jobs/Common/DeleteContact.php @@ -3,6 +3,8 @@ namespace App\Jobs\Common; use App\Abstracts\Job; +use App\Events\Common\ContactDeleted; +use App\Events\Common\ContactDeleting; use App\Interfaces\Job\ShouldDelete; use App\Jobs\Auth\DeleteUser; use App\Traits\Contacts; @@ -15,6 +17,8 @@ public function handle() :bool { $this->authorize(); + event(new ContactDeleting($this->model)); + \DB::transaction(function () { $this->deleteRelationships($this->model, ['contact_persons']); @@ -25,6 +29,8 @@ public function handle() :bool $this->model->delete(); }); + event(new ContactDeleted($this->model)); + return true; } diff --git a/app/Jobs/Common/UpdateContact.php b/app/Jobs/Common/UpdateContact.php index 353db23d3a6..5dcb27c2df0 100644 --- a/app/Jobs/Common/UpdateContact.php +++ b/app/Jobs/Common/UpdateContact.php @@ -3,6 +3,8 @@ namespace App\Jobs\Common; use App\Abstracts\Job; +use App\Events\Common\ContactUpdated; +use App\Events\Common\ContactUpdating; use App\Interfaces\Job\ShouldUpdate; use App\Jobs\Auth\CreateUser; use App\Jobs\Common\CreateContactPersons; @@ -15,6 +17,8 @@ public function handle(): Contact { $this->authorize(); + event(new ContactUpdating($this->model, $this->request)); + \DB::transaction(function () { if ($this->request->get('create_user', 'false') === 'true') { $this->createUser(); @@ -40,6 +44,8 @@ public function handle(): Contact $this->model->update($this->request->all()); }); + event(new ContactUpdated($this->model, $this->request)); + return $this->model; }