From 12d3acf09b9d83af78f3a023bcede01941650888 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Wed, 6 Jul 2022 20:23:57 +0300 Subject: [PATCH] =?UTF-8?q?[*]=20MQ=20=D1=84=D0=B8=D0=BA=D1=81=D1=8B=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B3=D0=BE=D0=B2=20=D1=81=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=B2=20?= =?UTF-8?q?=D0=B8=D1=81=D1=82=D0=BE=D1=80=D0=B8=D1=8E=20=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=D1=83=D1=89=D0=B5=D1=81=D1=82=D0=B2=D1=83=D1=8E=D1=89=D0=B5?= =?UTF-8?q?=D0=B9=20=D1=82=D0=B0=D1=81=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/lib/Core/CoreException.class.php | 5 +++ core/lib/Core/Models/DB.class.php | 8 ++++- core/lib/Core/Models/MQ.class.php | 40 +++++++++++++---------- core/lib/Core/Models/MQResponse.class.php | 29 +++++++++++++--- 4 files changed, 59 insertions(+), 23 deletions(-) diff --git a/core/lib/Core/CoreException.class.php b/core/lib/Core/CoreException.class.php index ab37e82..5d746a7 100644 --- a/core/lib/Core/CoreException.class.php +++ b/core/lib/Core/CoreException.class.php @@ -39,6 +39,11 @@ */ const ERROR_FILE_COPY = 501; + /** + * Ошибка SQL запроса + */ + const ERROR_SQL_QUERY = 600; + /** * Возвращает обработанный callTrace текущего исключения * diff --git a/core/lib/Core/Models/DB.class.php b/core/lib/Core/Models/DB.class.php index 14bad6b..53b8eab 100644 --- a/core/lib/Core/Models/DB.class.php +++ b/core/lib/Core/Models/DB.class.php @@ -3,6 +3,8 @@ namespace Core\Models; + use Core\CoreException; + /** * Класс для работы с базой данных * @@ -178,7 +180,11 @@ { $startTime = microtime(true); self::$quantity++; - $stmt = $this->db->query($sql); + try { + $stmt = $this->db->query($sql); + } catch (\Throwable $t) { + throw new CoreException('В SQL запросе произошла ошибка', CoreException::ERROR_SQL_QUERY); + } $this->lastInsertId = $this->db->lastInsertId() ?? null; $endTime = microtime(true); self::$workingTime += ($endTime - $startTime); diff --git a/core/lib/Core/Models/MQ.class.php b/core/lib/Core/Models/MQ.class.php index 8166fd8..fec5ea5 100644 --- a/core/lib/Core/Models/MQ.class.php +++ b/core/lib/Core/Models/MQ.class.php @@ -502,7 +502,8 @@ false ); - echo $t->getMessage() . ' on line ' . $t->getLine() . PHP_EOL; + // TODO: Следующая строка нужна больше для отладки - в дальнейшем нужно удалить ее + echo 'Exception: ' . $t->getFile() . ' в строке ' . $t->getLine() . PHP_EOL . $t->getMessage() . PHP_EOL; } return $response; @@ -519,22 +520,27 @@ private function saveExecutedTask(int $taskId): ?int { $arTask = $this->DB->getItem(self::TABLE, ['id' => $taskId]); - $taskHistoryId = $this->DB->addItem( - self::TABLE_HISTORY, [ - 'task_id' => $arTask['id'], - 'execution_time' => $arTask['execution_time'], - 'attempts' => $arTask['attempts'], - 'date_created' => $arTask['date_created'], - 'date_updated' => $arTask['date_updated'], - 'class' => addslashes($arTask['class']), - 'method' => $arTask['method'], - 'params' => $arTask['params'], - 'status' => $arTask['status'], - 'response' => $arTask['response'], - ] - ); - $this->removeTask($taskId); - return $taskHistoryId; + if(!empty($arTask)) { + $taskHistoryId = $this->DB->addItem( + self::TABLE_HISTORY, [ + 'task_id' => $arTask['id'], + 'execution_time' => $arTask['execution_time'], + 'attempts' => $arTask['attempts'], + 'date_created' => $arTask['date_created'], + 'date_updated' => $arTask['date_updated'], + 'class' => addslashes($arTask['class']), + 'method' => $arTask['method'], + 'params' => $arTask['params'], + 'status' => $arTask['status'], + 'response' => $arTask['response'], + ] + ); + $this->removeTask($taskId); + return $taskHistoryId; + } + + + return null; } diff --git a/core/lib/Core/Models/MQResponse.class.php b/core/lib/Core/Models/MQResponse.class.php index 71d4156..fc89ff0 100644 --- a/core/lib/Core/Models/MQResponse.class.php +++ b/core/lib/Core/Models/MQResponse.class.php @@ -37,7 +37,7 @@ private $paramsJson = null; /** - * @var $response Результат выполнения задания + * @var string|null $response Результат выполнения задания */ private $response = null; @@ -81,13 +81,32 @@ return $this->status; } + /** + * Получение параметров + * + * @return array|null + */ + public function getParams(): ?array + { + return $this->params; + } + + /** + * Получение JSON параметров + * + * @return string|null + */ + public function getParamsJson(): ?string + { + return $this->paramsJson; + } + /** * Установка текстового кода ответа внешней службы * * @param string $status Текстовый код ответа * * @return $this - * @throws CoreException */ public function setStatus(string $status): self { @@ -112,7 +131,7 @@ * * @param string|null $response Результат работы задания * - * @return Response + * @return $this */ public function setResponse(?string $response = null): self { @@ -122,7 +141,7 @@ /** - * Установка массива парамтров задания + * Установка массива параметров задания * * @param array|null $params * @@ -135,7 +154,7 @@ } /** - * Установка массива парамтров задания + * Установка массива параметров задания * * @param array $params *