Skip to content

Commit

Permalink
When deleting notes, delete associated attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Aug 25, 2019
1 parent db49939 commit e37437f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/bugnote_api.php
Expand Up @@ -34,6 +34,7 @@
* @uses email_api.php
* @uses error_api.php
* @uses event_api.php
* @uses file_api.php
* @uses helper_api.php
* @uses history_api.php
* @uses lang_api.php
Expand All @@ -53,6 +54,7 @@
require_api( 'email_api.php' );
require_api( 'error_api.php' );
require_api( 'event_api.php' );
require_api( 'file_api.php' );
require_api( 'helper_api.php' );
require_api( 'history_api.php' );
require_api( 'lang_api.php' );
Expand Down Expand Up @@ -371,6 +373,9 @@ function bugnote_delete( $p_bugnote_id ) {
# log deletion of bug
history_log_event_special( $t_bug_id, BUGNOTE_DELETED, bugnote_format_id( $p_bugnote_id ) );

# Delete attachments linked to bugnote in the db (i.e. bugnote_id is set)
file_delete_bugnote_attachments( $t_bug_id, $p_bugnote_id );

# Event integration
event_signal( 'EVENT_BUGNOTE_DELETED', array( $t_bug_id, $p_bugnote_id ) );

Expand Down
19 changes: 19 additions & 0 deletions core/file_api.php
Expand Up @@ -470,6 +470,25 @@ function file_delete_attachments( $p_bug_id ) {
return true;
}

/**
* Delete all files that are associated with the given bug note.
* @param integer $p_bug_id A bug identifier.
* @param integer $p_bugnote_id A bugnote identifier.
* @return boolean
*/
function file_delete_bugnote_attachments( $p_bug_id, $p_bugnote_id ) {
db_param_push();
$t_query = 'SELECT id, diskfile, filename FROM {bug_file} WHERE bug_id=' . db_param() . ' AND bugnote_id=' . db_param();
$t_result = db_query( $t_query, array( $p_bug_id, $p_bugnote_id ) );

while( $t_row = db_fetch_array( $t_result ) ) {
file_delete( (int)$t_row['id'] );
}

# db_query() errors on failure so:
return true;
}

/**
* Delete files by project
* @param integer $p_project_id A project identifier.
Expand Down

0 comments on commit e37437f

Please sign in to comment.