Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
livefeedindexcomment.php
1<?
3
4use \Bitrix\Main\Update\Stepper;
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Socialnetwork\Item\LogIndex;
7use \Bitrix\Socialnetwork\LogCommentTable;
8use \Bitrix\Socialnetwork\LogIndexTable;
9use \Bitrix\Main\Config\Option;
10use \Bitrix\Main\Loader;
11
12Loc::loadMessages(__FILE__);
13
14final class LivefeedIndexComment extends Stepper
15{
16 protected static $moduleId = "wiki";
17
18 public function execute(array &$result)
19 {
20 if (!(
21 Loader::includeModule("forum")
22 && Loader::includeModule("socialnetwork")
23 && Option::get('wiki', 'needLivefeedIndexComment', 'Y') == 'Y'
24 ))
25 {
26 return false;
27 }
28
29 $return = false;
30
31 $params = Option::get("wiki", "livefeedindexcomment", "");
32 $params = ($params !== "" ? @unserialize($params, ["allowed_classes" => false]) : array());
33 $params = (is_array($params) ? $params : array());
34 if (empty($params))
35 {
36 $params = array(
37 "lastId" => 0,
38 "number" => 0,
39 "count" => LogCommentTable::getCount(
40 array(
41 '=EVENT_ID' => "wiki_comment",
42 '!SOURCE_ID' => false
43 )
44 )
45 );
46 }
47
48 if ($params["count"] > 0)
49 {
50 $result["title"] = Loc::getMessage("FUPD_LF_WIKI_COMMENT_EVENT_INDEX_TITLE");
51 $result["progress"] = 1;
52 $result["steps"] = "";
53 $result["count"] = $params["count"];
54
55 $res = LogCommentTable::getList(array(
56 'order' => array('ID' => 'ASC'),
57 'filter' => array(
58 '>ID' => $params["lastId"],
59 '=EVENT_ID' => "wiki_comment",
60 '!SOURCE_ID' => false
61 ),
62 'select' => array('ID', 'EVENT_ID', 'SOURCE_ID'),
63 'offset' => 0,
64 'limit' => 100
65 ));
66
67 $found = false;
68 while ($record = $res->fetch())
69 {
70 LogIndex::setIndex(array(
71 'itemType' => LogIndexTable::ITEM_TYPE_COMMENT,
72 'itemId' => $record['ID'],
73 'fields' => $record
74 ));
75
76 $params["lastId"] = $record['ID'];
77 $params["number"]++;
78 $found = true;
79 }
80
81 if ($found)
82 {
83 Option::set("wiki", "livefeedindexcomment", serialize($params));
84 $return = true;
85 }
86
87 $result["progress"] = intval($params["number"] * 100/ $params["count"]);
88 $result["steps"] = $params["number"];
89
90 if ($found === false)
91 {
92 Option::delete("wiki", array("name" => "livefeedindexcomment"));
93 Option::set('wiki', 'needLivefeedIndexComment', 'N');
94 }
95 }
96 return $return;
97 }
98}
99?>
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29