update installation

This commit is contained in:
Flatlogic Bot 2026-02-28 07:24:57 +00:00
parent fcd101fb65
commit e93f08d5e0
2 changed files with 31 additions and 36 deletions

View File

@ -31,11 +31,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$host = $_POST['db_host'] ?? '127.0.0.1';
$name = $_POST['db_name'] ?? 'app_database';
$user = $_POST['db_user'] ?? 'root';
$pass = $_POST['db_pass'] ?? '';
$password = $_POST['db_pass'] ?? '';
// Test connection
try {
$test_pdo = new PDO("mysql:host=$host;dbname=$name;charset=utf8mb4", $user, $pass);
$test_pdo = new PDO("mysql:host=$host;dbname=$name;charset=utf8mb4", $user, $password);
$test_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Generate config file content
@ -44,16 +44,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$content .= "define('DB_HOST', " . var_export($host, true) . ");\n";
$content .= "define('DB_NAME', " . var_export($name, true) . ");\n";
$content .= "define('DB_USER', " . var_export($user, true) . ");\n";
$content .= "define('DB_PASS', " . var_export($pass, true) . ");\n";
$content .= "define('DB_PASS', " . var_export($password, true) . ");\n";
$content .= "\n";
$content .= "if (!function_exists('db')) {\n";
$content .= " function db() {\n";
$content .= " static \$pdo;\n";
$content .= " if (!\$pdo) {\n";
$content .= " try {\n";
$content .= " \$pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4', DB_USER, DB_PASS);\n";
$content .= " \$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);\n";
$content .= " \$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);\n";
$content .= " \$pdo = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8mb4', DB_USER, DB_PASS);
";
$content .= " \$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
";
$content .= " \$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
";
$content .= " } catch (PDOException \$e) {\n";
$content .= " die('Connection failed: ' . \$e->getMessage());\n";
$content .= " }\n";
@ -63,7 +66,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$content .= "}\n";
if (file_put_contents($config_file, $content)) {
header('Location: install.php?step=3');
header('Location: ' . $_SERVER['PHP_SELF'] . '?step=3');
exit;
} else {
$error = "Failed to write configuration file to $config_file. Please check permissions.";
@ -95,9 +98,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($sql)) continue;
try {
// Split SQL into multiple statements if necessary
// Simple split by semicolon. This might fail on some complex SQL,
// but usually works for basic migrations.
$statements = array_filter(array_map('trim', explode(';', $sql)));
foreach ($statements as $stmt_sql) {
if (empty($stmt_sql)) continue;
@ -105,11 +105,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pdo->exec($stmt_sql);
} catch (Throwable $e) {
$msg = $e->getMessage();
// Check if it's a common "already exists" error which we can safely ignore
if (strpos($msg, 'Duplicate column name') !== false ||
strpos($msg, 'Duplicate key name') !== false ||
strpos($msg, 'Duplicate table') !== false ||
strpos($msg, 'already exists') !== false) {
strpos($msg, 'already exists') !== false || strpos($msg, 'Duplicate key on write or update') !== false || strpos($msg, 'errno: 121') !== false) {
continue;
} else {
throw $e;
@ -124,7 +123,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($errors)) {
$success = "Successfully applied $applied migrations.";
header('Location: install.php?step=4');
header('Location: ' . $_SERVER['PHP_SELF'] . '?step=4');
exit;
} else {
$error = "Applied migrations, but some errors occurred:<br><ul><li>" . implode('</li><li>', $errors) . "</li></ul>";
@ -155,7 +154,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pdo->exec("INSERT IGNORE INTO charity_settings (id, charity_name) VALUES (1, 'Admin Panel')");
$pdo->exec("INSERT IGNORE INTO smtp_settings (id, is_enabled) VALUES (1, 0)");
header('Location: install.php?step=5');
header('Location: ' . $_SERVER['PHP_SELF'] . '?step=5');
exit;
} catch (Throwable $e) {
$error = "Failed to create admin account: " . $e->getMessage();
@ -190,10 +189,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<div class="text-center step-indicator">
<?php for ($i = 1; $i <= 5; $i++):
echo "<span class=\"step-dot ";
if ($i == $step) echo "active";
elseif ($i < $step) echo "completed";
echo "\">$i</span>\n";
$class = ($i == $step) ? 'active' : (($i < $step) ? 'completed' : '');
echo "<span class=\"step-dot $class\">$i</span>\n";
endfor; ?>
</div>
@ -221,7 +218,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
</ul>
<div class="d-grid">
<?php if ($all_requirements_met): ?>
<a href="install.php?step=2" class="btn btn-primary">Next: Database Config</a>
<a href="<?= $_SERVER['PHP_SELF'] ?>?step=2" class="btn btn-primary">Next: Database Config</a>
<?php else:
echo "<button class=\"btn btn-secondary\" disabled>Fix requirements to continue</button>";
endif; ?>
@ -229,7 +226,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<?php elseif ($step === 2): ?>
<h4>Step 2: Database Connection</h4>
<form method="POST">
<form method="POST" action="<?= $_SERVER['PHP_SELF'] ?>?step=2">
<div class="mb-3">
<label class="form-label">Database Host</label>
<input type="text" name="db_host" class="form-control" value="127.0.0.1" required>
@ -254,7 +251,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<?php elseif ($step === 3): ?>
<h4>Step 3: Database Migrations</h4>
<p>We will now run the SQL scripts to set up your database tables.</p>
<form method="POST">
<form method="POST" action="<?= $_SERVER['PHP_SELF'] ?>?step=3">
<div class="d-grid">
<button type="submit" class="btn btn-primary">Run Migrations</button>
</div>
@ -262,7 +259,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<?php elseif ($step === 4): ?>
<h4>Step 4: Admin Account</h4>
<form method="POST">
<form method="POST" action="<?= $_SERVER['PHP_SELF'] ?>?step=4">
<div class="mb-3">
<label class="form-label">Admin Username</label>
<input type="text" name="admin_user" class="form-control" value="admin" required>

View File

@ -66,7 +66,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$content .= "}\n";
if (file_put_contents($config_file, $content)) {
header('Location: install.php?step=3');
header('Location: ' . $_SERVER['PHP_SELF'] . '?step=3');
exit;
} else {
$error = "Failed to write configuration file to $config_file. Please check permissions.";
@ -109,7 +109,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (strpos($msg, 'Duplicate column name') !== false ||
strpos($msg, 'Duplicate key name') !== false ||
strpos($msg, 'Duplicate table') !== false ||
strpos($msg, 'already exists') !== false) {
strpos($msg, 'already exists') !== false || strpos($msg, 'Duplicate key on write or update') !== false || strpos($msg, 'errno: 121') !== false) {
continue;
} else {
throw $e;
@ -124,7 +124,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($errors)) {
$success = "Successfully applied $applied migrations.";
header('Location: install.php?step=4');
header('Location: ' . $_SERVER['PHP_SELF'] . '?step=4');
exit;
} else {
$error = "Applied migrations, but some errors occurred:<br><ul><li>" . implode('</li><li>', $errors) . "</li></ul>";
@ -155,7 +155,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$pdo->exec("INSERT IGNORE INTO charity_settings (id, charity_name) VALUES (1, 'Admin Panel')");
$pdo->exec("INSERT IGNORE INTO smtp_settings (id, is_enabled) VALUES (1, 0)");
header('Location: install.php?step=5');
header('Location: ' . $_SERVER['PHP_SELF'] . '?step=5');
exit;
} catch (Throwable $e) {
$error = "Failed to create admin account: " . $e->getMessage();
@ -190,10 +190,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<div class="text-center step-indicator">
<?php for ($i = 1; $i <= 5; $i++):
echo "<span class=\"step-dot ";
if ($i == $step) echo "active";
elseif ($i < $step) echo "completed";
echo ">$i</span>\n";
$class = ($i == $step) ? 'active' : (($i < $step) ? 'completed' : '');
echo "<span class=\"step-dot $class\">$i</span>\n";
endfor; ?>
</div>
@ -221,7 +219,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
</ul>
<div class="d-grid">
<?php if ($all_requirements_met): ?>
<a href="install.php?step=2" class="btn btn-primary">Next: Database Config</a>
<a href="<?= $_SERVER['PHP_SELF'] ?>?step=2" class="btn btn-primary">Next: Database Config</a>
<?php else:
echo "<button class=\"btn btn-secondary\" disabled>Fix requirements to continue</button>";
endif; ?>
@ -229,7 +227,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<?php elseif ($step === 2): ?>
<h4>Step 2: Database Connection</h4>
<form method="POST">
<form method="POST" action="<?= $_SERVER['PHP_SELF'] ?>?step=2">
<div class="mb-3">
<label class="form-label">Database Host</label>
<input type="text" name="db_host" class="form-control" value="127.0.0.1" required>
@ -254,7 +252,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<?php elseif ($step === 3): ?>
<h4>Step 3: Database Migrations</h4>
<p>We will now run the SQL scripts to set up your database tables.</p>
<form method="POST">
<form method="POST" action="<?= $_SERVER['PHP_SELF'] ?>?step=3">
<div class="d-grid">
<button type="submit" class="btn btn-primary">Run Migrations</button>
</div>
@ -262,7 +260,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
<?php elseif ($step === 4): ?>
<h4>Step 4: Admin Account</h4>
<form method="POST">
<form method="POST" action="<?= $_SERVER['PHP_SELF'] ?>?step=4">
<div class="mb-3">
<label class="form-label">Admin Username</label>
<input type="text" name="admin_user" class="form-control" value="admin" required>