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 *