CategoryDAO.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <?php
  2. declare(strict_types=1);
  3. class FreshRSS_CategoryDAO extends Minz_ModelPdo {
  4. public const DEFAULTCATEGORYID = 1;
  5. public function resetDefaultCategoryName(): bool {
  6. //FreshRSS 1.15.1
  7. $stm = $this->pdo->prepare('UPDATE `_category` SET name = :name WHERE id = :id');
  8. if ($stm !== false) {
  9. $stm->bindValue(':id', self::DEFAULTCATEGORYID, PDO::PARAM_INT);
  10. $stm->bindValue(':name', 'Uncategorized');
  11. }
  12. return $stm && $stm->execute();
  13. }
  14. protected function addColumn(string $name): bool {
  15. if ($this->pdo->inTransaction()) {
  16. $this->pdo->commit();
  17. }
  18. Minz_Log::warning(__method__ . ': ' . $name);
  19. try {
  20. if ($name === 'kind') { //v1.20.0
  21. return $this->pdo->exec('ALTER TABLE `_category` ADD COLUMN kind SMALLINT DEFAULT 0') !== false;
  22. } elseif ($name === 'lastUpdate') { //v1.20.0
  23. return $this->pdo->exec('ALTER TABLE `_category` ADD COLUMN `lastUpdate` BIGINT DEFAULT 0') !== false;
  24. } elseif ($name === 'error') { //v1.20.0
  25. return $this->pdo->exec('ALTER TABLE `_category` ADD COLUMN error SMALLINT DEFAULT 0') !== false;
  26. } elseif ('attributes' === $name) { //v1.15.0
  27. $ok = $this->pdo->exec('ALTER TABLE `_category` ADD COLUMN attributes TEXT') !== false;
  28. /** @var array<array{'id':int,'url':string,'kind':int,'category':int,'name':string,'website':string,'lastUpdate':int,
  29. * 'priority':int,'pathEntries':string,'httpAuth':string,'error':int,'keep_history':?int,'ttl':int,'attributes':string}> $feeds */
  30. $feeds = $this->fetchAssoc('SELECT * FROM `_feed`') ?? [];
  31. $stm = $this->pdo->prepare('UPDATE `_feed` SET attributes = :attributes WHERE id = :id');
  32. if ($stm === false) {
  33. Minz_Log::error('SQL error ' . __METHOD__ . json_encode($this->pdo->errorInfo()));
  34. return false;
  35. }
  36. foreach ($feeds as $feed) {
  37. if (empty($feed['keep_history']) || empty($feed['id'])) {
  38. continue;
  39. }
  40. $keepHistory = $feed['keep_history'];
  41. $attributes = empty($feed['attributes']) ? [] : json_decode($feed['attributes'], true);
  42. if (is_string($attributes)) { //Legacy risk of double-encoding
  43. $attributes = json_decode($attributes, true);
  44. }
  45. if (!is_array($attributes)) {
  46. $attributes = [];
  47. }
  48. if ($keepHistory > 0) {
  49. $attributes['archiving']['keep_min'] = (int)$keepHistory;
  50. } elseif ($keepHistory == -1) { //Infinite
  51. $attributes['archiving']['keep_period'] = false;
  52. $attributes['archiving']['keep_max'] = false;
  53. $attributes['archiving']['keep_min'] = false;
  54. } else {
  55. continue;
  56. }
  57. if (!($stm->bindValue(':id', $feed['id'], PDO::PARAM_INT) &&
  58. $stm->bindValue(':attributes', json_encode($attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)) &&
  59. $stm->execute())) {
  60. Minz_Log::error('SQL error ' . __METHOD__ . json_encode($stm->errorInfo()));
  61. }
  62. }
  63. if ($this->pdo->dbType() !== 'sqlite') { //SQLite does not support DROP COLUMN
  64. $this->pdo->exec('ALTER TABLE `_feed` DROP COLUMN keep_history');
  65. } else {
  66. $this->pdo->exec('DROP INDEX IF EXISTS feed_keep_history_index'); //SQLite at least drop index
  67. }
  68. $this->resetDefaultCategoryName();
  69. return $ok;
  70. }
  71. } catch (Exception $e) {
  72. Minz_Log::error(__method__ . ': ' . $e->getMessage());
  73. }
  74. return false;
  75. }
  76. /** @param array<string|int> $errorInfo */
  77. protected function autoUpdateDb(array $errorInfo): bool {
  78. if (isset($errorInfo[0])) {
  79. if ($errorInfo[0] === FreshRSS_DatabaseDAO::ER_BAD_FIELD_ERROR || $errorInfo[0] === FreshRSS_DatabaseDAOPGSQL::UNDEFINED_COLUMN) {
  80. $errorLines = explode("\n", (string)$errorInfo[2], 2); // The relevant column name is on the first line, other lines are noise
  81. foreach (['kind', 'lastUpdate', 'error', 'attributes'] as $column) {
  82. if (stripos($errorLines[0], $column) !== false) {
  83. return $this->addColumn($column);
  84. }
  85. }
  86. }
  87. }
  88. return false;
  89. }
  90. /**
  91. * @param array{'name':string,'id'?:int,'kind'?:int,'lastUpdate'?:int,'error'?:int|bool,'attributes'?:string|array<string,mixed>} $valuesTmp
  92. * @return int|false
  93. * @throws JsonException
  94. */
  95. public function addCategory(array $valuesTmp) {
  96. // TRIM() to provide a type hint as text
  97. // No tag of the same name
  98. $sql = <<<'SQL'
  99. INSERT INTO `_category`(kind, name, attributes)
  100. SELECT * FROM (SELECT ABS(?) AS kind, TRIM(?) AS name, TRIM(?) AS attributes) c2
  101. WHERE NOT EXISTS (SELECT 1 FROM `_tag` WHERE name = TRIM(?))
  102. SQL;
  103. $stm = $this->pdo->prepare($sql);
  104. $valuesTmp['name'] = mb_strcut(trim($valuesTmp['name']), 0, FreshRSS_DatabaseDAO::LENGTH_INDEX_UNICODE, 'UTF-8');
  105. if (!isset($valuesTmp['attributes'])) {
  106. $valuesTmp['attributes'] = [];
  107. }
  108. $values = [
  109. $valuesTmp['kind'] ?? FreshRSS_Category::KIND_NORMAL,
  110. $valuesTmp['name'],
  111. is_string($valuesTmp['attributes']) ? $valuesTmp['attributes'] : json_encode($valuesTmp['attributes'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
  112. $valuesTmp['name'],
  113. ];
  114. if ($stm !== false && $stm->execute($values) && $stm->rowCount() > 0) {
  115. $catId = $this->pdo->lastInsertId('`_category_id_seq`');
  116. return $catId === false ? false : (int)$catId;
  117. } else {
  118. $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
  119. if ($this->autoUpdateDb($info)) {
  120. return $this->addCategory($valuesTmp);
  121. }
  122. Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
  123. return false;
  124. }
  125. }
  126. /** @return int|false */
  127. public function addCategoryObject(FreshRSS_Category $category) {
  128. $cat = $this->searchByName($category->name());
  129. if (!$cat) {
  130. $values = [
  131. 'kind' => $category->kind(),
  132. 'name' => $category->name(),
  133. 'attributes' => $category->attributes(),
  134. ];
  135. return $this->addCategory($values);
  136. }
  137. return $cat->id();
  138. }
  139. /**
  140. * @param array{'name':string,'kind':int,'attributes'?:array<string,mixed>|mixed|null} $valuesTmp
  141. * @return int|false
  142. * @throws JsonException
  143. */
  144. public function updateCategory(int $id, array $valuesTmp) {
  145. // No tag of the same name
  146. $sql = <<<'SQL'
  147. UPDATE `_category` SET name=?, kind=?, attributes=? WHERE id=?
  148. AND NOT EXISTS (SELECT 1 FROM `_tag` WHERE name = ?)
  149. SQL;
  150. $stm = $this->pdo->prepare($sql);
  151. $valuesTmp['name'] = mb_strcut(trim($valuesTmp['name']), 0, FreshRSS_DatabaseDAO::LENGTH_INDEX_UNICODE, 'UTF-8');
  152. if (empty($valuesTmp['attributes'])) {
  153. $valuesTmp['attributes'] = [];
  154. }
  155. $values = [
  156. $valuesTmp['name'],
  157. $valuesTmp['kind'] ?? FreshRSS_Category::KIND_NORMAL,
  158. is_string($valuesTmp['attributes']) ? $valuesTmp['attributes'] : json_encode($valuesTmp['attributes'], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
  159. $id,
  160. $valuesTmp['name'],
  161. ];
  162. if ($stm !== false && $stm->execute($values)) {
  163. return $stm->rowCount();
  164. } else {
  165. $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
  166. if ($this->autoUpdateDb($info)) {
  167. return $this->updateCategory($id, $valuesTmp);
  168. }
  169. Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
  170. return false;
  171. }
  172. }
  173. /** @return int|false */
  174. public function updateLastUpdate(int $id, bool $inError = false, int $mtime = 0) {
  175. $sql = 'UPDATE `_category` SET `lastUpdate`=?, error=? WHERE id=?';
  176. $values = [
  177. $mtime <= 0 ? time() : $mtime,
  178. $inError ? 1 : 0,
  179. $id,
  180. ];
  181. $stm = $this->pdo->prepare($sql);
  182. if ($stm !== false && $stm->execute($values)) {
  183. return $stm->rowCount();
  184. } else {
  185. $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
  186. Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
  187. return false;
  188. }
  189. }
  190. /** @return int|false */
  191. public function deleteCategory(int $id) {
  192. if ($id <= self::DEFAULTCATEGORYID) {
  193. return false;
  194. }
  195. $sql = 'DELETE FROM `_category` WHERE id=:id';
  196. $stm = $this->pdo->prepare($sql);
  197. if ($stm !== false && $stm->bindParam(':id', $id, PDO::PARAM_INT) && $stm->execute()) {
  198. return $stm->rowCount();
  199. } else {
  200. $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
  201. Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
  202. return false;
  203. }
  204. }
  205. /** @return Traversable<array{'id':int,'name':string,'kind':int,'lastUpdate':int,'error':int,'attributes'?:array<string,mixed>}> */
  206. public function selectAll(): Traversable {
  207. $sql = 'SELECT id, name, kind, `lastUpdate`, error, attributes FROM `_category`';
  208. $stm = $this->pdo->query($sql);
  209. if ($stm !== false) {
  210. while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
  211. /** @var array{'id':int,'name':string,'kind':int,'lastUpdate':int,'error':int,'attributes'?:array<string,mixed>} $row */
  212. yield $row;
  213. }
  214. } else {
  215. $info = $this->pdo->errorInfo();
  216. if ($this->autoUpdateDb($info)) {
  217. yield from $this->selectAll();
  218. } else {
  219. Minz_Log::error(__method__ . ' error: ' . json_encode($info));
  220. }
  221. }
  222. }
  223. public function searchById(int $id): ?FreshRSS_Category {
  224. $sql = 'SELECT * FROM `_category` WHERE id=:id';
  225. $res = $this->fetchAssoc($sql, ['id' => $id]) ?? [];
  226. /** @var array<array{'name':string,'id':int,'kind':int,'lastUpdate':int,'error':int|bool,'attributes':string}> $res */
  227. $cat = self::daoToCategory($res);
  228. return $cat[0] ?? null;
  229. }
  230. public function searchByName(string $name): ?FreshRSS_Category {
  231. $sql = 'SELECT * FROM `_category` WHERE name=:name';
  232. $res = $this->fetchAssoc($sql, ['name' => $name]) ?? [];
  233. /** @var array<array{'name':string,'id':int,'kind':int,'lastUpdate':int,'error':int|bool,'attributes':string}> $res */
  234. $cat = self::daoToCategory($res);
  235. return $cat[0] ?? null;
  236. }
  237. /** @return array<FreshRSS_Category> */
  238. public function listSortedCategories(bool $prePopulateFeeds = true, bool $details = false): array {
  239. $categories = $this->listCategories($prePopulateFeeds, $details);
  240. uasort($categories, static function (FreshRSS_Category $a, FreshRSS_Category $b) {
  241. $aPosition = $a->attributeInt('position');
  242. $bPosition = $b->attributeInt('position');
  243. if ($aPosition === $bPosition) {
  244. return ($a->name() < $b->name()) ? -1 : 1;
  245. } elseif (null === $aPosition) {
  246. return 1;
  247. } elseif (null === $bPosition) {
  248. return -1;
  249. }
  250. return ($aPosition < $bPosition) ? -1 : 1;
  251. });
  252. return $categories;
  253. }
  254. /** @return array<FreshRSS_Category> */
  255. public function listCategories(bool $prePopulateFeeds = true, bool $details = false): array {
  256. if ($prePopulateFeeds) {
  257. $sql = 'SELECT c.id AS c_id, c.name AS c_name, c.kind AS c_kind, c.`lastUpdate` AS c_last_update, c.error AS c_error, c.attributes AS c_attributes, '
  258. . ($details ? 'f.* ' : 'f.id, f.name, f.url, f.kind, f.website, f.priority, f.error, f.`cache_nbEntries`, f.`cache_nbUnreads`, f.ttl ')
  259. . 'FROM `_category` c '
  260. . 'LEFT OUTER JOIN `_feed` f ON f.category=c.id '
  261. . 'WHERE f.priority >= :priority '
  262. . 'GROUP BY f.id, c_id '
  263. . 'ORDER BY c.name, f.name';
  264. $stm = $this->pdo->prepare($sql);
  265. $values = [ ':priority' => FreshRSS_Feed::PRIORITY_CATEGORY ];
  266. if ($stm !== false && $stm->execute($values)) {
  267. $res = $stm->fetchAll(PDO::FETCH_ASSOC) ?: [];
  268. /** @var array<array{'c_name':string,'c_id':int,'c_kind':int,'c_last_update':int,'c_error':int|bool,'c_attributes'?:string,
  269. * 'id'?:int,'name'?:string,'url'?:string,'kind'?:int,'category'?:int,'website'?:string,'priority'?:int,'error'?:int|bool,'cache_nbEntries'?:int,'cache_nbUnreads'?:int,'ttl'?:int}> $res */
  270. return self::daoToCategoryPrepopulated($res);
  271. } else {
  272. $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
  273. if ($this->autoUpdateDb($info)) {
  274. return $this->listCategories($prePopulateFeeds, $details);
  275. }
  276. Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
  277. return [];
  278. }
  279. } else {
  280. $res = $this->fetchAssoc('SELECT * FROM `_category` ORDER BY name');
  281. /** @var array<array{'name':string,'id':int,'kind':int,'lastUpdate'?:int,'error'?:int|bool,'attributes'?:string}> $res */
  282. return $res == null ? [] : self::daoToCategory($res);
  283. }
  284. }
  285. /** @return array<FreshRSS_Category> */
  286. public function listCategoriesOrderUpdate(int $defaultCacheDuration = 86400, int $limit = 0): array {
  287. $sql = 'SELECT * FROM `_category` WHERE kind = :kind AND `lastUpdate` < :lu ORDER BY `lastUpdate`'
  288. . ($limit < 1 ? '' : ' LIMIT ' . $limit);
  289. $stm = $this->pdo->prepare($sql);
  290. if ($stm !== false &&
  291. $stm->bindValue(':kind', FreshRSS_Category::KIND_DYNAMIC_OPML, PDO::PARAM_INT) &&
  292. $stm->bindValue(':lu', time() - $defaultCacheDuration, PDO::PARAM_INT) &&
  293. $stm->execute()) {
  294. return self::daoToCategory($stm->fetchAll(PDO::FETCH_ASSOC));
  295. } else {
  296. $info = $stm ? $stm->errorInfo() : $this->pdo->errorInfo();
  297. if ($this->autoUpdateDb($info)) {
  298. return $this->listCategoriesOrderUpdate($defaultCacheDuration, $limit);
  299. }
  300. Minz_Log::warning(__METHOD__ . ' error: ' . $sql . ' : ' . json_encode($info));
  301. return [];
  302. }
  303. }
  304. public function getDefault(): ?FreshRSS_Category {
  305. $sql = 'SELECT * FROM `_category` WHERE id=:id';
  306. $res = $this->fetchAssoc($sql, [':id' => self::DEFAULTCATEGORYID]) ?? [];
  307. /** @var array<array{'name':string,'id':int,'kind':int,'lastUpdate'?:int,'error'?:int|bool,'attributes'?:string}> $res */
  308. $cat = self::daoToCategory($res);
  309. if (isset($cat[0])) {
  310. return $cat[0];
  311. } else {
  312. if (FreshRSS_Context::$isCli) {
  313. fwrite(STDERR, 'FreshRSS database error: Default category not found!' . "\n");
  314. }
  315. Minz_Log::error('FreshRSS database error: Default category not found!');
  316. return null;
  317. }
  318. }
  319. /** @return int|bool */
  320. public function checkDefault() {
  321. $def_cat = $this->searchById(self::DEFAULTCATEGORYID);
  322. if ($def_cat == null) {
  323. $cat = new FreshRSS_Category(_t('gen.short.default_category'), self::DEFAULTCATEGORYID);
  324. $sql = 'INSERT INTO `_category`(id, name) VALUES(?, ?)';
  325. if ($this->pdo->dbType() === 'pgsql') {
  326. //Force call to nextval()
  327. $sql .= " RETURNING nextval('`_category_id_seq`');";
  328. }
  329. $stm = $this->pdo->prepare($sql);
  330. $values = [
  331. $cat->id(),
  332. $cat->name(),
  333. ];
  334. if ($stm !== false && $stm->execute($values)) {
  335. $catId = $this->pdo->lastInsertId('`_category_id_seq`');
  336. return $catId === false ? false : (int)$catId;
  337. } else {
  338. $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
  339. Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
  340. return false;
  341. }
  342. }
  343. return true;
  344. }
  345. public function count(): int {
  346. $sql = 'SELECT COUNT(*) AS count FROM `_category`';
  347. $res = $this->fetchColumn($sql, 0);
  348. return isset($res[0]) ? (int)$res[0] : -1;
  349. }
  350. public function countFeed(int $id): int {
  351. $sql = 'SELECT COUNT(*) AS count FROM `_feed` WHERE category=:id';
  352. $res = $this->fetchColumn($sql, 0, [':id' => $id]);
  353. return isset($res[0]) ? (int)$res[0] : -1;
  354. }
  355. public function countNotRead(int $id): int {
  356. $sql = 'SELECT COUNT(*) AS count FROM `_entry` e INNER JOIN `_feed` f ON e.id_feed=f.id WHERE category=:id AND e.is_read=0';
  357. $res = $this->fetchColumn($sql, 0, [':id' => $id]);
  358. return isset($res[0]) ? (int)$res[0] : -1;
  359. }
  360. /** @param array<FreshRSS_Category> $categories */
  361. public static function findFeed(array $categories, int $feed_id): ?FreshRSS_Feed {
  362. foreach ($categories as $category) {
  363. foreach ($category->feeds() as $feed) {
  364. if ($feed->id() === $feed_id) {
  365. $feed->_category($category); // Should already be done; just to be safe
  366. return $feed;
  367. }
  368. }
  369. }
  370. return null;
  371. }
  372. /**
  373. * @param array<FreshRSS_Category> $categories
  374. */
  375. public static function countUnread(array $categories, int $minPriority = 0): int {
  376. $n = 0;
  377. foreach ($categories as $category) {
  378. foreach ($category->feeds() as $feed) {
  379. if ($feed->priority() >= $minPriority) {
  380. $n += $feed->nbNotRead();
  381. }
  382. }
  383. }
  384. return $n;
  385. }
  386. /**
  387. * @param array<array{'c_name':string,'c_id':int,'c_kind':int,'c_last_update':int,'c_error':int|bool,'c_attributes'?:string,
  388. * 'id'?:int,'name'?:string,'url'?:string,'kind'?:int,'website'?:string,'priority'?:int,
  389. * 'error'?:int|bool,'cache_nbEntries'?:int,'cache_nbUnreads'?:int,'ttl'?:int}> $listDAO
  390. * @return array<int,FreshRSS_Category>
  391. */
  392. private static function daoToCategoryPrepopulated(array $listDAO) {
  393. $list = [];
  394. $previousLine = [];
  395. $feedsDao = [];
  396. $feedDao = FreshRSS_Factory::createFeedDao();
  397. foreach ($listDAO as $line) {
  398. FreshRSS_DatabaseDAO::pdoInt($line, ['c_id', 'c_kind', 'c_last_update', 'c_error',
  399. 'id', 'kind', 'priority', 'error', 'cache_nbEntries', 'cache_nbUnreads', 'ttl']);
  400. if (!empty($previousLine['c_id']) && $line['c_id'] !== $previousLine['c_id']) {
  401. // End of the current category, we add it to the $list
  402. $cat = new FreshRSS_Category(
  403. $previousLine['c_name'],
  404. $previousLine['c_id'],
  405. $feedDao::daoToFeed($feedsDao, $previousLine['c_id'])
  406. );
  407. $cat->_kind($previousLine['c_kind']);
  408. $cat->_attributes($previousLine['c_attributes'] ?? '[]');
  409. $list[(int)$previousLine['c_id']] = $cat;
  410. $feedsDao = []; //Prepare for next category
  411. }
  412. $previousLine = $line;
  413. $feedsDao[] = $line;
  414. }
  415. // add the last category
  416. if ($previousLine != null) {
  417. $cat = new FreshRSS_Category(
  418. $previousLine['c_name'],
  419. $previousLine['c_id'],
  420. $feedDao::daoToFeed($feedsDao, $previousLine['c_id'])
  421. );
  422. $cat->_kind($previousLine['c_kind']);
  423. $cat->_lastUpdate($previousLine['c_last_update'] ?? 0);
  424. $cat->_error($previousLine['c_error'] ?? 0);
  425. $cat->_attributes($previousLine['c_attributes'] ?? []);
  426. $list[(int)$previousLine['c_id']] = $cat;
  427. }
  428. return $list;
  429. }
  430. /**
  431. * @param array<array{'name':string,'id':int,'kind':int,'lastUpdate'?:int,'error'?:int|bool,'attributes'?:string}> $listDAO
  432. * @return array<FreshRSS_Category>
  433. */
  434. private static function daoToCategory(array $listDAO): array {
  435. $list = [];
  436. foreach ($listDAO as $dao) {
  437. FreshRSS_DatabaseDAO::pdoInt($dao, ['id', 'kind', 'lastUpdate', 'error']);
  438. $cat = new FreshRSS_Category(
  439. $dao['name'],
  440. $dao['id']
  441. );
  442. $cat->_kind($dao['kind']);
  443. $cat->_lastUpdate($dao['lastUpdate'] ?? 0);
  444. $cat->_error($dao['error'] ?? 0);
  445. $cat->_attributes($dao['attributes'] ?? '');
  446. $list[] = $cat;
  447. }
  448. return $list;
  449. }
  450. }