mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-02 05:10:59 +00:00
refactor: adopt modular domain architecture (#747)
* refactor: stabilize model identities for domain migration * refactor: extract module platform context * refactor: assign models to domain contexts * refactor: extract ai platform context * refactor: extract storage platform context * refactor: extract mail platform context * refactor: extract pdf platform context * refactor: extract operations platform context * refactor: move installation into operations platform * refactor: extract money domain context * refactor: extract taxation domain context * refactor: extract catalog domain context * refactor: extract metadata domain context * refactor: extract reporting domain context * refactor: extract purchases domain context * refactor: extract receivables domain context * refactor: extract accounts domain context * refactor: complete reporting statement boundary * refactor: extract contacts domain context * refactor: extract sales domain context * refactor: remove legacy application layers * fix: migrate legacy bouncer role identities
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Platform\Modules\Http\Controllers\Admin;
|
||||
|
||||
use App\Platform\Http\Controller;
|
||||
use App\Platform\Modules\Events\ModuleDisabledEvent;
|
||||
use App\Platform\Modules\Events\ModuleEnabledEvent;
|
||||
use App\Platform\Modules\Http\Resources\ModuleResource;
|
||||
use App\Platform\Modules\Marketplace\MarketplaceClient;
|
||||
use App\Platform\Modules\Models\Module as ModelsModule;
|
||||
use App\Platform\Modules\Runtime\DatabaseActivator;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
|
||||
class ModulesController extends Controller
|
||||
{
|
||||
public function index(MarketplaceClient $client)
|
||||
{
|
||||
$this->authorize('manage modules');
|
||||
|
||||
$response = $client->catalog();
|
||||
$body = $response->json();
|
||||
$modules = is_array($body) ? ($body['modules'] ?? $body['data'] ?? null) : null;
|
||||
|
||||
if (! $response->successful() || ! is_array($modules)) {
|
||||
return response()->json(['error' => 'marketplace_unavailable'], 503);
|
||||
}
|
||||
|
||||
return ModuleResource::collection(collect($modules));
|
||||
}
|
||||
|
||||
public function show(string $module, MarketplaceClient $client)
|
||||
{
|
||||
$this->authorize('manage modules');
|
||||
|
||||
$response = $client->module($module);
|
||||
$body = $response->json();
|
||||
|
||||
if ($response->status() === 404) {
|
||||
return response()->json(['error' => 'not_found'], 404);
|
||||
}
|
||||
|
||||
if (! $response->successful() || ! is_array($body) || ! is_array($body['module'] ?? null)) {
|
||||
return response()->json(['error' => 'marketplace_unavailable'], 503);
|
||||
}
|
||||
|
||||
return (new ModuleResource($body['module']))
|
||||
->additional(['meta' => [
|
||||
'modules' => ModuleResource::collection(
|
||||
collect($body['meta']['modules'] ?? [])
|
||||
),
|
||||
]]);
|
||||
}
|
||||
|
||||
public function enable(string $module): JsonResponse
|
||||
{
|
||||
$this->authorize('manage modules');
|
||||
|
||||
$module = ModelsModule::query()
|
||||
->where('name', $module)
|
||||
->where('installed', true)
|
||||
->firstOrFail();
|
||||
$installedModule = Module::find($module->name);
|
||||
|
||||
if ($installedModule === null) {
|
||||
$this->markRuntimeMissing($module);
|
||||
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'error' => 'module_runtime_missing',
|
||||
], 409);
|
||||
}
|
||||
|
||||
$installedModule->enable();
|
||||
$module->refresh();
|
||||
|
||||
ModuleEnabledEvent::dispatch($module);
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function disable(string $module, DatabaseActivator $activator): JsonResponse
|
||||
{
|
||||
$this->authorize('manage modules');
|
||||
|
||||
$module = ModelsModule::query()
|
||||
->where('name', $module)
|
||||
->where('installed', true)
|
||||
->firstOrFail();
|
||||
|
||||
$activator->setActiveByName($module->name, false);
|
||||
|
||||
if (Module::find($module->name) === null) {
|
||||
$this->markRuntimeMissing($module);
|
||||
} else {
|
||||
$module->refresh();
|
||||
}
|
||||
|
||||
ModuleDisabledEvent::dispatch($module);
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
}
|
||||
|
||||
private function markRuntimeMissing(ModelsModule $module): void
|
||||
{
|
||||
$module->update([
|
||||
'installed' => false,
|
||||
'enabled' => false,
|
||||
'state' => 'failed',
|
||||
'last_error' => 'module_runtime_missing',
|
||||
'last_failed_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user