24 Loader::includeModule(
"forum")
25 && Loader::includeModule(
"socialnetwork")
31 if (!array_key_exists(
"handlers", $result) || !is_array($result[
"handlers"]))
33 $result[
"handlers"] = array_merge(self::getSocialnetworkHandlersPostText(), [
"innerForum"]);
34 $result[
"steps"] = count($result[
"handlers"]);
38 if ($postMessage = reset($result[
"handlers"]))
41 Main\Config\Option::set(
"forum",
"LivefeedConvertServiceMessageStepper",
"inProgress");
42 if ($postMessage ===
"innerForum")
46 else if ($handler = (
new Socialnetwork\CommentAux\HandlerManager())->getHandlerByPostText($postMessage))
48 $status = $this->
convert($handler, $result[
"lastId"]);
50 if ($status === self::FINISH_EXECUTION)
52 array_shift($result[
"handlers"]);
53 unset($result[
"lastId"]);
57 $result[
"lastId"] = $status;
59 $result[
"count"] = $result[
"steps"] - count($result[
"handlers"]);
71 public function convert(Socialnetwork\CommentAux\Base $handler, $lastId)
74 $rowsCount = $comments->count();
78 $dbRes = Socialnetwork\LogCommentTable::getList([
79 "select" => [
"ID",
"EVENT_ID",
"SOURCE_ID",
"SHARE_DEST"],
81 "SOURCE_ID" => $comments->getIdList(),
82 "%RATING_TYPE_ID" =>
"FORUM",
86 while ($res = $dbRes->fetch())
88 $socnetComments[$res[
"SOURCE_ID"]] = $res;
91 while ($comment = $comments->current())
93 $socnetInfo = array_key_exists($comment[
"ID"], $socnetComments) ? $socnetComments[$comment[
"ID"]] : [
"SHARE_DEST" =>
""];
94 if ($handler instanceof Socialnetwork\CommentAux\TaskInfo && !empty($socnetInfo[
"SHARE_DEST"]))
97 if (!is_array($postMessage))
100 if (empty($postMessage))
102 $postMessage =
false;
106 if (is_array($postMessage))
108 $comment->setServiceType(
Forum\Comments\Service\Manager::TYPE_TASK_INFO);
109 $serviceData = Json::encode(is_array($postMessage) ? $postMessage : []);
110 $comment->setServiceData($serviceData);
111 $comment->setPostMessage(
Forum\Comments\Service\Manager::find([
112 "SERVICE_TYPE" =>
Forum\Comments\Service\Manager::TYPE_TASK_INFO
113 ])->getText($serviceData));
114 $comment->setPostMessageHtml($socnetInfo[
"SHARE_DEST"]);
115 $comment->setPostMessageFilter($handler::getPostText());
118 elseif ($handler instanceof Socialnetwork\CommentAux\CreateTask)
121 if (is_array($postMessage))
123 $comment->setServiceType(
Forum\Comments\Service\Manager::TYPE_TASK_CREATED);
124 $serviceData = Json::encode(is_array($postMessage) ? $postMessage : []);
125 $comment->setServiceData($serviceData);
126 $comment->setPostMessage(
Forum\Comments\Service\Manager::find([
127 "SERVICE_TYPE" =>
Forum\Comments\Service\Manager::TYPE_TASK_CREATED
128 ])->getText($serviceData));
129 $comment->setPostMessageHtml($socnetInfo[
"SHARE_DEST"]);
130 $comment->setPostMessageFilter($handler::getPostText());
133 elseif ($handler instanceof Socialnetwork\CommentAux\FileVersion && !empty($socnetInfo[
"SHARE_DEST"]))
135 if (
false && !empty($socnetInfo[
"SHARE_DEST"]))
137 $comment->setPostMessageFilter($handler::getPostText());
141 if ($comment->state !== State::RAW)
145 $lastId = $comment->getId();
222 "!SERVICE_TYPE" =>
null,
223 "SERVICE_DATA" =>
null
225 $rowsCount = $comments->count();
230 $currentLang = Main\Localization\Loc::getCurrentLang();
231 $defaultLanguage= Main\Localization\Loc::getDefaultLang(LANGUAGE_ID);
232 if ($currentLang !== $defaultLanguage)
234 Main\Localization\Loc::setCurrentLang($defaultLanguage);
236 while ($comment = $comments->current())
238 $serviceData = $comment->getPostMessage();
239 if ($handler =
Forum\Comments\Service\Manager::find([
240 "SERVICE_TYPE" => $comment->getServiceType()
243 $postMessage = $handler->getText($serviceData);
244 if ($postMessage !==
'')
246 $comment->setPostMessage($postMessage);
247 $comment->setServiceData(is_null($serviceData) ? Json::encode([]) : $serviceData);
251 $lastId = $comment->getId();
254 if ($currentLang !== $defaultLanguage)
256 Main\Localization\Loc::setCurrentLang($currentLang);