massive operations over events

This commit is contained in:
fbsanchez 2019-06-18 14:26:55 +02:00
parent 823581f398
commit 22272225b8
4 changed files with 103 additions and 33 deletions

View File

@ -109,7 +109,7 @@ if ($in_process_event) {
$id_evento = get_parameter('id_evento', 0);
// Check acl.
echo events_update_status($id_evento, EVENT_PROCESS, $filter);
var_dump(events_update_status($id_evento, EVENT_PROCESS, $filter));
return;
}

View File

@ -243,17 +243,36 @@ function events_delete($id_evento, $filter=null, $history=false)
true
);
$delete_sql = sprintf(
'DELETE tu FROM %s tu INNER JOIN ( %s ) tf
ON tu.estado = tf.estado
AND tu.evento = tf.evento
AND tu.id_agente = tf.id_agente
AND tu.id_agentmodule = tf.id_agentmodule
AND tf.max_id_evento = %d',
$table,
$sql,
$id_evento
$target_ids = db_get_all_rows_sql(
sprintf(
'SELECT tu.id_evento FROM %s tu INNER JOIN ( %s ) tf
ON tu.estado = tf.estado
AND tu.evento = tf.evento
AND tu.id_agente = tf.id_agente
AND tu.id_agentmodule = tf.id_agentmodule
AND tf.max_id_evento = %d',
$table,
$sql,
$id_evento
)
);
// Try to avoid deadlock while updating full set.
if ($target_ids !== false && count($target_ids) > 0) {
$target_ids = array_reduce(
$target_ids,
function ($carry, $item) {
$carry[] = $item['id_evento'];
return $carry;
}
);
$delete_sql = sprintf(
'DELETE FROM %s WHERE id_evento IN (%s)',
$table,
join(', ', $target_ids)
);
}
break;
}
@ -366,10 +385,12 @@ function events_update_status($id_evento, $status, $filter=null, $history=false)
global $config;
if (!$status) {
error_log('No hay estado');
return false;
}
if (!isset($id_evento) || $id_evento <= 0) {
error_log('No hay id_evento');
return false;
}
@ -413,23 +434,43 @@ function events_update_status($id_evento, $status, $filter=null, $history=false)
true
);
$update_sql = sprintf(
'UPDATE %s tu INNER JOIN ( %s ) tf
ON tu.estado = tf.estado
AND tu.evento = tf.evento
AND tu.id_agente = tf.id_agente
AND tu.id_agentmodule = tf.id_agentmodule
AND tf.max_id_evento = %d
SET tu.estado = %d,
tu.ack_utimestamp = %d,
tu.id_usuario = "%s"',
$table,
$sql,
$id_evento,
$status,
time(),
$config['id_user']
$target_ids = db_get_all_rows_sql(
sprintf(
'SELECT tu.id_evento FROM %s tu INNER JOIN ( %s ) tf
ON tu.estado = tf.estado
AND tu.evento = tf.evento
AND tu.id_agente = tf.id_agente
AND tu.id_agentmodule = tf.id_agentmodule
AND tf.max_id_evento = %d',
$table,
$sql,
$id_evento
)
);
// Try to avoid deadlock while updating full set.
if ($target_ids !== false && count($target_ids) > 0) {
$target_ids = array_reduce(
$target_ids,
function ($carry, $item) {
$carry[] = $item['id_evento'];
return $carry;
}
);
$update_sql = sprintf(
'UPDATE %s
SET estado = %d,
ack_utimestamp = %d,
id_usuario = "%s"
WHERE id_evento IN (%s)',
$table,
$status,
time(),
$config['id_user'],
join(',', $target_ids)
);
}
break;
}

View File

@ -710,6 +710,9 @@ function update_event(table, id_evento, type, row) {
.remove();
}
}
},
error: function() {
processed += 1;
}
});
}
@ -804,17 +807,30 @@ function execute_event_response(event_list_btn) {
switch (response_id) {
case "in_progress_selected":
$(".chk_val:checked").each(function() {
in_process_event(dt_events, $(this).val(), this.parentElement);
// Parent: TD. GrandParent: TR.
in_process_event(
dt_events,
$(this).val(),
this.parentElement.parentElement
);
});
break;
case "validate_selected":
$(".chk_val:checked").each(function() {
validate_event(dt_events, $(this).val(), this.parentElement);
validate_event(
dt_events,
$(this).val(),
this.parentElement.parentElement
);
});
break;
case "delete_selected":
$(".chk_val:checked").each(function() {
delete_event(dt_events, $(this).val(), this.parentElement);
delete_event(
dt_events,
$(this).val(),
this.parentElement.parentElement
);
});
break;
}

View File

@ -85,9 +85,9 @@ table.dataTable tbody td {
.info_table.events tr > th {
padding-left: 1em;
font-size: 1.3em;
font-weight: 400;
border-bottom: 2px solid #878787;
font-size: 8pt;
font-weight: 300;
border-bottom: 1px solid #878787;
cursor: pointer;
}
@ -315,3 +315,16 @@ div.multi-response-buttons {
width: 100%;
text-align: right;
}
div.criticity {
width: 150px;
height: 2em;
color: #fff;
text-align: center;
border-radius: 5px;
font-size: 0.8em;
padding: 5px;
margin: 0;
display: table-cell;
vertical-align: middle;
}