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

73 lines
2.0 KiB
PHP
Raw Normal View History

2024-09-06 20:59:56 +03:00
<?php
namespace Lucent\Http\Controller;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Lucent\Account\AccountService;
use Lucent\Channel\ChannelService;
use Lucent\LucentException;
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\Setup;
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;
use function Lucent\Response\fail;
use function Lucent\Response\ok;
class SetupController
{
public function __construct(
private readonly AccountService $accountService,
private readonly ChannelService $channelService,
private readonly Svelte $svelte,
)
{
}
public function setup(Request $request): View|RedirectResponse
{
2024-09-06 23:30:12 +03:00
2024-09-06 20:59:56 +03:00
$steps = array_reduce([
2024-09-06 23:30:12 +03:00
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);
if($allSuccess){
if ($this->accountService->countUsers() > 0) {
return redirect($this->channelService->channel->lucentUrl . "/login");
}
}
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,
2024-09-06 20:59:56 +03:00
]
);
}
}