예제 #1
0
파일: update.php 프로젝트: Satariall/izurit
 function Update()
 {
     if (CSupportUpdate::CurrentVersionLowerThanUpdateVersion()) {
         $dbType = CSupportUpdate::GetBD();
         $res = self::AlterTables($dbType);
         if (!$res) {
             return false;
         }
         $res = self::SeparateSLAandTimeTable($dbType);
         if (!$res) {
             return false;
         }
         CSupportTimetableCache::toCache();
         CTicketReminder::RecalculateSupportDeadline();
         CTicketReminder::StartAgent();
         CSupportUpdate::ChangeCurrentVersion();
         self::SetHotKeys();
     }
 }
예제 #2
0
<?php

require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_before.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/support/include.php";
require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/support/prolog.php";
IncludeModuleLangFile(__FILE__);
if (!check_bitrix_sessid("b_sessid")) {
    die;
}
if (isset($_REQUEST["action"]) && $_REQUEST["action"] === 'reindex' && isset($_REQUEST["data"]) && is_array($_REQUEST["data"])) {
    $interval = intval($_REQUEST["data"]["interval"]);
    $firstID = $_REQUEST["data"]["firstID"];
    $lastID = CSupportSearch::reindexAllTickets($firstID, $interval ?: 10);
    // build progress bar
    $maxID = CTicket::getMaxId();
    $progressBar = new CAdminMessage(array("DETAILS" => str_replace(array('#LAST_ID#', '#MAX_ID#'), array($lastID, $maxID), GetMessage('SUP_SEARCH_NDX_PROGRESS_BAR')), "HTML" => true, "TYPE" => "PROGRESS", "PROGRESS_TOTAL" => $maxID, "PROGRESS_VALUE" => $lastID));
    $progressBarHtml = $progressBar->Show();
    echo CUtil::PhpToJSObject(array('LAST_ID' => $lastID, 'BAR' => $progressBarHtml));
} elseif ($_REQUEST['MY_AJAX'] == 'restartAgentsAJAX') {
    CTicketReminder::StartAgent();
    echo json_encode(array("ALL_OK" => "OK"));
} else {
    echo '{};';
}
예제 #3
0
 function UpdateLastParamsN($ticketID, $dateType, $recalculateSupportDeadline = true, $setReopenDefault = true)
 {
     $err_mess = CAllTicket::err_mess() . "<br>Function: UpdateLastParamsN<br>Line: ";
     global $DB, $USER;
     $ticketID = intval($ticketID);
     if ($ticketID <= 0) {
         return;
     }
     $arSupportTeam = CTicket::GetSupportTeamAndAdminUsers();
     $arFields = array("LAST_MESSAGE_DATE" => "null", "LAST_MESSAGE_USER_ID" => "null", "LAST_MESSAGE_GUEST_ID" => "null", "LAST_MESSAGE_SID" => "null", "D_1_USER_M_AFTER_SUP_M" => "null", "ID_1_USER_M_AFTER_SUP_M" => "null", "LAST_MESSAGE_BY_SUPPORT_TEAM" => "'Y'");
     if ($setReopenDefault) {
         $arFields["REOPEN"] = "'N'";
     }
     $DB->StartUsingMasterOnly();
     $strSql = "\n\t\t\tSELECT\n\t\t\t\tT.ID,\n\t\t\t\tT.SLA_ID,\n\t\t\t\tT.DATE_CLOSE,\n\t\t\t\t" . $DB->DateToCharFunction("T.DEADLINE_SOURCE_DATE", "FULL") . " DEADLINE_SOURCE_DATE,\n\t\t\t\t" . $DB->DateToCharFunction("T.D_1_USER_M_AFTER_SUP_M", "FULL") . " DATE_OLD,\n\t\t\t\tT.IS_OVERDUE,\n\t\t\t\tSLA.RESPONSE_TIME_UNIT,\n\t\t\t\tSLA.RESPONSE_TIME,\n\t\t\t\tSLA.NOTICE_TIME_UNIT,\n\t\t\t\tSLA.NOTICE_TIME\n\t\t\tFROM\n\t\t\t\tb_ticket T\n\t\t\t\tINNER JOIN b_ticket_sla SLA\n\t\t\t\t\tON T.SLA_ID = SLA.ID\n\t\t\t\t\t\tAND T.ID = {$ticketID}\n\t\t\t";
     $rs = $DB->Query($strSql, false, $err_mess . __LINE__);
     $arTicket = $rs->Fetch();
     if (!$arTicket) {
         $DB->StopUsingMasterOnly();
         return;
     }
     $arMessagesAll = array();
     $arLastMess = null;
     $arFirstUserMessAfterSupportMess = null;
     $allTime = 0;
     $messages = 0;
     $messAfterSupportMess = true;
     $strSql = "\n\t\t\tSELECT\n\t\t\t\tID,\n\t\t\t\t" . $DB->DateToCharFunction("DATE_CREATE", "FULL") . " DATE_CREATE,\n\t\t\t\tOWNER_USER_ID,\n\t\t\t\tOWNER_GUEST_ID,\n\t\t\t\tOWNER_SID,\n\t\t\t\tTASK_TIME,\n\t\t\t\tIS_OVERDUE,\n\t\t\t\tIS_HIDDEN,\n\t\t\t\tNOT_CHANGE_STATUS\n\t\t\tFROM\n\t\t\t\tb_ticket_message\n\t\t\tWHERE\n\t\t\t\tTICKET_ID={$ticketID}\n\t\t\tAND(NOT(IS_LOG='Y'))\n\t\t\tORDER BY\n\t\t\t\tC_NUMBER\n\t\t\t";
     //NOT_CHANGE_STATUS
     //IS_HIDDEN
     //IS_OVERDUE
     $rs = $DB->Query($strSql, false, $err_mess . __LINE__);
     $DB->StopUsingMasterOnly();
     while ($arM = $rs->Fetch()) {
         $arMessagesAll[] = $arM;
         if ($arM["IS_OVERDUE"] !== 'Y') {
             if ($arM["IS_HIDDEN"] !== 'Y') {
                 if ($arM["NOT_CHANGE_STATUS"] !== 'Y') {
                     $arLastMess = $arM;
                 }
                 $messages++;
             }
             $allTime += intval($arM["TASK_TIME"]);
         }
         if ($arM["IS_HIDDEN"] !== 'Y' && $arM["NOT_CHANGE_STATUS"] !== 'Y') {
             if (in_array(intval($arM["OWNER_USER_ID"]), $arSupportTeam)) {
                 $arFirstUserMessAfterSupportMess = null;
                 $messAfterSupportMess = true;
             } elseif ($messAfterSupportMess) {
                 $arFirstUserMessAfterSupportMess = $arM;
                 $messAfterSupportMess = false;
             }
         }
     }
     if ($arLastMess !== null) {
         $arFields["LAST_MESSAGE_USER_ID"] = $arLastMess["OWNER_USER_ID"];
         //if ($changeLastMessageDate)
         //{
         $arFields["LAST_MESSAGE_DATE"] = $DB->CharToDateFunction($arLastMess["DATE_CREATE"]);
         //}
         $arFields["LAST_MESSAGE_GUEST_ID"] = intval($arLastMess["OWNER_GUEST_ID"]);
         $arFields["LAST_MESSAGE_SID"] = "'" . $DB->ForSql($arLastMess["OWNER_SID"], 255) . "'";
     }
     $arFields["MESSAGES"] = $messages;
     $arFields["PROBLEM_TIME"] = $allTime;
     if ($arFirstUserMessAfterSupportMess !== null) {
         $arFields["D_1_USER_M_AFTER_SUP_M"] = $DB->CharToDateFunction($arFirstUserMessAfterSupportMess["DATE_CREATE"]);
         $arFields["ID_1_USER_M_AFTER_SUP_M"] = intval($arFirstUserMessAfterSupportMess["ID"]);
         $arFields["LAST_MESSAGE_BY_SUPPORT_TEAM"] = "'N'";
     }
     if (is_array($dateType["EVENT"]) && in_array(CTicket::REOPEN, $dateType["EVENT"])) {
         $arFields["DEADLINE_SOURCE_DATE"] = $DB->CharToDateFunction(GetTime(time() + CTimeZone::GetOffset(), "FULL"));
     } elseif ($arTicket["IS_OVERDUE"] == "Y") {
         $recalculateSupportDeadline = false;
     }
     $recalculateSupportDeadline = $recalculateSupportDeadline && intval($arTicket["DATE_CLOSE"]) <= 0 && $arFields["LAST_MESSAGE_BY_SUPPORT_TEAM"] == "'N'";
     if (!$recalculateSupportDeadline) {
         if ($arFields["LAST_MESSAGE_BY_SUPPORT_TEAM"] == "'Y'" || intval($arTicket["DATE_CLOSE"]) > 0) {
             $arFields["SUPPORT_DEADLINE_NOTIFY"] = "null";
             $arFields["SUPPORT_DEADLINE"] = "null";
             $arFields["IS_OVERDUE"] = "'N'";
             $arFields["IS_NOTIFIED"] = "'N'";
         }
     }
     $DB->Update("b_ticket", $arFields, "WHERE ID='" . $ticketID . "'", $err_mess . __LINE__);
     if ($recalculateSupportDeadline) {
         $arTicket["M_ID"] = $arFirstUserMessAfterSupportMess["ID"];
         $arTicket["D_1_USER_M_AFTER_SUP_M"] = $arFirstUserMessAfterSupportMess["DATE_CREATE"];
         CTicketReminder::RecalculateSupportDeadlineForOneTicket($arTicket, $arFields, $dateType);
     }
     /*
     LAST_MESSAGE_DATE
     LAST_MESSAGE_USER_ID
     LAST_MESSAGE_GUEST_ID
     LAST_MESSAGE_SID
     MESSAGES
     REOPEN
     PROBLEM_TIME
     D_1_USER_M_AFTER_SUP_M
     ID_1_USER_M_AFTER_SUP_M
     LAST_MESSAGE_BY_SUPPORT_TEAM
     
     DEADLINE_SOURCE_DATE
     SUPPORT_DEADLINE_NOTIFY
     SUPPORT_DEADLINE
     IS_OVERDUE
     IS_NOTIFIED
     */
 }
예제 #4
0
 public static function ToCache($arFilter = array(), $RSD = true, $arFromGetEndDate = null)
 {
     /*
     $arFilter(
     	SLA => array()
     )
     */
     global $DB;
     $currD = time();
     $uniq = "";
     $dbType = strtolower($DB->type);
     if ($dbType === "mysql") {
         $DB->StartUsingMasterOnly();
         $uniq = COption::GetOptionString("main", "server_uniq_id", "");
         if (strlen($uniq) <= 0) {
             $uniq = md5(uniqid(rand(), true));
             COption::SetOptionString("main", "server_uniq_id", $uniq);
         }
         $db_lock = $DB->Query("SELECT GET_LOCK('" . $uniq . "_supportToCache', 0) as L");
         $ar_lock = $db_lock->Fetch();
         if ($ar_lock["L"] !== "1") {
             return;
         }
         //Перед пересчетом проверить в центральной базе что данных действительно нет, на случй здержки передачм данных в дочернюю базу(только для MYSQL)
         if (is_array($arFromGetEndDate)) {
             $res = self::getEndDate($arFromGetEndDate["SLA"], $arFromGetEndDate["PERIOD_MIN"], $arFromGetEndDate["DATE_FROM"], true);
             if ($res !== null) {
                 return $res;
             }
         }
     }
     $err_mess = self::err_mess() . "<br>Function: toCache<br>Line: ";
     $timetable_cache = self::TIMETABLE_CACHE;
     $ndF = self::GetNumberOfDaysForward();
     $ndB = self::GetNumberOfDaysBackward();
     $dateF = self::GetDayBegin($currD - $ndB * 24 * 60 * 60);
     $dateT = self::GetDayEnd($currD + $ndF * 24 * 60 * 60);
     self::$arrS = self::GetShedule($arFilter);
     if (count(self::$arrS) <= 0) {
         return null;
     }
     self::$arrH = self::GetHolidays($dateF - 24 * 60 * 60, $dateT + 24 * 60 * 60, self::$arrS, $arFilter);
     $arrSLA = array_keys(self::$arrS);
     $arSqlSearch = array();
     foreach ($arFilter as $key => $val) {
         if (is_array($val) && count($val) <= 0 || !is_array($val) && strlen($val) <= 0) {
             continue;
         }
         $key = strtoupper($key);
         if (is_array($val)) {
             $val = implode(" | ", $val);
         }
         switch ($key) {
             case "SLA_ID":
                 $arSqlSearch[] = GetFilterQuery("SLA_ID", $val, "N");
                 break;
         }
     }
     $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
     $DB->Query("DELETE FROM {$timetable_cache} WHERE {$strSqlSearch}", false, $err_mess . __LINE__);
     $f = new CSupportTableFields(self::$cache);
     $colNames = null;
     $strList = "";
     $coma = "";
     foreach ($arrSLA as $k => $sla) {
         $dateC = $dateF;
         $sum = 0;
         while ($dateC <= $dateT) {
             if (isset(self::$arrH[$sla]) && array_key_exists($dateC, self::$arrH[$sla])) {
                 $a = self::$arrH[$sla][$dateC];
             } else {
                 $a = self::$arrS[$sla][self::GetDayNom($dateC)];
             }
             foreach ($a as $k2 => $v2) {
                 $sum = $sum + $v2["T"] - $v2["F"];
                 $f->SLA_ID = $sla;
                 $f->DATE_FROM = $dateC + $v2["F"];
                 $f->DATE_TILL = $dateC + $v2["T"];
                 $f->W_TIME = $v2["T"] - $v2["F"];
                 $f->W_TIME_INC = $sum;
                 CTimeZone::Disable();
                 if ($dbType === "mysql") {
                     $arCurrTicketFields = $f->ToArray(CSupportTableFields::ALL, array(), true);
                     if ($colNames === null) {
                         $colNames = implode(", ", array_keys($arCurrTicketFields));
                     }
                     $strCurrTicketFields = "(" . implode(",", $arCurrTicketFields) . ")";
                     if (strlen($strList . ", " . $strCurrTicketFields) > 2000) {
                         $strSql = "INSERT INTO " . $timetable_cache . " (" . $colNames . ") VALUES " . $strList;
                         $strList = $strCurrTicketFields;
                     } else {
                         $strList .= $coma . $strCurrTicketFields;
                         $coma = ", ";
                         continue;
                     }
                     $DB->Query($strSql, false, $err_mess . __LINE__);
                 } else {
                     $DB->Insert($timetable_cache, $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true), $err_mess . __LINE__);
                 }
                 CTimeZone::Enable();
             }
             $dateC = self::GetDayBegin($dateC + 25 * 60 * 60);
         }
     }
     if ($dbType === "mysql") {
         if (strlen($strList) > 0) {
             $strSql = "INSERT INTO " . $timetable_cache . " (" . $colNames . ") VALUES " . $strList;
             $DB->Query($strSql, false, $err_mess . __LINE__);
         }
         $DB->Query("SELECT RELEASE_LOCK('" . $uniq . "_supportToCache')");
         $DB->StopUsingMasterOnly();
         //CAgent::AddAgent("CSupportTimetableCache::UpdateDiscardedTickets(" . $currD . ");", "support", "N", 5*60);
     }
     if ($RSD) {
         CTicketReminder::RecalculateSupportDeadline($arFilter);
     }
     return null;
 }
예제 #5
0
 function UpdateLastParams2($ticketID, $dateType)
 {
     global $DB;
     $strUsers = implode(",", CTicket::GetSupportTeamAndAdminUsers());
     $err_mess = CAllTicket::err_mess() . "<br>Function: UpdateLastParams2<br>Line: ";
     $arFields = array();
     $arFields["D_1_USER_M_AFTER_SUP_M"] = "null";
     $arFields["ID_1_USER_M_AFTER_SUP_M"] = "null";
     $arFields["LAST_MESSAGE_BY_SUPPORT_TEAM"] = "'Y'";
     $arFields["SUPPORT_DEADLINE_NOTIFY"] = "null";
     $arFields["SUPPORT_DEADLINE"] = "null";
     $arFields["IS_OVERDUE"] = "'N'";
     $arFields["IS_NOTIFIED"] = "'N'";
     // Get last support response
     $M_ID = 0;
     $strSql = "\n\t\t\tSELECT\n\t\t\t\tT.ID ID,\n\t\t\t\tMAX(TM.ID) M_ID\n\t\t\tFROM\n\t\t\t\tb_ticket T\n\t\t\t\tINNER JOIN b_ticket_message TM\n\t\t\t\t\tON T.ID = TM.TICKET_ID\n\t\t\t\t\t\tAND T.ID = {$ticketID}\n\t\t\t\t\t\tAND (TM.IS_LOG='N' OR TM.IS_LOG IS NULL OR " . $DB->Length("TM.IS_LOG") . " <= 0)\n\t\t\t\t\t\tAND TM.OWNER_USER_ID IN({$strUsers})\n\t\t\t\t\n\t\t\tGROUP BY\n\t\t\t\tT.ID";
     $rs = $DB->Query($strSql, false, $err_mess . __LINE__);
     if ($arrRs = $rs->Fetch()) {
         if (intval($arrRs["M_ID"]) > 0) {
             $M_ID = intval($arrRs["M_ID"]);
         }
     }
     // Get first user request after last support response
     $strSql = "\n\t\t\tSELECT\n\t\t\t\tT.SLA_ID,\n\t\t\t\tT.DATE_CLOSE,\n\t\t\t\tSLA.RESPONSE_TIME_UNIT,\n\t\t\t\tSLA.RESPONSE_TIME,\n\t\t\t\tSLA.NOTICE_TIME_UNIT,\n\t\t\t\tSLA.NOTICE_TIME,\n\t\t\t\tPZ2.M_ID,\n\t\t\t\tPZ2.D_1_USER_M_AFTER_SUP_M,\n\t\t\t\t" . $DB->DateToCharFunction("T.D_1_USER_M_AFTER_SUP_M", "FULL") . " DATE_OLD\n\t\t\tFROM\n\t\t\t\tb_ticket T\n\t\t\t\tINNER JOIN b_ticket_sla SLA\n\t\t\t\t\tON T.SLA_ID = SLA.ID\n\t\t\t\t\t\tAND T.ID = {$ticketID}\n\t\t\t\tLEFT JOIN (SELECT\n\t\t\t\t\tTM.ID M_ID,\n\t\t\t\t\tTM.TICKET_ID,\n\t\t\t\t\t" . $DB->DateToCharFunction("TM.DATE_CREATE", "FULL") . " D_1_USER_M_AFTER_SUP_M\n\t\t\t\tFROM\n\t\t\t\t\tb_ticket_message TM\n\t\t\t\t\tINNER JOIN (SELECT\n\t\t\t\t\t\t\tT.ID ID,\n\t\t\t\t\t\t\tMIN(TM.ID) M_ID\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\tb_ticket T\n\t\t\t\t\t\t\tINNER JOIN b_ticket_message TM\n\t\t\t\t\t\t\t\tON T.ID = TM.TICKET_ID\n\t\t\t\t\t\t\t\tAND T.ID = {$ticketID}\n\t\t\t\t\t\t\t\tAND (NOT(TM.IS_LOG='Y'))\n\t\t\t\t\t\t\t\tAND TM.ID > {$M_ID}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t\tT.ID) PZ\n\t\t\t\t\t\tON TM.ID = PZ.M_ID) PZ2\n\t\t\t\t\t\tON T.ID = PZ2.TICKET_ID\n\t\t\t\t\t\t\n\t\t";
     //AND (NOT(TM.IS_HIDDEN='Y'))
     $rs = $DB->Query($strSql, false, $err_mess . __LINE__);
     if (!($arrRs = $rs->Fetch())) {
         return;
     }
     if (intval($arrRs["M_ID"]) > 0) {
         $arFields["D_1_USER_M_AFTER_SUP_M"] = $DB->CharToDateFunction($arrRs["D_1_USER_M_AFTER_SUP_M"]);
         $arFields["ID_1_USER_M_AFTER_SUP_M"] = intval($arrRs["M_ID"]);
         $arFields["LAST_MESSAGE_BY_SUPPORT_TEAM"] = "'N'";
     }
     if (intval($arrRs["DATE_CLOSE"]) <= 0 && $arFields["LAST_MESSAGE_BY_SUPPORT_TEAM"] == "'N'") {
         $arrRs["ID"] = $ticketID;
         CTicketReminder::RecalculateSupportDeadlineForOneTicket($arrRs, $arFields, $dateType);
     } else {
         $DB->Update("b_ticket", $arFields, "WHERE ID='" . $ticketID . "'", $err_mess . __LINE__);
     }
 }
예제 #6
0
 static function ToCache($arFilter = array())
 {
     /*
     $arFilter(
     	SLA => array()
     )
     */
     global $DB;
     $err_mess = self::err_mess() . "<br>Function: toCache<br>Line: ";
     $timetable_cache = self::TIMETABLE_CACHE;
     $ndF = self::GetNumberOfDaysForward();
     $ndB = self::GetNumberOfDaysBackward();
     $currD = time();
     $dateF = self::GetDayBegin($currD - $ndB * 24 * 60 * 60);
     $dateT = self::GetDayEnd($currD + $ndF * 24 * 60 * 60);
     self::$arrS = self::GetShedule($arFilter);
     if (count(self::$arrS) <= 0) {
         return;
     }
     self::$arrH = self::GetHolidays($dateF - 24 * 60 * 60, $dateT + 24 * 60 * 60, self::$arrS, $arFilter);
     $arrSLA = array_keys(self::$arrS);
     $arSqlSearch = array();
     foreach ($arFilter as $key => $val) {
         if (is_array($val) && count($val) <= 0 || !is_array($val) && strlen($val) <= 0) {
             continue;
         }
         $key = strtoupper($key);
         if (is_array($val)) {
             $val = implode(" | ", $val);
         }
         switch ($key) {
             case "SLA_ID":
                 $arSqlSearch[] = GetFilterQuery("SLA_ID", $val, "N");
                 break;
         }
     }
     $strSqlSearch = GetFilterSqlSearch($arSqlSearch);
     $DB->Query("DELETE FROM {$timetable_cache} WHERE {$strSqlSearch}", false, $err_mess . __LINE__);
     $f = new CSupportTableFields(self::$cache);
     foreach ($arrSLA as $k => $sla) {
         $dateC = $dateF;
         $sum = 0;
         while ($dateC <= $dateT) {
             if (isset(self::$arrH[$sla]) && array_key_exists($dateC, self::$arrH[$sla])) {
                 $a = self::$arrH[$sla][$dateC];
             } else {
                 $a = self::$arrS[$sla][self::GetDayNom($dateC)];
             }
             foreach ($a as $k2 => $v2) {
                 $sum = $sum + $v2["T"] - $v2["F"];
                 $f->SLA_ID = $sla;
                 $f->DATE_FROM = $dateC + $v2["F"];
                 $f->DATE_TILL = $dateC + $v2["T"];
                 $f->W_TIME = $v2["T"] - $v2["F"];
                 $f->W_TIME_INC = $sum;
                 CTimeZone::Disable();
                 $DB->Insert($timetable_cache, $f->ToArray(CSupportTableFields::ALL, array(CSupportTableFields::NOT_NULL), true), $err_mess . __LINE__);
                 CTimeZone::Enable();
             }
             $dateC += 24 * 60 * 60;
         }
     }
     CTicketReminder::RecalculateSupportDeadline($arFilter);
 }