static function MoveTopic2Forum($TID, $FID, $leaveLink = "N")
{
global $DB;
$FID = intval($FID);
$arForum = CForumNew::GetByID($FID);
$arTopics = (is_array($TID) ? $TID : (intval($TID) > 0 ? array($TID) : array()));
$leaveLink = (mb_strtoupper($leaveLink) == "Y" ? "Y" : "N");
$arMsg = array();
$arForums = array();
if (empty($arForum))
{
$arMsg[] = array(
"id" => "FORUM_NOT_EXIST",
"text" => GetMessage("F_ERR_FORUM_NOT_EXIST", array("#FORUM_ID#" => $FID)));
}
if (empty($arTopics))
{
$arMsg[] = array(
"id" => "TOPIC_EMPTY",
"text" => GetMessage("F_ERR_EMPTY_TO_MOVE"));
}
if (!empty($arMsg))
{
$e = new CAdminException($arMsg);
$GLOBALS["APPLICATION"]->ThrowException($e);
return false;
}
$arTopicsCopy = $arTopics;
$arTopics = array();
foreach ($arTopicsCopy as $res)
{
$arTopics[intval($res)] = array("ID" => intval($res));
}
$db_res = CForumTopic::GetList(array(), array("@ID" => implode(", ", array_keys($arTopics))));
if ($db_res && ($res = $db_res->Fetch()))
{
do
{
if (intval($res["FORUM_ID"]) == $FID)
{
$arMsg[] = array(
"id" => "FORUM_ID_IDENTICAL",
"text" => GetMessage("F_ERR_THIS_TOPIC_IS_NOT_MOVE",
array("#TITLE#" => $res["TITLE"], "#ID#" => $res["ID"])));
continue;
}
// $DB->StartTransaction();
if ($leaveLink != "N")
{
CForumTopic::Add(
array(
"TITLE" => $res["TITLE"],
"DESCRIPTION" => $res["DESCRIPTION"],
"STATE" => "L",
"USER_START_NAME" => $res["USER_START_NAME"],
"START_DATE" => $res["START_DATE"],
"ICON" => $res["ICON"],
"POSTS" => "0",
"VIEWS" => "0",
"FORUM_ID" => $res["FORUM_ID"],
"TOPIC_ID" => $res["ID"],
"APPROVED" => $res["APPROVED"],
"SORT" => $res["SORT"],
"LAST_POSTER_NAME" => $res["LAST_POSTER_NAME"],
"LAST_POST_DATE" => $res["LAST_POST_DATE"],
"HTML" => $res["HTML"],
"USER_START_ID" => $res["USER_START_ID"],
"SOCNET_GROUP_ID" => $res["SOCNET_GROUP_ID"],
"OWNER_ID" => $res["OWNER_ID"]));
}
CForumTopic::Update($res["ID"], array("FORUM_ID" => $FID), true);
// move message
$strSql = "UPDATE b_forum_message SET FORUM_ID=".$FID.", POST_MESSAGE_HTML='' WHERE TOPIC_ID=".$res["ID"];
$DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
// move subscribe
$strSql = "UPDATE b_forum_subscribe SET FORUM_ID=".intval($FID)." WHERE TOPIC_ID=".$res["ID"];
$DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
$arForums[$res["FORUM_ID"]] = $res["FORUM_ID"];
unset($GLOBALS["FORUM_CACHE"]["TOPIC"][$res["ID"]]);
unset($GLOBALS["FORUM_CACHE"]["TOPIC_FILTER"][$res["ID"]]);
$arTopics[intval($res["ID"])] = $res;
// $DB->Commit();
CForumCacheManager::ClearTag("F", $res["ID"]);
$res_log["DESCRIPTION"] = str_replace(array("#TOPIC_TITLE#", "#TOPIC_ID#", "#FORUM_TITLE#", "#FORUM_ID#"),
array($res["TITLE"], $res["ID"], $arForum["NAME"], $arForum["ID"]),
($leaveLink != "N" ? GetMessage("F_LOGS_MOVE_TOPIC_WITH_LINK") : GetMessage("F_LOGS_MOVE_TOPIC")));
$res_log["FORUM_ID"] = $arForum["ID"];
$res_log["TOPIC_ID"] = $res["ID"];
$res_log["TITLE"] = $res["TITLE"];
$res_log["FORUM_TITLE"] = $arForum["NAME"];
CForumEventLog::Log("topic", "move", $res["ID"], serialize($res_log));
} while ($res = $db_res->Fetch());
}
/***************** Cleaning cache **********************************/
unset($GLOBALS["FORUM_CACHE"]["FORUM"][$FID]);
if(CACHED_b_forum !== false)
$GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum");
/***************** Cleaning cache/**********************************/
CForumNew::SetStat($FID);
foreach ($arForums as $key)
CForumNew::SetStat($key);
if (!empty($arMsg))
{
$e = new CAdminException($arMsg);
$GLOBALS["APPLICATION"]->ThrowException($e);
}
else
{
CForumCacheManager::ClearTag("F", $FID);
if ($leaveLink != "Y")
{
foreach($arTopics as $key => $res)
CForumCacheManager::ClearTag("F", $res["FORUM_ID"]);
}
}
return true;
}