Files
lucent-laravel/src/Http/Controller/SetupController.php
T

72 lines
2.0 KiB
PHP
Raw Normal View History

2024-09-06 20:59:56 +03:00
<?php
namespace Lucent\Http\Controller;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Lucent\Account\AccountService;
use Lucent\Channel\ChannelService;
use Lucent\Setup\Data\SetupStep;
2024-09-06 23:30:12 +03:00
use Lucent\Setup\Data\SetupStepStatus;
2024-09-06 20:59:56 +03:00
use Lucent\Setup\Step\ComposerStep;
2024-09-06 23:30:12 +03:00
use Lucent\Setup\Step\DatabaseSetupStep;
2024-09-06 20:59:56 +03:00
use Lucent\Setup\Step\IStep;
2024-09-06 23:30:12 +03:00
use Lucent\Setup\Step\LaravelEnvStep;
2024-09-06 20:59:56 +03:00
use Lucent\Setup\Step\LucentConfigStep;
2024-09-06 23:30:12 +03:00
use Lucent\Setup\Step\StorageLinkSetupStep;
use Lucent\Setup\Step\StorageSetupStep;
2024-09-06 20:59:56 +03:00
use Lucent\Svelte\Svelte;
class SetupController
{
public function __construct(
private readonly AccountService $accountService,
private readonly ChannelService $channelService,
2026-05-07 21:34:43 +03:00
private readonly Svelte $svelte,
) {}
2024-09-06 20:59:56 +03:00
public function setup(Request $request): View|RedirectResponse
{
2026-05-07 21:34:43 +03:00
$steps = array_reduce(
[
new ComposerStep(),
new LucentConfigStep(),
new LaravelEnvStep(),
new StorageSetupStep(),
new StorageLinkSetupStep(),
new DatabaseSetupStep(),
],
fn(array $carry, IStep $setupStep) => array_merge($carry, [
$setupStep(),
]),
[],
);
$allSuccess = array_reduce(
$steps,
fn(bool $carry, SetupStep $step) => !$carry
? false
: $step->status === SetupStepStatus::SUCCESS,
true,
);
2024-09-06 23:30:12 +03:00
2026-05-07 21:34:43 +03:00
if ($allSuccess) {
2024-09-06 23:30:12 +03:00
if ($this->accountService->countUsers() > 0) {
2026-05-07 21:34:43 +03:00
return redirect(
$this->channelService->channel->lucentUrl . "/login",
);
2024-09-06 23:30:12 +03:00
}
}
2024-09-06 20:59:56 +03:00
return $this->svelte->render(
layout: "account",
view: "setup",
title: "Setup Lucent",
data: [
2024-09-06 23:30:12 +03:00
"steps" => $steps,
"allSuccess" => $allSuccess,
2026-05-07 21:34:43 +03:00
],
2024-09-06 20:59:56 +03:00
);
}
}