user()?->can('updates.manage') ?? false; } public function install(Demo $demo): void { abort_unless(static::canAccess(), 403); @set_time_limit(300); try { $result = $demo->install(auth()->user()); } catch (Throwable $e) { report($e); Notification::make()->danger()->title('Demo-Inhalte nicht angelegt')->body($e->getMessage())->send(); return; } Audit::log('demo.installed', ['counts' => $result['counts']]); Notification::make()->success()->title('Demo-Inhalte angelegt') ->body(collect($result['counts'])->map(fn ($count, $label) => "{$count} {$label}")->implode(', ')) ->send(); $this->warn($result['warnings'], 'Einige Bereiche konnten nicht angelegt werden'); } public function remove(Demo $demo): void { abort_unless(static::canAccess(), 403); @set_time_limit(300); try { $result = $demo->remove(); } catch (Throwable $e) { report($e); Notification::make()->danger()->title('Demo-Inhalte nicht entfernt')->body($e->getMessage())->send(); return; } Audit::log('demo.removed', ['records' => $result['records'], 'files' => $result['files']]); Notification::make()->success()->title('Demo-Inhalte entfernt') ->body("{$result['records']} Einträge und {$result['files']} Dateien gelöscht.") ->send(); $this->warn($result['warnings'], 'Nicht alles konnte entfernt werden'); } /** * @param list $warnings */ private function warn(array $warnings, string $title): void { if ($warnings === []) { return; } Notification::make()->warning()->title($title) ->body(Str::limit(implode("\n", $warnings), 1000)) ->persistent() ->send(); } /** * @return array */ protected function getViewData(): array { $demo = app(Demo::class); return [ 'installed' => $demo->isInstalled(), 'installedAt' => $demo->installedAt(), 'counts' => $demo->counts(), ]; } }