From c8f54a2e05cee9e82dc902727d8d59c6f00ef262 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Fri, 27 Jan 2023 17:45:56 +0300 Subject: [PATCH] =?UTF-8?q?[*]=20=D0=BC=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=D0=B4=20php?= =?UTF-8?q?8.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Core/Models/DB.class.php | 51 +++++++++++++++++++------------ 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/core/lib/Core/Models/DB.class.php b/core/lib/Core/Models/DB.class.php index 76ad59a..356415c 100644 --- a/core/lib/Core/Models/DB.class.php +++ b/core/lib/Core/Models/DB.class.php @@ -47,9 +47,9 @@ public static int $quantity = 0; /** - * @var int $workingTime Время выполнения запросов + * @var float $workingTime Время выполнения запросов */ - public static int $workingTime = 0; + public static float $workingTime = 0; /** * ID последней добавленной записи @@ -61,22 +61,22 @@ /** * @var string|null $dbServer Сервер */ - private ?string $dbServer = null; + private ?string $dbServer; /** * @var string|null $dbUser Пользователь */ - private ?string $dbUser = null; + private ?string $dbUser; /** * @var string|null $dbPass Пароль */ - private ?string $dbPass = null; + private ?string $dbPass; /** * @var string|null $dbName Имя базы */ - private ?string $dbName = null; + private ?string $dbName; /** @@ -108,10 +108,24 @@ */ public function __destruct() { - unset($this->instance); - unset($this->db); + // TODO: на случай чего то стоящего... } + /** + * Отправка уведомления о критическом событии + * // TODO: метод-заглушка для возможности оповещения о критических событиях + * + * @param string $text Текст + * + * @return void + * @deprecated Вероятно, будет выпилено в дальнейшем + */ + public static function sendAlarm(string $text): void + { + if (function_exists('sendTelegram')) { + sendTelegram($text); + } + } /** * Получить объект класса @@ -138,7 +152,8 @@ { if (!is_array($where)) { return $where; - } elseif (empty($where)) { + } + if (empty($where)) { return '1'; } $where_string = ''; @@ -211,13 +226,13 @@ * * @return string */ - private function createInsertString($data, $param = 'key'): string + private function createInsertString($data, string $param = 'key'): string { $result = ''; foreach ($data as $k => $v) { - if ($param == 'key') { + if ($param === 'key') { $result .= $k . ', '; - } elseif ($param == 'value') { + } elseif ($param === 'value') { if (is_numeric($v)) { $result .= $v . ', '; } else { @@ -244,16 +259,14 @@ try { $stmt = $this->db->query($sql); } catch (\Throwable $t) { - sendTelegram( + self::sendAlarm( '' . date('d.m.Y H:i:s') . '' . PHP_EOL . 'SQL ERROR: ' . PHP_EOL . $this->db->errorInfo()[2] . PHP_EOL . 'QUERY: ' . PHP_EOL . $sql ); if(DEBUG) { throw new CoreException('В SQL запросе произошла ошибка. '.$this->db->errorInfo()[2].' Запрос: ' . $sql, CoreException::ERROR_SQL_QUERY); - } else { - throw new CoreException('В SQL запросе произошла ошибка', CoreException::ERROR_SQL_QUERY); } - + throw new CoreException('В SQL запросе произошла ошибка', CoreException::ERROR_SQL_QUERY); } $this->lastInsertId = $this->db->lastInsertId() ?? null; @@ -263,10 +276,10 @@ if ($returnObject) { return $stmt; - } else { - $result = $stmt->fetchAll(); - return $result ?: null; } + $result = $stmt->fetchAll(); + return $result ?: null; + } /**