Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also consider tickets orphaned when reports are deleted (8.0) #700

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down
26 changes: 24 additions & 2 deletions src/manage_sql_tickets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}, \
Expand Down Expand Up @@ -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}, \
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1598,6 +1599,27 @@ 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);

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);
}

/**
* @brief Remove all of a user's tasks from all tickets.
*
Expand Down
3 changes: 3 additions & 0 deletions src/manage_sql_tickets.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ restore_ticket (const char *);
void
empty_trashcan_tickets ();

void
tickets_remove_report (report_t);

void
check_tickets ();

Expand Down