This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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
|
||||
{
|
||||
if (Schema::hasTable('module_statuses')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::create('module_statuses', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('module')->unique();
|
||||
$table->boolean('enabled')->default(true);
|
||||
$table->text('description')->nullable();
|
||||
$table->string('version')->nullable();
|
||||
$table->unsignedInteger('sort_order')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('module_statuses');
|
||||
}
|
||||
};
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('module_statuses')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('module_statuses', function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('module_statuses', 'description')) {
|
||||
$table->text('description')->nullable()->after('enabled');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('module_statuses', 'version')) {
|
||||
$table->string('version')->nullable()->after('description');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('module_statuses', 'sort_order')) {
|
||||
$table->unsignedInteger('sort_order')->default(0)->after('version');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (! Schema::hasTable('module_statuses')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('module_statuses', function (Blueprint $table): void {
|
||||
if (Schema::hasColumn('module_statuses', 'sort_order')) {
|
||||
$table->dropColumn('sort_order');
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('module_statuses', 'version')) {
|
||||
$table->dropColumn('version');
|
||||
}
|
||||
|
||||
if (Schema::hasColumn('module_statuses', 'description')) {
|
||||
$table->dropColumn('description');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (! Schema::hasTable('module_statuses')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('module_statuses', function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('module_statuses', 'version')) {
|
||||
$table->string('version')->nullable()->after('description');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (! Schema::hasTable('module_statuses')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('module_statuses', function (Blueprint $table): void {
|
||||
if (Schema::hasColumn('module_statuses', 'version')) {
|
||||
$table->dropColumn('version');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('module_statuses', function (Blueprint $table): void {
|
||||
if (! Schema::hasColumn('module_statuses', 'icon')) {
|
||||
$table->string('icon')->nullable()->after('version');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('module_statuses', 'category')) {
|
||||
$table->string('category')->nullable()->after('icon');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('module_statuses', 'vendor_type')) {
|
||||
$table->string('vendor_type')->nullable()->after('category');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('module_statuses', 'author')) {
|
||||
$table->string('author')->nullable()->after('vendor_type');
|
||||
}
|
||||
|
||||
if (! Schema::hasColumn('module_statuses', 'notes')) {
|
||||
$table->text('notes')->nullable()->after('author');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('module_statuses', function (Blueprint $table): void {
|
||||
foreach (['notes', 'author', 'vendor_type', 'category', 'icon'] as $column) {
|
||||
if (Schema::hasColumn('module_statuses', $column)) {
|
||||
$table->dropColumn($column);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace absdev\Modules\database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use absdev\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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user