Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
removehumantype.php
1<?php
2
3namespace Bitrix\Im\Update;
4
10
12{
13 public const OPTION_NAME = 'remove_human_type_stepper_params';
14 private const MODULE_ID = 'im';
15
16 private int $queryCount = 50;
17
18 function execute(array &$result)
19 {
20 if (!Loader::includeModule(self::MODULE_ID))
21 {
22 return false;
23 }
24
25 $params = Option::get(self::MODULE_ID, self::OPTION_NAME, "");
26 $params = ($params !== "" ? @unserialize($params, ['allowed_classes' => false]) : []);
27 $params = (is_array($params) ? $params : []);
28
29 if (empty($params))
30 {
31 $lastId = 0;
32 }
33
34 $lastId = $lastId ?? $params['lastId'];
35
36 $query = BotTable::query()
37 ->setSelect(['BOT_ID', 'TYPE'])
38 ->setLimit($this->queryCount)
39 ->setOrder('BOT_ID', 'ASC')
40 ->where('BOT_ID' ,'>', $lastId)
41 ->exec()
42 ;
43
44 $found = false;
45 $botIds = [];
46 while ($row = $query->fetch())
47 {
48 $lastId = (int)$row['BOT_ID'];
49 $params['lastId'] = $lastId;
50
51 if ($row['TYPE'] === 'H')
52 {
53 $botIds[] = $lastId;
54 }
55
56 $found = true;
57 }
58
59 if (!empty($botIds))
60 {
61 BotTable::updateByFilter(
62 [
63 '=BOT_ID' => $botIds,
64 '=TYPE' => 'H',
65 ],
66 ['TYPE' => 'B']
67 );
68 }
69
70 foreach ($botIds as $botId)
71 {
72 BotData::cleanCache($botId);
73 }
74
75 if ($found)
76 {
77 Option::set(self::MODULE_ID, self::OPTION_NAME, serialize($params));
78
79 return true;
80 }
81
82 Option::delete(self::MODULE_ID, ["name" => self::OPTION_NAME]);
83
84 \Bitrix\Im\Bot::clearCache();
85
86 return false;
87 }
88}