6if (Loader::includeModule(
'replica'))
8 class TopicHandler
extends \Bitrix\Replica\Client\BaseHandler
10 protected $tasksForumId = 0;
12 protected $tableName =
"b_forum_topic";
13 protected $moduleId =
"forum";
15 protected $primary = array(
16 "ID" =>
"auto_increment",
18 protected $predicates = array(
20 protected $translation = array(
21 "ID" =>
"b_forum_topic.ID",
22 "USER_START_ID" =>
"b_user.ID",
23 "LAST_POSTER_ID" =>
"b_user.ID",
25 "ABS_LAST_POSTER_ID" =>
"b_user.ID",
27 "RESPONSIBLE_ID" =>
"b_user.ID",
28 "OWNER_ID" =>
"b_user.ID",
30 protected $children = array(
31 "ID" =>
"b_forum_message.TOPIC_ID",
40 if (\
Bitrix\Main\Loader::includeModule(
'tasks'))
42 $this->tasksForumId = (int)\CTasksTools::GetForumIdForIntranet();
55 public function onAfterTopicAdd($id, &$data)
57 \Bitrix\Replica\Db\Operation::writeInsert($this->tableName, array(
'ID'), array(
'ID' => $id));
70 public function onAfterTopicUpdate($id, $newTopic, $oldTopic)
72 \Bitrix\Replica\Db\Operation::writeUpdate($this->tableName, array(
'ID'), array(
'ID' => $id));
84 public function onAfterTopicDelete(&$id, $topic)
86 \Bitrix\Replica\Db\Operation::writeDelete($this->tableName, array(
'ID'), array(
'ID' => $id));
98 public function beforeInsertTrigger(array &$newRecord)
100 unset($newRecord[
"SOCNET_GROUP_ID"]);
101 if ($this->tasksForumId > 0 && $newRecord[
'FORUM_ID'] ===
'tasks_forum')
103 $newRecord[
'FORUM_ID'] = $this->tasksForumId;
104 if (preg_match(
"/^TASK_(.+)\$/", $newRecord[
"XML_ID"], $match))
106 $mapper = \Bitrix\Replica\Mapper::getInstance();
107 $taskId = $mapper->resolveLogGuid(
false,
'b_tasks.ID', $match[1]);
110 $newRecord[
'XML_ID'] =
'TASK_'.$taskId;
125 public function beforeUpdateTrigger(array $oldRecord, array &$newRecord)
127 unset($newRecord[
"SOCNET_GROUP_ID"]);
129 if ($this->tasksForumId > 0 && $newRecord[
'FORUM_ID'] ===
'tasks_forum')
131 $newRecord[
'FORUM_ID'] = $this->tasksForumId;
132 if (preg_match(
"/^TASK_(.+)\$/", $newRecord[
"XML_ID"], $match))
134 $mapper = \Bitrix\Replica\Mapper::getInstance();
135 $taskId = $mapper->resolveLogGuid(
false,
'b_tasks.ID', $match[1]);
138 $newRecord[
'XML_ID'] =
'TASK_'.$taskId;
151 public function beforeLogInsert(array $record)
153 if ($this->tasksForumId > 0 && $record[
'FORUM_ID'] == $this->tasksForumId)
170 public function beforeLogFormat(array &$record)
172 if ($this->tasksForumId > 0 && $record[
'FORUM_ID'] == $this->tasksForumId)
174 $record[
'FORUM_ID'] =
'tasks_forum';
175 if (preg_match(
"/^TASK_([0-9]+)\$/", $record[
"XML_ID"], $match))
177 $mapper = \Bitrix\Replica\Mapper::getInstance();
178 $guid = $mapper->getLogGuid(
"b_tasks.ID", $match[1]);
180 $record[
'XML_ID'] =
'TASK_'.$guid;