Skip to content

Commit

Permalink
Issue #11404: Record dropping of bug revisions in bug history
Browse files Browse the repository at this point in the history
When dropping bug revisions (bugnotes, description, steps to reproduce
and additional information) we should be recording this event in the bug
history. This maintains an audit log of who and at what time revision
data was permanently deleted.

This commit also fixes an issue whereby links in the history were still
shown for bug revisions that had been dropped. Users would thus click a
link to come across a 'revision not found' error message.
  • Loading branch information
davidhicks committed Jan 17, 2010
1 parent dac9d0a commit 14a00b7
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 16 deletions.
59 changes: 58 additions & 1 deletion core/bug_revision_api.php
Expand Up @@ -88,6 +88,24 @@ function bug_revision_add( $p_bug_id, $p_user_id, $p_type, $p_value, $p_bugnote_
return db_insert_id( $t_bug_rev_table );
}

/**
* Check if a bug revision exists
* @param int $p_revision_id Revision ID
* @return bool Whether or not the bug revision exists
*/
function bug_revision_exists( $p_revision_id ) {
$t_bug_rev_table = db_get_table( 'bug_revision' );

$t_query = "SELECT * FROM $t_bug_rev_table WHERE id=" . db_param();
$t_result = db_query_bound( $t_query, array( $p_revision_id ) );

if ( db_num_rows( $t_result ) < 1 ) {
return false;
}

return true;
}

/**
* Get a row of data for a given revision ID.
* @param int $p_revision_id Revision ID
Expand All @@ -106,6 +124,30 @@ function bug_revision_get( $p_revision_id ) {
return db_fetch_array( $t_result );
}

/**
* Get the name of the type of a bug revision.
* @param int $p_revision_id Revision type ID (see constant_inc.php for possible values)
* @return string Name of the type of the bug revision
*/
function bug_revision_get_type_name( $p_revision_type_id ) {
$t_type_name = '';
switch( $p_revision_type_id ) {
case REV_DESCRIPTION:
$t_type_name = lang_get( 'description' );
break;
case REV_STEPS_TO_REPRODUCE:
$t_type_name = lang_get( 'steps_to_reproduce' );
break;
case REV_ADDITIONAL_INFO:
$t_type_name = lang_get( 'additional_information' );
break;
case REV_BUGNOTE:
$t_type_name = lang_get( 'bugnote' );
break;
}
return $t_type_name;
}

/**
* Remove one or more bug revisions from the bug history.
* @param int $p_revision_id Revision ID, or array of revision IDs
Expand All @@ -115,19 +157,34 @@ function bug_revision_drop( $p_revision_id ) {
$t_bug_rev_table = db_get_table( 'bug_revision' );

if ( is_array( $p_revision_id ) ) {
$t_revisions = array();
$t_first = true;
$t_query = "DELETE FROM $t_bug_rev_table WHERE id IN ( ";

# TODO: Fetch bug revisions in one query (and cache them)
foreach( $p_revision_id as $t_rev_id ) {
$t_query .= ( $t_first ? db_param() : ', ' . db_param() );
$t_revisions[$t_rev_id] = bug_revision_get( $t_rev_id );
}

$t_query .= ' )';
db_query_bound( $t_query, $p_revision_id );

foreach( $p_revision_id as $t_rev_id ) {
if ( $t_revisions[$t_rev_id]['type'] == REV_BUGNOTE ) {
history_log_event_special( $t_revisions[$t_rev_id]['bug_id'], BUGNOTE_REVISION_DROPPED, bugnote_format_id( $t_rev_id ), $t_revisions[$t_rev_id]['bugnote_id'] );
} else {
history_log_event_special( $t_revisions[$t_rev_id]['bug_id'], BUG_REVISION_DROPPED, bugnote_format_id( $t_rev_id ), $t_revisions[$t_rev_id]['type'] );
}
}
} else {
$t_revision = bug_revision_get( $p_revision_id );
$t_query = "DELETE FROM $t_bug_rev_table WHERE id=" . db_param();
db_query_bound( $t_query, array( $p_revision_id ) );
if ( $t_revision['type'] == REV_BUGNOTE ) {
history_log_event_special( $t_revision['bug_id'], BUGNOTE_REVISION_DROPPED, bugnote_format_id( $p_revision_id ), $t_revision['bugnote_id'] );
} else {
history_log_event_special( $t_revision['bug_id'], BUG_REVISION_DROPPED, bugnote_format_id( $p_revision_id ), $t_revision['type'] );
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/constant_inc.php
Expand Up @@ -219,6 +219,8 @@
define( 'TAG_ATTACHED', 25 );
define( 'TAG_DETACHED', 26 );
define( 'TAG_RENAMED', 27 );
define( 'BUG_REVISION_DROPPED', 28 );
define( 'BUGNOTE_REVISION_DROPPED', 29 );
define( 'PLUGIN_HISTORY', 100 );

# bug revisions
Expand Down
33 changes: 18 additions & 15 deletions core/history_api.php
Expand Up @@ -26,6 +26,7 @@
* @uses access_api.php
* @uses authentication_api.php
* @uses bug_api.php
* @uses bug_revision_api.php
* @uses bugnote_api.php
* @uses columns_api.php
* @uses config_api.php
Expand All @@ -45,6 +46,7 @@
require_api( 'access_api.php' );
require_api( 'authentication_api.php' );
require_api( 'bug_api.php' );
require_api( 'bug_revision_api.php' );
require_api( 'bugnote_api.php' );
require_api( 'columns_api.php' );
require_api( 'config_api.php' );
Expand Down Expand Up @@ -435,47 +437,42 @@ function history_localize_item( $p_field_name, $p_type, $p_old_value, $p_new_val
break;
case BUGNOTE_ADDED:
$t_note = lang_get( 'bugnote_added' ) . ': ' . $p_old_value;
if ( $p_linkify && $p_new_value ) {
$t_change = '<a href="bug_revision_view_page.php?bugnote_id=' . $p_old_value . '#r' . $p_new_value . '">' .
lang_get( 'view_revisions' ) . '</a>';
$t_raw = false;
}
break;
case BUGNOTE_UPDATED:
$t_note = lang_get( 'bugnote_edited' ) . ': ' . $p_old_value;
if ( $p_linkify && $p_new_value ) {
$t_change = '<a href="bug_revision_view_page.php?bugnote_id=' . $p_old_value . '#r' . $p_new_value . '">' .
if ( $p_linkify && bug_revision_exists( $p_new_value ) ) {
if ( bugnote_exists( $p_old_value ) ) {
$t_bug_revision_view_page_argument = 'bugnote_id=' . $p_old_value . '#r' . $p_new_value;
} else {
$t_bug_revision_view_page_argument = 'rev_id=' . $p_new_value;
}
$t_change = '<a href="bug_revision_view_page.php?' . $t_bug_revision_view_page_argument . '">' .
lang_get( 'view_revisions' ) . '</a>';
$t_raw = false;
}
break;
case BUGNOTE_DELETED:
$t_note = lang_get( 'bugnote_deleted' ) . ': ' . $p_old_value;
if ( $p_linkify && $p_new_value ) {
$t_change = '<a href="bug_revision_view_page.php?bugnote_id=' . $p_old_value . '#r' . $p_new_value . '">' .
lang_get( 'view_revisions' ) . '</a>';
$t_raw = false;
}
break;
case DESCRIPTION_UPDATED:
$t_note = lang_get( 'description_updated' );
if ( $p_linkify && $p_old_value ) {
if ( $p_linkify && bug_revision_exists( $p_old_value ) ) {
$t_change = '<a href="bug_revision_view_page.php?rev_id=' . $p_old_value . '#r' . $p_old_value . '">' .
lang_get( 'view_revisions' ) . '</a>';
$t_raw = false;
}
break;
case ADDITIONAL_INFO_UPDATED:
$t_note = lang_get( 'additional_information_updated' );
if ( $p_linkify && $p_old_value ) {
if ( $p_linkify && bug_revision_exists( $p_old_value ) ) {
$t_change = '<a href="bug_revision_view_page.php?rev_id=' . $p_old_value . '#r' . $p_old_value . '">' .
lang_get( 'view_revisions' ) . '</a>';
$t_raw = false;
}
break;
case STEP_TO_REPRODUCE_UPDATED:
$t_note = lang_get( 'steps_to_reproduce_updated' );
if ( $p_linkify && $p_old_value ) {
if ( $p_linkify && bug_revision_exists( $p_old_value ) ) {
$t_change = '<a href="bug_revision_view_page.php?rev_id=' . $p_old_value . '#r' . $p_old_value . '">' .
lang_get( 'view_revisions' ) . '</a>';
$t_raw = false;
Expand Down Expand Up @@ -557,6 +554,12 @@ function history_localize_item( $p_field_name, $p_type, $p_old_value, $p_new_val
$t_note = lang_get( 'tag_history_renamed' );
$t_change = $p_old_value . ' => ' . $p_new_value;
break;
case BUG_REVISION_DROPPED:
$t_note = lang_get( 'bug_revision_dropped_history' ) . ': ' . bug_revision_get_type_name( $p_new_value ) . ': ' . $p_old_value;
break;
case BUGNOTE_REVISION_DROPPED:
$t_note = lang_get( 'bugnote_revision_dropped_history' ) . ': ' . $p_new_value . ': ' . $p_old_value;
break;
}
}

Expand Down
2 changes: 2 additions & 0 deletions lang/strings_english.txt
Expand Up @@ -657,6 +657,8 @@ $s_view_num_revisions = 'View %1$d revisions';
$s_revision = 'Revision';
$s_revision_by = '%1$s by %2$s';
$s_revision_drop = 'Drop';
$s_bug_revision_dropped_history = 'Bug Revision Dropped';
$s_bugnote_revision_dropped_history = 'Note Revision Dropped';
$s_all_revisions = 'All Revisions';
$s_back_to_issue = 'Back to Issue';
$s_confirm_revision_drop = 'Are you sure you want to drop this issue revision?';
Expand Down

0 comments on commit 14a00b7

Please sign in to comment.