- Модуль: pull
- Путь к файлу: ~/bitrix/modules/pull/classes/general/pull_watch.php
- Класс: CAllPullWatch
- Вызов: CAllPullWatch::DeferredSql
static function DeferredSql($userId = false)
{
global $DB, $USER;
if (empty(self::$arUpdate) && empty(self::$arInsert))
return false;
$userId = intval($userId);
if (!$userId)
{
if (defined('PULL_USER_ID'))
{
$userId = PULL_USER_ID;
}
else if (is_object($GLOBALS['USER']) && $GLOBALS['USER']->GetID() > 0)
{
$userId = $GLOBALS['USER']->GetId();
}
else if (intval($_SESSION["SESS_SEARCHER_ID"]) <= 0 && intval($_SESSION["SESS_GUEST_ID"]) > 0 && CPullOptions::GetGuestStatus())
{
$userId = intval($_SESSION["SESS_GUEST_ID"])*-1;
}
}
if ($userId === 0)
{
return false;
}
$arChannel = CPullChannel::Get($userId);
if (!$arChannel)
{
return false;
}
if (!empty(self::$arUpdate))
{
$DB->Query("
UPDATE b_pull_watch
SET DATE_CREATE = ".$DB->CurrentTimeFunction().", CHANNEL_ID = '".$DB->ForSQL($arChannel['CHANNEL_ID'])."'
WHERE ID IN (".(implode(',', self::$arUpdate)).")
");
}
if ($DB->type == "MYSQL")
{
if (!empty(self::$arInsert))
{
$strSqlPrefix = "INSERT INTO b_pull_watch (USER_ID, CHANNEL_ID, TAG, DATE_CREATE) VALUES ";
$maxValuesLen = 2048;
$strSqlValues = "";
foreach(self::$arInsert as $tag)
{
$strSqlValues .= ",n(".intval($userId).", '".$DB->ForSql($arChannel['CHANNEL_ID'])."', '".$DB->ForSql($tag)."', ".$DB->CurrentTimeFunction().")";
if(mb_strlen($strSqlValues) > $maxValuesLen)
{
$DB->Query($strSqlPrefix.mb_substr($strSqlValues, 2));
$strSqlValues = "";
}
}
if($strSqlValues <> '')
{
$DB->Query($strSqlPrefix.mb_substr($strSqlValues, 2));
}
}
}
else if (!empty(self::$arInsert))
{
foreach(self::$arInsert as $tag)
{
$DB->Query("INSERT INTO b_pull_watch (USER_ID, CHANNEL_ID, TAG, DATE_CREATE) VALUES (".intval($userId).", '".$DB->ForSql($arChannel['CHANNEL_ID'])."', '".$DB->ForSql($tag)."', ".$DB->CurrentTimeFunction().")");
}
}
self::$arInsert = Array();
self::$arUpdate = Array();
return true;
}