• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_tools.php
  • Класс: CSocNetLogTools
  • Вызов: CSocNetLogTools::DeleteComment_Forum
static function DeleteComment_Forum($arFields)
{
	$arRes = array();

	if (
		CModule::IncludeModule("forum")
		&& isset($arFields["SOURCE_ID"])
		&& intval($arFields["SOURCE_ID"]) > 0
		&& isset($arFields["EVENT_ID"])
		&& $arFields["EVENT_ID"] <> ''
		&& isset($arFields["LOG_SOURCE_ID"])
		&& (int)$arFields["LOG_SOURCE_ID"] > 0
	)
	{
		$logEventMeta = CSocNetLogTools::FindLogEventByCommentID($arFields["EVENT_ID"]);

		if (
			true || // we are not ready to use BitrixForumCommentsFeed yet
			$logEventMeta["EVENT_ID"] == "forum"
		)
		{
			if (CModule::IncludeModule("forum"))
			{
				ForumActions("DEL", array(
					'MID' => (int)$arFields['SOURCE_ID'],
					"PERMISSION" => "Y"
				), $strErrorMessage, $strOKMessage);

				$arRes["ERROR"] = $strErrorMessage;
				$arRes["NOTES"] = $strOKMessage;
			}
		}
		else
		{
			if ($logEventMeta)
			{
				$arForumMetaData = CSocNetLogTools::GetForumCommentMetaData($logEventMeta["EVENT_ID"]);
			}

			if ($arForumMetaData)
			{
				$messageId = (int)$arFields["SOURCE_ID"];

				$rsMessage = CForumMessage::GetList(
					array(),
					array("ID" => $messageId),
					false,
					0,
					array(
						"SELECT" => array("FORUM_ID")
					)
				);
				if ($arMessage = $rsMessage->Fetch())
				{
					$forumId = (int)$arMessage["FORUM_ID"];
				}

				if (
					$forumId
					&& intval($forumId) > 0
				)
				{
					if (
						(
							$arForumMetaData[0] == 'WF'
							|| $arForumMetaData[0] == 'FORUM'
						)
						&& isset($arFields["LOG_ID"])
						&& intval($arFields["LOG_ID"]) > 0
					)
					{
						$rsLog = CSocNetLog::GetList(
							array(),
							array("ID" => (int)$arFields["LOG_ID"]),
							false,
							false,
							array("MESSAGE", "RATING_ENTITY_ID")
						);
						if ($arLog = $rsLog->Fetch())
						{
							if ($arForumMetaData[0] === 'WF')
							{
								$entityId = $arLog["MESSAGE"];
							}
							elseif ($arForumMetaData[0] === 'FORUM')
							{
								$entityId = $arLog["RATING_ENTITY_ID"];
							}
						}
					}
					elseif (
						$arForumMetaData[0] === 'FORUM'
						&& isset($arFields["LOG_ID"])
						&& intval($arFields["LOG_ID"]) > 0
					)
					{
						$rsLog = CSocNetLog::GetList(
							array(),
							array("ID" => (int)$arFields["LOG_ID"]),
							false,
							false,
							array("MESSAGE")
						);
						if ($arLog = $rsLog->Fetch())
						{
							$entityId = $arLog["MESSAGE"];
						}
					}
					else
					{
						$entityId = $arFields["LOG_SOURCE_ID"];
					}

					$feed = new BitrixForumCommentsFeed(
						intval($forumId),
						array(
							"type" => $arForumMetaData[1],
							"id" => intval($arFields["LOG_SOURCE_ID"]),
							"xml_id" => $arForumMetaData[0]."_".$entityId
						)
					);

					if (!$feed->delete($messageId))
					{
						$arRes["ERROR"] = "";
						foreach($feed->getErrors() as $error)
						{
							$arRes["ERROR"] .= $error->getMessage();
						}
					}
					else
					{
						$arRes["NOTES"] = GetMessage("SONET_DELETE_COMMENT_SOURCE_SUCCESS");
					}
				}
			}
		}
	}

	if (!isset($arRes["NOTES"]))
	{
		$arRes["ERROR"] = GetMessage("SONET_DELETE_COMMENT_SOURCE_ERROR");
	}

	return $arRes;
}