Пример #1
0
 function Delete($ID)
 {
     global $DB;
     $ID = intVal($ID);
     $arMessage = array();
     if ($ID > 0) {
         $arMessage = CForumMessage::GetByID($ID, array("FILTER" => "N"));
     }
     if (empty($arMessage)) {
         return false;
     }
     /***************** Event onBeforeMessageAdd ************************/
     foreach (GetModuleEvents("forum", "onBeforeMessageDelete", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$ID, $arMessage)) === false) {
             return false;
         }
     }
     /***************** /Event ******************************************/
     $AUTHOR_ID = intVal($arMessage["AUTHOR_ID"]);
     $TOPIC_ID = intVal($arMessage["TOPIC_ID"]);
     $FORUM_ID = intVal($arMessage["FORUM_ID"]);
     $DB->StartTransaction();
     // delete votes
     if ($arMessage["PARAM1"] == "VT" && intVal($arMessage["PARAM2"]) > 0 && IsModuleInstalled("vote")) {
         CModule::IncludeModule("vote");
         CVote::Delete($arMessage["PARAM2"]);
     }
     // delete files
     CForumFiles::Delete(array("MESSAGE_ID" => $ID), array("DELETE_MESSAGE_FILE" => "Y"));
     // delete message
     $DB->Query("DELETE FROM b_forum_message WHERE ID=" . $ID);
     // after delete
     $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $TOPIC_ID), false, 1);
     $res = false;
     if (!($db_res && ($res = $db_res->Fetch()))) {
         CForumTopic::Delete($TOPIC_ID);
     } else {
         // if deleted message was first
         if ($arMessage["NEW_TOPIC"] == "Y") {
             $DB->Update('b_forum_message', array('NEW_TOPIC' => '"Y"'), "WHERE ID=" . $res["ID"]);
         }
         CForumTopic::SetStat($TOPIC_ID);
     }
     $DB->Commit();
     $GLOBALS["USER_FIELD_MANAGER"]->Delete("FORUM_MESSAGE", $ID);
     if ($AUTHOR_ID > 0) {
         CForumUser::SetStat($AUTHOR_ID);
     }
     CForumNew::SetStat($FORUM_ID);
     /***************** Event onBeforeMessageAdd ************************/
     foreach (GetModuleEvents("forum", "onAfterMessageDelete", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $arMessage));
     }
     /***************** /Event ******************************************/
     if (CModule::IncludeModule("search")) {
         CSearch::DeleteIndex("forum", $ID);
         if (is_array($res) && !empty($res)) {
             CForumMessage::Reindex($res["ID"], $res);
         }
     }
     return true;
 }
Пример #2
0
 function Delete($ID)
 {
     global $DB;
     $ID = intVal($ID);
     $arTopic = CForumTopic::GetByID($ID);
     if (empty($arTopic)) {
         return false;
     }
     /***************** Event onBeforeTopicDelete ***********************/
     $events = GetModuleEvents("forum", "onBeforeTopicDelete");
     while ($arEvent = $events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array(&$ID, $arTopic)) === false) {
             return false;
         }
     }
     /***************** /Event ******************************************/
     $arAuthor = array();
     $arVotes = array();
     $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $ID));
     while ($res = $db_res->Fetch()) {
         if (intVal($res["AUTHOR_ID"]) > 0) {
             $arAuthor[intVal($res["AUTHOR_ID"])] = $res["AUTHOR_ID"];
         }
         if ($res["PARAM1"] == "VT" && intVal($res["PARAM2"]) > 0) {
             $arVotes[] = intVal($res["PARAM2"]);
         }
     }
     if (!empty($arVotes) && IsModuleInstalled("vote") && CModule::IncludeModule("vote")) {
         foreach ($arVotes as $res) {
             CVote::Delete($res);
         }
     }
     //		$DB->StartTransaction();
     CForumFiles::Delete(array("TOPIC_ID" => $ID), array("DELETE_TOPIC_FILE" => "Y"));
     $DB->Query("DELETE FROM b_forum_subscribe WHERE TOPIC_ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_message WHERE TOPIC_ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_user_topic WHERE TOPIC_ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_topic WHERE ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_topic WHERE TOPIC_ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_stat WHERE TOPIC_ID = " . $ID . "");
     //		$DB->Commit();
     unset($GLOBALS["FORUM_CACHE"]["TOPIC"][$ID]);
     unset($GLOBALS["FORUM_CACHE"]["TOPIC_FILTER"][$ID]);
     foreach ($arAuthor as $key) {
         CForumUser::SetStat($key);
     }
     CForumNew::SetStat($arTopic["FORUM_ID"]);
     if (IsModuleInstalled("search") && CModule::IncludeModule("search")) {
         CSearch::DeleteIndex("forum", false, $arTopic["FORUM_ID"], $ID);
     }
     /***************** Event onAfterTopicDelete ************************/
     $events = GetModuleEvents("forum", "onAfterTopicDelete");
     while ($arEvent = $events->Fetch()) {
         ExecuteModuleEventEx($arEvent, array(&$ID, $arTopic));
     }
     /***************** /Event ******************************************/
     return true;
 }
Пример #3
0
 function Delete($ID)
 {
     global $DB;
     $ID = intVal($ID);
     $bCanDelete = true;
     /***************** Event OnBeforeForumDelete ***********************/
     foreach (GetModuleEvents("forum", "OnBeforeForumDelete", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$ID)) === false) {
             $bCanDelete = false;
             break;
         }
     }
     /***************** /Event ******************************************/
     if (!$bCanDelete) {
         return false;
     }
     /***************** Event OnForumDelete *****************************/
     foreach (GetModuleEvents("forum", "OnForumDelete", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$ID));
     }
     /***************** /Event ******************************************/
     /***************** Cleaning cache **********************************/
     unset($GLOBALS["FORUM_CACHE"]["FORUM"][$ID]);
     if (CACHED_b_forum !== false) {
         $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum");
     }
     if (CACHED_b_forum_perms !== false) {
         $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum_perms");
     }
     if (CACHED_b_forum2site !== false) {
         $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum2site");
     }
     /***************** Cleaning cache/**********************************/
     /***************** Search module ***********************************/
     set_time_limit(0);
     if (CModule::IncludeModule("search")) {
         CSearch::DeleteIndex("forum", false, $ID);
     }
     CForumFiles::Delete(array("FORUM_ID" => $ID), array("DELETE_FORUM_FILE" => "Y"));
     $DB->StartTransaction();
     // Update USER statistic
     $arProcAuth = array();
     $db_res = CForumMessage::GetList(array(), array("FORUM_ID" => $ID, "!AUTHOR_ID" => 0));
     while ($res = $db_res->Fetch()) {
         $res["AUTHOR_ID"] = intVal($res["AUTHOR_ID"]);
         if (!in_array($res["AUTHOR_ID"], $arProcAuth)) {
             $arProcAuth[] = intVal($res["AUTHOR_ID"]);
         }
     }
     if (IsModuleInstalled("vote")) {
         $db_res = CForumMessage::GetList(array(), array("FORUM_ID" => $ID, "PARAM1" => "VT", "!PARAM2" => 0));
         if ($db_res && ($res = $db_res->Fetch())) {
             CModule::IncludeModule("vote");
             do {
                 CVote::Delete($res["PARAM2"]);
             } while ($res = $db_res->Fetch());
         }
     }
     if (!$DB->Query("DELETE FROM b_forum_subscribe WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum_message WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum_topic WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum_perms WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum2site WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum WHERE ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     // Update USER statistic
     foreach ($arProcAuth as $i => $procAuth) {
         CForumUser::SetStat($procAuth);
     }
     $DB->Commit();
     /***************** Event OnAfterForumDelete ************************/
     foreach (GetModuleEvents("forum", "OnAfterForumDelete", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID));
     }
     /***************** /Event ******************************************/
     return true;
 }
Пример #4
0
	/**
	 * <p>Удаляет сообщение с кодом <i>ID</i>.</p> <p><b>Примечание</b>. Метод использует внутреннюю транзакцию. Если у вас используется <b>MySQL</b> и <b>InnoDB</b>, и ранее была открыта транзакция, то ее необходимо закрыть до подключения метода.</p>
	 *
	 *
	 *
	 *
	 * @param int $ID  Код сообщения, которое необходимо удалить.
	 *
	 *
	 *
	 * @return bool 
	 *
	 *
	 * <h4>See Also</h4> 
	 * <ul><li>Перед удалением сообщения следует проверить возможность
	 * удаления методом <a
	 * href="http://dev.1c-bitrix.ru/api_help/forum/developer/cforummessage/canuserdeletemessage.php">CForumMessage::CanUserDeleteMessage</a>
	 * </li></ul>
	 *
	 *
	 * @static
	 * @link http://dev.1c-bitrix.ru/api_help/forum/developer/cforummessage/delete.php
	 * @author Bitrix
	 */
	public static function Delete($ID)
	{
		global $DB;
		$ID = intVal($ID);
		$arMessage = array();
		if ($ID > 0)
			$arMessage = CForumMessage::GetByID($ID, array("FILTER" => "N"));
		if (empty($arMessage))
			return false;
/***************** Event onBeforeMessageAdd ************************/
		$events = GetModuleEvents("forum", "onBeforeMessageDelete");
		while ($arEvent = $events->Fetch())
		{
			if (ExecuteModuleEventEx($arEvent, array(&$ID, $arMessage)) === false)
				return false;
		}
/***************** /Event ******************************************/
		$AUTHOR_ID = intVal($arMessage["AUTHOR_ID"]);
		$TOPIC_ID = intVal($arMessage["TOPIC_ID"]);
		$FORUM_ID = intVal($arMessage["FORUM_ID"]);

		$DB->StartTransaction();
		// delete votes
		if ($arMessage["PARAM1"] == "VT" && intVal($arMessage["PARAM2"]) > 0 && IsModuleInstalled("vote")):
			CModule::IncludeModule("vote");
			CVote::Delete($arMessage["PARAM2"]);
		endif;
		// delete files
		CForumFiles::Delete(array("MESSAGE_ID" => $ID), array("DELETE_MESSAGE_FILE" => "Y"));
		// delete message
		$DB->Query("DELETE FROM b_forum_message WHERE ID=".$ID);
		// after delete
		$db_res = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $TOPIC_ID), false, 1);
		$res = false;
		if (!($db_res && $res = $db_res->Fetch())):
			CForumTopic::Delete($TOPIC_ID);
		else:
			// if deleted message was first
			if ($arMessage["NEW_TOPIC"] == "Y"):
				$DB->Query("UPDATE b_forum_message SET NEW_TOPIC='Y' WHERE ID=".$res["ID"]);
			endif;
			CForumTopic::SetStat($TOPIC_ID);
		endif;
		$DB->Commit();

		$GLOBALS["USER_FIELD_MANAGER"]->Delete("FORUM_MESSAGE", $ID);

		if ($AUTHOR_ID > 0):
			CForumUser::SetStat($AUTHOR_ID);
		endif;
		CForumNew::SetStat($FORUM_ID);
/***************** Event onBeforeMessageAdd ************************/
		$events = GetModuleEvents("forum", "onAfterMessageDelete");
		while ($arEvent = $events->Fetch())
			ExecuteModuleEventEx($arEvent, array($ID, $arMessage));
/***************** /Event ******************************************/
		if (CModule::IncludeModule("search"))
		{
			CSearch::DeleteIndex("forum", $ID);
		}
		return true;
	}