summaryrefslogtreecommitdiffstats
path: root/process_bug.cgi
blob: f6997d0e6dced6b5674e6dacdf18ce49fd496cf3 (plain)
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
#! /usr/bonsaitools/bin/mysqltcl
# -*- Mode: tcl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
# License for the specific language governing rights and limitations
# under the License.
# 
# The Original Code is the Bugzilla Bug Tracking System.
# 
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are Copyright (C) 1998
# Netscape Communications Corporation. All Rights Reserved.
# 
# Contributor(s): Terry Weissman <terry@mozilla.org>

source "CGI.tcl"

confirm_login

puts "Content-type: text/html\n"

GetVersionTable

if {![cequal $FORM(product) $dontchange]} {
    set prod [FormData product]
    set vok [expr [lsearch -exact $versions($prod) \
                       [FormData version]] >= 0]
    set cok [expr [lsearch -exact $components($prod) \
                       [FormData component]] >= 0]
    if {!$vok || !$cok} {
        puts "<H1>Changing product means changing version and component.</H1>"
        puts "You have chosen a new product, and now the version and/or"
        puts "component fields are not correct.  Please set them now.<p>"
        puts "<form>"
        puts "<table>"
        puts "<tr>"
        puts "<td align=right><b>Product:</b></td>"
        puts "<td>$prod</td>"
        puts "</tr><tr>"
        puts "<td align=right><b>Version:</b></td>"
        puts "<td>[Version_element [FormData version] $prod]</td>"
        puts "</tr><tr>"
        puts "<td align=right><b>Component:</b></td>"
        puts "<td>[Component_element [FormData component] $prod]</td>"
        puts "</tr>"
        puts "</table>"
        foreach i [array names FORM] {
            if {[lsearch -exact {version component} $i] < 0} {
                puts "<input type=hidden name=$i value=\"[value_quote $FORM($i)]\">"
            }
        }
        puts "<input type=submit value=Commit>"
        puts "</form>"
        puts "</hr>"
        puts "<a href=query.cgi>Cancel all this and go back to the query page.</a>"
        exit
    }
}


if {[info exists FORM(id)]} {
    set idlist $FORM(id)
} else {
    set idlist {}
    foreach i [array names FORM] {
        if {[string match "id_*" $i]} {
            lappend idlist [crange $i 3 end]
        }
    }
}

if {![info exists FORM(who)]} {
    set FORM(who) $COOKIE(Bugzilla_login)
}

puts "<TITLE>Update Bug $idlist</TITLE>"
if {[info exists FORM(id)]} {
    navigation_header
}
puts "<HR>"
set query "update bugs\nset"
set comma ""
umask 0

proc DoComma {} {
    global query comma
    append query "$comma\n    "
    set comma ","
}

proc ChangeStatus {str} {
    global dontchange query
    if {![cequal $str $dontchange]} {
        DoComma
        append query "bug_status = '$str'"
    }
}

proc ChangeResolution {str} {
    global dontchange query
    if {![cequal $str $dontchange]} {
        DoComma
        append query "resolution = '$str'"
    }
}




foreach field {rep_platform priority bug_severity url summary \
                   component bug_file_loc short_desc \
                   product version component} {
    if {[info exists FORM($field)]} {
        if {![cequal $FORM($field) $dontchange]} {
            DoComma
            regsub -all "'" [FormData $field] "''" value
            append query "$field = '$value'"
        }
    }
}



ConnectToDatabase

switch -exact $FORM(knob) {
    none {}
    accept {
        ChangeStatus ASSIGNED
    }
    clearresolution {
        ChangeResolution {}
    }
    resolve {
        ChangeStatus RESOLVED
        ChangeResolution $FORM(resolution)
    }
    reassign {
        ChangeStatus NEW
        DoComma
        set newid [DBNameToIdAndCheck $FORM(assigned_to)]
        append query "assigned_to = $newid"
    }
    reassignbycomponent {
        if {[cequal $FORM(component) $dontchange]} {
            puts "You must specify a component whose owner should get assigned"
            puts "these bugs."
            exit 0
        }
        ChangeStatus NEW
        DoComma
        SendSQL "select initialowner from components
where program='[SqlQuote $FORM(product)]'
and value='[SqlQuote $FORM(component)]'"
        set newname [lindex [FetchSQLData] 0]
        set newid [DBNameToIdAndCheck $newname 1]
        append query "assigned_to = $newid"
    }   
    reopen {
        ChangeStatus REOPENED
    }
    verify {
        ChangeStatus VERIFIED
    }
    close {
        ChangeStatus CLOSED
    }
    duplicate {
        ChangeStatus RESOLVED
        ChangeResolution DUPLICATE
        set num $FORM(dup_id)
        if {[catch {incr num}]} {
            puts "You must specify a bug number of which this bug is a"
            puts "duplicate.  The bug has not been changed."
            exit
        }
        if {$FORM(dup_id) == $FORM(id)} {
            puts "Nice try.  But it doesn't really make sense to mark a bug as"
            puts "a duplicate of itself, does it?"
            exit
        }
        AppendComment $FORM(dup_id) $FORM(who) "*** Bug $FORM(id) has been marked as a duplicate of this bug. ***"
        append FORM(comment) "\n\n*** This bug has been marked as a duplicate of $FORM(dup_id) ***"
        exec ./processmail $FORM(dup_id) < /dev/null > /dev/null 2> /dev/null &
    }
    default {
        puts "Unknown action $FORM(knob)!"
        exit
    }
}


if {[lempty $idlist]} {
    puts "You apparently didn't choose any bugs to modify."
    puts "<p>Click <b>Back</b> and try again."
    exit
}

if {[cequal $comma ""]} {
    set comment {}
    if {[info exists FORM(comment)]} {
        set comment $FORM(comment)
    }
    if {[cequal $comment ""]} {
        puts "Um, you apparently did not change anything on the selected bugs."
        puts "<p>Click <b>Back</b> and try again."
        exit
    }
}

set basequery $query

proc SnapShotBug {id} {
    global log_columns
    SendSQL "select [join $log_columns ","] from bugs where bug_id = $id"
    return [FetchSQLData]
}


foreach id $idlist {
    SendSQL "lock tables bugs write, bugs_activity write, cc write, profiles write"
    set oldvalues [SnapShotBug $id]

    set query "$basequery\nwhere bug_id = $id"
    
# puts "<PRE>$query</PRE>"

    if {![cequal $comma ""]} {
        if { [SendSQL $query] != 0 } {
          puts "<H1>Error -- Changes not applied</H1>"
          puts "OK, the database rejected the changes for some reason"
          puts "which bugzilla can't deal with.  The error string returned"
          puts "was:<PRE>$oramsg(errortxt)</PRE>"
          puts "Here is the query which caused the error:"
          puts "<PRE>$query</PRE>"
        }
        while {[MoreSQLData]} {
            FetchSQLData
        }
    }
    
    if {[info exists FORM(comment)]} {
        AppendComment $id $FORM(who) [FormData comment]
    }
    
    if {[info exists FORM(cc)] && [ShowCcList $id] != [lookup FORM cc]} {
        set ccids(zz) 1
        unset ccids(zz)
        foreach person [split $FORM(cc) " ,"] {
            if {![cequal $person ""]} {
                set cid [DBNameToIdAndCheck $person]
                set ccids($cid) 1
            }
        }
        
        SendSQL "delete from cc where bug_id = $id"
        while {[MoreSQLData]} { FetchSQLData }
        foreach ccid [array names ccids] {
            SendSQL "insert into cc (bug_id, who) values ($id, $ccid)"
            while { [ MoreSQLData ] } { FetchSQLData }
        }
    }

#    oracommit $lhandle

    set newvalues [SnapShotBug $id]
    foreach col $log_columns {
        set old [lvarpop oldvalues]
        set new [lvarpop newvalues]
        if {![cequal $old $new]} {
            if {![info exists whoid]} {
                set whoid [DBNameToIdAndCheck $FORM(who)]
                SendSQL "select delta_ts from bugs where bug_id = $id"
                set timestamp [lindex [FetchSQLData] 0]
            }
            if {[cequal $col assigned_to]} {
                set old [DBID_to_name $old]
                set new [DBID_to_name $new]
            }
            set q "insert into bugs_activity (bug_id,who,when,field,oldvalue,newvalue) values ($id,$whoid,$timestamp,'[SqlQuote $col]','[SqlQuote $old]','[SqlQuote $new]')"
            # puts "<pre>$q</pre>"
            SendSQL $q
        }
    }
    
    puts "<TABLE BORDER=1><TD><H1>Changes Submitted</H1>"
    puts "<TD><A HREF=\"show_bug.cgi?id=$id\">Back To BUG# $id</A></TABLE>"
    flush stdout

    SendSQL "unlock tables"

    exec ./processmail $id < /dev/null > /dev/null 2> /dev/null &
}

if {[info exists next_bug]} {
    set FORM(id) $next_bug
    puts "<HR>"

    navigation_header
    source "bug_form.tcl"
} else {
  puts "<BR><A HREF=\"query.cgi\">Back To Query Page</A>"
}