diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2021-07-22 14:09:46 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2021-07-22 15:52:12 +0200 |
commit | 261d490c4e8ad9b6cee46e82a8ad029eeaf6cd6b (patch) | |
tree | eef5c5974e3c33c26441da9b738b6e6d82fa5112 /src | |
parent | 33d8cecfe1ce64c517fe995875397b32e534bdb0 (diff) |
#1052 Populate session column when adding actions
If the scope of a command, procedure or task is related to a group of
computers then actions associated with that schedule can share the same
session value.
og_dbi_add_action was not initializing session value, as it is only used
for visualization purposes in the legacy web interface.
This patch enables og_dbi_add_action to populate session column by
assigning it the id value of the first action related to the scope.
Example: Power off command for a room scope of 4 clients will result in
4 actions, a power off for each client. The first action id will determine
the session value for the rest.
Diffstat (limited to 'src')
-rw-r--r-- | src/rest.c | 16 | ||||
-rw-r--r-- | src/schedule.h | 1 |
2 files changed, 14 insertions, 3 deletions
@@ -2666,7 +2666,7 @@ static int og_cmd_legacy(const char *input, struct og_cmd *cmd) return err; } -static int og_dbi_add_action(const struct og_dbi *dbi, const struct og_task *task, +static int og_dbi_add_action(const struct og_dbi *dbi, struct og_task *task, struct og_cmd *cmd) { char start_date_string[24]; @@ -2692,7 +2692,7 @@ static int og_dbi_add_action(const struct og_dbi *dbi, const struct og_task *tas "VALUES (%d, %d, %d, '%s', '%s', %d, %d, '%s', " "'%s', %d, %d, %d, %d, '%s', %d, %d, %d)", cmd->client_id, EJECUCION_TAREA, task->task_id, - "", cmd->ip, 0, task->command_id, + "", cmd->ip, task->session, task->command_id, task->params, start_date_string, ACCION_INICIADA, ACCION_SINRESULTADO, task->type_scope, task->scope, "", @@ -2704,13 +2704,23 @@ static int og_dbi_add_action(const struct og_dbi *dbi, const struct og_task *tas __func__, __LINE__, msglog); return -1; } + cmd->id = dbi_conn_sequence_last(dbi->conn, NULL); + if (!task->session) { + task->session = cmd->id; + dbi_result_free(result); + result = dbi_conn_queryf(dbi->conn, + "UPDATE acciones SET sesion=%d " + "WHERE idaccion=%d", + task->session, cmd->id); + } + dbi_result_free(result); return 0; } -static int og_queue_task_command(struct og_dbi *dbi, const struct og_task *task, +static int og_queue_task_command(struct og_dbi *dbi, struct og_task *task, char *query) { struct og_cmd *cmd; diff --git a/src/schedule.h b/src/schedule.h index 12c394c..69dbde9 100644 --- a/src/schedule.h +++ b/src/schedule.h @@ -55,6 +55,7 @@ struct og_task { uint32_t center_id; uint32_t schedule_id; uint32_t type_scope; + uint32_t session; uint32_t scope; const char *filtered_scope; const char *params; |