Skip to content

Commit

Permalink
Link attachments to note id when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Aug 25, 2019
1 parent af44213 commit 255dfdf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
7 changes: 4 additions & 3 deletions core/commands/IssueNoteAddCommand.php
Expand Up @@ -242,9 +242,6 @@ protected function process() {
$g_project_override = $this->issue->project_id;
}

# Handle the file upload
$t_file_infos = file_attach_files( $this->issue->id, $this->files );

# We always set the note time to BUGNOTE, and the API will overwrite it with TIME_TRACKING
# if time tracking is not 0 and the time tracking feature is enabled.
$t_note_id = bugnote_add(
Expand All @@ -256,10 +253,14 @@ protected function process() {
/* attr */ '',
/* user_id */ $this->reporterId,
/* send_email */ false );

if( !$t_note_id ) {
throw new ClientException( "Unable to add note", ERROR_GENERIC );
}

# Handle the file upload
$t_file_infos = file_attach_files( $this->issue->id, $this->files, $t_note_id );

# Process the mentions in the added note
$t_user_ids_that_got_mention_notifications = bugnote_process_mentions( $this->issue->id, $t_note_id, $this->payload( 'text' ) );

Expand Down
21 changes: 18 additions & 3 deletions core/file_api.php
Expand Up @@ -60,17 +60,28 @@
*
* @param int $p_bug_id The bug id.
* @param array $p_files The array of files, if null, then do nothing.
* @param int $p_bugnote_id The bugnote id, or 0 if issue attachments.
* @return array Array of file info arrays.
*/
function file_attach_files( $p_bug_id, $p_files ) {
function file_attach_files( $p_bug_id, $p_files, $p_bugnote_id = 0 ) {
if( $p_files === null || count( $p_files ) == 0 ) {
return array();
}

$t_file_infos = array();
foreach( $p_files as $t_file ) {
if( !empty( $t_file['name'] ) ) {
$t_file_infos[] = file_add( $p_bug_id, $t_file, 'bug' );
# $p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null, $p_date_added = 0, $p_skip_bug_update = false, $p_bugnote_id = 0
$t_file_infos[] = file_add(
$p_bug_id,
$t_file,
'bug',
'', /* title */
'', /* desc */
0, /* user_id */
0, /* date_added */
0, /* skip_bug_update */
$p_bugnote_id );
}
}

Expand Down Expand Up @@ -687,9 +698,10 @@ function file_is_name_unique( $p_name, $p_bug_id, $p_table = 'bug' ) {
* @param integer $p_user_id User id (defaults to current user).
* @param integer $p_date_added Date added.
* @param boolean $p_skip_bug_update Skip bug last modification update (useful when importing bug attachments).
* @param int $p_bugnote_id The bugnote id or 0 if associated with the issue.
* @return array The file info array (keys: name, size)
*/
function file_add( $p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null, $p_date_added = 0, $p_skip_bug_update = false ) {
function file_add( $p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null, $p_date_added = 0, $p_skip_bug_update = false, $p_bugnote_id = 0 ) {
$t_file_info = array();

if( !isset( $p_file['error'] ) ) {
Expand Down Expand Up @@ -839,11 +851,14 @@ function file_add( $p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p
'file_type' => $p_file['type'],
'date_added' => $p_date_added,
'user_id' => (int)$p_user_id,
'bugnote_id' => (int)$p_bugnote_id
);

# Oracle has to update BLOBs separately
if( !db_is_oracle() ) {
$t_param['content'] = $c_content;
}

$t_query_param = db_param();
for( $i = 1; $i < count( $t_param ); $i++ ) {
$t_query_param .= ', ' . db_param();
Expand Down

0 comments on commit 255dfdf

Please sign in to comment.