New design

This commit is contained in:
Mark Gregory
2026-07-01 10:17:41 +01:00
parent 567ab46979
commit 7e6d366043
13 changed files with 435 additions and 37 deletions
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace mpba\Modules\Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\File;
use mpba\Modules\DevelopmentSupport\Entities\ModuleStatus;
class ModuleStatusSeeder extends Seeder
{
/**
* Seed missing database module statuses from the existing file activator JSON.
*
* Existing database rows are left unchanged.
*/
public function run(): void
{
foreach ($this->readStatuses() as $module => $enabled) {
if (! is_string($module) || trim($module) === '') {
continue;
}
ModuleStatus::query()->firstOrCreate(
['module' => trim($module)],
['enabled' => (bool) $enabled]
);
}
}
/**
* @return array<string, bool>
*/
private function readStatuses(): array
{
$path = $this->statusesFilePath();
if ($path === null) {
return [];
}
$statuses = json_decode(File::get($path), true);
if (! is_array($statuses)) {
return [];
}
return $statuses;
}
private function statusesFilePath(): ?string
{
$configuredPath = config('modules.activators.file.statuses-file');
$paths = array_filter(array_unique([
is_string($configuredPath) ? $configuredPath : null,
base_path('modules_statuses.json'),
base_path('module_statuses.json'),
base_path('module_statues.json'),
]));
foreach ($paths as $path) {
if (File::exists($path)) {
return $path;
}
}
return null;
}
}
@@ -1,33 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
Schema::create('module_statuses', function (Blueprint $table): void {
$table->id();
$table->string('module')->unique();
$table->boolean('enabled')->default(true);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::dropIfExists('module_statuses');
}
};
@@ -1,5 +1,7 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -8,11 +10,13 @@ return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up(): void
{
if (Schema::hasTable('module_statuses')) {
return;
}
Schema::create('module_statuses', function (Blueprint $table): void {
$table->id();
$table->string('module')->unique();
@@ -23,8 +27,6 @@ return new class extends Migration
/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{