mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-09-06 15:14:13 +00:00
Backport of InvoiceShelf/InvoiceShelf#704 to 2.x. Fixes InvoiceShelf/docker#79. A fresh install using the shipped docker-compose.mysql.yml cannot get past the database step, because that compose file sets DB_CONNECTION=mariadb. getDatabaseEnvironment() switched on sqlite, pgsql and mysql with no arm for mariadb and no default, so it answered {"config":[]}. The wizard renders <component :is="database_connection">, which resolves to nothing, so the step came out blank — and nothing reached the log, because the app never errored, it just replied with nothing. Adds the mariadb arm plus a default, so an unrecognised driver is echoed back with server defaults rather than producing an unrenderable response. MariaDB is registered as an alias of the MySQL form, whose fields are identical, and offered in each driver picker. Tested against the original controller, where three of the new cases fail with "Failed asserting that null is identical to 'mariadb'".
110 lines
3.5 KiB
PHP
110 lines
3.5 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;
|
|
|
|
case 'mariadb':
|
|
$databaseData = [
|
|
'database_connection' => 'mariadb',
|
|
'database_host' => '127.0.0.1',
|
|
'database_port' => 3306,
|
|
];
|
|
|
|
break;
|
|
|
|
default:
|
|
// Never return an empty config: the wizard picks its form from
|
|
// database_connection, so an unrecognised driver used to render
|
|
// a blank step with no way forward. Echo it back with the
|
|
// server defaults instead.
|
|
$databaseData = [
|
|
'database_connection' => $connection,
|
|
'database_host' => '127.0.0.1',
|
|
'database_port' => 3306,
|
|
];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return response()->json([
|
|
'config' => $databaseData,
|
|
'success' => true,
|
|
]);
|
|
}
|
|
}
|