/
bug_api.php
315 lines (258 loc) · 8.84 KB
/
bug_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the files README and LICENSE for details
# --------------------------------------------------------
# $Id: bug_api.php,v 1.4 2002-08-27 04:26:42 jfitzell Exp $
# --------------------------------------------------------
###########################################################################
# Bug API
###########################################################################
# --------------------
function bug_add() {
}
# --------------------
function bug_update() {
}
# --------------------
# allows bug deletion :
# delete the bug, bugtext, bugnote, and bugtexts selected
# used in bug_delete.php & mass treatments
function bug_delete( $p_id, $p_bug_text_id ) {
global $g_mantis_bug_file_table, $g_mantis_bug_table, $g_mantis_bug_text_table,
$g_mantis_bugnote_table, $g_mantis_bugnote_text_table, $g_mantis_bug_history_table,
$g_file_upload_method ;
email_bug_deleted( $p_id );
$c_id = (integer)$p_id;
$c_bug_text_id = (integer)$p_bug_text_id;
$retval = true;
# Delete the bug entry
$query = "DELETE
FROM $g_mantis_bug_table
WHERE id='$c_id'";
$result = db_query( $query );
$retval = $retval && $result;
# Delete the corresponding bug text
$query = "DELETE
FROM $g_mantis_bug_text_table
WHERE id='$c_bug_text_id'";
$result = db_query( $query );
$retval = $retval && $result;
# Delete the bugnote text items
$query = "SELECT bugnote_text_id
FROM $g_mantis_bugnote_table
WHERE bug_id='$c_id'";
$result = db_query($query);
$retval = $retval && $result;
$bugnote_count = db_num_rows( $result );
for ($i=0;$i<$bugnote_count;$i++){
$row = db_fetch_array( $result );
$t_bugnote_text_id = $row['bugnote_text_id'];
# Delete the corresponding bugnote texts
$query = "DELETE
FROM $g_mantis_bugnote_text_table
WHERE id='$t_bugnote_text_id'";
$result = db_query( $query );
$retval = $retval && $result;
}
# Delete the corresponding bugnotes
$query = "DELETE
FROM $g_mantis_bugnote_table
WHERE bug_id='$c_id'";
$result = db_query($query);
$retval = $retval && $result;
if ( ( DISK == $g_file_upload_method ) || ( FTP == $g_file_upload_method ) ) {
# Delete files from disk
$query = "SELECT diskfile, filename
FROM $g_mantis_bug_file_table
WHERE bug_id='$c_id'";
$result = db_query( $query );
$retval = $retval && $result;
$file_count = db_num_rows( $result );
# there may be more than one file
for ($i=0;$i<$file_count;$i++){
$row = db_fetch_array( $result );
file_delete_local ( $row['diskfile'] );
if ( FTP == $g_file_upload_method ) {
$ftp = file_ftp_connect();
file_ftp_delete ( $ftp, $row['filename'] );
file_ftp_disconnect( $ftp );
}
}
}
# Delete the corresponding files
$query = "DELETE
FROM $g_mantis_bug_file_table
WHERE bug_id='$c_id'";
$result = db_query($query);
$retval = $retval && $result;
# Delete the bug history
$query = "DELETE
FROM $g_mantis_bug_history_table
WHERE bug_id='$c_id'";
$result = db_query($query);
$retval = $retval && $result;
return ($retval);
}
# --------------------
# Delete all bugs associated with a project
function bug_delete_all( $p_project_id ) {
$c_project_id = db_prepare_int( $p_project_id );
$t_bug_table = config_get( 'mantis_bug_table' );
$query = "SELECT id, bug_text_id
FROM $t_bug_table
WHERE project_id='$c_project_id'";
$result = db_query( $query );
$bug_count = db_num_rows( $result );
for ( $i=0 ; $i < $bug_count ; $i++ ) {
$row = db_fetch_array( $result );
bug_delete( $row['id'], $row['bug_text_id']);
}
# @@@ should we check the return value of each bug_delete() and
# return false if any of them return false? Presumable bug_delete()
# will eventually trigger an error on failure so it won't matter...
return true;
}
# --------------------
# This function assigns the bug to the current user
function bug_assign( $p_bug_id ) {
global $g_mantis_bug_table, $g_auto_set_status_to_assigned;
# extract current information into history variables
$result = get_bug_row ( $p_bug_id );
if ( 0 == db_num_rows( $result ) ) {
# speed is not an issue in this case, so re-use code
check_bug_exists( $p_bug_id );
}
$row = db_fetch_array( $result );
extract( $row, EXTR_PREFIX_ALL, 'h' );
if ( ON == $g_auto_set_status_to_assigned ) {
$t_ass_val = ASSIGNED;
} else {
$t_ass_val = $h_status;
}
$t_handler_id = get_current_user_field( 'id' );
if ( ( $t_ass_val != $h_status ) || ( $t_handler_id != $h_handler_id ) ) {
$c_id = (integer)$p_bug_id;
# get user id
$query ="UPDATE $g_mantis_bug_table ".
"SET handler_id='$t_handler_id', status='$t_ass_val' ".
"WHERE id='$c_id'";
$result = db_query( $query );
# updated the last_updated date
$result = bug_date_update( $p_bug_id );
# log changes
history_log_event_direct( $c_id, 'status', $h_status, $t_ass_val, $t_handler_id );
history_log_event_direct( $c_id, 'handler_id', $h_handler_id, $t_handler_id, $t_handler_id );
# send assigned to email
email_assign( $p_bug_id );
}
return true;
}
# --------------------
function bug_close( $p_bug_id, $p_bugnote_text ) {
global $g_mantis_bug_table;
#clean variables
$c_id = (integer)$p_bug_id;
$t_handler_id = get_current_user_field( 'id' );
$h_status = get_bug_field( $p_bug_id, 'status' );
# Update fields
$t_status_val = CLOSED;
$query ="UPDATE $g_mantis_bug_table ".
"SET status='$t_status_val' ".
"WHERE id='$c_id'";
$result = db_query( $query );
# log changes
history_log_event( $p_bug_id, 'status', $h_status );
$p_bugnote_text = trim( $p_bugnote_text );
# check for blank bugnote
if ( !empty( $p_bugnote_text ) ) {
# insert bugnote text
#@@@ jf - need to add string_prepare_textarea() call or something once that is resolved
$result = bugnote_add( $p_bug_id, $p_bugnote_text );
email_close( $p_bug_id );
}
return true;
}
# --------------------
function bug_get_field() {
}
# --------------------
# Returns the record of the specified bug
function get_bug_row( $p_bug_id ) {
global $g_mantis_bug_table;
$c_bug_id = (integer)$p_bug_id;
$query ="SELECT * ".
"FROM $g_mantis_bug_table ".
"WHERE id='$c_bug_id' ".
"LIMIT 1";
return db_query( $query );
}
# --------------------
# updates the last_updated field
function bug_date_update( $p_bug_id ) {
global $g_mantis_bug_table;
$c_bug_id = (integer)$p_bug_id;
$query ="UPDATE $g_mantis_bug_table ".
"SET last_updated=NOW() ".
"WHERE id='$c_bug_id'";
return db_query( $query );
}
# --------------------
# Returns the extended record of the specified bug, this includes
# the bug text fields
# @@@ include reporter name and handler name, the problem is that
# handler can be 0, in this case no corresponding name will be
# found. Use equivalent of (+) in Oracle.
function get_bug_row_ex( $p_bug_id ) {
global $g_mantis_bug_table, $g_mantis_bug_text_table;
$c_bug_id = (integer)$p_bug_id;
$query ="SELECT b.*, bt.*, b.id as id ".
"FROM $g_mantis_bug_table b, $g_mantis_bug_text_table bt ".
"WHERE b.id='$c_bug_id' AND b.bug_text_id = bt.id ".
"LIMIT 1";
return db_query( $query );
}
# --------------------
# Returns the specified field value of the specified bug
function get_bug_field( $p_bug_id, $p_field_name ) {
global $g_mantis_bug_table;
$c_bug_id = (integer)$p_bug_id;
$query ="SELECT $p_field_name ".
"FROM $g_mantis_bug_table ".
"WHERE id='$c_bug_id' ".
"LIMIT 1";
$result = db_query( $query );
return db_result( $result, 0 );
}
# --------------------
# Returns the specified field value of the specified bug text
function get_bug_text_field( $p_bug_id, $p_field_name ) {
global $g_mantis_bug_text_table;
$t_bug_text_id = get_bug_field( $p_bug_id, 'bug_text_id' );
$query ="SELECT $p_field_name ".
"FROM $g_mantis_bug_text_table ".
"WHERE id='$t_bug_text_id' ".
"LIMIT 1";
$result = db_query( $query );
return db_result( $result, 0 );
}
# --------------------
# Returns the number of bugnotes for the given bug_id
function bug_bugnote_count( $p_bug_id ) {
global $g_mantis_bugnote_table, $g_private_bugnote_threshold;
$c_bug_id = db_prepare_int( $p_bug_id );
if ( !access_level_check_greater_or_equal( $g_private_bugnote_threshold ) ) {
$t_restriction = 'AND view_state=' . PUBLIC;
} else {
$t_restriction = '';
}
$query ="SELECT COUNT(*) ".
"FROM $g_mantis_bugnote_table ".
"WHERE bug_id ='$c_bug_id' $t_restriction";
$result = db_query( $query );
# @@@ check $result and error or something
return db_result( $result, 0 );
}
?>