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