From 6ef67892ba907cffb9d0190e8e4c100401ce4610 Mon Sep 17 00:00:00 2001 From: Wojciech Matusiak Date: Fri, 8 Jun 2012 02:21:03 +0200 Subject: [PATCH] Fixed #0009936: add history information - reapply code on 1.2.x --- api/soap/mantisconnect.php | 33 ++++++++++++++++++++++++++++++- api/soap/mc_issue_api.php | 47 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/api/soap/mantisconnect.php b/api/soap/mantisconnect.php index 819dced..86ae370 100644 --- a/api/soap/mantisconnect.php +++ b/api/soap/mantisconnect.php @@ -241,6 +241,36 @@ $l_oServer->wsdl->addComplexType( 'tns:IssueNoteData' ); +### HistoryData +$l_oServer->wsdl->addComplexType( + 'HistoryData', + 'complexType', + 'struct', + 'all', + '', + array( + 'date_modified' => array( 'name' => 'date_modified', 'type' => 'xsd:dateTime'), + 'username' => array( 'name' => 'username', 'type' => 'xsd:string'), + 'field' => array( 'name' => 'field', 'type' => 'xsd:string'), + 'change' => array( 'name' => 'change', 'type' => 'xsd:string'), + ) +); + +### HistoryDataArray +$l_oServer->wsdl->addComplexType( + 'HistoryDataArray', + 'complexType', + 'array', + '', + 'SOAP-ENC:Array', + array(), + array(array( + 'ref' => 'SOAP-ENC:arrayType', + 'wsdl:arrayType' => 'tns:HistoryData[]' + )), + 'tns:HistoryData' +); + ### IssueData $l_oServer->wsdl->addComplexType( 'IssueData', @@ -290,7 +320,8 @@ $l_oServer->wsdl->addComplexType( 'due_date' => array( 'name' => 'due_date', 'type' => 'xsd:dateTime', 'minOccurs' => '0' ), 'monitors' => array( 'name' => 'monitors', 'type' => 'tns:AccountDataArray', 'minOccurs' => '0'), 'sticky' => array( 'name' => 'sticky', 'type' => 'xsd:boolean', 'minOccurs' => '0'), - 'tags' => array( 'name' => 'tags', 'type' => 'tns:ObjectRefArray', 'minOccurs' => '0') + 'tags' => array( 'name' => 'tags', 'type' => 'tns:ObjectRefArray', 'minOccurs' => '0'), + 'histories' => array( 'name' => 'histories', 'type' => 'tns:HistoryDataArray', 'minOccurs' => '0' ) ) ); diff --git a/api/soap/mc_issue_api.php b/api/soap/mc_issue_api.php index 251b12d..3b51885 100644 --- a/api/soap/mc_issue_api.php +++ b/api/soap/mc_issue_api.php @@ -112,6 +112,7 @@ function mc_issue_get( $p_username, $p_password, $p_issue_id ) { $t_issue_data['relationships'] = mci_issue_get_relationships( $p_issue_id, $t_user_id ); $t_issue_data['notes'] = mci_issue_get_notes( $p_issue_id ); $t_issue_data['custom_fields'] = mci_issue_get_custom_fields( $p_issue_id ); + $t_issue_data['histories'] = mci_issue_get_histories( $p_issue_id ); $t_issue_data['monitors'] = mci_account_get_array_by_ids( bug_get_monitors ( $p_issue_id ) ); $t_issue_data['tags'] = mci_issue_get_tags_for_bug_id( $p_issue_id , $t_user_id ); @@ -1390,6 +1391,7 @@ function mci_issue_data_as_array( $p_issue_data, $p_user_id, $p_lang ) { $t_issue['relationships'] = mci_issue_get_relationships( $p_issue_data->id, $p_user_id ); $t_issue['notes'] = mci_issue_get_notes( $p_issue_data->id ); $t_issue['custom_fields'] = mci_issue_get_custom_fields( $p_issue_data->id ); + $t_issue['histories'] = mci_issue_get_histories( $p_issue_data->id ); $t_issue['tags'] = mci_issue_get_tags_for_bug_id( $p_issue_data->id, $p_user_id ); return $t_issue; @@ -1447,3 +1449,48 @@ function mci_issue_data_as_header_array( $p_issue_data ) { return $t_issue; } + + +/** + * Get the histories of an issue. + * + * @param integer $p_issue_id The id of the issue to retrieve the histories for + * @return Array that represents an HistoryData structure + */ +function mci_issue_get_histories( $p_issue_id ) { + $t_history_rows = mci_history_get_events_array( $p_issue_id ); + $t_result = array(); + + foreach( $t_history_rows as $t_history_row ) { + $t_history = array(); + $t_history['date_modified'] = timestamp_to_iso8601( $t_history_row['date'] ); + $t_history['username'] = user_get_name($t_history_row['userid']); + $t_history['field'] = $t_history_row['note']; + $t_history['change'] = $t_history_row['change']; + $t_result[] = $t_history; + } + + return $t_result; +} + +# -------------------- +# Retrieves the history events for the specified bug id and returns it in an array +# The array is indexed from 0 to N-1. The second dimension is: 'date', 'username', +# 'note', 'change'. +function mci_history_get_events_array( $p_bug_id, $p_user_id = null ) { + $t_normal_date_format = config_get( 'normal_date_format' ); + + $raw_history = history_get_raw_events_array( $p_bug_id, $p_user_id ); + $raw_history_count = count( $raw_history ); + $history = array(); + + for ( $i=0; $i < $raw_history_count; $i++ ) { + $history[$i] = history_localize_item( $raw_history[$i]['field'], $raw_history[$i]['type'], $raw_history[$i]['old_value'], $raw_history[$i]['new_value'] ); + # get Date with db_unixtimestamp format + $history[$i]['date'] = $raw_history[$i]['date']; + $history[$i]['userid'] = $raw_history[$i]['userid']; + $history[$i]['username'] = $raw_history[$i]['username']; + } + + return ( $history ); +} -- 1.7.9.5