Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
topicservicecounter.php
1<?
2namespace Bitrix\Forum\Update;
3
4use \Bitrix\Main\Update\Stepper;
5use \Bitrix\Forum\Integration;
6use \Bitrix\Main\Loader;
7use \Bitrix\Main;
8use \Bitrix\Forum\MessageTable;
9
11{
12 protected static $moduleId = "forum";
13 protected const TOPIC_LIMIT = 100;
14
15 public function execute(array &$result)
16 {
17 if (!Loader::includeModule("forum"))
18 {
19 return self::finishExecution();
20 }
21
22 if (Main\Config\Option::get("forum", "LivefeedConvertServiceMessageStepper") === "inProgress")
23 {
25 }
26
27 if (!array_key_exists("lastId", $result) || (int)$result["lastId"] <= 0)
28 {
29 $result["lastId"] = 0;
30
31 $res = MessageTable::getList([
32 "select" => [ "CNT"],
33 "filter" => [
34 '>SERVICE_TYPE' => 0
35 ],
36 'runtime' => [
37 new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(*)')
38 ]
39 ]);
40 $topicData = $res->fetch();
41 $result["count"] = (int)$topicData['CNT'];
42 }
43
44 $filter = [
45 '>SERVICE_TYPE' => 0
46 ];
47 if ($result["lastId"] > 0)
48 {
49 $filter["<TOPIC_ID"] = $result["lastId"];
50 }
51
52 Main\Config\Option::set("forum", "TopicServiceCounterStepper", "inProgress");
53
54 $lastId = 0;
55
56 $res = MessageTable::getList([
57 "select" => ["TOPIC_ID", "CNT"],
58 "filter" => $filter,
59 'runtime' => [
60 new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(*)')
61 ],
62 "group" => ["TOPIC_ID"],
63 "limit" => self::TOPIC_LIMIT,
64 "order" => ["TOPIC_ID" => "DESC"]
65 ]);
66 while($topicData = $res->fetch())
67 {
68 $topic = \Bitrix\Forum\EO_Topic::wakeUp($topicData["TOPIC_ID"]);
69 $topic->setPostsService($topicData["CNT"]);
70 $topic->save();
71 $lastId = $topicData["TOPIC_ID"];
72 }
73
74 if ($lastId > 0)
75 {
76 $result["lastId"] = $lastId;
77 }
78 else
79 {
80 return self::finishExecution();
81 }
82
84 }
85
86 protected static function finishExecution()
87 {
88 Main\Config\Option::delete("forum", ["name" => "TopicServiceCounterStepper"]);
90 }
91}
92?>