Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-09-09 20:54:42 +02:00
parent 963342f858
commit eaee4d5f1c
6 changed files with 1843 additions and 12 deletions
+32
View File
@@ -147,6 +147,7 @@ function ensure_tables_exist(PDO $pdo): void {
"ALTER TABLE users ADD COLUMN theme VARCHAR(20) NOT NULL DEFAULT 'dark' AFTER notification_settings",
"ALTER TABLE users ADD COLUMN avatar_url VARCHAR(255) NULL AFTER theme",
"ALTER TABLE users ADD COLUMN backup_codes TEXT NULL AFTER two_factor_enabled",
"ALTER TABLE board_card_schedules ADD UNIQUE KEY uk_sched_card (card_id)",
];
foreach ($colUpgrades as $sql) {
try {
@@ -155,6 +156,37 @@ function ensure_tables_exist(PDO $pdo): void {
// Stil negeren indien kolom al bestaat
}
}
// Zorg dat er ten minste één standaard bord met standaard lanes aanwezig is
try {
$boardCount = (int)$pdo->query("SELECT COUNT(*) FROM boards")->fetchColumn();
if ($boardCount === 0) {
$firstAdminId = (int)$pdo->query("SELECT id FROM users ORDER BY (role = 'ADMIN') DESC, id ASC LIMIT 1")->fetchColumn();
if ($firstAdminId > 0) {
$pdo->prepare("INSERT INTO boards (title, description, created_by_id) VALUES (?, ?, ?)")
->execute(['Hoofdbord', 'Standaard team- en takenbord voor opdrachten', $firstAdminId]);
$boardId = (int)$pdo->lastInsertId();
// Maak beheerder lid van het bord
$pdo->prepare("INSERT INTO board_members (board_id, user_id, role) VALUES (?, ?, 'ADMIN')")
->execute([$boardId, $firstAdminId]);
// Maak de 4 standaard lanes aan
$defaultLanes = [
['title' => 'Open', 'color' => 'slate', 'pos' => 0],
['title' => 'In uitvoering', 'color' => 'amber', 'pos' => 1],
['title' => 'Testen', 'color' => 'purple', 'pos' => 2],
['title' => 'Klaar', 'color' => 'emerald', 'pos' => 3],
];
$laneStmt = $pdo->prepare("INSERT INTO board_lanes (board_id, title, color, position) VALUES (?, ?, ?, ?)");
foreach ($defaultLanes as $l) {
$laneStmt->execute([$boardId, $l['title'], $l['color'], $l['pos']]);
}
}
}
} catch (Throwable $e) {
// Stil negeren indien tabellen nog in opbouw zijn
}
} catch (Throwable $e) {
error_log("Fout bij controleren tabellen: " . $e->getMessage());
}