mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 05:31:24 +00:00
* docs: add CLAUDE.md for Claude Code guidance * fix: handle missing settings table in installation middlewares RedirectIfInstalled crashed with "no such table: settings" when the database_created marker file existed but the database was empty. Changed to use isDbCreated() which verifies actual tables, and added try-catch around Setting queries in both middlewares. * feat: pre-select database driver from env in installation wizard The database step now reads DB_CONNECTION from the environment and pre-selects the matching driver on load, including correct defaults for hostname and port. * feat: pre-select mail driver and config from env in installation wizard The email step now fetches the current mail configuration on load instead of hardcoding the driver to 'mail'. SMTP fields fall back to Laravel config values from the environment. * refactor: remove file-based DB marker in favor of direct DB checks The database_created marker file was a second source of truth that could drift out of sync with the actual database. InstallUtils now checks the database directly via Schema::hasTable which is cached per-request and handles all error cases gracefully.
88 lines
2.7 KiB
PHP
88 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\V1\Installation;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\DatabaseEnvironmentRequest;
|
|
use App\Space\EnvironmentManager;
|
|
use App\Space\InstallUtils;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
|
|
class DatabaseConfigurationController extends Controller
|
|
{
|
|
/**
|
|
* @var EnvironmentManager
|
|
*/
|
|
protected $EnvironmentManager;
|
|
|
|
public function __construct(EnvironmentManager $environmentManager)
|
|
{
|
|
$this->environmentManager = $environmentManager;
|
|
}
|
|
|
|
public function saveDatabaseEnvironment(DatabaseEnvironmentRequest $request)
|
|
{
|
|
Artisan::call('config:clear');
|
|
Artisan::call('cache:clear');
|
|
|
|
$results = $this->environmentManager->saveDatabaseVariables($request);
|
|
|
|
if (array_key_exists('success', $results)) {
|
|
// Automatically regenerating the key is disabled to prevent complications in the wizard process.
|
|
// This can cause issues with the CSRF token, resulting in "Token Mismatch" or "Invalid CSRF Token" errors.
|
|
// It is recommended that the user manually generates the key before running the wizard to ensure application security and stability.
|
|
// Artisan::call('key:generate --force');
|
|
Artisan::call('optimize:clear');
|
|
Artisan::call('config:clear');
|
|
Artisan::call('cache:clear');
|
|
Artisan::call('storage:link');
|
|
Artisan::call('migrate --seed --force');
|
|
// Set version.
|
|
InstallUtils::setCurrentVersion();
|
|
}
|
|
|
|
return response()->json($results);
|
|
}
|
|
|
|
public function getDatabaseEnvironment(Request $request)
|
|
{
|
|
$databaseData = [];
|
|
$connection = $request->connection ?? config('database.default');
|
|
|
|
switch ($connection) {
|
|
case 'sqlite':
|
|
$databaseData = [
|
|
'database_connection' => 'sqlite',
|
|
'database_name' => config('database.connections.sqlite.database', storage_path('database.sqlite')),
|
|
];
|
|
|
|
break;
|
|
|
|
case 'pgsql':
|
|
$databaseData = [
|
|
'database_connection' => 'pgsql',
|
|
'database_host' => '127.0.0.1',
|
|
'database_port' => 5432,
|
|
];
|
|
|
|
break;
|
|
|
|
case 'mysql':
|
|
$databaseData = [
|
|
'database_connection' => 'mysql',
|
|
'database_host' => '127.0.0.1',
|
|
'database_port' => 3306,
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return response()->json([
|
|
'config' => $databaseData,
|
|
'success' => true,
|
|
]);
|
|
}
|
|
}
|