Fix #11417: Allow EVENT_MENU_MAIN plugin events to return null
[mantis/radio.git] / bug_update.php
blob63c62f833c89fc69f9289cbd4a9d45da4095bb47
1 <?php
2 # MantisBT - A PHP based bugtracking system
4 # MantisBT is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 2 of the License, or
7 # (at your option) any later version.
9 # MantisBT is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Update bug data then redirect to the appropriate viewing page
20 * @package MantisBT
21 * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
22 * @copyright Copyright (C) 2002 - 2010 MantisBT Team - mantisbt-dev@lists.sourceforge.net
23 * @link http://www.mantisbt.org
25 * @uses core.php
26 * @uses access_api.php
27 * @uses authentication_api.php
28 * @uses bug_api.php
29 * @uses bugnote_api.php
30 * @uses config_api.php
31 * @uses constant_inc.php
32 * @uses custom_field_api.php
33 * @uses error_api.php
34 * @uses event_api.php
35 * @uses form_api.php
36 * @uses gpc_api.php
37 * @uses helper_api.php
38 * @uses lang_api.php
39 * @uses print_api.php
42 require_once( 'core.php' );
43 require_api( 'access_api.php' );
44 require_api( 'authentication_api.php' );
45 require_api( 'bug_api.php' );
46 require_api( 'bugnote_api.php' );
47 require_api( 'config_api.php' );
48 require_api( 'constant_inc.php' );
49 require_api( 'custom_field_api.php' );
50 require_api( 'error_api.php' );
51 require_api( 'event_api.php' );
52 require_api( 'form_api.php' );
53 require_api( 'gpc_api.php' );
54 require_api( 'helper_api.php' );
55 require_api( 'lang_api.php' );
56 require_api( 'print_api.php' );
58 form_security_validate( 'bug_update' );
60 $f_bug_id = gpc_get_int( 'bug_id' );
61 $f_update_mode = gpc_get_bool( 'update_mode', FALSE ); # set if called from generic update page
62 $f_new_status = gpc_get_int( 'status', bug_get_field( $f_bug_id, 'status' ) );
64 $t_bug_data = bug_get( $f_bug_id, true );
65 if( $t_bug_data->project_id != helper_get_current_project() ) {
66 # in case the current project is not the same project of the bug we are viewing...
67 # ... override the current project. This to avoid problems with categories and handlers lists etc.
68 $g_project_override = $t_bug_data->project_id;
71 if ( !(
72 ( access_has_bug_level( access_get_status_threshold( $f_new_status, bug_get_field( $f_bug_id, 'project_id' ) ), $f_bug_id ) ) ||
73 ( access_has_bug_level( config_get( 'update_bug_threshold' ) , $f_bug_id ) ) ||
74 ( ( bug_get_field( $f_bug_id, 'reporter_id' ) == auth_get_current_user_id() ) &&
75 ( ( ON == config_get( 'allow_reporter_reopen' ) ) ||
76 ( ON == config_get( 'allow_reporter_close' ) ) ) )
77 ) ) {
78 access_denied();
81 # extract current extended information
82 $t_old_bug_status = $t_bug_data->status;
84 $t_bug_data->reporter_id = gpc_get_int( 'reporter_id', $t_bug_data->reporter_id );
85 $t_bug_data->handler_id = gpc_get_int( 'handler_id', $t_bug_data->handler_id );
86 $t_bug_data->duplicate_id = gpc_get_int( 'duplicate_id', $t_bug_data->duplicate_id );
87 $t_bug_data->priority = gpc_get_int( 'priority', $t_bug_data->priority );
88 $t_bug_data->severity = gpc_get_int( 'severity', $t_bug_data->severity );
89 $t_bug_data->reproducibility = gpc_get_int( 'reproducibility', $t_bug_data->reproducibility );
90 $t_bug_data->status = gpc_get_int( 'status', $t_bug_data->status );
91 $t_bug_data->resolution = gpc_get_int( 'resolution', $t_bug_data->resolution );
92 $t_bug_data->projection = gpc_get_int( 'projection', $t_bug_data->projection );
93 $t_bug_data->category_id = gpc_get_int( 'category_id', $t_bug_data->category_id );
94 $t_bug_data->eta = gpc_get_int( 'eta', $t_bug_data->eta );
95 $t_bug_data->os = gpc_get_string( 'os', $t_bug_data->os );
96 $t_bug_data->os_build = gpc_get_string( 'os_build', $t_bug_data->os_build );
97 $t_bug_data->platform = gpc_get_string( 'platform', $t_bug_data->platform );
98 $t_bug_data->version = gpc_get_string( 'version', $t_bug_data->version );
99 $t_bug_data->build = gpc_get_string( 'build', $t_bug_data->build );
100 $t_bug_data->fixed_in_version = gpc_get_string( 'fixed_in_version', $t_bug_data->fixed_in_version );
101 $t_bug_data->view_state = gpc_get_int( 'view_state', $t_bug_data->view_state );
102 $t_bug_data->summary = gpc_get_string( 'summary', $t_bug_data->summary );
103 $t_due_date = gpc_get_string( 'due_date', null );
105 if( access_has_project_level( config_get( 'roadmap_update_threshold' ), $t_bug_data->project_id ) ) {
106 $t_bug_data->target_version = gpc_get_string( 'target_version', $t_bug_data->target_version );
109 if( $t_due_date !== null) {
110 if ( is_blank ( $t_due_date ) ) {
111 $t_bug_data->due_date = 1;
112 } else {
113 $t_bug_data->due_date = strtotime( $t_due_date );
117 $t_bug_data->description = gpc_get_string( 'description', $t_bug_data->description );
118 $t_bug_data->steps_to_reproduce = gpc_get_string( 'steps_to_reproduce', $t_bug_data->steps_to_reproduce );
119 $t_bug_data->additional_information = gpc_get_string( 'additional_information', $t_bug_data->additional_information );
121 $f_private = gpc_get_bool( 'private' );
122 $f_bugnote_text = gpc_get_string( 'bugnote_text', '' );
123 $f_time_tracking = gpc_get_string( 'time_tracking', '0:00' );
124 $f_close_now = gpc_get_string( 'close_now', false );
126 # Handle auto-assigning
127 if ( ( config_get( 'bug_submit_status' ) == $t_bug_data->status )
128 && ( $t_bug_data->status == $t_old_bug_status )
129 && ( 0 != $t_bug_data->handler_id )
130 && ( ON == config_get( 'auto_set_status_to_assigned' ) ) ) {
131 $t_bug_data->status = config_get( 'bug_assigned_status' );
134 helper_call_custom_function( 'issue_update_validate', array( $f_bug_id, $t_bug_data, $f_bugnote_text ) );
136 $t_resolved = config_get( 'bug_resolved_status_threshold' );
137 $t_closed = config_get( 'bug_closed_status_threshold' );
139 $t_custom_status_label = "update"; # default info to check
140 if ( $t_bug_data->status == $t_resolved ) {
141 $t_custom_status_label = "resolved";
143 if ( $t_bug_data->status == $t_closed ) {
144 $t_custom_status_label = "closed";
147 $t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug_data->project_id );
148 foreach( $t_related_custom_field_ids as $t_id ) {
149 $t_def = custom_field_get_definition( $t_id );
151 # Only update the field if it would have been display for editing
152 if( !( ( !$f_update_mode && $t_def['require_' . $t_custom_status_label] ) ||
153 ( !$f_update_mode && $t_def['display_' . $t_custom_status_label] && in_array( $t_custom_status_label, array( "resolved", "closed" ) ) ) ||
154 ( $f_update_mode && $t_def['display_update'] ) ||
155 ( $f_update_mode && $t_def['require_update'] ) ) ) {
156 continue;
159 # Do not set custom field value if user has no write access.
160 if( !custom_field_has_write_access( $t_id, $f_bug_id ) ) {
161 continue;
164 if ( $t_def['require_' . $t_custom_status_label] && !gpc_isset_custom_field( $t_id, $t_def['type'] ) ) {
165 error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
166 trigger_error( ERROR_EMPTY_FIELD, ERROR );
169 # Only update the field if it is posted,
170 # or if it is empty, and the current value isn't the default
171 if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) &&
172 ( custom_field_get_value( $t_id, $f_bug_id ) == $t_def['default_value'] ) ) {
173 continue;
176 if ( !custom_field_set_value( $t_id, $f_bug_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) {
177 error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) );
178 trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR );
182 $t_notify = true;
183 $t_bug_note_set = false;
184 if ( ( $t_old_bug_status != $t_bug_data->status ) && ( FALSE == $f_update_mode ) ) {
185 # handle status transitions that come from pages other than bug_*update_page.php
186 # this does the minimum to act on the bug and sends a specific message
187 if ( $t_bug_data->status >= $t_resolved
188 && $t_bug_data->status < $t_closed
189 && $t_old_bug_status < $t_resolved ) {
190 # bug_resolve updates the status, fixed_in_version, resolution, handler_id and bugnote and sends message
191 bug_resolve( $f_bug_id, $t_bug_data->resolution, $t_bug_data->fixed_in_version,
192 $f_bugnote_text, $t_bug_data->duplicate_id, $t_bug_data->handler_id,
193 $f_private, $f_time_tracking );
194 $t_notify = false;
195 $t_bug_note_set = true;
197 if ( $f_close_now ) {
198 bug_set_field( $f_bug_id, 'status', $t_closed );
201 // update bug data with fields that may be updated inside bug_resolve(), otherwise changes will be overwritten
202 // in bug_update() call below.
203 $t_bug_data->handler_id = bug_get_field( $f_bug_id, 'handler_id' );
204 $t_bug_data->status = bug_get_field( $f_bug_id, 'status' );
205 } else if ( $t_bug_data->status >= $t_closed
206 && $t_old_bug_status < $t_closed ) {
207 # bug_close updates the status and bugnote and sends message
208 bug_close( $f_bug_id, $f_bugnote_text, $f_private, $f_time_tracking );
209 $t_notify = false;
210 $t_bug_note_set = true;
211 } else if ( $t_bug_data->status == config_get( 'bug_reopen_status' )
212 && $t_old_bug_status >= $t_resolved ) {
213 bug_set_field( $f_bug_id, 'handler_id', $t_bug_data->handler_id ); # fix: update handler_id before calling bug_reopen
214 # bug_reopen updates the status and bugnote and sends message
215 bug_reopen( $f_bug_id, $f_bugnote_text, $f_time_tracking, $f_private );
216 $t_notify = false;
217 $t_bug_note_set = true;
219 // update bug data with fields that may be updated inside bug_resolve(), otherwise changes will be overwritten
220 // in bug_update() call below.
221 $t_bug_data->status = bug_get_field( $f_bug_id, 'status' );
222 $t_bug_data->resolution = bug_get_field( $f_bug_id, 'resolution' );
226 # Plugin support
227 $t_new_bug_data = event_signal( 'EVENT_UPDATE_BUG', $t_bug_data, $f_bug_id );
228 if ( !is_null( $t_new_bug_data ) ) {
229 $t_bug_data = $t_new_bug_data;
232 # Add a bugnote if there is one
233 if ( false == $t_bug_note_set ) {
234 bugnote_add( $f_bug_id, $f_bugnote_text, $f_time_tracking, $f_private, 0, '', NULL, FALSE );
237 # Update the bug entry, notify if we haven't done so already
238 $t_bug_data->update( true, ( false == $t_notify ) );
240 form_security_purge( 'bug_update' );
242 helper_call_custom_function( 'issue_update_notify', array( $f_bug_id ) );
244 print_successful_redirect_to_bug( $f_bug_id );