Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
openlinesindex.php
1<?php
2
3namespace Bitrix\Im\Update;
9
10final class OpenLinesIndex extends Stepper
11{
12 public const OPTION_NAME = "im_index_open_lines";
13 public const LIMIT = 500;
14 protected static $moduleId = "im";
15
16 public function execute(array &$option)
17 {
18 return false;
19
20 if (!Loader::includeModule(self::$moduleId))
21 {
22 return false;
23 }
24 $return = false;
25
26 $params = Option::get(self::$moduleId, self::OPTION_NAME, "");
27 $params = ($params !== "" ? @unserialize($params, ['allowed_classes' => false]) : []);
28 $params = (is_array($params) ? $params : []);
29
30 if (empty($params))
31 {
32 $lastIdQuery =
33 ChatTable::query()
34 ->addSelect('ID')
35 ->where('TYPE', Chat::TYPE_OPEN_LINE)
36 ->addOrder('ID', 'DESC')
37 ->setLimit(1)
38 ->fetch()
39 ;
40 $params = [
41 "lastId" => (int)$lastIdQuery['ID'] + 1,
42 "number" => 0,
43 "count" => ChatTable::getCount([
44 '=TYPE' => [Chat::TYPE_OPEN_LINE],
45 ]),
46 ];
47 }
48
49 if ($params["count"] > 0)
50 {
51 $query =
52 ChatTable::query()
53 ->setSelect(['ID', 'ENTITY_TYPE'])
54 ->where('ID', '<', $params['lastId'])
55 ->where('TYPE', Chat::TYPE_OPEN_LINE)
56 ->addOrder('ID', 'DESC')
57 ->setLimit(self::LIMIT)
58 ;
59
60 $found = false;
61 foreach ($query->exec() as $row)
62 {
63 \CIMChat::index($row['ID']);
64
65 $params["lastId"] = $row['ID'];
66 $found = true;
67 }
68
69 if ($found)
70 {
71 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
72 $return = true;
73 }
74 else
75 {
76 Option::delete(self::$moduleId, ["name" => self::OPTION_NAME]);
77 }
78 }
79
80 return $return;
81 }
82}
const TYPE_OPEN_LINE
Definition chat.php:26