21 public function execute(array &$result): bool
23 Option::delete(self::$moduleId, [
'name' => self::OPTION_NAME]);
27 if (!Loader::includeModule(self::$moduleId))
34 $params = Option::get(self::$moduleId, self::OPTION_NAME);
35 $params = ($params !==
'' ? @unserialize($params, [
'allowed_classes' =>
false]) : []);
36 $params = (is_array($params) ? $params : []);
43 'count' => RelationTable::getCount([
50 if ($params[
'count'] > 0)
52 $result[
'steps'] =
'';
53 $result[
'count'] = $params[
'count'];
55 $cursor = RelationTable::getList([
56 'select' => [
'ID',
'CHAT_ID'],
58 '>ID' => $params[
'lastId'],
62 'order' => [
'ID' =>
'ASC'],
66 $connection = \Bitrix\Main\Application::getInstance()->getConnection();
67 $sqlDate = $connection->getSqlHelper()->addDaysToDateTime(-30);
70 while ($row = $cursor->fetch())
74 SET M.NOTIFY_READ = 'Y'
75 WHERE M.CHAT_ID = " . $row[
'CHAT_ID'] .
"
76 AND M.NOTIFY_READ <> 'Y'
77 AND M.DATE_CREATE < {$sqlDate}
80 $counterResult = $DB->Query(
"
81 SELECT COUNT(1) as CNT
83 WHERE M.CHAT_ID = " . $row[
'CHAT_ID'] .
"
84 AND NOTIFY_READ <> 'Y'
87 RelationTable::update($row[
'ID'], [
88 'COUNTER' => $counterResult[
'CNT']
91 $params[
'lastId'] = $row[
'ID'];
98 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
103 \Bitrix\Im\Counter::clearCache();
104 Option::delete(self::$moduleId, [
'name' => self::OPTION_NAME]);
107 $result[
'steps'] = $params[
'number'];