From c42bc58e4e880e343045d7158613a3b4e0c2aee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= <53110792+CihanSenturk@users.noreply.github.com> Date: Fri, 2 Dec 2022 11:08:32 +0300 Subject: [PATCH] Added delete widget to module uninstall listener --- app/Listeners/Module/FinishUninstallation.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/Listeners/Module/FinishUninstallation.php b/app/Listeners/Module/FinishUninstallation.php index 3d947b1c4..484d9981e 100644 --- a/app/Listeners/Module/FinishUninstallation.php +++ b/app/Listeners/Module/FinishUninstallation.php @@ -6,9 +6,11 @@ use App\Events\Module\Uninstalled as Event; use App\Exceptions\Common\LastDashboard; use App\Jobs\Common\DeleteDashboard; use App\Jobs\Common\DeleteReport; +use App\Jobs\Common\DeleteWidget; use App\Jobs\Setting\DeleteEmailTemplate; use App\Models\Common\Dashboard; use App\Models\Common\Report; +use App\Models\Common\Widget; use App\Models\Setting\EmailTemplate; use App\Traits\Jobs; use Throwable; @@ -26,6 +28,7 @@ class FinishUninstallation public function handle(Event $event) { $this->deleteDashboards($event->alias); + $this->deleteWidgets($event->alias); $this->deleteEmailTemplates($event->alias); $this->deleteReports($event->alias); } @@ -51,6 +54,23 @@ class FinishUninstallation }); } + /** + * Delete any widget created by the module. + * + * @param string $alias + * @return void + */ + protected function deleteWidgets($alias) + { + Widget::alias($alias)->get()->each(function ($widget) { + try { + $this->dispatch(new DeleteWidget($widget)); + } catch (Throwable $e) { + report($e); + } + }); + } + /** * Delete any email template created by the module. *