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

Added a new modification_time column to reports #1513

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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ include (CPack)

## Variables

set (GVMD_DATABASE_VERSION 243)
set (GVMD_DATABASE_VERSION 244)

set (GVMD_SCAP_DATABASE_VERSION 18)

Expand Down
1 change: 1 addition & 0 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions src/manage_migrators.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}};

Expand Down
35 changes: 30 additions & 5 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 }, \
Expand Down Expand Up @@ -23662,14 +23662,31 @@ 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 ())
report_cache_counts (report, 0, 0, NULL);
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.
*
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down