From 90a894b7056f808a45f1d8c866dd99694ad32393 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Thu, 15 Aug 2019 11:50:17 +0200 Subject: [PATCH 1/5] Clear ticket report when the report is deleted --- src/manage_sql.c | 1 + src/manage_sql_tickets.c | 12 ++++++++++++ src/manage_sql_tickets.h | 3 +++ 3 files changed, 16 insertions(+) diff --git a/src/manage_sql.c b/src/manage_sql.c index 4a127a82d..f2ebff1d0 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -26907,6 +26907,7 @@ delete_report_internal (report_t report) permissions_set_orphans ("report", report, LOCATION_TABLE); tags_remove_resource ("report", report, LOCATION_TABLE); + tickets_remove_report (report); /* Update the task state. */ diff --git a/src/manage_sql_tickets.c b/src/manage_sql_tickets.c index ad37e89ad..09aa1ecdc 100644 --- a/src/manage_sql_tickets.c +++ b/src/manage_sql_tickets.c @@ -1598,6 +1598,18 @@ tickets_remove_task (task_t task) sql ("UPDATE tickets_trash SET task = -1 WHERE task = %llu;", task); } +/** + * @brief Remove a report from all tickets. + * + * @param[in] report Report. + */ +void +tickets_remove_report (report_t report) +{ + sql ("UPDATE tickets SET report = -1 WHERE report = %llu;", report); + sql ("UPDATE tickets_trash SET report = -1 WHERE report = %llu;", report); +} + /** * @brief Remove all of a user's tasks from all tickets. * diff --git a/src/manage_sql_tickets.h b/src/manage_sql_tickets.h index 67a5c7fb3..6e1658a3b 100644 --- a/src/manage_sql_tickets.h +++ b/src/manage_sql_tickets.h @@ -53,6 +53,9 @@ restore_ticket (const char *); void empty_trashcan_tickets (); +void +tickets_remove_report (report_t); + void check_tickets (); From 4136bb3059ac66c7da5a140b8d383c370dc9ca8d Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Thu, 15 Aug 2019 11:52:36 +0200 Subject: [PATCH 2/5] Include report in orphan check --- src/manage_sql_tickets.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manage_sql_tickets.c b/src/manage_sql_tickets.c index 09aa1ecdc..49129e33c 100644 --- a/src/manage_sql_tickets.c +++ b/src/manage_sql_tickets.c @@ -159,7 +159,7 @@ ticket_status_name (ticket_status_t status) {"closed_time", "closed", KEYWORD_TYPE_INTEGER}, \ {"iso_time (fix_verified_time)", NULL, KEYWORD_TYPE_STRING}, \ {"fix_verified_time", "fix_verified", KEYWORD_TYPE_INTEGER}, \ - {"(task = -1)", \ + {"(task = -1 OR report = -1)", \ "orphan", \ KEYWORD_TYPE_INTEGER}, \ {"open_note", NULL, KEYWORD_TYPE_STRING}, \ @@ -209,7 +209,7 @@ ticket_status_name (ticket_status_t status) {"closed_time", "closed", KEYWORD_TYPE_INTEGER}, \ {"iso_time (fix_verified_time)", NULL, KEYWORD_TYPE_STRING}, \ {"fix_verified_time", "fix_verified", KEYWORD_TYPE_INTEGER}, \ - {"(task = -1)", \ + {"(task = -1 OR report = -1)", \ "orphan", \ KEYWORD_TYPE_INTEGER}, \ {"open_note", NULL, KEYWORD_TYPE_STRING}, \ From cba4b7e2a496b1e92818f630864a85458eef4860 Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Thu, 15 Aug 2019 11:53:59 +0200 Subject: [PATCH 3/5] Clear ticket_results references when deleting report --- src/manage_sql_tickets.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/manage_sql_tickets.c b/src/manage_sql_tickets.c index 49129e33c..016a88f60 100644 --- a/src/manage_sql_tickets.c +++ b/src/manage_sql_tickets.c @@ -1608,6 +1608,15 @@ tickets_remove_report (report_t report) { sql ("UPDATE tickets SET report = -1 WHERE report = %llu;", report); sql ("UPDATE tickets_trash SET report = -1 WHERE report = %llu;", report); + + sql ("UPDATE ticket_results" + " SET report = -1, result = -1" + " WHERE report = %llu;", + report); + sql ("UPDATE ticket_results_trash" + " SET report = -1, result = -1" + " WHERE report = %llu;", + report); } /** From 93ec03ab8c9787ff3285daf942ad62b4d3acf3dd Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Thu, 15 Aug 2019 11:55:42 +0200 Subject: [PATCH 4/5] Exclude deleted results when getting ticket results --- src/manage_sql_tickets.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/manage_sql_tickets.c b/src/manage_sql_tickets.c index 016a88f60..0cb63cebf 100644 --- a/src/manage_sql_tickets.c +++ b/src/manage_sql_tickets.c @@ -509,6 +509,7 @@ init_ticket_result_iterator (iterator_t *iterator, " result_uuid" " FROM ticket_results%s" " WHERE ticket = %llu" + " AND report > 0" " ORDER BY id;", trash ? "_trash" : "", ticket); From 8bccf88198821a319ccf5be2c569c5b10dc01cde Mon Sep 17 00:00:00 2001 From: Matt Mundell Date: Thu, 15 Aug 2019 12:13:47 +0200 Subject: [PATCH 5/5] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a2dcd7d7..7c4f5e905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,7 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix GET_SYSTEM_REPORTS using slave_id [#667](https://github.com/greenbone/gvmd/pull/667) - Fix RAW_DATA when calling GET_INFO with type NVT without attributes name or info_id [#682](https://github.com/greenbone/gvmd/pull/682) - Fix assignment of orphaned tickets to the current user [#686](https://github.com/greenbone/gvmd/pull/686) -- Fix ORPHAN calculation in GET_TICKETS [#687](https://github.com/greenbone/gvmd/pull/687) +- Fix ORPHAN calculations in GET_TICKETS [#687](https://github.com/greenbone/gvmd/pull/687) [#700](https://github.com/greenbone/gvmd/pull/700) ### Removed