Adds a fast plugin DB guard in bootstrap, to ensure tables existence.

main
Yasen Pramatarov 2026-04-29 21:05:24 +03:00
parent e2284695fc
commit e7b32da062
1 changed files with 18 additions and 0 deletions

View File

@ -42,11 +42,29 @@ if (!function_exists('logs_ensure_tables')) {
if (!$pdo instanceof \PDO) { if (!$pdo instanceof \PDO) {
return; return;
} }
$tableExists = false;
try {
$check = $pdo->query("SHOW TABLES LIKE 'log'");
$tableExists = $check && $check->fetch(\PDO::FETCH_NUM);
} catch (\PDOException $e) {
if (defined('APP_ENV') && APP_ENV === 'development') {
error_log('Logs plugin table check failed: ' . $e->getMessage());
}
}
if ($tableExists) {
$ensured = true;
return;
}
$migrationFile = __DIR__ . '/migrations/create_log_table.sql'; $migrationFile = __DIR__ . '/migrations/create_log_table.sql';
if (is_readable($migrationFile)) { if (is_readable($migrationFile)) {
$sql = file_get_contents($migrationFile); $sql = file_get_contents($migrationFile);
if ($sql !== false && trim($sql) !== '') { if ($sql !== false && trim($sql) !== '') {
$pdo->exec($sql); $pdo->exec($sql);
} else {
$ensured = true;
return;
} }
} }
$ensured = true; $ensured = true;