fix: address code review feedback (DB filename, migration query, error handling)
Co-authored-by: naielv <109038805+naielv@users.noreply.github.com>
This commit is contained in:
@@ -4,12 +4,12 @@
|
||||
*
|
||||
* Provides a PDO SQLite connection and a lightweight migration runner.
|
||||
* All application data previously stored as JSON files under /DATA is now
|
||||
* persisted in /DATA/axia4.db.
|
||||
* persisted in /DATA/axia4.sqlite.
|
||||
*
|
||||
* Usage: db() → returns the shared PDO instance (auto-migrates on first call).
|
||||
*/
|
||||
|
||||
define('DB_PATH', '/DATA/axia4.db');
|
||||
define('DB_PATH', '/DATA/axia4.sqlite');
|
||||
define('MIGRATIONS_DIR', __DIR__ . '/migrations');
|
||||
|
||||
// ── Connection ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -63,8 +63,9 @@ if (is_dir($users_dir)) {
|
||||
$user_id = (int) $db->lastInsertId();
|
||||
if ($user_id === 0) {
|
||||
// Already existed – look it up
|
||||
$row = $db->prepare("SELECT id FROM users WHERE username = ?")->execute([$username]);
|
||||
$user_id = (int) $db->query("SELECT id FROM users WHERE username = " . $db->quote($username))->fetchColumn();
|
||||
$stmt2 = $db->prepare("SELECT id FROM users WHERE username = ?");
|
||||
$stmt2->execute([$username]);
|
||||
$user_id = (int) $stmt2->fetchColumn();
|
||||
}
|
||||
|
||||
// Entreaulas centro assignment
|
||||
|
||||
@@ -72,8 +72,11 @@ switch ($form_action) {
|
||||
Sf($_POST["name"] ?? ""),
|
||||
Sf($_POST["icon"] ?? "/static/logo-entreaulas.png"),
|
||||
]);
|
||||
// Create Alumnos directory for photo-based features
|
||||
@mkdir("/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id/Proyectos/", 0755, true);
|
||||
// Create Proyectos directory for project file storage
|
||||
$proyectos_dir = "/DATA/entreaulas/Centros/$centro_id/Aularios/$aulario_id/Proyectos/";
|
||||
if (!is_dir($proyectos_dir)) {
|
||||
mkdir($proyectos_dir, 0755, true);
|
||||
}
|
||||
header("Location: ?action=index");
|
||||
exit();
|
||||
break;
|
||||
|
||||
@@ -32,8 +32,8 @@ switch ($form_action) {
|
||||
db()->prepare("INSERT INTO centros (centro_id) VALUES (?)")->execute([$centro_id]);
|
||||
// Keep filesystem directory for activity photos (Panel/Actividades)
|
||||
$centro_path = "/DATA/entreaulas/Centros/$centro_id";
|
||||
if (!is_dir($centro_path)) {
|
||||
mkdir($centro_path, 0755, true);
|
||||
if (!is_dir($centro_path) && !mkdir($centro_path, 0755, true) && !is_dir($centro_path)) {
|
||||
error_log("centros.php: failed to create directory $centro_path");
|
||||
}
|
||||
header("Location: ?action=index");
|
||||
exit();
|
||||
|
||||
Reference in New Issue
Block a user