delete email templates after module uninstall

#1kxwd3z
This commit is contained in:
Denis Duliçi
2021-11-19 10:54:18 +03:00
parent 7c81eba203
commit 1d82157d7a
2 changed files with 35 additions and 1 deletions

View File

@ -6,7 +6,9 @@ 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\Setting\DeleteEmailTemplate;
use App\Models\Common\Dashboard;
use App\Models\Common\EmailTemplate;
use App\Models\Common\Report;
use App\Traits\Jobs;
use Throwable;
@ -24,6 +26,7 @@ class FinishUninstallation
public function handle(Event $event)
{
$this->deleteDashboards($event->alias);
$this->deleteEmailTemplates($event->alias);
$this->deleteReports($event->alias);
}
@ -48,6 +51,23 @@ class FinishUninstallation
});
}
/**
* Delete any email template created by the module.
*
* @param string $alias
* @return void
*/
protected function deleteEmailTemplates($alias)
{
EmailTemplate::moduleAlias($alias)->get()->each(function ($template) {
try {
$this->dispatch(new DeleteEmailTemplate($template));
} catch (Throwable $e) {
report($e);
}
});
}
/**
* Delete any report created by the module.
*