From c1149d89be3976b97ade00cc4dec916effb79f9e Mon Sep 17 00:00:00 2001 From: Juan Pablo Vial Date: Mon, 2 Jun 2025 18:03:43 -0400 Subject: [PATCH] FIX: Cleanup after create, but before initialized query. --- app/common/Implement/Log/MySQLHandler.php | 26 +++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/app/common/Implement/Log/MySQLHandler.php b/app/common/Implement/Log/MySQLHandler.php index d7b03f0..c2629a5 100644 --- a/app/common/Implement/Log/MySQLHandler.php +++ b/app/common/Implement/Log/MySQLHandler.php @@ -19,9 +19,12 @@ class MySQLHandler extends AbstractProcessingHandler public function write(LogRecord $record): void { if (!$this->initialized) { + if (!$this->checkTableExists()) { + $this->createTable(); + } + $this->cleanup(); $this->initialized(); } - $this->cleanup(); $this->statement->execute([ 'channel' => $record->channel, 'level' => $record->level->getName(), @@ -35,6 +38,21 @@ class MySQLHandler extends AbstractProcessingHandler private function initialized(): void { $query = <<statement = $this->connection->getPDO()->prepare($query); + $this->initialized = true; + } + private function checkTableExists(): bool + { + $query = "SHOW TABLES LIKE 'monolog'"; + $result = $this->connection->query($query); + return $result->rowCount() > 0; + } + private function createTable(): void + { + $query = <<connection->getPDO()->exec($query); - $query = <<statement = $this->connection->getPDO()->prepare($query); - $this->initialized = true; } private function cleanup(): void {