Commit dfcc2146 authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 303695: Eliminate deprecated Bugzilla::DB routines from post_bug.cgi - Patch…

Bug 303695: Eliminate deprecated Bugzilla::DB routines from post_bug.cgi - Patch by Gabriel Sales de Oliveira <gabriel@async.com.br> r=LpSolit a=justdave
parent 5de2bb1d
...@@ -145,14 +145,14 @@ if (Param("commentoncreate") && !trim($cgi->param('comment'))) { ...@@ -145,14 +145,14 @@ if (Param("commentoncreate") && !trim($cgi->param('comment'))) {
# If bug_file_loc is "http://", the default, use an empty value instead. # If bug_file_loc is "http://", the default, use an empty value instead.
$cgi->param('bug_file_loc', '') if $cgi->param('bug_file_loc') eq 'http://'; $cgi->param('bug_file_loc', '') if $cgi->param('bug_file_loc') eq 'http://';
my $sql_product = SqlQuote($cgi->param('product'));
my $sql_component = SqlQuote($cgi->param('component'));
# Default assignee is the component owner. # Default assignee is the component owner.
if (!UserInGroup("editbugs") || $cgi->param('assigned_to') eq "") { if (!UserInGroup("editbugs") || $cgi->param('assigned_to') eq "") {
SendSQL("SELECT initialowner FROM components " . my $initialowner = $dbh->selectrow_array(q{SELECT initialowner
"WHERE id = $component_id"); FROM components
$cgi->param(-name => 'assigned_to', -value => FetchOneColumn()); WHERE id = ?},
undef, $component_id);
$cgi->param(-name => 'assigned_to', -value => $initialowner);
} else { } else {
$cgi->param(-name => 'assigned_to', $cgi->param(-name => 'assigned_to',
-value => DBNameToIdAndCheck(trim($cgi->param('assigned_to')))); -value => DBNameToIdAndCheck(trim($cgi->param('assigned_to'))));
...@@ -177,9 +177,10 @@ if (Param("useqacontact")) { ...@@ -177,9 +177,10 @@ if (Param("useqacontact")) {
my $qa_contact; my $qa_contact;
if (!UserInGroup("editbugs") || !defined $cgi->param('qa_contact') if (!UserInGroup("editbugs") || !defined $cgi->param('qa_contact')
|| trim($cgi->param('qa_contact')) eq "") { || trim($cgi->param('qa_contact')) eq "") {
SendSQL("SELECT initialqacontact FROM components " . ($qa_contact) = $dbh->selectrow_array(q{SELECT initialqacontact
"WHERE id = $component_id"); FROM components
$qa_contact = FetchOneColumn(); WHERE id = ?},
undef, $component_id);
} else { } else {
$qa_contact = DBNameToIdAndCheck(trim($cgi->param('qa_contact'))); $qa_contact = DBNameToIdAndCheck(trim($cgi->param('qa_contact')));
} }
...@@ -198,15 +199,24 @@ if (UserInGroup("editbugs") || UserInGroup("canconfirm")) { ...@@ -198,15 +199,24 @@ if (UserInGroup("editbugs") || UserInGroup("canconfirm")) {
} else { } else {
# Default to UNCONFIRMED if we are using it, NEW otherwise # Default to UNCONFIRMED if we are using it, NEW otherwise
$cgi->param(-name => 'bug_status', -value => 'UNCONFIRMED'); $cgi->param(-name => 'bug_status', -value => 'UNCONFIRMED');
SendSQL("SELECT votestoconfirm FROM products WHERE id = $product_id"); my $votestoconfirm = $dbh->selectrow_array(q{SELECT votestoconfirm
if (!FetchOneColumn()) { FROM products
WHERE id = ?},
undef, $product_id);
if (!$votestoconfirm) {
$cgi->param(-name => 'bug_status', -value => "NEW"); $cgi->param(-name => 'bug_status', -value => "NEW");
} }
} }
trick_taint($product);
if (!defined $cgi->param('target_milestone')) { if (!defined $cgi->param('target_milestone')) {
SendSQL("SELECT defaultmilestone FROM products WHERE name=$sql_product"); my $defaultmilestone = $dbh->selectrow_array(q{SELECT defaultmilestone
$cgi->param(-name => 'target_milestone', -value => FetchOneColumn()); FROM products
WHERE name = ?},
undef, $product);
$cgi->param(-name => 'target_milestone', -value => $defaultmilestone);
} }
if (!Param('letsubmitterchoosepriority')) { if (!Param('letsubmitterchoosepriority')) {
...@@ -329,53 +339,67 @@ if (UserInGroup("editbugs")) { ...@@ -329,53 +339,67 @@ if (UserInGroup("editbugs")) {
} }
# get current time # get current time
SendSQL("SELECT NOW()"); my $timestamp = $dbh->selectrow_array(q{SELECT NOW()});
my $timestamp = FetchOneColumn();
my $sql_timestamp = SqlQuote($timestamp);
# Build up SQL string to add bug. # Build up SQL string to add bug.
# creation_ts will only be set when all other fields are defined. # creation_ts will only be set when all other fields are defined.
my $sql = "INSERT INTO bugs " .
"(" . join(",", @used_fields) . ", reporter, delta_ts, " . my @fields_values;
"estimated_time, remaining_time, deadline) " .
"VALUES (";
foreach my $field (@used_fields) { foreach my $field (@used_fields) {
$sql .= SqlQuote($cgi->param($field)) . ","; my $value = $cgi->param($field);
trick_taint($value);
push (@fields_values, $value);
} }
my $sql_used_fields = join(", ", @used_fields);
my $sql_placeholders = "?, " x scalar(@used_fields);
my $query = qq{INSERT INTO bugs ($sql_used_fields, reporter, delta_ts,
estimated_time, remaining_time, deadline)
VALUES ($sql_placeholders ?, ?, ?, ?, ?)};
$comment =~ s/\r\n?/\n/g; # Get rid of \r. $comment =~ s/\r\n?/\n/g; # Get rid of \r.
$comment = trim($comment); $comment = trim($comment);
# If comment is all whitespace, it'll be null at this point. That's # If comment is all whitespace, it'll be null at this point. That's
# OK except for the fact that it causes e-mail to be suppressed. # OK except for the fact that it causes e-mail to be suppressed.
$comment = $comment ? $comment : " "; $comment = $comment ? $comment : " ";
$sql .= $user->id . ", $sql_timestamp, "; push (@fields_values, $user->id);
push (@fields_values, $timestamp);
my $est_time = 0;
my $deadline;
# Time Tracking # Time Tracking
if (UserInGroup(Param("timetrackinggroup")) && if (UserInGroup(Param("timetrackinggroup")) &&
defined $cgi->param('estimated_time')) { defined $cgi->param('estimated_time')) {
my $est_time = $cgi->param('estimated_time'); $est_time = $cgi->param('estimated_time');
Bugzilla::Bug::ValidateTime($est_time, 'estimated_time'); Bugzilla::Bug::ValidateTime($est_time, 'estimated_time');
$sql .= SqlQuote($est_time) . "," . SqlQuote($est_time) . ","; trick_taint($est_time);
} else {
$sql .= "0, 0, ";
} }
push (@fields_values, $est_time, $est_time);
if ((UserInGroup(Param("timetrackinggroup"))) && ($cgi->param('deadline'))) { if ((UserInGroup(Param("timetrackinggroup"))) && ($cgi->param('deadline'))) {
validate_date($cgi->param('deadline')) validate_date($cgi->param('deadline'))
|| ThrowUserError('illegal_date', {date => $cgi->param('deadline'), || ThrowUserError('illegal_date', {date => $cgi->param('deadline'),
format => 'YYYY-MM-DD'}); format => 'YYYY-MM-DD'});
$sql .= SqlQuote($cgi->param('deadline')); $deadline = $cgi->param('deadline');
} else { trick_taint($deadline);
$sql .= "NULL";
} }
$sql .= ")"; push (@fields_values, $deadline);
# Groups # Groups
my @groupstoadd = (); my @groupstoadd = ();
my $sth_othercontrol = $dbh->prepare(q{SELECT othercontrol
FROM group_control_map
WHERE group_id = ?
AND product_id = ?});
foreach my $b (grep(/^bit-\d*$/, $cgi->param())) { foreach my $b (grep(/^bit-\d*$/, $cgi->param())) {
if ($cgi->param($b)) { if ($cgi->param($b)) {
my $v = substr($b, 4); my $v = substr($b, 4);
...@@ -391,9 +415,8 @@ foreach my $b (grep(/^bit-\d*$/, $cgi->param())) { ...@@ -391,9 +415,8 @@ foreach my $b (grep(/^bit-\d*$/, $cgi->param())) {
} }
my ($permit) = $user->in_group_id($v); my ($permit) = $user->in_group_id($v);
if (!$permit) { if (!$permit) {
SendSQL("SELECT othercontrol FROM group_control_map my $othercontrol = $dbh->selectrow_array($sth_othercontrol,
WHERE group_id = $v AND product_id = $product_id"); undef, ($v, $product_id));
my ($othercontrol) = FetchSQLData();
$permit = (($othercontrol == CONTROLMAPSHOWN) $permit = (($othercontrol == CONTROLMAPSHOWN)
|| ($othercontrol == CONTROLMAPDEFAULT)); || ($othercontrol == CONTROLMAPDEFAULT));
} }
...@@ -403,13 +426,19 @@ foreach my $b (grep(/^bit-\d*$/, $cgi->param())) { ...@@ -403,13 +426,19 @@ foreach my $b (grep(/^bit-\d*$/, $cgi->param())) {
} }
} }
SendSQL("SELECT DISTINCT groups.id, groups.name, " . my $groups = $dbh->selectall_arrayref(q{
"membercontrol, othercontrol, description " . SELECT DISTINCT groups.id, groups.name, membercontrol,
"FROM groups LEFT JOIN group_control_map " . othercontrol, description
"ON group_id = id AND product_id = $product_id " . FROM groups
" WHERE isbuggroup != 0 AND isactive != 0 ORDER BY description"); LEFT JOIN group_control_map
while (MoreSQLData()) { ON group_id = id
my ($id, $groupname, $membercontrol, $othercontrol ) = FetchSQLData(); AND product_id = ?
WHERE isbuggroup != 0
AND isactive != 0
ORDER BY description}, undef, $product_id);
foreach my $group (@$groups) {
my ($id, $groupname, $membercontrol, $othercontrol) = @$group;
$membercontrol ||= 0; $membercontrol ||= 0;
$othercontrol ||= 0; $othercontrol ||= 0;
# Add groups required # Add groups required
...@@ -428,15 +457,16 @@ $dbh->bz_lock_tables('bugs WRITE', 'bug_group_map WRITE', 'longdescs WRITE', ...@@ -428,15 +457,16 @@ $dbh->bz_lock_tables('bugs WRITE', 'bug_group_map WRITE', 'longdescs WRITE',
'user_group_map READ', 'group_group_map READ', 'user_group_map READ', 'group_group_map READ',
'keyworddefs READ', 'fielddefs READ'); 'keyworddefs READ', 'fielddefs READ');
SendSQL($sql); $dbh->do($query, undef, @fields_values);
# Get the bug ID back. # Get the bug ID back.
my $id = $dbh->bz_last_key('bugs', 'bug_id'); my $id = $dbh->bz_last_key('bugs', 'bug_id');
# Add the group restrictions # Add the group restrictions
my $sth_addgroup = $dbh->prepare(q{
INSERT INTO bug_group_map (bug_id, group_id) VALUES (?, ?)});
foreach my $grouptoadd (@groupstoadd) { foreach my $grouptoadd (@groupstoadd) {
SendSQL("INSERT INTO bug_group_map (bug_id, group_id) $sth_addgroup->execute($id, $grouptoadd);
VALUES ($id, $grouptoadd)");
} }
# Add the initial comment, allowing for the fact that it may be private # Add the initial comment, allowing for the fact that it may be private
...@@ -445,40 +475,43 @@ if (Param("insidergroup") && UserInGroup(Param("insidergroup"))) { ...@@ -445,40 +475,43 @@ if (Param("insidergroup") && UserInGroup(Param("insidergroup"))) {
$privacy = $cgi->param('commentprivacy') ? 1 : 0; $privacy = $cgi->param('commentprivacy') ? 1 : 0;
} }
SendSQL("INSERT INTO longdescs (bug_id, who, bug_when, thetext, isprivate) trick_taint($comment);
VALUES ($id, " . SqlQuote($user->id) . ", $sql_timestamp, " . $dbh->do(q{INSERT INTO longdescs (bug_id, who, bug_when, thetext,isprivate)
SqlQuote($comment) . ", $privacy)"); VALUES (?, ?, ?, ?, ?)}, undef, ($id, $user->id, $timestamp,
$comment, $privacy));
# Insert the cclist into the database # Insert the cclist into the database
my $sth_cclist = $dbh->prepare(q{INSERT INTO cc (bug_id, who) VALUES (?,?)});
foreach my $ccid (keys(%ccids)) { foreach my $ccid (keys(%ccids)) {
SendSQL("INSERT INTO cc (bug_id, who) VALUES ($id, $ccid)"); $sth_cclist->execute($id, $ccid);
} }
my @all_deps; my @all_deps;
my $sth_addkeyword = $dbh->prepare(q{
INSERT INTO keywords (bug_id, keywordid) VALUES (?, ?)});
if (UserInGroup("editbugs")) { if (UserInGroup("editbugs")) {
foreach my $keyword (@keywordlist) { foreach my $keyword (@keywordlist) {
SendSQL("INSERT INTO keywords (bug_id, keywordid) $sth_addkeyword->execute($id, $keyword);
VALUES ($id, $keyword)");
} }
if (@keywordlist) { if (@keywordlist) {
# Make sure that we have the correct case for the kw # Make sure that we have the correct case for the kw
SendSQL("SELECT name FROM keyworddefs WHERE id IN ( " . my $kw_ids = join(', ', @keywordlist);
join(',', @keywordlist) . ")"); my $list = $dbh->selectcol_arrayref(q{
my @list; SELECT name
while (MoreSQLData()) { FROM keyworddefs
push (@list, FetchOneColumn()); WHERE id IN ($kw_ids)});
} my $kw_list = join(', ', @$list);
SendSQL("UPDATE bugs SET delta_ts = $sql_timestamp," . $dbh->do(q{UPDATE bugs
" keywords = " . SqlQuote(join(', ', @list)) . SET delta_ts = ?, keywords = ?
" WHERE bug_id = $id"); WHERE bug_id = ?}, undef, ($timestamp, $kw_list, $id));
} }
if ($cgi->param('dependson') || $cgi->param('blocked')) { if ($cgi->param('dependson') || $cgi->param('blocked')) {
foreach my $pair (["blocked", "dependson"], ["dependson", "blocked"]) { foreach my $pair (["blocked", "dependson"], ["dependson", "blocked"]) {
my ($me, $target) = @{$pair}; my ($me, $target) = @{$pair};
my $sth_dep = $dbh->prepare(qq{
INSERT INTO dependencies ($me, $target) VALUES (?, ?)});
foreach my $i (@{$deps{$target}}) { foreach my $i (@{$deps{$target}}) {
SendSQL("INSERT INTO dependencies ($me, $target) values " . $sth_dep->execute($id, $i);
"($id, $i)");
push(@all_deps, $i); # list for mailing dependent bugs push(@all_deps, $i); # list for mailing dependent bugs
# Log the activity for the other bug: # Log the activity for the other bug:
LogActivityEntry($i, $me, "", $id, $user->id, $timestamp); LogActivityEntry($i, $me, "", $id, $user->id, $timestamp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment