From d16873d3f3bf433703f7ce75776ac7e931587615 Mon Sep 17 00:00:00 2001 From: Lenny Petschl Date: Tue, 15 Jul 2025 11:11:52 +0000 Subject: [PATCH] Add SettingsDiscoverCommand for creating all settings Add textarea field to settings table Some better error handling in CustomLivewireException --- .../Commands/SettingsDiscoverCommand.php | 68 +++++++++++++++++++ app/Models/Setting.php | 1 + app/Traits/WithCustomLivewireException.php | 7 ++ ..._075832_add_textarea_to_settings_table.php | 27 ++++++++ version.json | 2 +- 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 app/Console/Commands/SettingsDiscoverCommand.php create mode 100644 database/migrations/2025_07_15_075832_add_textarea_to_settings_table.php diff --git a/app/Console/Commands/SettingsDiscoverCommand.php b/app/Console/Commands/SettingsDiscoverCommand.php new file mode 100644 index 00000000..ffd9270d --- /dev/null +++ b/app/Console/Commands/SettingsDiscoverCommand.php @@ -0,0 +1,68 @@ +settingsService = $settingsService; + } + + public function handle() + { + $this->info('Discovering settings...'); + + $paths = [ + app_path(), + resource_path('views'), + ]; + + foreach (Module::allEnabled() as $module) { + $paths[] = module_path($module); + } + + $settingKeys = []; + $pattern = "/settings\(\s*['\"]([^'\"]+)['\"]/"; + + $files = (new Finder())->in($paths)->files()->name(['*.php', '*.blade.php']); + + foreach ($files as $file) { + $content = File::get($file->getRealPath()); + if (preg_match_all($pattern, $content, $matches)) { + foreach ($matches[1] as $key) { + $settingKeys[$key] = true; + } + } + } + + $uniqueKeys = array_keys($settingKeys); + + if (empty($uniqueKeys)) { + $this->info('No settings found.'); + return 0; + } + + $this->info('Found '.count($uniqueKeys).' unique settings. Creating them now...'); + + foreach ($uniqueKeys as $key) { + $this->settingsService->getSetting($key); + $this->line('Ensured setting exists: '.$key); + } + + $this->info('Settings discovery and creation complete.'); + return 0; + } +} diff --git a/app/Models/Setting.php b/app/Models/Setting.php index c37eb766..11199eba 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -10,6 +10,7 @@ class Setting extends Model protected $fillable = [ 'key', 'value', + 'is_textarea', 'is_locked', ]; diff --git a/app/Traits/WithCustomLivewireException.php b/app/Traits/WithCustomLivewireException.php index 12983288..17c83070 100755 --- a/app/Traits/WithCustomLivewireException.php +++ b/app/Traits/WithCustomLivewireException.php @@ -4,6 +4,7 @@ use Exception; use Filament\Notifications\Notification; +use Illuminate\Support\Facades\Log; use Illuminate\Validation\ValidationException; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -12,6 +13,12 @@ trait WithCustomLivewireException public function exception($e, $stopPropagation) { if (config('app.env') === 'local' || config('app.debug')) { + once(function () use ($e) { + Log::error($e->getMessage(), [ + 'exception' => $e, + 'trace' => $e->getTraceAsString(), + ]); + }); throw $e; // @phpstan-ignore-line } diff --git a/database/migrations/2025_07_15_075832_add_textarea_to_settings_table.php b/database/migrations/2025_07_15_075832_add_textarea_to_settings_table.php new file mode 100644 index 00000000..8199ed7f --- /dev/null +++ b/database/migrations/2025_07_15_075832_add_textarea_to_settings_table.php @@ -0,0 +1,27 @@ +boolean('is_textarea')->default(false)->after('value'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('settings', function (Blueprint $table) { + $table->dropColumn('is_textarea'); + }); + } +}; diff --git a/version.json b/version.json index b2a1491c..beb82e7e 100755 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { - "base": "4.2.1", + "base": "4.3.0", "dev": false }