PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/mantisbt-1.2.8/bug_update.php

#
PHP | 226 lines | 146 code | 34 blank | 46 comment | 51 complexity | 306dd2ca458e0360ee047d1c0e5005a6 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. # MantisBT - a php based bugtracking system
  3. # MantisBT is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # MantisBT is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * Update bug data then redirect to the appropriate viewing page
  17. *
  18. * @package MantisBT
  19. * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
  20. * @copyright Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
  21. * @link http://www.mantisbt.org
  22. */
  23. /**
  24. * MantisBT Core API's
  25. */
  26. require_once( 'core.php' );
  27. require_once( 'bug_api.php' );
  28. require_once( 'bugnote_api.php' );
  29. require_once( 'custom_field_api.php' );
  30. form_security_validate( 'bug_update' );
  31. $f_bug_id = gpc_get_int( 'bug_id' );
  32. $f_update_mode = gpc_get_bool( 'update_mode', FALSE ); # set if called from generic update page
  33. $f_new_status = gpc_get_int( 'status', bug_get_field( $f_bug_id, 'status' ) );
  34. $t_bug_data = bug_get( $f_bug_id, true );
  35. if( $t_bug_data->project_id != helper_get_current_project() ) {
  36. # in case the current project is not the same project of the bug we are viewing...
  37. # ... override the current project. This to avoid problems with categories and handlers lists etc.
  38. $g_project_override = $t_bug_data->project_id;
  39. }
  40. if ( !(
  41. ( access_has_bug_level( access_get_status_threshold( $f_new_status, bug_get_field( $f_bug_id, 'project_id' ) ), $f_bug_id ) ) ||
  42. ( access_has_bug_level( config_get( 'update_bug_threshold' ) , $f_bug_id ) ) ||
  43. ( ( bug_get_field( $f_bug_id, 'reporter_id' ) == auth_get_current_user_id() ) &&
  44. ( ( ON == config_get( 'allow_reporter_reopen' ) ) ||
  45. ( ON == config_get( 'allow_reporter_close' ) ) ) )
  46. ) ) {
  47. access_denied();
  48. }
  49. # extract current extended information
  50. $t_old_bug_status = $t_bug_data->status;
  51. $t_bug_data->reporter_id = gpc_get_int( 'reporter_id', $t_bug_data->reporter_id );
  52. $t_bug_data->handler_id = gpc_get_int( 'handler_id', $t_bug_data->handler_id );
  53. $t_bug_data->duplicate_id = gpc_get_int( 'duplicate_id', $t_bug_data->duplicate_id );
  54. $t_bug_data->priority = gpc_get_int( 'priority', $t_bug_data->priority );
  55. $t_bug_data->severity = gpc_get_int( 'severity', $t_bug_data->severity );
  56. $t_bug_data->reproducibility = gpc_get_int( 'reproducibility', $t_bug_data->reproducibility );
  57. $t_bug_data->status = gpc_get_int( 'status', $t_bug_data->status );
  58. $t_bug_data->resolution = gpc_get_int( 'resolution', $t_bug_data->resolution );
  59. $t_bug_data->projection = gpc_get_int( 'projection', $t_bug_data->projection );
  60. $t_bug_data->category_id = gpc_get_int( 'category_id', $t_bug_data->category_id );
  61. $t_bug_data->eta = gpc_get_int( 'eta', $t_bug_data->eta );
  62. $t_bug_data->os = gpc_get_string( 'os', $t_bug_data->os );
  63. $t_bug_data->os_build = gpc_get_string( 'os_build', $t_bug_data->os_build );
  64. $t_bug_data->platform = gpc_get_string( 'platform', $t_bug_data->platform );
  65. $t_bug_data->version = gpc_get_string( 'version', $t_bug_data->version );
  66. $t_bug_data->build = gpc_get_string( 'build', $t_bug_data->build );
  67. $t_bug_data->fixed_in_version = gpc_get_string( 'fixed_in_version', $t_bug_data->fixed_in_version );
  68. $t_bug_data->view_state = gpc_get_int( 'view_state', $t_bug_data->view_state );
  69. $t_bug_data->summary = gpc_get_string( 'summary', $t_bug_data->summary );
  70. $t_due_date = gpc_get_string( 'due_date', null );
  71. if( access_has_project_level( config_get( 'roadmap_update_threshold' ), $t_bug_data->project_id ) ) {
  72. $t_bug_data->target_version = gpc_get_string( 'target_version', $t_bug_data->target_version );
  73. }
  74. if( $t_due_date !== null) {
  75. if ( is_blank ( $t_due_date ) ) {
  76. $t_bug_data->due_date = 1;
  77. } else {
  78. $t_bug_data->due_date = strtotime( $t_due_date );
  79. }
  80. }
  81. $t_bug_data->description = gpc_get_string( 'description', $t_bug_data->description );
  82. $t_bug_data->steps_to_reproduce = gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
  83. $t_bug_data->additional_information = gpc_get_string( 'additional_information', $t_bug_data->additional_information );
  84. $f_private = gpc_get_bool( 'private' );
  85. $f_bugnote_text = gpc_get_string( 'bugnote_text', '' );
  86. $f_time_tracking = gpc_get_string( 'time_tracking', '0:00' );
  87. $f_close_now = gpc_get_string( 'close_now', false );
  88. # Handle auto-assigning
  89. if ( ( config_get( 'bug_submit_status' ) == $t_bug_data->status )
  90. && ( $t_bug_data->status == $t_old_bug_status )
  91. && ( 0 != $t_bug_data->handler_id )
  92. && ( ON == config_get( 'auto_set_status_to_assigned' ) ) ) {
  93. $t_bug_data->status = config_get( 'bug_assigned_status' );
  94. }
  95. helper_call_custom_function( 'issue_update_validate', array( $f_bug_id, $t_bug_data, $f_bugnote_text ) );
  96. $t_resolved = config_get( 'bug_resolved_status_threshold' );
  97. $t_closed = config_get( 'bug_closed_status_threshold' );
  98. $t_custom_status_label = "update"; # default info to check
  99. if ( $t_bug_data->status == $t_resolved ) {
  100. $t_custom_status_label = "resolved";
  101. }
  102. if ( $t_bug_data->status == $t_closed ) {
  103. $t_custom_status_label = "closed";
  104. }
  105. $t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug_data->project_id );
  106. foreach( $t_related_custom_field_ids as $t_id ) {
  107. $t_def = custom_field_get_definition( $t_id );
  108. # Only update the field if it would have been display for editing
  109. if( !( ( !$f_update_mode && $t_def['require_' . $t_custom_status_label] ) ||
  110. ( !$f_update_mode && $t_def['display_' . $t_custom_status_label] && in_array( $t_custom_status_label, array( "resolved", "closed" ) ) ) ||
  111. ( $f_update_mode && $t_def['display_update'] ) ||
  112. ( $f_update_mode && $t_def['require_update'] ) ) ) {
  113. continue;
  114. }
  115. # Do not set custom field value if user has no write access.
  116. if( !custom_field_has_write_access( $t_id, $f_bug_id ) ) {
  117. continue;
  118. }
  119. # Produce an error if the field is required but wasn't posted
  120. if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
  121. ( $t_def['require_' . $t_custom_status_label] ) ) {
  122. error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
  123. trigger_error( ERROR_EMPTY_FIELD, ERROR );
  124. }
  125. $t_new_custom_field_value = gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' );
  126. $t_old_custom_field_value = custom_field_get_value( $t_id, $f_bug_id );
  127. # Don't update the custom field if the new value both matches the old value and is valid
  128. # This ensures that changes to custom field validation will force the update of old invalid custom field values
  129. if( $t_new_custom_field_value === $t_old_custom_field_value &&
  130. custom_field_validate( $t_id, $t_new_custom_field_value ) ) {
  131. continue;
  132. }
  133. # Attempt to set the new custom field value
  134. if ( !custom_field_set_value( $t_id, $f_bug_id, $t_new_custom_field_value ) ) {
  135. error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
  136. trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
  137. }
  138. }
  139. $t_notify = true;
  140. $t_bug_note_set = false;
  141. if ( ( $t_old_bug_status != $t_bug_data->status ) && ( FALSE == $f_update_mode ) ) {
  142. # handle status transitions that come from pages other than bug_*update_page.php
  143. # this does the minimum to act on the bug and sends a specific message
  144. if ( $t_bug_data->status >= $t_resolved
  145. && $t_bug_data->status < $t_closed
  146. && $t_old_bug_status < $t_resolved ) {
  147. # bug_resolve updates the status, fixed_in_version, resolution, handler_id and bugnote and sends message
  148. bug_resolve( $f_bug_id, $t_bug_data->resolution, $t_bug_data->fixed_in_version,
  149. $f_bugnote_text, $t_bug_data->duplicate_id, $t_bug_data->handler_id,
  150. $f_private, $f_time_tracking );
  151. $t_notify = false;
  152. $t_bug_note_set = true;
  153. if ( $f_close_now ) {
  154. bug_set_field( $f_bug_id, 'status', $t_closed );
  155. }
  156. // update bug data with fields that may be updated inside bug_resolve(), otherwise changes will be overwritten
  157. // in bug_update() call below.
  158. $t_bug_data->handler_id = bug_get_field( $f_bug_id, 'handler_id' );
  159. $t_bug_data->status = bug_get_field( $f_bug_id, 'status' );
  160. } else if ( $t_bug_data->status >= $t_closed
  161. && $t_old_bug_status < $t_closed ) {
  162. # bug_close updates the status and bugnote and sends message
  163. bug_close( $f_bug_id, $f_bugnote_text, $f_private, $f_time_tracking );
  164. $t_notify = false;
  165. $t_bug_note_set = true;
  166. } else if ( $t_bug_data->status == config_get( 'bug_reopen_status' )
  167. && $t_old_bug_status >= $t_resolved ) {
  168. bug_set_field( $f_bug_id, 'handler_id', $t_bug_data->handler_id ); # fix: update handler_id before calling bug_reopen
  169. # bug_reopen updates the status and bugnote and sends message
  170. bug_reopen( $f_bug_id, $f_bugnote_text, $f_time_tracking, $f_private );
  171. $t_notify = false;
  172. $t_bug_note_set = true;
  173. // update bug data with fields that may be updated inside bug_resolve(), otherwise changes will be overwritten
  174. // in bug_update() call below.
  175. $t_bug_data->status = bug_get_field( $f_bug_id, 'status' );
  176. $t_bug_data->resolution = bug_get_field( $f_bug_id, 'resolution' );
  177. }
  178. }
  179. # Plugin support
  180. $t_new_bug_data = event_signal( 'EVENT_UPDATE_BUG', $t_bug_data, $f_bug_id );
  181. if ( !is_null( $t_new_bug_data ) ) {
  182. $t_bug_data = $t_new_bug_data;
  183. }
  184. # Add a bugnote if there is one
  185. if ( false == $t_bug_note_set ) {
  186. bugnote_add( $f_bug_id, $f_bugnote_text, $f_time_tracking, $f_private, 0, '', NULL, FALSE );
  187. }
  188. # Update the bug entry, notify if we haven't done so already
  189. $t_bug_data->update( true, ( false == $t_notify ) );
  190. form_security_purge( 'bug_update' );
  191. helper_call_custom_function( 'issue_update_notify', array( $f_bug_id ) );
  192. print_successful_redirect_to_bug( $f_bug_id );