Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
livefeedindexcalendar.php
1<?
3
4use \Bitrix\Main\Update\Stepper;
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Calendar\Integration;
7use \Bitrix\Socialnetwork\Item\LogIndex;
8use \Bitrix\Socialnetwork\LogTable;
9use \Bitrix\Socialnetwork\LogIndexTable;
10use \Bitrix\Main\Config\Option;
11use \Bitrix\Main\Loader;
12
13Loc::loadMessages(__FILE__);
14
15final class LivefeedIndexCalendar extends Stepper
16{
17 protected static $moduleId = "calendar";
18
19 public function execute(array &$result)
20 {
21 if (!(
22 Loader::includeModule("calendar")
23 && Loader::includeModule("socialnetwork")
24 && Option::get('calendar', 'needLivefeedIndex', 'Y') == 'Y'
25 ))
26 {
27 return false;
28 }
29
30 $return = false;
31
32 $result["title"] = Loc::getMessage("FUPD_LF_CALENDAR_EVENT_INDEX_TITLE");
33 $result["progress"] = 1;
34 $result["steps"] = "";
35 $result["count"] = "";
36
37 $params = Option::get("calendar", "livefeedindexcalendar", "");
38
39 $params = ($params !== "" ? @unserialize($params, ['allowed_classes' => false]) : array());
40 $params = (is_array($params) ? $params : array());
41 if (empty($params))
42 {
43 $params = array(
44 "lastId" => 0,
45 "number" => 0,
46 "count" => LogTable::getCount(
47 array(
48 '@EVENT_ID' => Integration\Socialnetwork\Log::getEventIdList(),
49 '!SOURCE_ID' => false
50 )
51 )
52 );
53 if ($params["count"] > 0)
54 {
55 Option::set("calendar", "livefeedindexcalendar", serialize($params));
56 }
57 else
58 {
59 return $return;
60 }
61 }
62
63 if (
64 isset($params["finished"])
65 && $params["finished"] === true
66 )
67 {
68 Option::delete("calendar", array("name" => "livefeedindexcalendar"));
69 Option::set('calendar', 'needLivefeedIndex', 'N');
70 return false;
71 }
72 else
73 {
74 $return = true;
75 }
76
77 $result["progress"] = intval($params["number"] * 100/ $params["count"]);
78 $result["steps"] = $params["number"];
79 $result["count"] = $params["count"];
80
81 if ($params["count"] > 0)
82 {
83 $tmpUser = false;
84 if (!isset($GLOBALS["USER"]) || !is_object($GLOBALS["USER"]))
85 {
86 $tmpUser = True;
87 $GLOBALS["USER"] = new \CUser;
88 }
89
90 \Bitrix\Calendar\Update\LivefeedIndexCalendar::run();
91
92 if ($tmpUser)
93 {
94 unset($GLOBALS["USER"]);
95 }
96 }
97
98 return $return;
99 }
100
101 public static function run()
102 {
103 $params = Option::get("calendar", "livefeedindexcalendar", false);
104 $params = ($params !== "" ? @unserialize($params, ['allowed_classes' => false]) : array());
105
106 $found = false;
107
108 if (
109 is_array($params)
110 && intval($params["lastId"]) >= 0
111 )
112 {
113 $res = LogTable::getList(array(
114 'order' => array('ID' => 'ASC'),
115 'filter' => array(
116 '>ID' => $params["lastId"],
117 '@EVENT_ID' => Integration\Socialnetwork\Log::getEventIdList(),
118 '!SOURCE_ID' => false
119 ),
120 'select' => array('ID', 'EVENT_ID', 'SOURCE_ID'),
121 'offset' => 0,
122 'limit' => 100
123 ));
124
125 while ($record = $res->fetch())
126 {
127 LogIndex::setIndex(array(
128 'itemType' => LogIndexTable::ITEM_TYPE_LOG,
129 'itemId' => $record['ID'],
130 'fields' => $record
131 ));
132
133 $params["lastId"] = $record['ID'];
134 $params["number"]++;
135 $found = true;
136 }
137 }
138
139 if (!$found)
140 {
141 $params["finished"] = true;
142 }
143
144 Option::set("calendar", "livefeedindexcalendar", serialize($params));
145 }
146}
147?>
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
$GLOBALS['____1444769544']
Definition license.php:1