22 public function execute(array &$result): bool
26 if (!Loader::includeModule(self::$moduleId))
33 $params = Option::get(self::$moduleId, self::OPTION_NAME);
34 $params = ($params !==
'' ? @unserialize($params, [
'allowed_classes' =>
false]) : []);
35 $params = (is_array($params) ? $params : []);
42 'count' => UserTable::getCount([
44 '=IS_REAL_USER' =>
true,
49 if ($params[
'count'] > 0)
51 $result[
'steps'] =
'';
52 $result[
'count'] = $params[
'count'];
54 $cursor = UserTable::getList([
57 '>ID' => $params[
'lastId'],
59 '=IS_REAL_USER' =>
true,
61 'order' => [
'ID' =>
'ASC'],
66 $connection = \Bitrix\Main\Application::getInstance()->getConnection();
70 while ($row = $cursor->fetch())
72 if (count($users) === 100)
78 $users[] = (int)$row[
'ID'];
80 $params[
'lastId'] = (int)$row[
'ID'];
89 $sqlDate = $connection->getSqlHelper()->addDaysToDateTime(-30);
90 foreach ($batch as $users)
92 $sqlUserIds = implode(
', ', $users);
96 b_im_relation R USE INDEX (IX_IM_REL_2)
97 INNER JOIN b_im_chat C
98 INNER JOIN b_im_message M
104 and R.USER_ID IN (".$sqlUserIds.
")
106 and M.ID = C.LAST_MESSAGE_ID
107 and M.DATE_CREATE < {$sqlDate}
112 b_im_relation R USE INDEX (IX_IM_REL_2)
113 INNER JOIN b_im_chat C
114 INNER JOIN b_im_message M
120 and R.USER_ID IN (".$sqlUserIds.
")
122 and M.ID = C.LAST_MESSAGE_ID
123 and M.DATE_CREATE < {$sqlDate}
128 b_im_relation R USE INDEX (IX_IM_REL_2)
129 INNER JOIN b_im_chat C
130 INNER JOIN b_im_message M
136 and R.USER_ID IN (".$sqlUserIds.
")
138 and M.ID = C.LAST_MESSAGE_ID
139 and M.DATE_CREATE < {$sqlDate}
142 foreach ($users as $userId)
150 Option::set(self::$moduleId, self::OPTION_NAME, serialize($params));
155 Option::delete(self::$moduleId, [
'name' => self::OPTION_NAME]);
158 $result[
'steps'] = $params[
'number'];