diff --git a/services/DatabaseService.php b/services/DatabaseService.php index be5486b6..c394a4af 100644 --- a/services/DatabaseService.php +++ b/services/DatabaseService.php @@ -29,9 +29,18 @@ class DatabaseService { $pdo = $this->GetDbConnectionRaw(); + if (GROCY_MODE === 'dev') + { + $logFilePath = GROCY_DATAPATH . '/sql.log'; + if (file_exists($logFilePath)) + { + file_put_contents($logFilePath, $sql . PHP_EOL, FILE_APPEND); + } + } + if ($pdo->exec($sql) === false) { - throw new Exception($pdo->errorInfo()); + throw new \Exception($pdo->errorInfo()); } return true; @@ -49,6 +58,17 @@ class DatabaseService self::$DbConnection = new Database($this->GetDbConnectionRaw()); } + if (GROCY_MODE === 'dev') + { + $logFilePath = GROCY_DATAPATH . '/sql.log'; + if (file_exists($logFilePath)) + { + self::$DbConnection->setQueryCallback(function ($query, $params) use ($logFilePath) { + file_put_contents($logFilePath, $query . ' #### ' . implode(';', $params) . PHP_EOL, FILE_APPEND); + }); + } + } + return self::$DbConnection; } diff --git a/services/PrintService.php b/services/PrintService.php index e53dec70..6b47ac9d 100644 --- a/services/PrintService.php +++ b/services/PrintService.php @@ -3,7 +3,6 @@ namespace Grocy\Services; use DateTime; -use Exception; use Mike42\Escpos\PrintConnectors\NetworkPrintConnector; use Mike42\Escpos\PrintConnectors\FilePrintConnector; use Mike42\Escpos\Printer; @@ -15,7 +14,7 @@ class PrintService extends BaseService $printer = self::getPrinterHandle(); if ($printer === false) { - throw new Exception('Unable to connect to printer'); + throw new \Exception('Unable to connect to printer'); } if ($printHeader) diff --git a/services/StockService.php b/services/StockService.php index 16cb468c..3b38fc72 100644 --- a/services/StockService.php +++ b/services/StockService.php @@ -509,7 +509,7 @@ class StockService extends BaseService } else { - throw new Exception("Transaction type $transactionType is not valid (StockService.ConsumeProduct)"); + throw new \Exception("Transaction type $transactionType is not valid (StockService.ConsumeProduct)"); } }