コード例 #1
0
function tool_main_add_restart_notification($sequence_id, $service_su, $service_egs, $shard_id, $sorbot_message_type, $sql_connection, $shard_lang = 'en')
{
    nt_common_add_debug('tool_main_add_restart_notification()');
    if ($sql_connection != '') {
        $csdb = new sql_db_string($sql_connection);
        if (is_object($csdb)) {
            $sequence_info = tool_main_get_restart_sequence_by_id($sequence_id);
            $shard_info = tool_main_get_domain_shard_data($sequence_info['restart_sequence_domain_id'], $sequence_info['restart_sequence_shard_id']);
            if ($sorbot_message_type == 4102) {
                //$open_timer	= 60*25; // 25 minutes before a shard opens itself
                // new timer
                $open_timer = 60 * 10;
                // 10 minutes before a shard opens itself
            } else {
                $open_timer = 0;
            }
            if ($sequence_info && $shard_info) {
                // lets find the shard id used by the ticket system
                $sql = "SELECT * FROM ForumCS_tickets_shards WHERE shard_ca='" . $shard_info['domain_application'] . "' AND shard_id='" . $shard_id . "'";
                if ($result = $csdb->sql_query($sql)) {
                    if ($csdb->sql_numrows($result)) {
                        $ticketsystem_shard_info = $csdb->sql_fetchrow($result);
                        nt_common_add_debug($ticketsystem_shard_info);
                        $ticketsystem_shard_id = $ticketsystem_shard_info['id'];
                        // now we have the shard id, lets see which klients servers wants events for it
                        $sql = "SELECT * FROM Sorbot_botconfig WHERE config_name='shardRestart' AND config_value LIKE '%:" . $ticketsystem_shard_id . ":%'";
                        if ($result2 = $csdb->sql_query($sql)) {
                            if ($csdb->sql_numrows($result2)) {
                                //$klients_servers = array();
                                //while ($row = $csdb->sql_fetchrow($result2))
                                //{
                                //	$klients_servers[] = $row['server_name'];
                                //}
                                // NOTE: live but not in CVS yet !
                                $local_timer = $open_timer;
                                $klients_servers = array();
                                while ($row = $csdb->sql_fetchrow($result2)) {
                                    $klients_servers[] = $row['server_name'];
                                    // lets find if there is any specific opening timer, and keep the lowest one
                                    $sql = "SELECT * FROM Sorbot_botconfig WHERE server_name='" . $row['server_name'] . "' AND config_name='shardRestartOpenTimer'";
                                    if ($result3 = $csdb->sql_query($sql)) {
                                        if ($csdb->sql_numrows($result3)) {
                                            $timer_row = $csdb->sql_fetchrow($result3);
                                            if ($timer_row['config_value'] < $local_timer) {
                                                $local_timer = $timer_row['config_value'];
                                            }
                                        }
                                    }
                                }
                                $open_timer = $local_timer;
                                // END NOTE: live but not in CVS yet !
                                // ok now we the list of servers that want this event, lets give it to them
                                // lets build some messages
                                $klients_countdown = '';
                                tool_main_get_elapsed_time_string($sequence_info['restart_sequence_timer'] - $sequence_info['restart_sequence_date_end'], $klients_countdown);
                                $klients_countdown = trim($klients_countdown);
                                $klients_open_countdown = '';
                                tool_main_get_elapsed_time_string($open_timer, $klients_open_countdown);
                                $klients_open_countdown = trim($klients_open_countdown);
                                $opening_message = tool_admin_restart_messages_get_list_from_name('opening', $shard_lang);
                                $opening_message = $opening_message[0]['restart_message_value'];
                                $opened_message = tool_admin_restart_messages_get_list_from_name('opened', $shard_lang);
                                $opened_message = $opening_message[0]['restart_message_value'];
                                $klients_messages = array('before' => array(".topic Shard Maintenance in progress for '" . $ticketsystem_shard_info['shard_name'] . "' - Shard LOCKED - (" . date("r", $sequence_info['restart_sequence_date_start']) . " - Countdown set to " . $klients_countdown . ")", "[Shard Maintenance] A Shard Restart has been triggered for shard '" . $ticketsystem_shard_info['shard_name'] . "' on " . date("r", $sequence_info['restart_sequence_date_start']), "[Shard Maintenance] Shard is LOCKED and should go down in " . $klients_countdown), 'at' => array(".topic Shard Maintenance in progress for '" . $ticketsystem_shard_info['shard_name'] . "' - Shard DOWN - (" . date("r", $sequence_info['restart_sequence_date_start']) . ")", "[Shard Maintenance] A Shard Restart has been triggered for shard '" . $ticketsystem_shard_info['shard_name'] . "' on " . date("r", $sequence_info['restart_sequence_date_start']), "[Shard Maintenance] Shard is DOWN after a countdown of " . $klients_countdown), 'over' => array(".topic Shard Maintenance in finished for '" . $ticketsystem_shard_info['shard_name'] . "' - Shard LOCKED - Ready for CSRs ! ETA : |EventETA| - To Open : .sorOpenShard |EventID| 0", "[Shard Maintenance] The Shard Restart that has been triggered for shard '" . $ticketsystem_shard_info['shard_name'] . "' on " . date("r", $sequence_info['restart_sequence_date_start']) . " is now finished !", "[Shard Maintenance] Shard is LOCKED and Ready for CSRs, it will OPEN automatically in |EventTIME| !", "[Shard Maintenance] To change the OPEN countdown,  you need to send me the command : .sorOpenShard |EventID| <seconds>", "[Shard Maintenance] Example to OPEN the Shard now, you need to send me the command : .sorOpenShard |EventID| 0"), 'open' => array(".topic Shard Maintenance over for '" . $ticketsystem_shard_info['shard_name'] . "' - Shard OPEN ", "[Shard Maintenance] The shard '" . $ticketsystem_shard_info['shard_name'] . "' should now be OPEN to all !"), 'cancel' => array(".topic Shard Maintenance has been cancelled for '" . $ticketsystem_shard_info['shard_name'] . "' - Shard OPEN", "[Shard Maintenance] The shard restart has been CANCELLED for '" . $ticketsystem_shard_info['shard_name'] . "', the shard is OPEN again !"), 'giveup' => array(".topic Shard Maintenance for '" . $ticketsystem_shard_info['shard_name'] . "' is on hold for technical issues - Shard DOWN", "[Shard Maintenance] The shard restart has been set ON HOLD for technical issues !"), 'opening' => $opening_message, 'opened' => $opened_message);
                                $notification_info = array('sequence' => $sequence_info, 'ts' => $ticketsystem_shard_info, 'messages' => $klients_messages, 'shard' => $shard_info, 'opentimer' => $open_timer, 'shardid' => $shard_id, 'shardsu' => $service_su, 'shardegs' => $service_egs);
                                $notification_data = base64_encode(serialize($notification_info));
                                $event_insert_ids = array();
                                $sql = "LOCK TABLES Sorbot_events WRITE";
                                $csdb->sql_query($sql);
                                reset($klients_servers);
                                foreach ($klients_servers as $klient_server) {
                                    $sql = "INSERT INTO Sorbot_events (`server_name`,`event_action`,`event_time`,`event_lap`,`event_params`) ";
                                    $sql .= " VALUES ('" . $klient_server . "'," . $sorbot_message_type . "," . time() . "," . $open_timer . ",'" . $notification_data . "')";
                                    $csdb->sql_query($sql);
                                    $event_insert_ids[] = $csdb->sql_nextid();
                                }
                                // we have a list of all the events, lets save them somewhere
                                // lets inform each events of all other events for the same sequence
                                if (sizeof($event_insert_ids)) {
                                    $notification_info['eventlist'] = array_values($event_insert_ids);
                                    $notification_data = base64_encode(serialize($notification_info));
                                    $sql = "UPDATE Sorbot_events SET event_params='" . $notification_data . "' WHERE event_id IN (" . implode(',', array_values($event_insert_ids)) . ")";
                                    $csdb->sql_query($sql);
                                    // save the events locally too
                                    tool_main_set_restart_sequence_events($sequence_id, implode(',', array_values($event_insert_ids)));
                                }
                                $sql = "UNLOCK TABLES";
                                $csdb->sql_query($sql);
                            } else {
                                nt_common_add_debug('no klients server found wanting to hear about this event');
                            }
                        }
                    } else {
                        nt_common_add_debug('no shard found in TS matching the application and shard id');
                    }
                } else {
                    nt_common_add_debug('query failed ?!');
                }
            } else {
                nt_common_add_debug('missing some information about the sequence ?!');
            }
            $csdb->sql_close();
        } else {
            nt_common_add_debug('failed to init db!');
        }
    } else {
        nt_common_add_debug('no db string to work with');
    }
}
コード例 #2
0
ファイル: index.php プロジェクト: cls1991/ryzomcore
     if ($tool_seq_id == $tool_restart_info['restart_sequence_id']) {
         $tool_restart_info = tool_main_set_next_restart_sequence_step($tool_seq_id, $tool_seq_step + 1);
         $tpl->assign('tool_restart_info', $tool_restart_info);
     }
 } elseif (isset($NELTOOL['POST_VARS']['restart_giveup'])) {
     // update klients events to giveup mode
     //$klients_events = explode(',',$tool_restart_info['restart_sequence_events']);
     //tool_main_change_restart_notification($klients_events, 4105, $AS_CsSQL);
     tool_main_add_restart_notification($tool_seq_id, $service_su, $service_egs, $restart_shard_id, 4105, $AS_CsSQL, $AS_ShardLang);
     tool_main_set_end_restart_sequence($tool_seq_id);
     nt_common_redirect('index.php');
     exit;
 } elseif (isset($NELTOOL['POST_VARS']['restart_cancel'])) {
     if ($restart_ws_state != 'open') {
         // - broadcast a message on the shard
         $restart_reboot_message_data = tool_admin_restart_messages_get_list_from_name('cancel', $AS_ShardLang);
         if (sizeof($restart_reboot_message_data)) {
             $restart_reboot_message = $restart_reboot_message_data[0]['restart_message_value'];
             if ($restart_reboot_message != '') {
                 $service_command = "broadcast " . $restart_reboot_message;
                 nt_log("Domain '{$AS_Name}' : '{$service_command}' on " . $service_egs);
                 nt_common_add_debug("about to run command '{$service_command}' on '{$service_egs}' ...");
                 $adminService->serviceCmd($service_egs, $service_command);
                 if (!$adminService->waitCallback()) {
                     nt_common_add_debug('Error while waiting for callback on service \'' . $service_egs . '\' for command : ' . $service_command);
                 }
                 $tpl->clear_assign('tool_execute_result');
             }
         }
         // update the klients events to cancelled mode
         $klients_events = explode(',', $tool_restart_info['restart_sequence_events']);