diff --git a/app/Events/Common/ItemCreated.php b/app/Events/Common/ItemCreated.php new file mode 100644 index 00000000000..c75369ba5df --- /dev/null +++ b/app/Events/Common/ItemCreated.php @@ -0,0 +1,21 @@ +item = $item; + } +} diff --git a/app/Events/Common/ItemCreating.php b/app/Events/Common/ItemCreating.php new file mode 100644 index 00000000000..182ed381091 --- /dev/null +++ b/app/Events/Common/ItemCreating.php @@ -0,0 +1,20 @@ +request = $request; + } +} diff --git a/app/Events/Common/ItemDeleted.php b/app/Events/Common/ItemDeleted.php new file mode 100644 index 00000000000..78721f12b87 --- /dev/null +++ b/app/Events/Common/ItemDeleted.php @@ -0,0 +1,20 @@ +item = $item; + } +} diff --git a/app/Events/Common/ItemDeleting.php b/app/Events/Common/ItemDeleting.php new file mode 100644 index 00000000000..484aa55572f --- /dev/null +++ b/app/Events/Common/ItemDeleting.php @@ -0,0 +1,20 @@ +item = $item; + } +} diff --git a/app/Events/Common/ItemUpdated.php b/app/Events/Common/ItemUpdated.php new file mode 100644 index 00000000000..c824955b667 --- /dev/null +++ b/app/Events/Common/ItemUpdated.php @@ -0,0 +1,25 @@ +item = $item; + $this->request = $request; + } +} diff --git a/app/Events/Common/ItemUpdating.php b/app/Events/Common/ItemUpdating.php new file mode 100644 index 00000000000..1c6215b8263 --- /dev/null +++ b/app/Events/Common/ItemUpdating.php @@ -0,0 +1,25 @@ +item = $item; + $this->request = $request; + } +} diff --git a/app/Jobs/Common/CreateItem.php b/app/Jobs/Common/CreateItem.php index f888eec63fb..91de31fca6f 100644 --- a/app/Jobs/Common/CreateItem.php +++ b/app/Jobs/Common/CreateItem.php @@ -3,6 +3,8 @@ namespace App\Jobs\Common; use App\Abstracts\Job; +use App\Events\Common\ItemCreated; +use App\Events\Common\ItemCreating; use App\Interfaces\Job\HasOwner; use App\Interfaces\Job\HasSource; use App\Interfaces\Job\ShouldCreate; @@ -13,6 +15,8 @@ class CreateItem extends Job implements HasOwner, HasSource, ShouldCreate { public function handle(): Item { + event(new ItemCreating($this->request)); + \DB::transaction(function () { $this->model = Item::create($this->request->all()); @@ -26,6 +30,8 @@ public function handle(): Item $this->dispatch(new CreateItemTaxes($this->model, $this->request)); }); + event(new ItemCreated($this->model, $this->request)); + return $this->model; } } diff --git a/app/Jobs/Common/DeleteItem.php b/app/Jobs/Common/DeleteItem.php index 6bd21b70935..df4234d3167 100644 --- a/app/Jobs/Common/DeleteItem.php +++ b/app/Jobs/Common/DeleteItem.php @@ -3,6 +3,8 @@ namespace App\Jobs\Common; use App\Abstracts\Job; +use App\Events\Common\ItemDeleted; +use App\Events\Common\ItemDeleting; use App\Interfaces\Job\ShouldDelete; class DeleteItem extends Job implements ShouldDelete @@ -11,12 +13,16 @@ public function handle(): bool { $this->authorize(); + event(new ItemDeleting($this->model)); + \DB::transaction(function () { $this->deleteRelationships($this->model, ['taxes']); $this->model->delete(); }); + event(new ItemDeleted($this->model)); + return true; } diff --git a/app/Jobs/Common/UpdateItem.php b/app/Jobs/Common/UpdateItem.php index a5eceb42f5b..761dd04a0ed 100644 --- a/app/Jobs/Common/UpdateItem.php +++ b/app/Jobs/Common/UpdateItem.php @@ -3,6 +3,8 @@ namespace App\Jobs\Common; use App\Abstracts\Job; +use App\Events\Common\ItemUpdated; +use App\Events\Common\ItemUpdating; use App\Interfaces\Job\ShouldUpdate; use App\Jobs\Common\CreateItemTaxes; use App\Models\Common\Item; @@ -11,6 +13,8 @@ class UpdateItem extends Job implements ShouldUpdate { public function handle(): Item { + event(new ItemUpdating($this->model, $this->request)); + \DB::transaction(function () { $this->model->update($this->request->all()); @@ -26,6 +30,8 @@ public function handle(): Item $this->dispatch(new CreateItemTaxes($this->model, $this->request)); }); + event(new ItemUpdated($this->model, $this->request)); + return $this->model; } }