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