removed setup controller
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Lucent\Database\Database;
|
||||
|
||||
class Setup extends Command
|
||||
{
|
||||
|
||||
protected $signature = 'lucent:setup';
|
||||
|
||||
protected $description = 'Setup a new lucent installation';
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->updateComposer();
|
||||
$this->call('vendor:publish', ['--tag' => 'lucent-config']);
|
||||
$this->call('vendor:publish', ['--tag' => 'lucent']);
|
||||
$this->database();
|
||||
$this->info("Head to /lucent in your browser to create the first user");
|
||||
|
||||
}
|
||||
|
||||
private function updateComposer()
|
||||
{
|
||||
|
||||
if (!$this->confirm('Update composer.json?')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$composerFile = json_decode(file_get_contents(base_path("composer.json")), true);
|
||||
$postAutoloadDumpList = data_get($composerFile, "scripts.post-autoload-dump", []);
|
||||
|
||||
if (in_array("@php artisan vendor:publish --tag=lucent --force", $postAutoloadDumpList)) {
|
||||
$this->info("Composer file was already correct");
|
||||
return;
|
||||
}
|
||||
|
||||
$composerFile["scripts"]["post-autoload-dump"][] = "@php artisan vendor:publish --tag=lucent --force";
|
||||
file_put_contents(base_path("composer.json"), json_encode($composerFile, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||
$this->info("Composer file was updated");
|
||||
|
||||
}
|
||||
|
||||
private function database(): void
|
||||
{
|
||||
$databaseConnectionName = config("lucent.database");
|
||||
if (!$this->confirm("Your current database connection is $databaseConnectionName. Running the database migration script will wipe off any existing data. Run?")) {
|
||||
return;
|
||||
}
|
||||
$this->call('lucent:setup-db');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -18,8 +18,8 @@ class SetupDatabase extends Command
|
||||
{
|
||||
|
||||
$dbConnection = config("lucent.database");
|
||||
$databasePath = config("database.connections.$dbConnection.database");
|
||||
|
||||
$databasePath = config("database.connections.$dbConnection.database");
|
||||
if(file_exists($databasePath)){
|
||||
$this->error("Database already exists.");
|
||||
return 0;
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
<?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;
|
||||
use Lucent\Setup\Data\SetupStepStatus;
|
||||
use Lucent\Setup\Setup;
|
||||
use Lucent\Setup\Step\ComposerStep;
|
||||
use Lucent\Setup\Step\DatabaseSetupStep;
|
||||
use Lucent\Setup\Step\IStep;
|
||||
use Lucent\Setup\Step\LaravelEnvStep;
|
||||
use Lucent\Setup\Step\LucentConfigStep;
|
||||
use Lucent\Setup\Step\StorageLinkSetupStep;
|
||||
use Lucent\Setup\Step\StorageSetupStep;
|
||||
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
|
||||
{
|
||||
|
||||
|
||||
$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);
|
||||
|
||||
if($allSuccess){
|
||||
if ($this->accountService->countUsers() > 0) {
|
||||
return redirect($this->channelService->channel->lucentUrl . "/login");
|
||||
}
|
||||
}
|
||||
|
||||
return $this->svelte->render(
|
||||
layout: "account",
|
||||
view: "setup",
|
||||
title: "Setup Lucent",
|
||||
data: [
|
||||
"steps" => $steps,
|
||||
"allSuccess" => $allSuccess,
|
||||
]
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -10,10 +10,8 @@ use Lucent\Http\Controller\HomeController;
|
||||
use Lucent\Http\Controller\MemberController;
|
||||
use Lucent\Http\Controller\RecordController;
|
||||
use Lucent\Http\Controller\RevisionController;
|
||||
use Lucent\Http\Controller\SetupController;
|
||||
|
||||
|
||||
Route::get('/lucent/setup', [SetupController::class, 'setup']);
|
||||
Route::get('/lfs-{disk}/{any}', [FileController::class, 'fromDisk'])->where('any', '.*');
|
||||
|
||||
|
||||
@@ -23,7 +21,6 @@ Route::group([
|
||||
], function () {
|
||||
|
||||
|
||||
|
||||
Route::middleware(['lucent.guest'])->group(function () {
|
||||
Route::get('/', [AuthController::class, 'login']);
|
||||
|
||||
@@ -95,6 +92,5 @@ Route::group([
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ use Lucent\Commands\GenerateCollectionSchema;
|
||||
use Lucent\Commands\GenerateFileSchema;
|
||||
use Lucent\Commands\RebuildThumbnails;
|
||||
use Lucent\Commands\RemoveOrphanEdges;
|
||||
use Lucent\Commands\Setup;
|
||||
use Lucent\Commands\SetupDatabase;
|
||||
use Lucent\Commands\UpgradeFiles122;
|
||||
use Lucent\File\FileService;
|
||||
@@ -75,6 +76,7 @@ class LucentServiceProvider extends ServiceProvider
|
||||
|
||||
if ($this->app->runningInConsole()) {
|
||||
$this->commands([
|
||||
Setup::class,
|
||||
CompileSchemas::class,
|
||||
RebuildThumbnails::class,
|
||||
RemoveOrphanEdges::class,
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Data;
|
||||
|
||||
class SetupStep
|
||||
{
|
||||
public function __construct(
|
||||
public string $name,
|
||||
public string $instructions,
|
||||
public SetupStepStatus $status,
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
public static function makeSuccess(string $name, string $instructions): self
|
||||
{
|
||||
return new self($name, $instructions, SetupStepStatus::SUCCESS);
|
||||
}
|
||||
|
||||
public static function makeFail(string $name, string $instructions): self
|
||||
{
|
||||
return new self($name, $instructions, SetupStepStatus::FAIL);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Data;
|
||||
|
||||
enum SetupStepStatus: string
|
||||
{
|
||||
case SUCCESS = "success";
|
||||
case FAIL = "fail";
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
class ComposerStep implements IStep
|
||||
{
|
||||
|
||||
public function __invoke(): SetupStep
|
||||
{
|
||||
|
||||
$composerFile = json_decode(file_get_contents(base_path("composer.json")), true);
|
||||
|
||||
$postAutoloadDumpList = data_get($composerFile, "scripts.post-autoload-dump", []);
|
||||
|
||||
$name = "Composer File";
|
||||
|
||||
$instructions = <<<EOD
|
||||
# Append this line in post-autoload-dump in your composer.json.:
|
||||
|
||||
"@php artisan vendor:publish --tag=lucent --force"
|
||||
|
||||
example:
|
||||
{
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"@php artisan vendor:publish --tag=lucent --force"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
EOD;
|
||||
|
||||
|
||||
return match (in_array("@php artisan vendor:publish --tag=lucent --force", $postAutoloadDumpList)) {
|
||||
true => SetupStep::makeSuccess($name, $instructions),
|
||||
false => SetupStep::makeFail($name, $instructions),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Lucent\Database\Database;
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
class DatabaseSetupStep implements IStep
|
||||
{
|
||||
|
||||
public function __invoke(): SetupStep
|
||||
{
|
||||
|
||||
|
||||
$name = "Database Connection";
|
||||
|
||||
$databaseConnectionName = config("lucent.database");
|
||||
|
||||
|
||||
$databaseConfig = config('database.connections.'.$databaseConnectionName);
|
||||
|
||||
if (empty($databaseConfig)) {
|
||||
$instructions = <<<EOD
|
||||
# You need to setup a database connection for $databaseConnectionName in database.php config. You can choose either sqlite or pgsql
|
||||
# example:
|
||||
|
||||
'connections' => [
|
||||
'$databaseConnectionName' => [
|
||||
'driver' => 'sqlite',
|
||||
'url' => env('LUCENT_DATABASE_URL'),
|
||||
'database' => env('LUCENT_DB_DATABASE', database_path('database.sqlite')),
|
||||
'prefix' => '',
|
||||
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||||
],
|
||||
EOD;
|
||||
return SetupStep::makeFail($name, $instructions);
|
||||
}
|
||||
|
||||
|
||||
if(!in_array($driver = $databaseConfig["driver"],["sqlite","pgsql"])){
|
||||
$instructions = <<<EOD
|
||||
You can choose either sqlite or pgsql. You current config is: $driver
|
||||
EOD;
|
||||
return SetupStep::makeFail($name, $instructions);
|
||||
}
|
||||
|
||||
try {
|
||||
Database::make()->table("records")->get();
|
||||
} catch (QueryException $e) {
|
||||
$instructions = <<<EOD
|
||||
# Make sure you run:
|
||||
php artisan lucent:setup-db
|
||||
EOD;
|
||||
return SetupStep::makeFail($name, $instructions);
|
||||
}
|
||||
|
||||
return SetupStep::makeSuccess($name, "Database Connection successfully created");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
interface IStep
|
||||
{
|
||||
public function __invoke(): SetupStep;
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
class LaravelEnvStep implements IStep
|
||||
{
|
||||
|
||||
public function __invoke(): SetupStep
|
||||
{
|
||||
$name = "Laravel ENV";
|
||||
$instructions = <<<EOD
|
||||
# Make sure in your env that you APP_URL is the same as the one in your browser right now. Or the other way round.
|
||||
EOD;
|
||||
|
||||
|
||||
return match (config("lucent.url") === request()->getSchemeAndHttpHost()) {
|
||||
true => SetupStep::makeSuccess($name, $instructions),
|
||||
false => SetupStep::makeFail($name, $instructions),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
class LucentConfigStep implements IStep
|
||||
{
|
||||
|
||||
public function __invoke(): SetupStep
|
||||
{
|
||||
|
||||
$lucentConfig = config("lucent.schemas_path");
|
||||
|
||||
$name = "Generate Lucent config";
|
||||
|
||||
$instructions = <<<EOD
|
||||
# Run the following command to generate the configuration file:
|
||||
|
||||
php artisan vendor:publish --tag=lucent-config
|
||||
|
||||
# A lucent.php file will be created in your config folder
|
||||
|
||||
EOD;
|
||||
|
||||
|
||||
return match (!empty($lucentConfig)) {
|
||||
true => SetupStep::makeSuccess($name, $instructions),
|
||||
false => SetupStep::makeFail($name, $instructions),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
class StorageLinkSetupStep implements IStep
|
||||
{
|
||||
|
||||
public function __invoke(): SetupStep
|
||||
{
|
||||
|
||||
$storageDriver = config("filesystems.disks.lucent.driver");
|
||||
|
||||
|
||||
|
||||
|
||||
$name = "Storage Link";
|
||||
|
||||
$instructions = <<<EOD
|
||||
# If you have chosen to store your file locally then you have to generate a link to the public folder
|
||||
# run:
|
||||
|
||||
php artisan storage:link
|
||||
EOD;
|
||||
|
||||
if($storageDriver !== "local"){
|
||||
return SetupStep::makeSuccess($name, $instructions);
|
||||
}
|
||||
|
||||
$storageLinks = config("filesystems.links");
|
||||
$allLinksExist = array_reduce(array_keys($storageLinks),fn(bool $carry, string $link) => !$carry ? false : is_link($link) , true);
|
||||
|
||||
return match ($allLinksExist) {
|
||||
true => SetupStep::makeSuccess($name, $instructions),
|
||||
false => SetupStep::makeFail($name, $instructions),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Lucent\Setup\Step;
|
||||
|
||||
use Lucent\Setup\Data\SetupStep;
|
||||
|
||||
class StorageSetupStep implements IStep
|
||||
{
|
||||
|
||||
public function __invoke(): SetupStep
|
||||
{
|
||||
|
||||
$storage = config("filesystems.disks.lucent");
|
||||
|
||||
$name = "Storage setup";
|
||||
|
||||
$instructions = <<<EOD
|
||||
# You can use your local filesystem or s3 compatible storage. Lucent expects you to have a valid configuration inside config/filesystems.php
|
||||
# example:
|
||||
|
||||
return [
|
||||
'disks' => [
|
||||
'lucent' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'public',
|
||||
'throw' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
EOD;
|
||||
|
||||
|
||||
return match (!empty($storage)) {
|
||||
true => SetupStep::makeSuccess($name, $instructions),
|
||||
false => SetupStep::makeFail($name, $instructions),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user