• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/classes/general/log_comments.php
  • Класс: CAllSocNetLogComments
  • Вызов: CAllSocNetLogComments::Delete
static function Delete($ID, $bSetSource = false)
{
	global $DB, $APPLICATION, $USER_FIELD_MANAGER;

	$ID = intval($ID);
	if ($ID <= 0)
	{
		$APPLICATION->ThrowException(GetMessage("SONET_GLC_WRONG_PARAMETER_ID"), "ERROR_NO_ID");
		return false;
	}

	$bSuccess = false;

	if ($arComment = CSocNetLogComments::GetByID($ID))
	{
		if ($bSetSource)
		{
			if ($arComment["EVENT_ID"] <> '')
			{
				$arCommentEvent = CSocNetLogTools::FindLogCommentEventByID($arComment["EVENT_ID"]);
				if (
					!$arCommentEvent
					|| !array_key_exists("DELETE_CALLBACK", $arCommentEvent)
					|| !is_callable($arCommentEvent["DELETE_CALLBACK"])
				)
				{
					$bSetSource = false;
				}
			}
		}

		$bSuccess = true;

		if ($bSetSource)
		{
			$arSource = CSocNetLogComments::SetSource($arComment, "DELETE");
		}

		if (
			!$bSetSource
			|| (
				is_array($arSource)
				&& (
					!isset($arSource["ERROR"])
					|| empty($arSource["ERROR"])
				)
			)
		)
		{
			if ($bSuccess)
			{
				$bSuccess = $DB->Query("DELETE FROM b_sonet_log_comment WHERE ID = ".$ID, true);
			}

			if ($bSuccess)
			{
				$USER_FIELD_MANAGER->Delete("SONET_COMMENT", $ID);

				$db_events = GetModuleEvents("socialnetwork", "OnSocNetLogCommentDelete");
				while ($arEvent = $db_events->Fetch())
				{
					ExecuteModuleEventEx($arEvent, array($ID));
				}

				LogIndex::deleteIndex(array(
					'itemType' => LogIndexTable::ITEM_TYPE_COMMENT,
					'itemId' => $ID
				));

				LogTagTable::deleteByItem(array(
					'itemType' => LogTagTable::ITEM_TYPE_COMMENT,
					'itemId' => $ID
				));

				CRatings::deleteRatingVoting([
					'ENTITY_TYPE_ID' => $arComment['RATING_TYPE_ID'],
					'ENTITY_ID' => $arComment['RATING_ENTITY_ID']
				]);

				if ((int)$arComment["LOG_ID"] > 0)
				{
					CSocNetLogComments::UpdateLogData($arComment["LOG_ID"], false, true);

					$cache = new CPHPCache;
					$cacheSubFolder = (int)((int)$arComment["LOG_ID"] / 1000);
					$cache->CleanDir("/sonet/log/".$cacheSubFolder."/".$arComment["LOG_ID"]."/entry/");
					$cache->CleanDir("/sonet/log/".$cacheSubFolder."/".$arComment["LOG_ID"]."/comments/");
				}
			}
		}
		elseif (
			is_array($arSource)
			&& isset($arSource["ERROR"])
			&& is_string($arSource["ERROR"])
			&& !empty($arSource["ERROR"])
		)
		{
			$APPLICATION->ThrowException($arSource["ERROR"], "ERROR_DELETE_SOURCE");
			$bSuccess = false;
		}
	}

	return $bSuccess;
}