public static function send($eventId, $arParams) { $result = false; if (!isset($arParams["ORDER"]) && isset($arParams["ORDER_ID"])) { $arParams["ORDER"] = CSaleOrder::GetById($arParams["ORDER_ID"]); } if (in_array($eventId, self::$arEvents) && isset($arParams["ORDER"]) && CModule::IncludeModule("pull")) { $arUsers = self::getSubscribers($eventId, $arParams); if (!empty($arUsers)) { $text = self::makeMessage($eventId, $arParams); $title = self::makeTitle($eventId, $arParams); $arMessages = array(); foreach ($arUsers as $userId) { if (!self::checkRights($userId, $eventId, array("ORDER_ID" => $arParams["ORDER"]["ID"]))) { continue; } $arMessages[] = array("USER_ID" => $userId, "TITLE" => $title, "APP_ID" => "BitrixAdmin", "MESSAGE" => $text, "PARAMS" => "sl_" . $arParams["ORDER"]["ID"]); } $pushMe = new CPushManager(); $result = $pushMe->SendMessage($arMessages); } } return $result; }
public static function SendAgent() { global $DB; if (!CPullOptions::GetPushStatus()) { return false; } $count = 0; $maxId = 0; $pushLimit = 70; $arPush = array(); $sqlDate = ""; $dbType = strtolower($DB->type); if ($dbType == "mysql") { $sqlDate = " WHERE DATE_CREATE < DATE_SUB(NOW(), INTERVAL 15 SECOND) "; } else { if ($dbType == "mssql") { $sqlDate = " WHERE DATE_CREATE < dateadd(SECOND, -15, getdate()) "; } else { if ($dbType == "oracle") { $sqlDate = " WHERE DATE_CREATE < SYSDATE-(1/24/60/60*15) "; } } } $strSql = $DB->TopSql("SELECT ID, USER_ID, MESSAGE, PARAMS FROM b_pull_push_queue" . $sqlDate, 280); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $dbRes->Fetch()) { $arPush[$count][] = $arRes; if ($pushLimit <= count($arPush[$count])) { $count++; } $maxId = $maxId < $arRes['ID'] ? $arRes['ID'] : $maxId; } foreach ($arPush as $arStack) { $CPushManager = new CPushManager(); $CPushManager->SendMessage($arStack, defined('PULL_PUSH_SANDBOX') ? true : false); } if ($maxId > 0) { $strSql = "DELETE FROM b_pull_push_queue WHERE ID <= " . $maxId; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } $strSql = "SELECT COUNT(ID) CNT FROM b_pull_push_queue"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { if ($arRes['CNT'] > 280) { CAgent::RemoveAgent("CPushManager::SendAgent();", "pull"); CAgent::AddAgent("CPushManager::SendAgent();", "pull", "N", 15, "", "Y", ConvertTimeStamp(time() + CTimeZone::GetOffset() + 15, "FULL")); } else { if ($arRes['CNT'] > 0) { return "CPushManager::SendAgent();"; } } } return false; }
public static function SendAgent() { global $DB; if (!CPullOptions::GetPushStatus()) { return false; } $count = 0; $maxId = 0; $pushLimit = 70; $arPush = array(); $sqlDate = ""; $dbType = strtolower($DB->type); if ($dbType == "mysql") { $sqlDate = " WHERE DATE_CREATE < DATE_SUB(NOW(), INTERVAL 15 SECOND) "; } else { if ($dbType == "mssql") { $sqlDate = " WHERE DATE_CREATE < dateadd(SECOND, -15, getdate()) "; } else { if ($dbType == "oracle") { $sqlDate = " WHERE DATE_CREATE < SYSDATE-(1/24/60/60*15) "; } } } $strSql = $DB->TopSql("SELECT ID, USER_ID, MESSAGE, PARAMS, BADGE, APP_ID FROM b_pull_push_queue" . $sqlDate, 280); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); while ($arRes = $dbRes->Fetch()) { if ($arRes['BADGE'] == '') { unset($arRes['BADGE']); } $arPush[$count][] = $arRes; if ($pushLimit <= count($arPush[$count])) { $count++; } $maxId = $maxId < $arRes['ID'] ? $arRes['ID'] : $maxId; } if ($maxId > 0) { $strSql = "DELETE FROM b_pull_push_queue WHERE ID <= " . $maxId; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } $CPushManager = new CPushManager(); foreach ($arPush as $arStack) { $CPushManager->SendMessage($arStack); } $strSql = "SELECT COUNT(ID) CNT FROM b_pull_push_queue"; $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { global $pPERIOD; if ($arRes['CNT'] > 280) { $pPERIOD = 10; return "CPushManager::SendAgent();"; } else { if ($arRes['CNT'] > 0) { $pPERIOD = 30; return "CPushManager::SendAgent();"; } } } return false; }
public static function SendBadges($userID) { if (!(CModule::IncludeModule('pull') && CPullOptions::GetPushStatus())) return false; $arPush = Array(); if (!is_array($userID)) $userID = Array(intval($userID)); global $DB; if (empty($userID)) return false; foreach ($userID as $key => $userId) $userID[$key] = intval($userId); $sql = "SELECT SUM(CNT) CNT, USER_ID FROM b_user_counter WHERE USER_ID IN (".implode(',', $userID).") and SITE_ID = '**' and CODE IN ('im_notify', 'im_message', 'im_chat') GROUP BY USER_ID"; $res = $DB->Query($sql); while($row = $res->Fetch()) $arPush[] = Array('USER_ID' => $row['USER_ID'], 'BADGE' => $row['CNT']); $CPushManager = new CPushManager(); $CPushManager->SendMessage($arPush, defined('PULL_PUSH_SANDBOX')? true: false); }