Fixes log plugin

main
Yasen Pramatarov 2025-04-27 15:41:01 +03:00
parent 1f3d331b25
commit fa3e75f722
2 changed files with 19 additions and 5 deletions

View File

@ -0,0 +1,14 @@
-- --------------------------------------------------------
-- Logger Plugin: Create `log` table if it does not exist
-- --------------------------------------------------------
CREATE TABLE IF NOT EXISTS `log` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`user_id` INT(11) NOT NULL,
`time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`level` VARCHAR(10) NOT NULL DEFAULT 'info',
`scope` set('user','system') NOT NULL,
`message` VARCHAR(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`),
CONSTRAINT `log_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;

View File

@ -15,11 +15,11 @@ class LoggerFactory
{
// Auto-migration: ensure log table exists
$pdo = $db->getConnection();
// $migrationFile = __DIR__ . '/../migrations/create_log_table.sql';
// if (file_exists($migrationFile)) {
// $sql = file_get_contents($migrationFile);
// $pdo->exec($sql);
// }
$migrationFile = __DIR__ . '/../migrations/create_log_table.sql';
if (file_exists($migrationFile)) {
$sql = file_get_contents($migrationFile);
$pdo->exec($sql);
}
// Load models and core IP helper
require_once __DIR__ . '/Log.php';