[ Index ] |
|
Code source de Mantis 1.1.0rc3 |
1 <?php 2 # Mantis - a php based bugtracking system 3 4 # Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org 5 # Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net 6 7 # Mantis is free software: you can redistribute it and/or modify 8 # it under the terms of the GNU General Public License as published by 9 # the Free Software Foundation, either version 2 of the License, or 10 # (at your option) any later version. 11 # 12 # Mantis is distributed in the hope that it will be useful, 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 # GNU General Public License for more details. 16 # 17 # You should have received a copy of the GNU General Public License 18 # along with Mantis. If not, see <http://www.gnu.org/licenses/>. 19 20 # -------------------------------------------------------- 21 # $Id: history_api.php,v 1.43.2.1 2007-10-13 22:35:31 giallu Exp $ 22 # -------------------------------------------------------- 23 24 ### History API ### 25 26 # -------------------- 27 # log the changes (old / new value are supplied to reduce db access) 28 # events should be logged *after* the modification 29 function history_log_event_direct( $p_bug_id, $p_field_name, $p_old_value, $p_new_value, $p_user_id = null ) { 30 # Only log events that change the value 31 if ( $p_new_value != $p_old_value ) { 32 if ( null === $p_user_id ) { 33 $p_user_id = auth_get_current_user_id(); 34 } 35 36 $c_field_name = db_prepare_string( $p_field_name ); 37 $c_old_value = db_prepare_string( $p_old_value ); 38 $c_new_value = db_prepare_string( $p_new_value ); 39 $c_bug_id = db_prepare_int( $p_bug_id ); 40 $c_user_id = db_prepare_int( $p_user_id ); 41 42 $t_mantis_bug_history_table = config_get( 'mantis_bug_history_table' ); 43 44 $query = "INSERT INTO $t_mantis_bug_history_table 45 ( user_id, bug_id, date_modified, field_name, old_value, new_value ) 46 VALUES 47 ( '$c_user_id', '$c_bug_id', " . db_now() . ", '$c_field_name', '$c_old_value', '$c_new_value' )"; 48 $result = db_query( $query ); 49 } 50 } 51 # -------------------- 52 # log the changes 53 # events should be logged *after* the modification 54 function history_log_event( $p_bug_id, $p_field_name, $p_old_value ) { 55 history_log_event_direct( $p_bug_id, $p_field_name, $p_old_value, bug_get_field( $p_bug_id, $p_field_name ) ); 56 } 57 # -------------------- 58 # log the changes 59 # events should be logged *after* the modification 60 # These are special case logs (new bug, deleted bugnote, etc.) 61 function history_log_event_special( $p_bug_id, $p_type, $p_optional='', $p_optional2='' ) { 62 $c_bug_id = db_prepare_int( $p_bug_id ); 63 $c_type = db_prepare_int( $p_type ); 64 $c_optional = db_prepare_string( $p_optional ); 65 $c_optional2 = db_prepare_string( $p_optional2 ); 66 $t_user_id = auth_get_current_user_id(); 67 68 $t_mantis_bug_history_table = config_get( 'mantis_bug_history_table' ); 69 70 $query = "INSERT INTO $t_mantis_bug_history_table 71 ( user_id, bug_id, date_modified, type, old_value, new_value, field_name ) 72 VALUES 73 ( '$t_user_id', '$c_bug_id', " . db_now() . ", '$c_type', '$c_optional', '$c_optional2', '' )"; 74 $result = db_query( $query ); 75 } 76 # -------------------- 77 # return all bug history for a given bug id ordered by date 78 function history_get_events( $p_bug_id ) { 79 $t_mantis_bug_history_table = config_get( 'mantis_bug_history_table' ); 80 $t_mantis_user_table = config_get( 'mantis_user_table' ); 81 82 $c_bug_id = db_prepare_int( $p_bug_id ); 83 84 $query = "SELECT b.*, u.username 85 FROM $t_bug_history_table b 86 LEFT JOIN $t_mantis_user_table u 87 ON b.user_id=u.id 88 WHERE bug_id='$c_bug_id' 89 ORDER BY date_modified DESC"; 90 $result = db_query( $query ); 91 } 92 # -------------------- 93 # Retrieves the history events for the specified bug id and returns it in an array 94 # The array is indexed from 0 to N-1. The second dimension is: 'date', 'username', 95 # 'note', 'change'. 96 function history_get_events_array( $p_bug_id, $p_user_id = null ) { 97 $t_normal_date_format = config_get( 'normal_date_format' ); 98 99 $raw_history = history_get_raw_events_array( $p_bug_id, $p_user_id ); 100 $raw_history_count = count( $raw_history ); 101 $history = array(); 102 103 for ( $i=0; $i < $raw_history_count; $i++ ) { 104 $history[$i] = history_localize_item( $raw_history[$i]['field'], $raw_history[$i]['type'], $raw_history[$i]['old_value'], $raw_history[$i]['new_value'] ); 105 $history[$i]['date'] = date( $t_normal_date_format, $raw_history[$i]['date'] ); 106 $history[$i]['userid'] = $raw_history[$i]['userid']; 107 $history[$i]['username'] = $raw_history[$i]['username']; 108 } 109 110 return ( $history ); 111 } 112 113 # -------------------- 114 # Retrieves the raw history events for the specified bug id and returns it in an array 115 # The array is indexed from 0 to N-1. The second dimension is: 'date', 'userid', 'username', 116 # 'field','type','old_value','new_value' 117 function history_get_raw_events_array( $p_bug_id, $p_user_id = null ) { 118 $t_mantis_bug_history_table = config_get( 'mantis_bug_history_table' ); 119 $t_mantis_user_table = config_get( 'mantis_user_table' ); 120 $t_history_order = config_get( 'history_order' ); 121 $c_bug_id = db_prepare_int( $p_bug_id ); 122 123 $t_user_id = ( ( null === $p_user_id ) ? auth_get_current_user_id() : $p_user_id ); 124 125 $t_roadmap_view_access_level = config_get( 'roadmap_view_threshold' ); 126 127 # grab history and display by date_modified then field_name 128 # @@@ by MASC I guess it's better by id then by field_name. When we have more history lines with the same 129 # date, it's better to respect the storing order otherwise we should risk to mix different information 130 # I give you an example. We create a child of a bug with different custom fields. In the history of the child 131 # bug we will find the line related to the relationship mixed with the custom fields (the history is creted 132 # for the new bug with the same timestamp...) 133 $query = "SELECT * 134 FROM $t_mantis_bug_history_table 135 WHERE bug_id='$c_bug_id' 136 ORDER BY date_modified $t_history_order,id"; 137 $result = db_query( $query ); 138 $raw_history_count = db_num_rows( $result ); 139 $raw_history = array(); 140 141 $t_private_bugnote_threshold = config_get( 'private_bugnote_threshold' ); 142 $t_private_bugnote_visible = access_has_bug_level( 143 config_get( 'private_bugnote_threshold' ), $p_bug_id, $t_user_id ); 144 145 for ( $i=0,$j=0; $i < $raw_history_count; ++$i ) { 146 $row = db_fetch_array( $result ); 147 extract( $row, EXTR_PREFIX_ALL, 'v' ); 148 149 // check that the item should be visible to the user 150 // custom fields - we are passing 32 here to notify the API that the custom field name is truncated by the history column from 64 to 32 characters. 151 $t_field_id = custom_field_get_id_from_name( $v_field_name, 32 ); 152 if ( false !== $t_field_id && 153 !custom_field_has_read_access( $t_field_id, $p_bug_id, $t_user_id ) ) { 154 continue; 155 } 156 157 if ( ( $v_field_name == 'target_version' ) && !access_has_bug_level( $t_roadmap_view_access_level, $p_bug_id, $t_user_id ) ) { 158 continue; 159 } 160 161 // bugnotes 162 if ( $t_user_id != $v_user_id ) { // bypass if user originated note 163 if ( ( $v_type == BUGNOTE_ADDED ) || 164 ( $v_type == BUGNOTE_UPDATED ) || 165 ( $v_type == BUGNOTE_DELETED ) ) { 166 if ( !$t_private_bugnote_visible && 167 ( bugnote_get_field( $v_old_value, 'view_state' ) == VS_PRIVATE ) ) { 168 continue; 169 } 170 } 171 172 if ( $v_type == BUGNOTE_STATE_CHANGED ) { 173 if ( !$t_private_bugnote_visible && 174 ( bugnote_get_field( $v_new_value, 'view_state' ) == VS_PRIVATE ) ) { 175 continue; 176 } 177 } 178 } 179 180 // tags 181 if ( $v_type == TAG_ATTACHED || 182 $v_type == TAG_DETACHED || 183 $v_type == TAG_RENAMED ) { 184 if ( !access_has_global_level( config_get( 'tag_view_threshold' ) ) ) { 185 continue; 186 } 187 } 188 189 $raw_history[$j]['date'] = db_unixtimestamp( $v_date_modified ); 190 $raw_history[$j]['userid'] = $v_user_id; 191 192 # user_get_name handles deleted users, and username vs realname 193 $raw_history[$j]['username'] = user_get_name( $v_user_id ); 194 195 $raw_history[$j]['field'] = $v_field_name; 196 $raw_history[$j]['type'] = $v_type; 197 $raw_history[$j]['old_value'] = $v_old_value; 198 $raw_history[$j]['new_value'] = $v_new_value; 199 200 $j++; 201 } # end for loop 202 203 return $raw_history; 204 } 205 206 # -------------------- 207 # Localizes one raw history item specified by set the next parameters: $p_field_name, $p_type, $p_old_value, $p_new_value 208 # Returns array with two elements indexed as 'note' and 'change' 209 # 210 function history_localize_item( $p_field_name, $p_type, $p_old_value, $p_new_value ) { 211 $t_note = ''; 212 $t_change = ''; 213 $t_field_localized = $p_field_name; 214 215 switch ( $p_field_name ) { 216 case 'category': 217 $t_field_localized = lang_get( 'category' ); 218 break; 219 case 'status': 220 $p_old_value = get_enum_element( 'status', $p_old_value ); 221 $p_new_value = get_enum_element( 'status', $p_new_value ); 222 $t_field_localized = lang_get( 'status' ); 223 break; 224 case 'severity': 225 $p_old_value = get_enum_element( 'severity', $p_old_value ); 226 $p_new_value = get_enum_element( 'severity', $p_new_value ); 227 $t_field_localized = lang_get( 'severity' ); 228 break; 229 case 'reproducibility': 230 $p_old_value = get_enum_element( 'reproducibility', $p_old_value ); 231 $p_new_value = get_enum_element( 'reproducibility', $p_new_value ); 232 $t_field_localized = lang_get( 'reproducibility' ); 233 break; 234 case 'resolution': 235 $p_old_value = get_enum_element( 'resolution', $p_old_value ); 236 $p_new_value = get_enum_element( 'resolution', $p_new_value ); 237 $t_field_localized = lang_get( 'resolution' ); 238 break; 239 case 'priority': 240 $p_old_value = get_enum_element( 'priority', $p_old_value ); 241 $p_new_value = get_enum_element( 'priority', $p_new_value ); 242 $t_field_localized = lang_get( 'priority' ); 243 break; 244 case 'eta': 245 $p_old_value = get_enum_element( 'eta', $p_old_value ); 246 $p_new_value = get_enum_element( 'eta', $p_new_value ); 247 $t_field_localized = lang_get( 'eta' ); 248 break; 249 case 'view_state': 250 $p_old_value = get_enum_element( 'view_state', $p_old_value ); 251 $p_new_value = get_enum_element( 'view_state', $p_new_value ); 252 $t_field_localized = lang_get( 'view_status' ); 253 break; 254 case 'projection': 255 $p_old_value = get_enum_element( 'projection', $p_old_value ); 256 $p_new_value = get_enum_element( 'projection', $p_new_value ); 257 $t_field_localized = lang_get( 'projection' ); 258 break; 259 case 'sticky': 260 $p_old_value = gpc_string_to_bool( $p_old_value ) ? lang_get( 'yes' ) : lang_get( 'no' ) ; 261 $p_new_value = gpc_string_to_bool( $p_new_value ) ? lang_get( 'yes' ) : lang_get( 'no' ) ; 262 $t_field_localized = lang_get( 'sticky_issue' ); 263 break; 264 case 'project_id': 265 if ( project_exists( $p_old_value ) ) { 266 $p_old_value = project_get_field( $p_old_value, 'name' ); 267 } else { 268 $p_old_value = '@'.$p_old_value.'@'; 269 } 270 271 # Note that the new value maybe an intermediately project and not the 272 # current one. 273 if ( project_exists( $p_new_value ) ) { 274 $p_new_value = project_get_field( $p_new_value, 'name' ); 275 } else { 276 $p_new_value = '@'.$p_new_value.'@'; 277 } 278 $t_field_localized = lang_get( 'email_project' ); 279 break; 280 case 'handler_id': 281 $t_field_localized = lang_get( 'assigned_to' ); 282 case 'reporter_id': 283 if ( 'reporter_id' == $p_field_name ) { 284 $t_field_localized = lang_get( 'reporter' ); 285 } 286 if ( 0 == $p_old_value ) { 287 $p_old_value = ''; 288 } else { 289 $p_old_value = user_get_name( $p_old_value ); 290 } 291 292 if ( 0 == $p_new_value ) { 293 $p_new_value = ''; 294 } else { 295 $p_new_value = user_get_name( $p_new_value ); 296 } 297 break; 298 case 'fixed_in_version': 299 $t_field_localized = lang_get( 'fixed_in_version' ); 300 break; 301 case 'target_version': 302 $t_field_localized = lang_get( 'target_version' ); 303 break; 304 case 'date_submitted': 305 $t_field_localized = lang_get( 'date_submitted' ); 306 break; 307 case 'last_updated': 308 $t_field_localized = lang_get( 'last_update' ); 309 break; 310 case 'summary': 311 $t_field_localized = lang_get( 'summary' ); 312 break; 313 case 'duplicate_id': 314 $t_field_localized = lang_get( 'duplicate_id' ); 315 break; 316 case 'sponsorship_total': 317 $t_field_localized = lang_get( 'sponsorship_total' ); 318 break; 319 default: 320 # assume it's a custom field name 321 $t_field_id = custom_field_get_id_from_name( $p_field_name ); 322 if ( false !== $t_field_id ) { 323 $t_cf_type = custom_field_type( $t_field_id ); 324 if ( '' != $p_old_value ) { 325 $p_old_value = string_custom_field_value_for_email( $p_old_value, $t_cf_type ); 326 } 327 $p_new_value = string_custom_field_value_for_email( $p_new_value, $t_cf_type ); 328 } 329 } 330 331 if ( NORMAL_TYPE != $p_type ) { 332 switch ( $p_type ) { 333 case NEW_BUG: 334 $t_note = lang_get( 'new_bug' ); 335 break; 336 case BUGNOTE_ADDED: 337 $t_note = lang_get( 'bugnote_added' ) . ": " . $p_old_value; 338 break; 339 case BUGNOTE_UPDATED: 340 $t_note = lang_get( 'bugnote_edited' ) . ": " . $p_old_value; 341 break; 342 case BUGNOTE_DELETED: 343 $t_note = lang_get( 'bugnote_deleted' ) . ": " . $p_old_value; 344 break; 345 case DESCRIPTION_UPDATED: 346 $t_note = lang_get( 'description_updated' ); 347 break; 348 case ADDITIONAL_INFO_UPDATED: 349 $t_note = lang_get( 'additional_information_updated' ); 350 break; 351 case STEP_TO_REPRODUCE_UPDATED: 352 $t_note = lang_get( 'steps_to_reproduce_updated' ); 353 break; 354 case FILE_ADDED: 355 $t_note = lang_get( 'file_added' ) . ": " . $p_old_value; 356 break; 357 case FILE_DELETED: 358 $t_note = lang_get( 'file_deleted' ) . ": " . $p_old_value; 359 break; 360 case BUGNOTE_STATE_CHANGED: 361 $p_old_value = get_enum_element( 'view_state', $p_old_value ); 362 $t_note = lang_get( 'bugnote_view_state' ) . ": " . $p_old_value . ": " . $p_new_value; 363 break; 364 case BUG_MONITOR: 365 $p_old_value = user_get_name( $p_old_value ); 366 $t_note = lang_get( 'bug_monitor' ) . ": " . $p_old_value; 367 break; 368 case BUG_UNMONITOR: 369 $p_old_value = user_get_name( $p_old_value ); 370 $t_note = lang_get( 'bug_end_monitor' ) . ": " . $p_old_value; 371 break; 372 case BUG_DELETED: 373 $t_note = lang_get( 'bug_deleted' ) . ": " . $p_old_value; 374 break; 375 case BUG_ADD_SPONSORSHIP: 376 $t_note = lang_get( 'sponsorship_added' ); 377 $t_change = user_get_name( $p_old_value ) . ': ' . sponsorship_format_amount( $p_new_value ); 378 break; 379 case BUG_UPDATE_SPONSORSHIP: 380 $t_note = lang_get( 'sponsorship_updated' ); 381 $t_change = user_get_name( $p_old_value ) . ': ' . sponsorship_format_amount( $p_new_value ); 382 break; 383 case BUG_DELETE_SPONSORSHIP: 384 $t_note = lang_get( 'sponsorship_deleted' ); 385 $t_change = user_get_name( $p_old_value ) . ': ' . sponsorship_format_amount( $p_new_value ); 386 break; 387 case BUG_PAID_SPONSORSHIP: 388 $t_note = lang_get( 'sponsorship_paid' ); 389 $t_change = user_get_name( $p_old_value ) . ': ' . get_enum_element( 'sponsorship', $p_new_value ); 390 break; 391 case BUG_ADD_RELATIONSHIP: 392 $t_note = lang_get( 'relationship_added' ); 393 $t_change = relationship_get_description_for_history( $p_old_value ) . ' ' . bug_format_id( $p_new_value ); 394 break; 395 case BUG_REPLACE_RELATIONSHIP: 396 $t_note = lang_get( 'relationship_replaced' ); 397 $t_change = relationship_get_description_for_history( $p_old_value ) . ' ' . bug_format_id( $p_new_value ); 398 break; 399 case BUG_DEL_RELATIONSHIP: 400 $t_note = lang_get( 'relationship_deleted' ); 401 402 # Fix for #7846: There are some cases where old value is empty, this may be due to an old bug. 403 if ( !is_blank( $p_old_value ) && $p_old_value > 0 ) { 404 $t_change = relationship_get_description_for_history( $p_old_value ) . ' ' . bug_format_id( $p_new_value ); 405 } else { 406 $t_change = bug_format_id( $p_new_value ); 407 } 408 break; 409 case BUG_CLONED_TO: 410 $t_note = lang_get( 'bug_cloned_to' ); 411 $t_change = bug_format_id( $p_new_value ); 412 break; 413 case BUG_CREATED_FROM: 414 $t_note = lang_get( 'bug_created_from' ); 415 $t_change = bug_format_id( $p_new_value ); 416 break; 417 case CHECKIN: 418 $t_note = lang_get( 'checkin' ); 419 break; 420 case TAG_ATTACHED: 421 $t_note = lang_get( 'tag_history_attached' ) .': '. $p_old_value; 422 break; 423 case TAG_DETACHED: 424 $t_note = lang_get( 'tag_history_detached' ) .': '. $p_old_value; 425 break; 426 case TAG_RENAMED: 427 $t_note = lang_get( 'tag_history_renamed' ); 428 $t_change = $p_old_value . ' => ' . $p_new_value; 429 break; 430 } 431 } 432 433 # output special cases 434 if ( NORMAL_TYPE == $p_type ) { 435 $t_note = $t_field_localized; 436 $t_change = $p_old_value . ' => ' . $p_new_value; 437 } # end if DEFAULT 438 return array( 'note' => $t_note, 'change' => $t_change ); 439 } 440 441 # -------------------- 442 # delete all history associated with a bug 443 function history_delete( $p_bug_id ) { 444 $c_bug_id = db_prepare_int( $p_bug_id ); 445 446 $t_bug_history_table = config_get( 'mantis_bug_history_table' ); 447 448 $query = "DELETE FROM $t_bug_history_table 449 WHERE bug_id='$c_bug_id'"; 450 db_query($query); 451 452 # db_query() errors on failure so: 453 return true; 454 } 455 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 09:42:17 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |