Пример #1
0
 function UnregisterExpiredAgent($id = false)
 {
     global $DB;
     $handledMembers = array();
     if ($id > 0) {
         $strAddWhere = 'AND M.ID = ' . intval($id);
     } else {
         $strAddWhere = '';
     }
     $strSql = "\n\t\t\tSELECT M.ID\n\t\t\tFROM b_controller_member M\n\t\t\tINNER JOIN b_controller_group G ON M.CONTROLLER_GROUP_ID = G.ID\n\t\t\tWHERE\n\t\t\t\tG.TRIAL_PERIOD > 0\n\t\t\t\tAND TO_DAYS(now()) - TO_DAYS(M.IN_GROUP_FROM) >= G.TRIAL_PERIOD\n\t\t\t\tAND SITE_ACTIVE = 'Y'\n\t\t\t\tAND DISCONNECTED = 'N'\n\t\t\t\t" . $strAddWhere . "\n\t\t";
     $dbr = $DB->Query($strSql);
     while ($ar = $dbr->Fetch()) {
         if ($id > 0) {
             CControllerMember::CloseMember($id, true);
             return true;
         } elseif (!isset($handledMembers[$ar["ID"]])) {
             $handledMembers[$ar["ID"]] = $ar["ID"];
             CControllerTask::Add(array("TASK_ID" => "CLOSE_MEMBER", "CONTROLLER_MEMBER_ID" => $ar["ID"], "INIT_EXECUTE_PARAMS" => true));
         }
     }
     $strSql = "\n\t\t\tSELECT M.ID\n\t\t\tFROM b_controller_member M\n\t\t\tWHERE\n\t\t\t\t(DATE_ACTIVE_FROM IS NULL OR DATE_ACTIVE_FROM <= " . $DB->CurrentTimeFunction() . ")\n\t\t\t\tAND (DATE_ACTIVE_TO IS NULL OR DATE_ACTIVE_TO >= " . $DB->CurrentTimeFunction() . ")\n\t\t\t\tAND ACTIVE = 'Y'\n\t\t\t\tAND SITE_ACTIVE <> 'Y'\n\t\t\t\tAND DISCONNECTED = 'N'\n\t\t\t\t" . $strAddWhere . "\n\t\t";
     $dbr = $DB->Query($strSql);
     while ($ar = $dbr->Fetch()) {
         if ($id > 0) {
             CControllerMember::CloseMember($id, false);
             return true;
         } elseif (!isset($handledMembers[$ar["ID"]])) {
             $handledMembers[$ar["ID"]] = $ar["ID"];
             CControllerTask::Add(array("TASK_ID" => "CLOSE_MEMBER", "CONTROLLER_MEMBER_ID" => $ar["ID"], "INIT_EXECUTE_PARAMS" => false));
         }
     }
     $strSql = "\n\t\t\tSELECT M.ID\n\t\t\tFROM b_controller_member M\n\t\t\tWHERE\n\t\t\t\t(\n\t\t\t\t\tDATE_ACTIVE_FROM > " . $DB->CurrentTimeFunction() . "\n\t\t\t\t\tOR DATE_ACTIVE_TO < " . $DB->CurrentTimeFunction() . "\n\t\t\t\t\tOR ACTIVE = 'N'\n\t\t\t\t)\n\t\t\t\tAND SITE_ACTIVE = 'Y'\n\t\t\t\tAND DISCONNECTED = 'N'\n\t\t\t\t" . $strAddWhere . "\n\t\t";
     $dbr = $DB->Query($strSql);
     while ($ar = $dbr->Fetch()) {
         if ($id > 0) {
             CControllerMember::CloseMember($id, true);
             return true;
         } elseif (!isset($handledMembers[$ar["ID"]])) {
             $handledMembers[$ar["ID"]] = $ar["ID"];
             CControllerTask::Add(array("TASK_ID" => "CLOSE_MEMBER", "CONTROLLER_MEMBER_ID" => $ar["ID"], "INIT_EXECUTE_PARAMS" => true));
         }
     }
     if ($id > 0) {
         return true;
     }
     return "CControllerMember::UnregisterExpiredAgent();";
 }
Пример #2
0
 function UnregisterExpiredAgent($id = false)
 {
     global $DB;
     if ($id > 0) {
         $strAddWhere = ' AND M.ID=' . IntVal($id);
     } else {
         $strAddWhere = '';
     }
     $strSql = "SELECT M.ID " . "FROM b_controller_member M  " . "   INNER JOIN b_controller_group G ON M.CONTROLLER_GROUP_ID=G.ID " . "WHERE G.TRIAL_PERIOD>0 " . "\tAND TO_DAYS(now()) - TO_DAYS(M.IN_GROUP_FROM) >= G.TRIAL_PERIOD  " . "\tAND SITE_ACTIVE = 'Y' " . $strAddWhere;
     $dbr = $DB->Query($strSql);
     while ($ar = $dbr->Fetch()) {
         if ($id > 0) {
             CControllerMember::CloseMember($id, true);
             return true;
         } else {
             CControllerTask::Add(array("TASK_ID" => "CLOSE_MEMBER", "CONTROLLER_MEMBER_ID" => $ar["ID"], "INIT_EXECUTE_PARAMS" => true));
         }
     }
     $strSql = "SELECT M.ID " . "FROM b_controller_member M " . "WHERE (DATE_ACTIVE_FROM IS NULL OR DATE_ACTIVE_FROM <= " . $DB->CurrentTimeFunction() . ") " . "\tAND (DATE_ACTIVE_TO IS NULL OR DATE_ACTIVE_TO >= " . $DB->CurrentTimeFunction() . ") " . "\tAND ACTIVE = 'Y' " . "\tAND SITE_ACTIVE <> 'Y'" . $strAddWhere;
     $dbr = $DB->Query($strSql);
     while ($ar = $dbr->Fetch()) {
         if ($id > 0) {
             CControllerMember::CloseMember($id, false);
             return true;
         } else {
             CControllerTask::Add(array("TASK_ID" => "CLOSE_MEMBER", "CONTROLLER_MEMBER_ID" => $ar["ID"], "INIT_EXECUTE_PARAMS" => false));
         }
     }
     $strSql = "SELECT M.ID " . "FROM b_controller_member M " . "WHERE (DATE_ACTIVE_FROM>" . $DB->CurrentTimeFunction() . " " . "\tOR DATE_ACTIVE_TO<" . $DB->CurrentTimeFunction() . " " . "\tOR ACTIVE = 'N') " . "\tAND SITE_ACTIVE = 'Y'" . $strAddWhere;
     $dbr = $DB->Query($strSql);
     while ($ar = $dbr->Fetch()) {
         if ($id > 0) {
             CControllerMember::CloseMember($id, true);
         } else {
             CControllerTask::Add(array("TASK_ID" => "CLOSE_MEMBER", "CONTROLLER_MEMBER_ID" => $ar["ID"], "INIT_EXECUTE_PARAMS" => true));
         }
     }
     if ($id > 0) {
         return true;
     }
     return "CControllerMember::UnregisterExpiredAgent();";
 }
Пример #3
0
 function ProcessTask($ID)
 {
     global $DB, $APPLICATION;
     $ID = IntVal($ID);
     $uniq = $APPLICATION->GetServerUniqID();
     $uniq = "X" . $uniq . "_ctask";
     $STATUS = "0";
     // locking the task
     if (!CControllerAgent::_Lock($uniq)) {
         AddMessage2Log('ERROR_GET_LOCK');
         return $STATUS;
     }
     // selecting task
     $strSql = "SELECT T.*, M.SHARED_KERNEL " . "FROM b_controller_task T LEFT JOIN b_controller_member M ON T.CONTROLLER_MEMBER_ID=M.ID " . "WHERE T.ID='" . $ID . "' AND T.STATUS<>'Y'";
     $db_task = $DB->Query($strSql);
     if ($ar_task = $db_task->Fetch()) {
         $arControllerLog = array('CONTROLLER_MEMBER_ID' => $ar_task["CONTROLLER_MEMBER_ID"], 'TASK_ID' => $ar_task['ID'], 'STATUS' => 'Y');
         $RESULT = '';
         $STATUS = 'Y';
         unset($INIT_EXECUTE_PARAMS);
         switch ($ar_task['TASK_ID']) {
             case 'SET_SETTINGS':
                 $arControllerLog['NAME'] = 'SET_SETTINGS';
                 $APPLICATION->ResetException();
                 $res = CControllerMember::SetGroupSettings($ar_task["CONTROLLER_MEMBER_ID"], $ar_task['ID']);
                 if ($res !== false) {
                     $RESULT = $res;
                 } else {
                     $e = $APPLICATION->GetException();
                     $STATUS = "F";
                     $RESULT = $e->GetString();
                     $arControllerLog['STATUS'] = 'N';
                 }
                 break;
             case 'CLOSE_MEMBER':
                 $arControllerLog['NAME'] = 'SITE_CLOSING';
                 $APPLICATION->ResetException();
                 $res = CControllerMember::CloseMember($ar_task["CONTROLLER_MEMBER_ID"], $ar_task['INIT_EXECUTE_PARAMS']);
                 if ($res !== false) {
                     $RESULT = $res;
                 } else {
                     $e = $APPLICATION->GetException();
                     $STATUS = "F";
                     $RESULT = $e->GetString();
                     $arControllerLog['STATUS'] = 'N';
                 }
                 break;
             case 'UPDATE':
                 $arControllerLog['NAME'] = 'SITE_UPDATE';
                 $APPLICATION->ResetException();
                 if ($ar_task["SHARED_KERNEL"] == "Y") {
                     $STATUS = "F";
                     $RESULT = GetMessage("CTRLR_TASK_ERR_KERNEL");
                     $arControllerLog['STATUS'] = 'N';
                 } else {
                     $command = 'require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/classes/general/update_client.php");';
                     if ($ar_task["STATUS"] == "P" && strlen($ar_task["INIT_EXECUTE_PARAMS"]) > 0) {
                         $command .= 'echo trim(CUpdateControllerSupport::Update("' . EscapePHPString($ar_task["INIT_EXECUTE_PARAMS"]) . '"));';
                     } else {
                         $command .= 'echo trim(CUpdateControllerSupport::Update(""));';
                     }
                     $res = CControllerMember::RunCommand($ar_task["CONTROLLER_MEMBER_ID"], $command, array(), $ar_task['ID']);
                     if ($res !== false) {
                         if (($p = strpos($res, "|")) > 0) {
                             $result_code = substr($res, 0, $p);
                             $RESULT = substr($res, $p + 1);
                         } else {
                             $result_code = $res;
                             $RESULT = $res;
                         }
                         if ($result_code == 'ERR') {
                             $STATUS = "F";
                             $arControllerLog['STATUS'] = 'N';
                         } elseif ($result_code == 'STP0') {
                             $STATUS = "P";
                         } elseif ($result_code != 'FIN') {
                             $STATUS = "P";
                             $INIT_EXECUTE_PARAMS = $result_code;
                         } else {
                             $RESULT = GetMessage("CTRLR_TASK_UPD_COMPL");
                         }
                     } else {
                         $STATUS = "F";
                         $e = $APPLICATION->GetException();
                         $RESULT = $e->GetString();
                         $arControllerLog['STATUS'] = 'N';
                     }
                 }
                 break;
             case 'COUNTERS_UPDATE':
                 $arControllerLog['NAME'] = 'UPDATE_COUNTERS';
                 $APPLICATION->ResetException();
                 $res = CControllerMember::UpdateCounters($ar_task["CONTROLLER_MEMBER_ID"], $ar_task['ID']);
                 $RESULT = '';
                 if ($res !== false) {
                     foreach ($res as $k => $v) {
                         $RESULT .= "{$k}={$v};\r\n";
                     }
                 } else {
                     $e = $APPLICATION->GetException();
                     $STATUS = "F";
                     $RESULT = $e->GetString();
                     $arControllerLog['STATUS'] = 'N';
                 }
                 break;
             case 'REMOTE_COMMAND':
                 $APPLICATION->ResetException();
                 $arControllerLog['NAME'] = 'REMOTE_COMMAND';
                 if (strlen($ar_task['INIT_EXECUTE_PARAMS']) > 0) {
                     $ar_task['INIT_EXECUTE_PARAMS'] = unserialize($ar_task['INIT_EXECUTE_PARAMS']);
                 } else {
                     $ar_task['INIT_EXECUTE_PARAMS'] = array();
                 }
                 $res = CControllerMember::RunCommand($ar_task["CONTROLLER_MEMBER_ID"], $ar_task['INIT_EXECUTE'], $ar_task['INIT_EXECUTE_PARAMS'], $ar_task['ID']);
                 if ($res !== false) {
                     $RESULT = $res;
                 } else {
                     $STATUS = "F";
                     $e = $APPLICATION->GetException();
                     $RESULT = $e->GetString();
                     $arControllerLog['STATUS'] = 'N';
                 }
                 break;
             case 'SEND_FILE':
                 $APPLICATION->ResetException();
                 $arControllerLog['NAME'] = 'SEND_FILE';
                 break;
         }
         if (!isset($arControllerLog['DESCRIPTION'])) {
             $arControllerLog['DESCRIPTION'] = $RESULT;
         }
         CControllerLog::Add($arControllerLog);
         // updating status
         $arUpdateFields = array("STATUS" => $STATUS, "~DATE_EXECUTE" => $DB->CurrentTimeFunction(), "RESULT_EXECUTE" => $RESULT, "INDEX_SALT" => rand());
         if (isset($INIT_EXECUTE_PARAMS)) {
             $arUpdateFields["INIT_EXECUTE_PARAMS"] = $INIT_EXECUTE_PARAMS;
         }
         $arUpdateBinds = array();
         $strUpdate = $DB->PrepareUpdateBind("b_controller_task", $arUpdateFields, "", false, $arUpdateBinds);
         $strSql = "UPDATE b_controller_task SET " . $strUpdate . " WHERE ID=" . $ID;
         $arBinds = array();
         foreach ($arUpdateBinds as $field_id) {
             $arBinds[$field_id] = $arUpdateFields[$field_id];
         }
         $DB->QueryBind($strSql, $arBinds);
     }
     // unlocking
     CControllerAgent::_UnLock($uniq);
     return $STATUS;
 }