BxDolAiQuery.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolAiQuery extends BxDolDb
  10. {
  11. public function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. static protected function _getObject(int $iId, string $sTable): array|bool
  16. {
  17. $oDb = BxDolDb::getInstance();
  18. $a = $oDb->getRow("SELECT * FROM `$sTable` WHERE `id` = :id", ['id' => $iId]);
  19. if(!$a || !is_array($a))
  20. return false;
  21. return $a;
  22. }
  23. static public function getModelObject(int $iId): array|bool
  24. {
  25. return self::_getObject($iId, 'sys_agents_models');
  26. }
  27. static public function getVectorStoreObject(int $iId): array|bool
  28. {
  29. return self::_getObject($iId, 'sys_agents_vector_store');
  30. }
  31. static public function getAgentObject(int $iId): array|bool
  32. {
  33. return self::_getObject($iId, 'sys_agents_agents');
  34. }
  35. static public function getToolObject(int $iId): array|bool
  36. {
  37. return self::_getObject($iId, 'sys_agents_tools');
  38. }
  39. public function insertModel($aModel)
  40. {
  41. if(empty($aModel))
  42. return false;
  43. return (int)$this->query("INSERT INTO `sys_agents_models` SET " . $this->arrayToSQL($aModel));
  44. }
  45. public function getModelsBy($aParams = [])
  46. {
  47. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  48. $sWhereClause = "";
  49. switch($aParams['sample']) {
  50. case 'id':
  51. $aMethod['name'] = 'getRow';
  52. $aMethod['params'][1] = [
  53. 'id' => $aParams['id']
  54. ];
  55. $sWhereClause .= " AND `id`=:id";
  56. break;
  57. case 'all_pairs':
  58. $aMethod['name'] = 'getPairs';
  59. $aMethod['params'][1] = 'id';
  60. $aMethod['params'][2] = 'title';
  61. $aMethod['params'][3] = [];
  62. if(isset($aParams['active'])) {
  63. $aMethod['params'][3]['active'] = $aParams['active'];
  64. $sWhereClause .= " AND `active`=:active";
  65. }
  66. if(isset($aParams['capabilities'])) {
  67. if (is_array($aParams['capabilities']))
  68. {
  69. $sWhereClause .= " AND `capabilities` IN (" . $this->implode_escape($aParams['capabilities']) . ")";
  70. }
  71. else {
  72. $aMethod['params'][3]['capabilities'] = $aParams['capabilities'];
  73. $sWhereClause .= " AND `capabilities` = :capabilities";
  74. }
  75. }
  76. break;
  77. }
  78. $aMethod['params'][0] = "SELECT *
  79. FROM `sys_agents_models`
  80. WHERE 1" . $sWhereClause;
  81. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  82. }
  83. public function getVectorStores (): mixed
  84. {
  85. $sQuery = "SELECT `id`, `title` FROM `sys_agents_vector_store` WHERE `active` = 1 ORDER BY `title` ASC";
  86. return $this->getPairs($sQuery, 'id', 'title');
  87. }
  88. public function getVectorStoreById (int $iId): mixed
  89. {
  90. $sQuery = "SELECT * FROM `sys_agents_vector_store` WHERE `id` = :id";
  91. return $this->getRow($sQuery, ['id' => $iId]);
  92. }
  93. public function insertVectorStore($aVectorStore)
  94. {
  95. if(empty($aVectorStore) || !is_array($aVectorStore))
  96. return false;
  97. return (int)$this->query("INSERT INTO `sys_agents_vector_store` SET " . $this->arrayToSQL($aVectorStore));
  98. }
  99. public function getVectorStoreDataNum (int $iVectorStoreId): int
  100. {
  101. $sQuery = "SELECT COUNT(*) FROM `sys_agents_vector_store_data` WHERE `vector_store_id` = :vector_store_id";
  102. return (int)$this->getOne($sQuery, ['vector_store_id' => $iVectorStoreId]);
  103. }
  104. public function addVectorStoreData (int $iVectorStoreId, string $sType, string $sName, int $iFileSize, string $sMetadata, string $sSettings, string $sContent): bool
  105. {
  106. $sQuery = "INSERT INTO `sys_agents_vector_store_data` SET
  107. `vector_store_id` = :vector_store_id,
  108. `type` = :type,
  109. `name` = :name,
  110. `size` = :size,
  111. `metadata` = :metadata,
  112. `settings` = :settings,
  113. `content` = :content,
  114. `added` = :ts
  115. ";
  116. return $this->query($sQuery, [
  117. 'vector_store_id' => $iVectorStoreId,
  118. 'type' => $sType,
  119. 'name' => $sName,
  120. 'size' => $iFileSize,
  121. 'metadata' => $sMetadata,
  122. 'settings' => $sSettings,
  123. 'content' => $sContent,
  124. 'ts' => time()]) > 0;
  125. }
  126. public function getVectorStoreDataById (int $iId): mixed
  127. {
  128. $sQuery = "SELECT * FROM `sys_agents_vector_store_data` WHERE `id` = :id";
  129. return $this->getRow($sQuery, ['id' => $iId]);
  130. }
  131. static public function getVectorStorePendingData (int $iLimit = 1): mixed
  132. {
  133. $oDb = BxDolDb::getInstance();
  134. $sQuery = "SELECT * FROM `sys_agents_vector_store_data` WHERE `status` = 'pending' ORDER BY `added` ASC LIMIT :limit";
  135. return $oDb->getAll($sQuery, ['limit' => $iLimit]);
  136. }
  137. static public function updateVectorStoreDataStatus (int $iId, string $sStatus): mixed
  138. {
  139. $oDb = BxDolDb::getInstance();
  140. $sQuery = "UPDATE `sys_agents_vector_store_data` SET `status` = :status WHERE `id` = :id";
  141. return $oDb->query($sQuery, ['status' => $sStatus, 'id' => $iId]);
  142. }
  143. public function getAgentsWithAlert($bActiveOnly = true)
  144. {
  145. return $this->fromCache('sys_agents_with_alert', 'getAll', "SELECT * FROM `sys_agents_agents` WHERE `trigger` = 'alert' AND `active` = :active", ['active' => $bActiveOnly ? 1 : 0]);
  146. }
  147. public function getAgentsByProfileId($iProfileId, $bActiveOnly = true)
  148. {
  149. return $this->getAll("SELECT * FROM `sys_agents_agents` WHERE `trigger` = 'message' AND `profile_id` = :profile AND `active` = :active", ['profile' => $iProfileId, 'active' => $bActiveOnly ? 1 : 0]);
  150. }
  151. public function getAgentsByFormObject($sFormObject, $bActiveOnly = true)
  152. {
  153. return $this->fromMemory('sys_agents_with_form_' . $sFormObject, 'getAll', "SELECT * FROM `sys_agents_agents` WHERE `trigger` = 'form-input' AND `form_object` = :form_object AND `active` = :active", ['form_object' => $sFormObject, 'active' => $bActiveOnly ? 1 : 0]);
  154. }
  155. public function getAgentsBy($aParams = [])
  156. {
  157. $aMethod = ['name' => 'getAll', 'params' => [0 => 'query']];
  158. $sWhereClause = "";
  159. switch($aParams['sample']) {
  160. case 'id':
  161. $aMethod['name'] = 'getRow';
  162. $aMethod['params'][1] = [
  163. 'id' => $aParams['id']
  164. ];
  165. $sWhereClause .= " AND `id`=:id";
  166. break;
  167. case 'all':
  168. if(isset($aParams['active'])) {
  169. $aMethod['params'][3]['active'] = $aParams['active'];
  170. $sWhereClause .= " AND `active`=:active";
  171. }
  172. break;
  173. }
  174. $aMethod['params'][0] = "SELECT *
  175. FROM `sys_agents_agents`
  176. WHERE 1" . $sWhereClause;
  177. return call_user_func_array([$this, $aMethod['name']], $aMethod['params']);
  178. }
  179. public function getAgentById(int $iId): mixed
  180. {
  181. return $this->getAgentsBy(['sample' => 'id', 'id' => $iId]);
  182. }
  183. public function getAgentByTriggerWebhookKey($sKey, $bActiveOnly = true)
  184. {
  185. return $this->getRow("SELECT * FROM `sys_agents_agents` WHERE `trigger` = 'webhook' AND `webhook_key` = :key AND `active` = :active", ['key' => $sKey, 'active' => $bActiveOnly ? 1 : 0]);
  186. }
  187. public function getAgentsByTriggerType($sTrigger, $bActiveOnly = true)
  188. {
  189. return $this->getAll("SELECT * FROM `sys_agents_agents` WHERE `trigger` = :trigger AND `active` = :active", ['trigger' => $sTrigger, 'active' => $bActiveOnly ? 1 : 0]);
  190. }
  191. public function updateAgentField($iId, $sField, $sValue)
  192. {
  193. return $this->query("UPDATE `sys_agents_agents` SET `$sField` = :value WHERE `id` = :id", ['value' => $sValue, 'id' => $iId]);
  194. }
  195. public function getToolById (int $iId): mixed
  196. {
  197. $sQuery = "SELECT * FROM `sys_agents_tools` WHERE `id` = :id";
  198. return $this->getRow($sQuery, ['id' => $iId]);
  199. }
  200. public function insertTool(array $aFields): int
  201. {
  202. if(empty($aFields) || !is_array($aFields))
  203. return false;
  204. return (int)$this->query("INSERT INTO `sys_agents_tools` SET " . $this->arrayToSQL($aFields));
  205. }
  206. public function getTools()
  207. {
  208. $sQuery = "SELECT `id`, `title` FROM `sys_agents_tools` WHERE `active` = 1 ORDER BY `title` ASC";
  209. return $this->getPairs($sQuery, 'id', 'title');
  210. }
  211. public function wipeAgentChatHistory($aAgent)
  212. {
  213. $sQuery = "DELETE FROM `sys_agents_chat_history` WHERE `thread_id` LIKE :val";
  214. $iAffected = 0;
  215. $iAffected += $this->query($sQuery, ['val' => $aAgent['trigger'] . ':' . $aAgent['id'] . ':%']);
  216. $iAffected += $this->query($sQuery, ['val' => $aAgent['trigger'] . ':' . $aAgent['id']]);
  217. return $iAffected;
  218. }
  219. public function getAgentChatHistoryRows($aAgent)
  220. {
  221. $sExact = ($aAgent['trigger'] ?? '') . ':' . ($aAgent['id'] ?? '');
  222. $sFields = "`id`, `thread_id`, `messages`, `created_at`, `updated_at`";
  223. if ($this->isFieldExists('sys_agents_chat_history', 'closed_reason'))
  224. $sFields .= ", `closed_reason`";
  225. return $this->getAll("
  226. SELECT $sFields
  227. FROM `sys_agents_chat_history`
  228. WHERE `thread_id` = :exact OR `thread_id` LIKE :prefix
  229. ORDER BY `updated_at` DESC
  230. LIMIT 200
  231. ", [
  232. 'exact' => $sExact,
  233. 'prefix' => $sExact . ':%',
  234. ]);
  235. }
  236. public function getChatHistoryIdByThreadId($sThreadId)
  237. {
  238. $sThreadId = (string)$sThreadId;
  239. if ($sThreadId === '' || $sThreadId === ':')
  240. return 0;
  241. return (int)$this->getOne("SELECT `id` FROM `sys_agents_chat_history` WHERE `thread_id` = :t", [
  242. 't' => $sThreadId,
  243. ]);
  244. }
  245. public function getChatHistoryMessagesByThreadId($sThreadId)
  246. {
  247. $sThreadId = (string)$sThreadId;
  248. if ($sThreadId === '')
  249. return '';
  250. return $this->getOne("SELECT `messages` FROM `sys_agents_chat_history` WHERE `thread_id` = :t", [
  251. 't' => $sThreadId,
  252. ]);
  253. }
  254. public function getChatHistoryClosedReasonById($iHistoryId)
  255. {
  256. $iHistoryId = (int)$iHistoryId;
  257. if ($iHistoryId <= 0 || !$this->isFieldExists('sys_agents_chat_history', 'closed_reason'))
  258. return '';
  259. return (string)$this->getOne(
  260. "SELECT `closed_reason` FROM `sys_agents_chat_history` WHERE `id` = :id",
  261. ['id' => $iHistoryId]
  262. );
  263. }
  264. public function isNewChatSession($sThreadId)
  265. {
  266. $sThreadId = (string)$sThreadId;
  267. if ($sThreadId === '')
  268. return true;
  269. $aRow = $this->getRow("SELECT `ip`, `messages` FROM `sys_agents_chat_history` WHERE `thread_id` = :t", [
  270. 't' => $sThreadId,
  271. ]);
  272. if (!$aRow)
  273. return true;
  274. $iIp = (int)($aRow['ip'] ?? 0);
  275. $sMessages = trim((string)($aRow['messages'] ?? ''));
  276. return $iIp <= 0 || $sMessages === '' || $sMessages === '[]';
  277. }
  278. public function countChatSessionsByIp($sIp, $sPrefix, $iWindowSec)
  279. {
  280. $sSince = date('Y-m-d H:i:s', time() - (int)$iWindowSec);
  281. return (int)$this->getOne("
  282. SELECT COUNT(*) FROM `sys_agents_chat_history`
  283. WHERE `ip` = :ip
  284. AND (`thread_id` = :prefix OR `thread_id` LIKE :prefix_like)
  285. AND `created_at` >= :since
  286. ", [
  287. 'ip' => $sIp,
  288. 'prefix' => $sPrefix,
  289. 'prefix_like' => $sPrefix . ':%',
  290. 'since' => $sSince,
  291. ]);
  292. }
  293. public function getChatArtifactsByHistoryIds($aIds)
  294. {
  295. $aIds = array_values(array_unique(array_filter(array_map('intval', (array)$aIds))));
  296. if (!$aIds)
  297. return [];
  298. $sIn = implode(',', $aIds);
  299. $aRows = $this->getAll("
  300. SELECT `history_id`, `field_name`, `field_value`
  301. FROM `sys_agents_chat_artifacts`
  302. WHERE `history_id` IN ($sIn)
  303. ORDER BY `id` ASC
  304. ");
  305. return $this->mapChatArtifactRows($aRows);
  306. }
  307. public function getChatArtifactsByThreadId($sThreadId)
  308. {
  309. $sThreadId = (string)$sThreadId;
  310. if ($sThreadId === '')
  311. return [];
  312. $aRows = $this->getAll("
  313. SELECT `a`.`history_id`, `a`.`field_name`, `a`.`field_value`
  314. FROM `sys_agents_chat_artifacts` AS `a`
  315. INNER JOIN `sys_agents_chat_history` AS `h` ON `h`.`id` = `a`.`history_id`
  316. WHERE `h`.`thread_id` = :t
  317. ORDER BY `a`.`id` ASC
  318. ", [
  319. 't' => $sThreadId,
  320. ]);
  321. $aMap = $this->mapChatArtifactRows($aRows);
  322. if (!$aMap)
  323. return [];
  324. return (array)reset($aMap);
  325. }
  326. public function getChatArtifactsForAgent($aAgent)
  327. {
  328. $sExact = ($aAgent['trigger'] ?? '') . ':' . ($aAgent['id'] ?? '');
  329. if ($sExact === ':')
  330. return [];
  331. $aRows = $this->getAll("
  332. SELECT `a`.`history_id`, `a`.`field_name`, `a`.`field_value`
  333. FROM `sys_agents_chat_artifacts` AS `a`
  334. INNER JOIN `sys_agents_chat_history` AS `h` ON `h`.`id` = `a`.`history_id`
  335. WHERE `h`.`thread_id` = :exact OR `h`.`thread_id` LIKE :prefix
  336. ORDER BY `a`.`id` ASC
  337. ", [
  338. 'exact' => $sExact,
  339. 'prefix' => $sExact . ':%',
  340. ]);
  341. return $this->mapChatArtifactRows($aRows);
  342. }
  343. protected function mapChatArtifactRows($aRows)
  344. {
  345. if (!is_array($aRows) || !$aRows)
  346. return [];
  347. $aOut = [];
  348. foreach ($aRows as $aRow) {
  349. if (!is_array($aRow))
  350. continue;
  351. $iHistoryId = (int)($aRow['history_id'] ?? 0);
  352. $sName = trim((string)($aRow['field_name'] ?? ''));
  353. if ($iHistoryId <= 0 || $sName === '')
  354. continue;
  355. $aOut[$iHistoryId][] = [
  356. 'field_name' => $sName,
  357. 'field_value' => (string)($aRow['field_value'] ?? ''),
  358. ];
  359. }
  360. return $aOut;
  361. }
  362. public function getExpiredAgentChatHistoryIds($aAgent, $iTtlMin)
  363. {
  364. if (!$this->isFieldExists('sys_agents_chat_history', 'closed_reason'))
  365. return [];
  366. $sExact = ($aAgent['trigger'] ?? '') . ':' . ($aAgent['id'] ?? '');
  367. $iTtlMin = (int)$iTtlMin;
  368. if ($sExact === ':' || $iTtlMin <= 0)
  369. return [];
  370. return $this->getColumn("
  371. SELECT `id` FROM `sys_agents_chat_history`
  372. WHERE (`thread_id` = :exact OR `thread_id` LIKE :prefix)
  373. AND `messages` IS NOT NULL AND `messages` != '' AND `messages` != '[]'
  374. AND (`closed_reason` = '' OR `closed_reason` IS NULL)
  375. AND `updated_at` <= DATE_SUB(NOW(), INTERVAL :ttl MINUTE)
  376. ", [
  377. 'exact' => $sExact,
  378. 'prefix' => $sExact . ':%',
  379. 'ttl' => $iTtlMin,
  380. ]);
  381. }
  382. /**
  383. * Rename this agent's guest threads (`…:{sessionId}`) onto a profile id.
  384. * If the member thread already has messages, drop the guest copy.
  385. */
  386. public function adoptGuestChatHistory($aAgent, $sSessionId, $iProfileId)
  387. {
  388. $sSessionId = (string)$sSessionId;
  389. $iProfileId = (int)$iProfileId;
  390. if ($sSessionId === '' || !$iProfileId || empty($aAgent['id']))
  391. return 0;
  392. $sPrefix = $aAgent['trigger'] . ':' . $aAgent['id'] . ':';
  393. $sOldSuffix = ':' . $sSessionId;
  394. $sNewSuffix = ':' . $iProfileId;
  395. $iLen = strlen($sOldSuffix);
  396. $aBindings = [
  397. 'p' => $sPrefix . '%',
  398. 'o' => $sOldSuffix,
  399. 'n' => $sNewSuffix,
  400. ];
  401. $this->query("
  402. DELETE `g` FROM `sys_agents_chat_history` AS `g`
  403. INNER JOIN `sys_agents_chat_history` AS `m`
  404. ON `m`.`thread_id` = CONCAT(LEFT(`g`.`thread_id`, CHAR_LENGTH(`g`.`thread_id`) - $iLen), :n)
  405. WHERE `g`.`thread_id` LIKE :p AND RIGHT(`g`.`thread_id`, $iLen) = :o
  406. AND `m`.`messages` IS NOT NULL AND `m`.`messages` != '' AND `m`.`messages` != '[]'
  407. ", $aBindings);
  408. $this->query("
  409. DELETE `m` FROM `sys_agents_chat_history` AS `m`
  410. INNER JOIN `sys_agents_chat_history` AS `g`
  411. ON `g`.`thread_id` LIKE :p AND RIGHT(`g`.`thread_id`, $iLen) = :o
  412. AND `m`.`thread_id` = CONCAT(LEFT(`g`.`thread_id`, CHAR_LENGTH(`g`.`thread_id`) - $iLen), :n)
  413. WHERE `m`.`messages` = '' OR `m`.`messages` = '[]' OR `m`.`messages` IS NULL
  414. ", $aBindings);
  415. $iAffected = (int)$this->query("
  416. UPDATE `sys_agents_chat_history`
  417. SET `thread_id` = CONCAT(LEFT(`thread_id`, CHAR_LENGTH(`thread_id`) - $iLen), :n)
  418. WHERE `thread_id` LIKE :p AND RIGHT(`thread_id`, $iLen) = :o
  419. ", $aBindings);
  420. return $iAffected;
  421. }
  422. static public function getAlert($s) {
  423. if (!$s)
  424. return false;
  425. $a = explode(':', $s);
  426. $oDb = BxDolDb::getInstance();
  427. return $oDb->getRow("SELECT * FROM `sys_alerts_log` WHERE `unit` = :unit AND `action` = :action", [
  428. 'unit' => $a[0] ?? '',
  429. 'action' => $a[1] ?? '',
  430. ]);
  431. }
  432. public function getAlerts()
  433. {
  434. $aValues = [];
  435. $aAlerts = $this->getAll("SELECT `unit`, `action`, `counter_24h`, `counter_per_request` FROM `sys_alerts_log` ORDER BY `unit`, `action`");
  436. foreach ($aAlerts as $a) {
  437. $sKey = $a['unit'] . ':' . $a['action'];
  438. $aValues[$sKey] = [
  439. 'key' => $sKey,
  440. 'unit' => $a['unit'],
  441. 'action' => $a['action'],
  442. 'name' => $a['unit'] . ' - ' . $a['action'],
  443. 'desc' => $this->getAlertDesc($a['unit'] . ':' . $a['action']),
  444. 'counter_24h' => $a['counter_24h'],
  445. 'counter_per_request' => $a['counter_per_request'],
  446. ];
  447. }
  448. return $aValues;
  449. }
  450. public function getFormDisplay($sObject)
  451. {
  452. $aDisplays = $this->getColumn("SELECT `display_name` FROM `sys_form_displays` WHERE `object` = :object", ['object' => $sObject]);
  453. return $aDisplays ? current($aDisplays) : null;
  454. }
  455. public function getFormObjects()
  456. {
  457. $aValues = [];
  458. $aForms = $this->getAll("SELECT `f`.`object`, `f`.`title`, `f`.`module`, `m`.`title` AS `module_title` FROM `sys_objects_form` AS f INNER JOIN `sys_modules` as `m` ON `m`.`name` = `f`.`module` ORDER BY `f`.`module`, `f`.`object` ASC");
  459. foreach ($aForms as $r) {
  460. if ('system' != $r['module']) {
  461. $oModule = BxDolModule::getInstance($r['module']);
  462. if (!$oModule || !$oModule->isEnabled())
  463. continue;
  464. }
  465. $sDisplay = $this->getFormDisplay($r['object']);
  466. if (!$sDisplay)
  467. continue;
  468. $oForm = BxDolForm::getObjectInstance($r['object'], $sDisplay);
  469. $sFormId = $oForm->getId();
  470. $aValues[$r['object']] = [
  471. 'form_id' => $sFormId,
  472. 'form_object' => $r['object'],
  473. 'module' => $r['module'],
  474. 'module_title' => $r['module_title'],
  475. 'form_title' => _t($r['title']),
  476. ];
  477. }
  478. return $aValues;
  479. }
  480. static public function getAlertDesc($sAlert)
  481. {
  482. if (!$sAlert)
  483. return '';
  484. $oDb = BxDolDb::getInstance();
  485. [$sUnit, $sAction] = explode(':', $sAlert);
  486. $sDesc = $oDb->getOne("SELECT `description` FROM `sys_alerts_desc` WHERE `unit` = :unit AND `action` = :action LIMIT 1", [
  487. 'unit' => $sUnit,
  488. 'action' => $sAction,
  489. ]);
  490. if (!$sDesc) {
  491. $sDesc = $oDb->getOne("SELECT `description` FROM `sys_alerts_desc` WHERE `unit` LIKE '{%}' AND `action` = :action LIMIT 1", [
  492. 'action' => $sAction,
  493. ]);
  494. }
  495. return $sDesc;
  496. }
  497. }
  498. /** @} */