mirror of
git://f0xx.org/android_cast
synced 2026-07-29 08:19:00 +03:00
Fix tickets API false missing-table when session skips DB.
Auth: :user() returns early when companies are cached, so requireTicketsTable() ran with no PDO and always failed. Always open the connection before checking tickets. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -21,11 +21,24 @@ try {
|
||||
json_out(['ok' => true] + $data);
|
||||
} catch (RuntimeException $e) {
|
||||
error_log('tickets api: ' . $e->getMessage());
|
||||
json_out([
|
||||
$out = [
|
||||
'ok' => false,
|
||||
'error' => 'tickets_table_missing',
|
||||
'hint' => $e->getMessage(),
|
||||
], 503);
|
||||
];
|
||||
if (cfg('debug')) {
|
||||
try {
|
||||
$pdo = Database::pdo();
|
||||
$out['db_driver'] = Database::driver();
|
||||
$out['tickets_table'] = Database::ticketsTableExists($pdo);
|
||||
if (Database::isMysql()) {
|
||||
$out['mysql_database'] = $pdo->query('SELECT DATABASE()')->fetchColumn();
|
||||
}
|
||||
} catch (Throwable $diag) {
|
||||
$out['diag_error'] = $diag->getMessage();
|
||||
}
|
||||
}
|
||||
json_out($out, 503);
|
||||
} catch (Throwable $e) {
|
||||
error_log('tickets api: ' . $e->getMessage());
|
||||
$out = ['ok' => false, 'error' => 'list failed'];
|
||||
|
||||
@@ -159,15 +159,20 @@ final class Database {
|
||||
self::ensureTicketsTable($pdo);
|
||||
}
|
||||
|
||||
/** Active PDO; opens the pool when callers have not touched the DB yet (e.g. cached Auth session). */
|
||||
private static function connection(?PDO $pdo = null): PDO {
|
||||
return $pdo ?? self::$pdo ?? self::pdo();
|
||||
}
|
||||
|
||||
public static function ticketsTableExists(?PDO $pdo = null): bool {
|
||||
$pdo ??= self::$pdo;
|
||||
return $pdo !== null && self::tableExists($pdo, 'tickets');
|
||||
return self::tableExists(self::connection($pdo), 'tickets');
|
||||
}
|
||||
|
||||
/** @throws RuntimeException when `tickets` is missing (MariaDB needs root migration). */
|
||||
public static function requireTicketsTable(?PDO $pdo = null): void {
|
||||
$pdo = self::connection($pdo);
|
||||
self::ensureTicketsTable($pdo);
|
||||
if (!self::ticketsTableExists($pdo)) {
|
||||
if (!self::tableExists($pdo, 'tickets')) {
|
||||
throw new RuntimeException(self::ticketsMigrationHint());
|
||||
}
|
||||
}
|
||||
@@ -179,8 +184,8 @@ final class Database {
|
||||
}
|
||||
|
||||
public static function ensureTicketsTable(?PDO $pdo = null): void {
|
||||
$pdo ??= self::$pdo;
|
||||
if ($pdo === null || self::tableExists($pdo, 'tickets')) {
|
||||
$pdo = self::connection($pdo);
|
||||
if (self::tableExists($pdo, 'tickets')) {
|
||||
return;
|
||||
}
|
||||
$ok = false;
|
||||
|
||||
Reference in New Issue
Block a user