mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-07-17 22:35:19 +00:00
ModuleInstaller has the same shape as Updater (moved in 7cf72b9f): every method is public static, no constructor, no DI, no instance state. It orchestrates marketplace operations — fetch catalog, download zip, verify checksum, unzip, copy files, run module:migrate/module:enable, dispatch install/enable events — but the orchestration itself is stateless procedural plumbing.
Emitting events and writing to the Module eloquent model doesn't make it a service; plenty of static helpers touch models. The distinguishing factor is stateless-procedural vs DI-injected-workflow, and this is clearly the former.
4 consumers updated: ModulesController, ModuleInstallationController, InstallModuleCommand, and a doc comment in config/invoiceshelf.php. 350 tests still pass.
This leaves app/Services/ with no single-file driver-less subdirs except Mail/Module/Pdf/Storage which have multiple files each. The Module/ subdir in Services is now deleted entirely — the marketplace installer moved out and there were no other files in there.
87 lines
2.6 KiB
PHP
87 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Modules;
|
|
|
|
use App\Events\ModuleDisabledEvent;
|
|
use App\Events\ModuleEnabledEvent;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Resources\ModuleResource;
|
|
use App\Models\Module as ModelsModule;
|
|
use App\Support\Module\ModuleInstaller;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Nwidart\Modules\Facades\Module;
|
|
|
|
class ModulesController extends Controller
|
|
{
|
|
public function index(Request $request)
|
|
{
|
|
$this->authorize('manage modules');
|
|
|
|
$response = ModuleInstaller::getModules();
|
|
|
|
if (($response['status'] ?? 0) !== 200 || ! isset($response['body']->modules)) {
|
|
return response()->json(['error' => 'marketplace_unavailable'], 503);
|
|
}
|
|
|
|
return ModuleResource::collection(collect($response['body']->modules));
|
|
}
|
|
|
|
public function show(Request $request, string $module)
|
|
{
|
|
$this->authorize('manage modules');
|
|
|
|
$response = ModuleInstaller::getModule($module);
|
|
|
|
if (($response['status'] ?? 0) === 404) {
|
|
return response()->json(['error' => 'not_found'], 404);
|
|
}
|
|
|
|
if (($response['status'] ?? 0) !== 200 || ! isset($response['body']->data)) {
|
|
return response()->json(['error' => 'marketplace_unavailable'], 503);
|
|
}
|
|
|
|
return (new ModuleResource($response['body']->data))
|
|
->additional(['meta' => [
|
|
'modules' => ModuleResource::collection(
|
|
collect($response['body']->meta->modules ?? [])
|
|
),
|
|
]]);
|
|
}
|
|
|
|
public function checkToken(Request $request): JsonResponse
|
|
{
|
|
$this->authorize('manage modules');
|
|
|
|
return ModuleInstaller::checkToken($request->api_token);
|
|
}
|
|
|
|
public function enable(Request $request, string $module): JsonResponse
|
|
{
|
|
$this->authorize('manage modules');
|
|
|
|
$module = ModelsModule::where('name', $module)->first();
|
|
$module->update(['enabled' => true]);
|
|
$installedModule = Module::find($module->name);
|
|
$installedModule->enable();
|
|
|
|
ModuleEnabledEvent::dispatch($module);
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
|
|
public function disable(Request $request, string $module): JsonResponse
|
|
{
|
|
$this->authorize('manage modules');
|
|
|
|
$module = ModelsModule::where('name', $module)->first();
|
|
$module->update(['enabled' => false]);
|
|
$installedModule = Module::find($module->name);
|
|
$installedModule->disable();
|
|
|
|
ModuleDisabledEvent::dispatch($module);
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
}
|