diff --git a/CHANGELOG.md b/CHANGELOG.md index f5d38dcf8..252b0ce73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [21.10] (unreleased) ### Added +- Add a new modification_time column to reports [#1513](https://github.com/greenbone/gvmd/pull/1513) ### Changed - Use pg-gvm extension for C PostgreSQL functions [#1400](https://github.com/greenbone/gvmd/pull/1400), [#1453](https://github.com/greenbone/gvmd/pull/1453) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e67f6ccc..3530a951b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ include (CPack) ## Variables -set (GVMD_DATABASE_VERSION 243) +set (GVMD_DATABASE_VERSION 244) set (GVMD_SCAP_DATABASE_VERSION 18) diff --git a/src/manage.c b/src/manage.c index ececa199f..42f60b55f 100644 --- a/src/manage.c +++ b/src/manage.c @@ -3113,6 +3113,7 @@ cve_scan_host (task_t task, report_t report, gvm_host_t *gvm_host) report_host_set_end_time (prognosis_report_host, time (NULL)); insert_report_host_detail (report, ip, "cve", "", "CVE Scanner", "CVE Scan", "1"); + update_report_modification_time (report); } } cleanup_iterator (&report_hosts); diff --git a/src/manage_migrators.c b/src/manage_migrators.c index 459169bb2..b984b9895 100644 --- a/src/manage_migrators.c +++ b/src/manage_migrators.c @@ -2682,6 +2682,37 @@ migrate_242_to_243 () return 0; } +/** + * @brief Migrate the database from version 243 to version 244. + * + * @return 0 success, -1 error. + */ +int +migrate_243_to_244 () +{ + sql_begin_immediate (); + + /* Ensure that the database is currently version 243. */ + + if (manage_db_version () != 243) + { + sql_rollback (); + return -1; + } + + /* Update the database. */ + + sql ("ALTER TABLE reports ADD COLUMN modification_time integer;"); + sql ("UPDATE reports SET modification_time = end_time;"); + + /* Set the database version to 244. */ + + set_db_version (244); + + sql_commit (); + + return 0; +} #undef UPDATE_DASHBOARD_SETTINGS @@ -2733,6 +2764,7 @@ static migrator_t database_migrators[] = { {241, migrate_240_to_241}, {242, migrate_241_to_242}, {243, migrate_242_to_243}, + {244, migrate_243_to_244}, /* End marker. */ {-1, NULL}}; diff --git a/src/manage_sql.c b/src/manage_sql.c index 169cdf7bd..b1cba6752 100644 --- a/src/manage_sql.c +++ b/src/manage_sql.c @@ -12022,13 +12022,13 @@ generate_report_filename (report_t report, report_format_t report_format, report_id = report_uuid (report); creation_time - = sql_string ("SELECT iso_time (start_time)" + = sql_string ("SELECT iso_time (date)" " FROM reports" " WHERE id = %llu", report); modification_time - = sql_string ("SELECT iso_time (end_time)" + = sql_string ("SELECT iso_time (modification_time)" " FROM reports" " WHERE id = %llu", report); @@ -20941,9 +20941,9 @@ report_add_result (report_t report, result_t result) { "iso_time (date)", "name", KEYWORD_TYPE_STRING }, \ { "''", NULL, KEYWORD_TYPE_STRING }, \ { "iso_time (date)", NULL, KEYWORD_TYPE_STRING }, \ - { "iso_time (end_time)", NULL, KEYWORD_TYPE_STRING }, \ + { "iso_time (modification_time)", NULL, KEYWORD_TYPE_STRING }, \ { "date", "created", KEYWORD_TYPE_INTEGER }, \ - { "end_time", "modified", KEYWORD_TYPE_INTEGER }, \ + { "modification_time", "modified", KEYWORD_TYPE_INTEGER }, \ { "(SELECT name FROM users WHERE users.id = reports.owner)", \ "_owner", \ KEYWORD_TYPE_STRING }, \ @@ -23662,7 +23662,8 @@ report_scan_run_status (report_t report, task_status_t* status) int set_report_scan_run_status (report_t report, task_status_t status) { - sql ("UPDATE reports SET scan_run_status = %u WHERE id = %llu;", + sql ("UPDATE reports SET scan_run_status = %u," + " modification_time = m_now() WHERE id = %llu;", status, report); if (setting_auto_cache_rebuild_int ()) @@ -23670,6 +23671,22 @@ set_report_scan_run_status (report_t report, task_status_t status) return 0; } +/** + * @brief Update modification_time of a report to current time. + * + * @param[in] report Report. + * + * @return 0. + */ +int +update_report_modification_time (report_t report) +{ + sql("UPDATE reports SET modification_time = m_now() WHERE id = %llu;", + report); + + return 0; +} + /** * @brief Get the result severity counts for a report. * @@ -28640,6 +28657,7 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) const char *str; char *defs_file = NULL; time_t start_time, end_time; + gboolean has_results = FALSE; assert (task); assert (report); @@ -28677,6 +28695,9 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) goto end_parse_osp_report; } results = child->entities; + if (results) + has_results = TRUE; + defs_file = task_definitions_file (task); while (results) { @@ -28784,6 +28805,10 @@ parse_osp_report (task_t task, report_t report, const char *report_xml) results = next_entities (results); } + if (has_results) + sql ("UPDATE reports SET modification_time = m_now() WHERE id = %llu;", + report); + end_parse_osp_report: sql_commit (); g_free (defs_file); diff --git a/src/manage_sql.h b/src/manage_sql.h index a0688d0cc..4f1d66636 100644 --- a/src/manage_sql.h +++ b/src/manage_sql.h @@ -296,6 +296,8 @@ int delete_report_internal (report_t); int set_report_scan_run_status (report_t, task_status_t); +int update_report_modification_time (report_t); + int set_report_slave_progress (report_t, int); void init_task_file_iterator (iterator_t *, task_t, const char *);