function tool_main_set_lock_shard($domain_id, $shard_id, $log = true)
{
    global $db;
    global $nel_user;
    global $AS_Name, $AS_ShardName;
    // we need to check if the shard is *all*
    // if its the case, we go for a lock domain instead
    $sql = "SELECT * FROM " . NELDB_SHARD_TABLE . " WHERE shard_id=" . $shard_id;
    if ($result = $db->sql_query($sql)) {
        if ($db->sql_numrows($result)) {
            $shard_row = $db->sql_fetchrow($result);
            if ($shard_row['shard_as_id'] == "*") {
                return tool_main_set_lock_domain($domain_id, $log);
            }
        }
    }
    $data = tool_main_get_lock($domain_id, $shard_id);
    $now = time();
    if (is_array($data) && $data['lock_shard_id'] > 0) {
        if ($log) {
            nt_log("Shard Lock (Domain: '" . $AS_Name . "' - Shard: '" . $AS_ShardName . "') by '" . $nel_user['user_name'] . "'");
        }
        $sql = "UPDATE " . NELDB_LOCK_TABLE . " SET lock_user_name='" . $nel_user['user_name'] . "',lock_update=" . $now . " WHERE lock_id=" . $data['lock_id'];
        $db->sql_query($sql);
    } elseif (!$data) {
        if ($log) {
            nt_log("Shard Lock (Domain: '" . $AS_Name . "' - Shard: '" . $AS_ShardName . "') by '" . $nel_user['user_name'] . "'");
        }
        $sql = "INSERT INTO " . NELDB_LOCK_TABLE . " (`lock_shard_id`,`lock_user_name`,`lock_date`,`lock_update`) VALUES (" . $shard_id . ",'" . $nel_user['user_name'] . "'," . $now . "," . $now . ")";
        $db->sql_query($sql);
    }
}
Exemple #2
0
if (tool_admin_applications_check('tool_main_lock_shard') || tool_admin_applications_check('tool_main_lock_domain')) {
    if (isset($NELTOOL['POST_VARS']['lock'])) {
        $tool_lock_mode = $NELTOOL['POST_VARS']['lock'];
        switch ($tool_lock_mode) {
            case 'lock shard':
                if (tool_admin_applications_check('tool_main_lock_shard')) {
                    tool_main_set_lock_shard($view_domain_id, $view_shard_id);
                    $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
                    if ($AS_ShardRestart > 0) {
                        tool_main_set_restart_sequence_user($AS_ShardRestart);
                    }
                }
                break;
            case 'lock domain':
                if (tool_admin_applications_check('tool_main_lock_domain')) {
                    tool_main_set_lock_domain($view_domain_id);
                    $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
                }
                break;
            case 'unlock shard':
                if (is_array($tool_lock_info) && $tool_lock_info['lock_user_name'] == $nel_user['user_name']) {
                    tool_main_delete_lock_shard($view_shard_id);
                    $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
                }
                break;
            case 'unlock domain':
                if (is_array($tool_lock_info) && $tool_lock_info['lock_user_name'] == $nel_user['user_name']) {
                    tool_main_delete_lock_domain($view_domain_id);
                    $tool_lock_info = tool_main_get_lock($view_domain_id, $view_shard_id);
                }
                break;