schneespur/release/schneespur-1.0.2/app/Console/Commands/ModulesRemove.php
Michael 7288b93500 Release v1.0.2: diagnostic infrastructure core
Add neutral diagnostic framework for future reporting modules:
- DiagnosticReporterInterface, Registry, Manager, PayloadSanitizer
- Laravel exception hook in bootstrap/app.php
- Module permission declarations (requires_permissions in module.json)
- Core diagnostic report points (module boot/install/update failures)
- Module documentation update (moduldoku.md)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 16:54:11 +00:00

63 lines
1.8 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\Module;
use App\Services\SchneespurModuleClient;
use App\Services\SchneespurModuleInstaller;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Schema;
class ModulesRemove extends Command
{
protected $signature = 'schneespur:modules-remove
{slug : The module slug to remove}
{--force : Skip confirmation prompt}';
protected $description = 'Remove an installed module completely.';
public function handle(
SchneespurModuleInstaller $installer,
SchneespurModuleClient $client,
): int {
if (! Schema::hasTable('modules')) {
$this->error('Modules-Tabelle nicht vorhanden. Bitte zuerst "php artisan migrate" ausführen.');
return 1;
}
$slug = $this->argument('slug');
$module = Module::bySlug($slug)->first();
if (! $module) {
$this->error("Modul \"{$slug}\" nicht gefunden.");
return 1;
}
if (! $this->option('force')) {
if (! $this->confirm("Modul \"{$slug}\" (v{$module->version}) wirklich entfernen?")) {
$this->info('Abgebrochen.');
return 0;
}
}
$module->update(['enabled' => false]);
$removed = $installer->remove($slug);
if (! $removed) {
$this->warn("Modul-Dateien für \"{$slug}\" konnten nicht gelöscht werden (evtl. bereits entfernt).");
}
$module->delete();
$state = $client->loadState();
$state['installed'] = Module::pluck('slug')->toArray();
$state['orphans'] = array_values(array_diff($state['orphans'] ?? [], [$slug]));
$client->writeState($state);
$this->info("Modul \"{$slug}\" wurde entfernt.");
return 0;
}
}