From e7b32da062ee256dca7e458208ad352979085cd9 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Wed, 29 Apr 2026 21:05:24 +0300 Subject: [PATCH] Adds a fast plugin DB guard in bootstrap, to ensure tables existence. --- plugins/logs/bootstrap.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/logs/bootstrap.php b/plugins/logs/bootstrap.php index 97e5587..3bb1298 100644 --- a/plugins/logs/bootstrap.php +++ b/plugins/logs/bootstrap.php @@ -42,11 +42,29 @@ if (!function_exists('logs_ensure_tables')) { if (!$pdo instanceof \PDO) { 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'; if (is_readable($migrationFile)) { $sql = file_get_contents($migrationFile); if ($sql !== false && trim($sql) !== '') { $pdo->exec($sql); + } else { + $ensured = true; + return; } } $ensured = true;