diff --git a/plugins/logs/migrations/create_log_table.sql b/plugins/logs/migrations/create_log_table.sql new file mode 100644 index 0000000..68fc348 --- /dev/null +++ b/plugins/logs/migrations/create_log_table.sql @@ -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; diff --git a/plugins/logs/models/LoggerFactory.php b/plugins/logs/models/LoggerFactory.php index f27d672..a9cf00c 100644 --- a/plugins/logs/models/LoggerFactory.php +++ b/plugins/logs/models/LoggerFactory.php @@ -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';