• Модуль: forum
  • Путь к файлу: ~/bitrix/modules/forum/classes/general/rest.php
  • Класс: CForumRestService
  • Вызов: CForumRestService::deleteMessage
static function deleteMessage($arFields)
{
	global $USER;
	static $obCache = null;

	$messageId = intval($arFields['MESSAGE_ID']);

	if($messageId <= 0)
	{
		throw new Exception('Wrong message ID');
	}

	$currentUserId = (
		isset($arFields["USER_ID"])
		&& intval($arFields["USER_ID"]) > 0
		&& self::isAdmin()
			? $arFields["USER_ID"]
			: $USER->getId()
	);

	$arMessage = self::getForumMessageFields($messageId);
	if (empty($arMessage))
	{
		throw new Exception('No message found');
	}

	$currentUserPerm = self::getForumMessagePerm(array(
		'USER_ID' => $currentUserId,
		'MESSAGE_ID' => $messageId
	));

	if ($currentUserPerm < self::PERM_WRITE)
	{
		throw new Exception('No write perms');
	}

	if (
		($result = CForumMessage::Delete($messageId))
		&& Loader::includeModule('socialnetwork')
	)
	{
		$logIdList = array();

		$res = BitrixSocialnetworkLogTable::getList(array(
			'filter' => array(
				'=SOURCE_ID' => $messageId,
				'@EVENT_ID' => array('forum') // replace with provider getEventId
			),
			'select' => array('ID')
		));
		while ($logFields = $res->fetch())
		{
			if (CSocNetLog::delete($logFields['ID']))
			{
				$logIdList[] = intval($logFields['ID']);
			}
		}

		if (empty($logIdList))
		{
			$res = BitrixSocialnetworkLogCommentTable::getList(array(
				'filter' => array(
					'=SOURCE_ID' => $messageId,
					'@EVENT_ID' => array('forum', 'tasks_comment', 'calendar_comment', 'timeman_entry_comment', 'report_comment', 'photo_comment', 'wiki_comment', 'lists_new_element_comment') // replace with provider getEventId
				),
				'select' => array('ID', 'LOG_ID')
			));
			while ($logCommentFields = $res->fetch())
			{
				if (CSocNetLogComments::delete($logCommentFields['ID']))
				{
					$logIdList[] = intval($logFields['LOG_ID']);
				}
			}
		}

		if (!empty($logIdList))
		{
			foreach($logIdList as $logId)
			{
				if ($obCache === null)
				{
					$obCache = new CPHPCache;
				}
				$obCache->CleanDir("/sonet/log/".intval($logId / 1000)."/".$logId."/comments/");
			}
		}
	}

	return (bool)$result;
}