Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions app/Console/Commands/SettingsDiscoverCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace App\Console\Commands;

use App\Services\SettingsService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Nwidart\Modules\Facades\Module;
use Symfony\Component\Finder\Finder;

class SettingsDiscoverCommand extends Command
{
protected $signature = 'settings:discover';
protected $description = 'Discover and create settings from their usage in the code.';

protected SettingsService $settingsService;

public function __construct(SettingsService $settingsService)
{
parent::__construct();
$this->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;
}
}
1 change: 1 addition & 0 deletions app/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Setting extends Model
protected $fillable = [
'key',
'value',
'is_textarea',
'is_locked',
];

Expand Down
7 changes: 7 additions & 0 deletions app/Traits/WithCustomLivewireException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('settings', function (Blueprint $table) {
$table->boolean('is_textarea')->default(false)->after('value');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('settings', function (Blueprint $table) {
$table->dropColumn('is_textarea');
});
}
};
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"base": "4.2.1",
"base": "4.3.0",
"dev": false
}