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

Bug 303708: Eliminate deprecated Bugzilla::DB routines from BugzillaEmail.pm,…

Bug 303708: Eliminate deprecated Bugzilla::DB routines from BugzillaEmail.pm, bug_email.pl and bugzilla_email_append.pl in contrib - Patch by Gabriel Sales de Oliveira <gabriel@async.com.br> r=LpSolit a=justdave
parent 9530fd5a
...@@ -32,7 +32,6 @@ require "globals.pl"; ...@@ -32,7 +32,6 @@ require "globals.pl";
use strict; use strict;
my $dbh = Bugzilla->dbh;
my $EMAIL_TRANSFORM_NONE = "email_transform_none"; my $EMAIL_TRANSFORM_NONE = "email_transform_none";
my $EMAIL_TRANSFORM_BASE_DOMAIN = "email_transform_base_domain"; my $EMAIL_TRANSFORM_BASE_DOMAIN = "email_transform_base_domain";
...@@ -41,42 +40,38 @@ my $EMAIL_TRANSFORM_NAME_ONLY = "email_transform_name_only"; ...@@ -41,42 +40,38 @@ my $EMAIL_TRANSFORM_NAME_ONLY = "email_transform_name_only";
# change to do incoming email address fuzzy matching # change to do incoming email address fuzzy matching
my $email_transform = $EMAIL_TRANSFORM_NAME_ONLY; my $email_transform = $EMAIL_TRANSFORM_NAME_ONLY;
# findUser()
# This function takes an email address and returns the user email. # This function takes an email address and returns the user email.
# matching is sloppy based on the $email_transform parameter # matching is sloppy based on the $email_transform parameter
sub findUser($) { sub findUser($) {
my $dbh = Bugzilla->dbh;
my ($address) = @_; my ($address) = @_;
# if $email_transform is $EMAIL_TRANSFORM_NONE, return the address, otherwise, return undef # if $email_transform is $EMAIL_TRANSFORM_NONE, return the address, otherwise, return undef
if ($email_transform eq $EMAIL_TRANSFORM_NONE) { if ($email_transform eq $EMAIL_TRANSFORM_NONE) {
my $stmt = "SELECT login_name FROM profiles WHERE " . my $stmt = q{SELECT login_name FROM profiles WHERE } .
$dbh->sql_istrcmp('login_name', $dbh->quote($address)); $dbh->sql_istrcmp('login_name', '?');
SendSQL($stmt); my $found_address = $dbh->selectrow_array($stmt, undef, $address);
my $found_address = FetchOneColumn();
return $found_address; return $found_address;
} elsif ($email_transform eq $EMAIL_TRANSFORM_BASE_DOMAIN) { } elsif ($email_transform eq $EMAIL_TRANSFORM_BASE_DOMAIN) {
my ($username) = ($address =~ /(.+)@/); my ($username) = ($address =~ /(.+)@/);
my $stmt = "SELECT login_name FROM profiles WHERE " . $dbh->sql_regexp( my $stmt = q{SELECT login_name FROM profiles WHERE } . $dbh->sql_regexp(
$dbh->sql_istring('login_name'), $dbh->sql_istring($dbh->quote($username))); $dbh->sql_istring('login_name'), $dbh->sql_istring('?'));
SendSQL($stmt);
my $found_address = $dbh->selectcol_arrayref($stmt, undef, $username);
my $domain; my $domain;
my $found = undef;
my $found_address;
my $new_address = undef; my $new_address = undef;
while ((!$found) && ($found_address = FetchOneColumn())) { foreach my $addr (@$found_address) {
($domain) = ($found_address =~ /.+@(.+)/); ($domain) = ($addr =~ /.+@(.+)/);
if ($address =~ /$domain/) { if ($address =~ /$domain/) {
$found = 1; $new_address = $addr;
$new_address = $found_address; last;
} }
} }
return $new_address; return $new_address;
} elsif ($email_transform eq $EMAIL_TRANSFORM_NAME_ONLY) { } elsif ($email_transform eq $EMAIL_TRANSFORM_NAME_ONLY) {
my ($username) = ($address =~ /(.+)@/); my ($username) = ($address =~ /(.+)@/);
my $stmt = "SELECT login_name FROM profiles WHERE " .$dbh->sql_regexp( my $stmt = q{SELECT login_name FROM profiles WHERE } . $dbh->sql_regexp(
$dbh->sql_istring('login_name'), $dbh->sql_istring($dbh->quote($username))); $dbh->sql_istring('login_name'), $dbh->sql_istring('?'));
SendSQL($stmt); my $found_address = $dbh->selectrow_array($stmt, undef, $username);
my $found_address = FetchOneColumn();
return $found_address; return $found_address;
} }
} }
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
# #
# You need to work with bug_email.pl the MIME::Parser installed. # You need to work with bug_email.pl the MIME::Parser installed.
# #
# $Id: bug_email.pl,v 1.33 2006/02/23 04:38:27 timeless%mozdev.org Exp $ # $Id: bug_email.pl,v 1.34 2006/05/14 19:12:13 lpsolit%gmail.com Exp $
############################################################### ###############################################################
# 02/12/2000 (SML) # 02/12/2000 (SML)
...@@ -87,6 +87,7 @@ BEGIN { ...@@ -87,6 +87,7 @@ BEGIN {
} }
require "globals.pl"; require "globals.pl";
use Bugzilla;
use BugzillaEmail; use BugzillaEmail;
use Bugzilla::Config qw(:DEFAULT $datadir); use Bugzilla::Config qw(:DEFAULT $datadir);
...@@ -133,9 +134,18 @@ sub storeAttachments( $$ ) ...@@ -133,9 +134,18 @@ sub storeAttachments( $$ )
my $data; my $data;
my $listref = \@attachments; my $listref = \@attachments;
my $att_count = 0; my $att_count = 0;
my $dbh = Bugzilla->dbh;
$submitter_id ||= 0; $submitter_id ||= 0;
my $timestamp = $dbh->selectrow_array("SELECT NOW()");
my $sth_attach = $dbh->prepare(q{
INSERT INTO attachments (bug_id, creation_ts, description,
mimetype, ispatch, filename, submitter_id)
VALUES (?, ?, ?, ?, 0, ?, ?) });
my $sth_data = $dbh->prepare(q{INSERT INTO attach_data (id, thedata)
VALUES (LAST_INSERT_ID(), ?)});
foreach my $pairref ( @$listref ) { foreach my $pairref ( @$listref ) {
my ($decoded_file, $mime, $on_disk, $description) = @$pairref; my ($decoded_file, $mime, $on_disk, $description) = @$pairref;
...@@ -161,19 +171,12 @@ sub storeAttachments( $$ ) ...@@ -161,19 +171,12 @@ sub storeAttachments( $$ )
# data is in the scalar # data is in the scalar
$data = $decoded_file; $data = $decoded_file;
} }
my @values = ($bugid, $timestamp, $description, $mime, $decoded_file, $submitter_id);
unless ($test) {
# Make SQL-String $sth_attach->execute(@values);
my $sql = "insert into attachments (bug_id, creation_ts, description, mimetype, ispatch, filename, submitter_id) values ("; $sth_data->execute($data);
$sql .= "$bugid, now(), " . SqlQuote( $description ) . ", "; }
$sql .= SqlQuote( $mime ) . ", ";
$sql .= "0, ";
$sql .= SqlQuote( $decoded_file ) . ", ";
$sql .= "$submitter_id );";
SendSQL( $sql ) unless( $test );
$sql = "insert into attach_data (id, thedata) values (LAST_INSERT_ID(), ";
$sql .= SqlQuote( $data ) . ")";
SendSQL( $sql ) unless( $test );
} }
return( $att_count ); return( $att_count );
...@@ -192,26 +195,9 @@ sub horLine( ) ...@@ -192,26 +195,9 @@ sub horLine( )
############################################################### ###############################################################
# Check if $Name is in $GroupName # Check if $Name is in $GroupName
# This is no more CreateBugs group, so I'm using this routine to just determine if the user is
# in the database. Eventually, here should be a separate routine or renamed, or something (SML)
sub CheckPermissions { sub CheckPermissions {
my ($GroupName, $Name) = @_; my ($GroupName, $Name) = @_;
# SendSQL("select login_name from profiles,groups where groups.name='$GroupName' and profiles.groupset & groups.bit = groups.bit and profiles.login_name=\'$Name\'");
# my $NewName = FetchOneColumn();
# if ( $NewName eq $Name ) {
# return $Name;
# } else {
# return;
# }
# my $query = "SELECT login_name FROM profiles WHERE profiles.login_name=\'$Name\'";
# SendSQL($query);
# my $check_name = FetchOneColumn();
# if ($check_name eq $Name) {
# return $Name;
# } else {
# return;
# }
return findUser($Name); return findUser($Name);
} }
...@@ -219,14 +205,11 @@ sub CheckPermissions { ...@@ -219,14 +205,11 @@ sub CheckPermissions {
# Check if product is valid. # Check if product is valid.
sub CheckProduct { sub CheckProduct {
my $Product = shift; my $Product = shift;
my $dbh = Bugzilla->dbh;
SendSQL("select name from products where name = " . SqlQuote($Product)); my $prod_name = $dbh->selectrow_array(q{SELECT name
my $Result = FetchOneColumn(); FROM products
if (lc($Result) eq lc($Product)) { WHERE name = ?}, undef, $Product);
return $Result; return $prod_name || "";
} else {
return "";
}
} }
############################################################### ###############################################################
...@@ -234,14 +217,16 @@ sub CheckProduct { ...@@ -234,14 +217,16 @@ sub CheckProduct {
sub CheckComponent { sub CheckComponent {
my $Product = shift; my $Product = shift;
my $Component = shift; my $Component = shift;
my $dbh = Bugzilla->dbh;
SendSQL("select components.name from components, products where components.product_id = products.id AND products.name=" . SqlQuote($Product) . " and components.name=" . SqlQuote($Component)); my $comp_name = $dbh->selectrow_array(q{SELECT components.name
my $Result = FetchOneColumn(); FROM components
if (lc($Result) eq lc($Component)) { INNER JOIN products
return $Result; ON components.product_id = products.id
} else { WHERE products.name= ?
return ""; AND components.name= ?},
} undef, $Product, $Component);
return $comp_name || "";
} }
############################################################### ###############################################################
...@@ -249,14 +234,15 @@ sub CheckComponent { ...@@ -249,14 +234,15 @@ sub CheckComponent {
sub CheckVersion { sub CheckVersion {
my $Product = shift; my $Product = shift;
my $Version = shift; my $Version = shift;
my $dbh = Bugzilla->dbh;
SendSQL("select value from versions, products where versions.product_id = products.id AND products.name=" . SqlQuote($Product) . " and value=" . SqlQuote($Version)); my $version_value = $dbh->selectrow_array(q{SELECT value
my $Result = FetchOneColumn(); FROM versions
if (lc($Result) eq lc($Version)) { INNER JOIN products
return $Result; ON versions.product_id = products.id
} else { WHERE products.name= ?
return ""; AND value= ?}, undef, $Product, $Version);
} return $version_value || "";
} }
############################################################### ###############################################################
...@@ -314,7 +300,7 @@ sub CheckPriority ...@@ -314,7 +300,7 @@ sub CheckPriority
my $Text = "You sent wrong priority-setting, valid values are:" . my $Text = "You sent wrong priority-setting, valid values are:" .
join( "\n\t", @$all_prios ) . "\n\n"; join( "\n\t", @$all_prios ) . "\n\n";
$Text .= "* The priority is set to the default value ". $Text .= "* The priority is set to the default value ".
SqlQuote( Param('defaultpriority')) . "\n"; Param('defaultpriority') . "\n";
BugMailError( 0, $Text ); BugMailError( 0, $Text );
...@@ -337,8 +323,7 @@ sub CheckSeverity ...@@ -337,8 +323,7 @@ sub CheckSeverity
# OK, Prio was not defined - create Answer # OK, Prio was not defined - create Answer
my $Text = "You sent wrong bug_severity-setting, valid values are:" . my $Text = "You sent wrong bug_severity-setting, valid values are:" .
join( "\n\t", @$all_sever ) . "\n\n"; join( "\n\t", @$all_sever ) . "\n\n";
$Text .= "* The bug_severity is set to the default value ". $Text .= "* The bug_severity is set to the default value 'normal' \n";
SqlQuote( "normal" ) . "\n";
BugMailError( 0, $Text ); BugMailError( 0, $Text );
...@@ -359,8 +344,7 @@ sub CheckArea ...@@ -359,8 +344,7 @@ sub CheckArea
# OK, Area was not defined - create Answer # OK, Area was not defined - create Answer
my $Text = "You sent wrong area-setting, valid values are:" . my $Text = "You sent wrong area-setting, valid values are:" .
join( "\n\t", @$all ) . "\n\n"; join( "\n\t", @$all ) . "\n\n";
$Text .= "* The area is set to the default value ". $Text .= "* The area is set to the default value 'BUILD' \n";
SqlQuote( "BUILD" ) . "\n";
BugMailError( 0, $Text ); BugMailError( 0, $Text );
...@@ -381,8 +365,7 @@ sub CheckPlatform ...@@ -381,8 +365,7 @@ sub CheckPlatform
# OK, Prio was not defined - create Answer # OK, Prio was not defined - create Answer
my $Text = "You sent wrong platform-setting, valid values are:" . my $Text = "You sent wrong platform-setting, valid values are:" .
join( "\n\t", @$all ) . "\n\n"; join( "\n\t", @$all ) . "\n\n";
$Text .= "* The rep_platform is set to the default value ". $Text .= "* The rep_platform is set to the default value 'All' \n";
SqlQuote( "All" ) . "\n";
BugMailError( 0, $Text ); BugMailError( 0, $Text );
...@@ -403,8 +386,7 @@ sub CheckSystem ...@@ -403,8 +386,7 @@ sub CheckSystem
# OK, Prio was not defined - create Answer # OK, Prio was not defined - create Answer
my $Text = "You sent wrong OS-setting, valid values are:" . my $Text = "You sent wrong OS-setting, valid values are:" .
join( "\n\t", @$all ) . "\n\n"; join( "\n\t", @$all ) . "\n\n";
$Text .= "* The op_sys is set to the default value ". $Text .= "* The op_sys is set to the default value 'Linux' \n";
SqlQuote( "Linux" ) . "\n";
BugMailError( 0, $Text ); BugMailError( 0, $Text );
...@@ -413,21 +395,6 @@ sub CheckSystem ...@@ -413,21 +395,6 @@ sub CheckSystem
} }
} }
###############################################################
# Fetches all lines of a query with a single column selected and
# returns it as an array
#
sub FetchAllSQLData( )
{
my @res = ();
while( MoreSQLData() ){
push( @res, FetchOneColumn() );
}
return( @res );
}
############################################################### ###############################################################
# Error Handler for Errors in the mail # Error Handler for Errors in the mail
# #
...@@ -830,10 +797,14 @@ if (Param("useqacontact")) { ...@@ -830,10 +797,14 @@ if (Param("useqacontact")) {
&& $Control{'qa_contact'} !~ /^\s*$/ ) { && $Control{'qa_contact'} !~ /^\s*$/ ) {
$Control{'qa_contact'} = DBname_to_id($Control{'qa_contact'}); $Control{'qa_contact'} = DBname_to_id($Control{'qa_contact'});
} else { } else {
SendSQL("select initialqacontact from components, products where components.product_id = products.id AND products.name=" . $Control{'qa_contact'} = $dbh->selectrow_array(q{
SqlQuote($Control{'product'}) . SELECT initialqacontact
" and components.name=" . SqlQuote($Control{'component'})); FROM components
$Control{'qa_contact'} = FetchOneColumn(); INNER JOIN products
ON components.product_id = products.id
WHERE products.name = ?
AND components.name = ?},
undef, $Control{'product'}, $Control{'component'});
} }
} }
...@@ -841,7 +812,7 @@ if (Param("useqacontact")) { ...@@ -841,7 +812,7 @@ if (Param("useqacontact")) {
# depends on the product ! # depends on the product !
# => first check product ! # => first check product !
# Product # Product
my @all_products = (); my $all_products;
# set to the default product. If the default product is empty, this has no effect # set to the default product. If the default product is empty, this has no effect
my $Product = $DEFAULT_PRODUCT; my $Product = $DEFAULT_PRODUCT;
$Product = CheckProduct( $Control{'product'} ) if( defined( $Control{ 'product'} )); $Product = CheckProduct( $Control{'product'} ) if( defined( $Control{ 'product'} ));
...@@ -853,16 +824,16 @@ if ( $Product eq "" ) { ...@@ -853,16 +824,16 @@ if ( $Product eq "" ) {
if( defined( $Control{ 'product'} )); if( defined( $Control{ 'product'} ));
$Text .= "Valid products are:\n\t"; $Text .= "Valid products are:\n\t";
$all_products = $dbh->selectcol_arrayref(q{SELECT name
SendSQL("select name from products ORDER BY name"); FROM products
@all_products = FetchAllSQLData(); ORDER BY name});
$Text .= join( "\n\t", @all_products ) . "\n\n"; $Text .= join( "\n\t", @$all_products ) . "\n\n";
$Text .= horLine(); $Text .= horLine();
BugMailError( 1, $Text ); BugMailError( 1, $Text );
} else { } else {
# Fill list @all_products, which is needed in case of component-help # Fill list @all_products, which is needed in case of component-help
@all_products = ( $Product ); @$all_products = ( $Product );
$product_valid = 1; $product_valid = 1;
} }
$Control{'product'} = $Product; $Control{'product'} = $Product;
...@@ -890,24 +861,28 @@ if ( $Component eq "" ) { ...@@ -890,24 +861,28 @@ if ( $Component eq "" ) {
# Attention: If no product was sent, the user needs info for all components of all # Attention: If no product was sent, the user needs info for all components of all
# products -> big reply mail :) # products -> big reply mail :)
# if a product was sent, only reply the components of the sent product # if a product was sent, only reply the components of the sent product
my @val_components = (); my $val_components;
foreach my $prod ( @all_products ) { my $sth_comp = $dbh->prepare(q{SELECT components.name
FROM components
INNER JOIN products
ON components.product_id = products.id
WHERE products.name = ?});
foreach my $prod ( @$all_products ) {
$Text .= "\nValid components for product `$prod' are: \n\t"; $Text .= "\nValid components for product `$prod' are: \n\t";
SendSQL("SELECT components.name FROM components, products WHERE components.product_id=products.id AND products.name = " . SqlQuote($prod)); $val_components = $dbh->selectcol_arrayref($sth_comp, undef, $prod);
@val_components = FetchAllSQLData();
$Text .= join( "\n\t", @val_components ) . "\n"; $Text .= join( "\n\t", @$val_components ) . "\n";
} }
# Special: if there is a valid product, maybe it has only one component -> use it ! # Special: if there is a valid product, maybe it has only one component -> use it !
# #
my $amount_of_comps = @val_components; my $amount_of_comps = scalar(@$val_components);
if( $product_valid && $amount_of_comps == 1 ) { if( $product_valid && $amount_of_comps == 1 ) {
$Component = $val_components[0]; $Component = @$val_components[0];
$Text .= " * You did not send a component, but a valid product " . SqlQuote( $Product ) . ".\n"; $Text .= " * You did not send a component, but a valid product $Product.\n";
$Text .= " * This product only has one component ". SqlQuote( $Component ) .".\n" . $Text .= " * This product only has one component $Component.\n" .
" * This component was set by bugzilla for submitting the bug.\n\n"; " * This component was set by bugzilla for submitting the bug.\n\n";
BugMailError( 0, $Text ); # No blocker BugMailError( 0, $Text ); # No blocker
...@@ -927,11 +902,14 @@ if ( defined($Control{'assigned_to'}) ...@@ -927,11 +902,14 @@ if ( defined($Control{'assigned_to'})
&& $Control{'assigned_to'} !~ /^\s*$/ ) { && $Control{'assigned_to'} !~ /^\s*$/ ) {
$Control{'assigned_to'} = login_to_id($Control{'assigned_to'}); $Control{'assigned_to'} = login_to_id($Control{'assigned_to'});
} else { } else {
SendSQL("select initialowner from components, products where " . $Control{'assigned_to'} = $dbh->selectrow_array(q{
" components.product_id=products.id AND products.name=" . SELECT initialowner
SqlQuote($Control{'product'}) . FROM components
" and components.name=" . SqlQuote($Control{'component'})); INNER JOIN products
$Control{'assigned_to'} = FetchOneColumn(); ON components.product_id=products.id
WHERE products.name= ?
AND components.name= ?},
undef, $Control{'product'}, $Control{'component'});
} }
if ( $Control{'assigned_to'} == 0 ) { if ( $Control{'assigned_to'} == 0 ) {
...@@ -971,11 +949,16 @@ if ( $Version eq "" ) { ...@@ -971,11 +949,16 @@ if ( $Version eq "" ) {
my $anz_versions; my $anz_versions;
my @all_versions; my @all_versions;
# Assemble help text # Assemble help text
foreach my $prod ( @all_products ) { my $sth_versions = $dbh->prepare(q{SELECT value
$Text .= "Valid versions for product " . SqlQuote( $prod ) . " are: \n\t"; FROM versions
INNER JOIN products
ON versions.product_id = products.id
WHERE products.name= ?});
SendSQL("select value from versions, products where versions.product_id=products.id AND products.name=" . SqlQuote( $prod )); foreach my $prod ( @$all_products ) {
@all_versions = FetchAllSQLData(); $Text .= "Valid versions for product $prod are: \n\t";
@all_versions = @{$dbh->selectcol_arrayref($sth_versions, undef, $prod)};
$anz_versions = @all_versions; $anz_versions = @all_versions;
$Text .= join( "\n\t", @all_versions ) . "\n" ; $Text .= join( "\n\t", @all_versions ) . "\n" ;
...@@ -985,8 +968,8 @@ if ( $Version eq "" ) { ...@@ -985,8 +968,8 @@ if ( $Version eq "" ) {
if( $anz_versions == 1 && $product_valid ) { if( $anz_versions == 1 && $product_valid ) {
$Version = $all_versions[0]; $Version = $all_versions[0];
# Fine, there is only one version string # Fine, there is only one version string
$Text .= " * You did not send a version, but a valid product " . SqlQuote( $Product ) . ".\n"; $Text .= " * You did not send a version, but a valid product $Product.\n";
$Text .= " * This product has has only the one version ". SqlQuote( $Version) .".\n" . $Text .= " * This product has has only the one version $Version.\n" .
" * This version was set by bugzilla for submitting the bug.\n\n"; " * This version was set by bugzilla for submitting the bug.\n\n";
$Text .= horLine(); $Text .= horLine();
BugMailError( 0, $Text ); # No blocker BugMailError( 0, $Text ); # No blocker
...@@ -1010,8 +993,11 @@ $GroupSet = $Control{'groupset'} if( defined( $Control{ 'groupset' })); ...@@ -1010,8 +993,11 @@ $GroupSet = $Control{'groupset'} if( defined( $Control{ 'groupset' }));
# #
# Fetch the default value for groupsetting # Fetch the default value for groupsetting
my $DefaultGroup = 'ReadInternal'; my $DefaultGroup = 'ReadInternal';
SendSQL("select id from groups where name=" . SqlQuote( $DefaultGroup ));
my $default_group = FetchOneColumn(); my $default_group = $dbh->selectrow_array(q{
SELECT id
FROM groups
WHERE name= ?}, undef, $DefaultGroup);
if( $GroupSet eq "" ) { if( $GroupSet eq "" ) {
# Too bad: Groupset does not contain anything -> set to default # Too bad: Groupset does not contain anything -> set to default
...@@ -1031,10 +1017,11 @@ if( $GroupSet eq "" ) { ...@@ -1031,10 +1017,11 @@ if( $GroupSet eq "" ) {
# #
# Split literal Groupsettings either on Whitespaces, +-Signs or , # Split literal Groupsettings either on Whitespaces, +-Signs or ,
# Then search for every Literal in the DB - col name # Then search for every Literal in the DB - col name
my $sth_groups = $dbh->prepare(q{SELECT id, name
FROM groups
WHERE name= ?});
foreach ( split /\s+|\s*\+\s*|\s*,\s*/, $GroupSet ) { foreach ( split /\s+|\s*\+\s*|\s*,\s*/, $GroupSet ) {
SendSQL("select id, Name from groups where name=" . SqlQuote($_)); my( $bval, $bname ) = $dbh->selectrow_array($sth_groups, undef, $_);
my( $bval, $bname ) = FetchSQLData();
if( defined( $bname ) && $_ eq $bname ) { if( defined( $bname ) && $_ eq $bname ) {
$GroupArr{$bname} = $bval; $GroupArr{$bname} = $bval;
} else { } else {
...@@ -1048,9 +1035,15 @@ if( $GroupSet eq "" ) { ...@@ -1048,9 +1035,15 @@ if( $GroupSet eq "" ) {
if( $gserr > 0 ) { if( $gserr > 0 ) {
# There happend errors # There happend errors
$Text .= "Here are all valid literal Groupsetting-strings:\n\t"; $Text .= "Here are all valid literal Groupsetting-strings:\n\t";
SendSQL( "select g.name from groups g, user_group_map u where u.user_id=".$Control{'reporter'}. my $groups = $dbh->selectcol_arrayref(q{
" and g.isbuggroup=1 and g.id = u.group_id group by g.name;" ); SELECT g.name
$Text .= join( "\n\t", FetchAllSQLData()) . "\n"; FROM groups g
INNER JOIN user_group_map u
ON g.id = u.group_id
WHERE u.user_id = ?
AND g.isbuggroup = 1 } .
$dbh->sql_group_by('g.name'), undef, $Control{'reporter'});
$Text .= join( "\n\t", @$groups ) . "\n";
BugMailError( 0, $Text ); BugMailError( 0, $Text );
} }
} # End of checking groupsets } # End of checking groupsets
...@@ -1089,25 +1082,21 @@ END ...@@ -1089,25 +1082,21 @@ END
$reply .= "Your Bug-ID is "; $reply .= "Your Bug-ID is ";
my $reporter = ""; my $reporter = "";
my $query = "insert into bugs (\n" . join(",\n", @used_fields ) .
", bug_status, creation_ts, delta_ts, everconfirmed) values ( ";
# 'Yuck'. Then again, this whole file should be rewritten anyway...
$query =~ s/product/product_id/;
$query =~ s/component/component_id/;
my $tmp_reply = "These values were stored by bugzilla:\n"; my $tmp_reply = "These values were stored by bugzilla:\n";
my $val; my $val;
my @values = ();
foreach my $field (@used_fields) { foreach my $field (@used_fields) {
if( $field eq "groupset" ) { if( $field eq "groupset" ) {
$query .= $Control{$field} . ",\n"; push (@values, $Control{$field});
} elsif ( $field eq 'product' ) { } elsif ( $field eq 'product' ) {
$query .= get_product_id($Control{$field}) . ",\n"; push (@values, get_product_id($Control{$field}));
} elsif ( $field eq 'component' ) { } elsif ( $field eq 'component' ) {
$query .= get_component_id(get_product_id($Control{'product'}), push (@values, get_component_id(get_product_id($Control{'product'}),
$Control{$field}) . ",\n"; $Control{$field}));
} else { } else {
$query .= SqlQuote($Control{$field}) . ",\n"; push (@values, $Control{$field});
} }
$val = $Control{ $field }; $val = $Control{ $field };
...@@ -1132,35 +1121,44 @@ END ...@@ -1132,35 +1121,44 @@ END
$comment =~ s/\r/\n/g; # Get rid of mac-style line endings. $comment =~ s/\r/\n/g; # Get rid of mac-style line endings.
$comment = trim($comment); $comment = trim($comment);
SendSQL("SELECT now()"); my $bug_when = $dbh->selectrow_array("SELECT NOW()");
my $bug_when = FetchOneColumn();
my $ever_confirmed = 0; my $ever_confirmed = 0;
my $state = SqlQuote("UNCONFIRMED"); my $state = "UNCONFIRMED";
SendSQL("SELECT votestoconfirm FROM products WHERE name = " . my $v_confirm = $dbh->selectrow_array(q{SELECT votestoconfirm
SqlQuote($Control{'product'})); FROM products
if (!FetchOneColumn()) { WHERE name = ?}, undef, $Control{'product'});
if (!$v_confirm) {
$ever_confirmed = 1; $ever_confirmed = 1;
$state = SqlQuote("NEW"); $state = "NEW";
} }
$query .= $state . ", \'$bug_when\', \'$bug_when\', $ever_confirmed)\n"; my $sql_placeholders = "?, " x scalar(@values);
# $query .= SqlQuote( "NEW" ) . ", now(), " . SqlQuote($comment) . " )\n"; my $sql_used_fields = join(", ", @used_fields);
SendSQL("SELECT userid FROM profiles WHERE " . my $query = qq{INSERT INTO bugs ($sql_used_fields, bug_status,
$dbh->sql_istrcmp('login_name', $dbh->quote($reporter))); creation_ts, delta_ts, everconfirmed)
my $userid = FetchOneColumn(); VALUES ($sql_placeholders ?, ?, ?, ? )};
my $id; $query =~ s/product/product_id/;
$query =~ s/component/component_id/;
push (@values, $state, $bug_when, $bug_when, $ever_confirmed);
my $userid = $dbh->selectrow_array(q{SELECT userid FROM profiles WHERE } .
$dbh->sql_istrcmp('login_name', '?'),
undef, $reporter);
my $id;
if( ! $test ) { if( ! $test ) {
SendSQL($query);
$id = Bugzilla->dbh->bz_last_key('bugs', 'bug_id'); $dbh->do($query, undef, @values);
$id = $dbh->bz_last_key('bugs', 'bug_id');
my $long_desc_query = "INSERT INTO longdescs SET bug_id=$id, who=$userid, bug_when=\'$bug_when\', thetext=" . SqlQuote($comment); $dbh->do(q{INSERT INTO longdescs
SendSQL($long_desc_query); SET bug_id= ?, who= ?, bug_when= ?, thetext= ?},
undef, $id, $userid, $bug_when, $comment);
# Cool, the mail was successful # Cool, the mail was successful
# system("./processmail", $id, $SenderShort); # system("./processmail", $id, $SenderShort);
...@@ -1173,9 +1171,10 @@ END ...@@ -1173,9 +1171,10 @@ END
# #
# Handle GroupArr # Handle GroupArr
# #
my $sth_groups = $dbh->prepare(q{INSERT INTO bug_group_map SET bug_id= ?, group_id= ?});
foreach my $grp (keys %GroupArr) { foreach my $grp (keys %GroupArr) {
if( ! $test) { if( ! $test) {
SendSQL("INSERT INTO bug_group_map SET bug_id=$id, group_id=$GroupArr{$grp}"); $sth_groups->execute($id, $GroupArr{$grp});
} else { } else {
print "INSERT INTO bug_group_map SET bug_id=$id, group_id=$GroupArr{$grp}\n"; print "INSERT INTO bug_group_map SET bug_id=$id, group_id=$GroupArr{$grp}\n";
} }
...@@ -1188,7 +1187,6 @@ END ...@@ -1188,7 +1187,6 @@ END
$tmp_reply .= "\n\tYou sent $attaches attachment(s). \n" if( $attaches > 0 ); $tmp_reply .= "\n\tYou sent $attaches attachment(s). \n" if( $attaches > 0 );
$reply .= $id . "\n\n" . $tmp_reply . "\n" . getWarningText(); $reply .= $id . "\n\n" . $tmp_reply . "\n" . getWarningText();
$entity->purge(); # Removes all temp files $entity->purge(); # Removes all temp files
# #
......
...@@ -38,6 +38,7 @@ BEGIN { ...@@ -38,6 +38,7 @@ BEGIN {
} }
require "globals.pl"; require "globals.pl";
use Bugzilla;
use BugzillaEmail; use BugzillaEmail;
use Bugzilla::Config qw(:DEFAULT $datadir); use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::BugMail; use Bugzilla::BugMail;
...@@ -94,18 +95,17 @@ my ($bugid) = ($Subject =~ /\[Bug ([\d]+)\]/); ...@@ -94,18 +95,17 @@ my ($bugid) = ($Subject =~ /\[Bug ([\d]+)\]/);
print "The bugid is $bugid\n"; print "The bugid is $bugid\n";
# make sure the bug exists # make sure the bug exists
my $found_id = $dbh->selectrow_array(q{SELECT bug_id
SendSQL("SELECT bug_id FROM bugs WHERE bug_id = $bugid;"); FROM bugs
my $found_id = FetchOneColumn(); WHERE bug_id = ?}, undef, $bugid);
print "Did we find the bug? $found_id-\n"; print "Did we find the bug? $found_id-\n";
if (!defined($found_id)) { if (!defined($found_id)) {
DealWithError("Bug $bugid does not exist"); DealWithError("Bug $bugid does not exist");
} }
# get the user id # get the user id
SendSQL("SELECT userid FROM profiles WHERE " . my $userid = $dbh->selectrow_array(q{SELECT userid FROM profiles WHERE } .
$dbh->sql_istrcmp('login_name', $dbh->quote($SenderShort))); $dbh->sql_istrcmp('login_name', '?'), undef, $SenderShort);
my $userid = FetchOneColumn();
if (!defined($userid)) { if (!defined($userid)) {
DealWithError("Userid not found for $SenderShort"); DealWithError("Userid not found for $SenderShort");
} }
...@@ -119,8 +119,8 @@ $Subject =~ s/\[Bug [\d]+\]//; ...@@ -119,8 +119,8 @@ $Subject =~ s/\[Bug [\d]+\]//;
my $Body = "Subject: " . $Subject . "\n" . $Comment; my $Body = "Subject: " . $Subject . "\n" . $Comment;
# shove it in the table # shove it in the table
my $long_desc_query = "INSERT INTO longdescs SET bug_id=$found_id, who=$userid, bug_when=NOW(), thetext=" . SqlQuote($Body) . ";"; $dbh->do(q{INSERT INTO longdescs SET bug_id= ?, who= ?, bug_when= NOW(), thetext= ? },
SendSQL($long_desc_query); undef, $found_id, $userid, $Body);
Bugzilla::BugMail::Send( $found_id, { changer => $SenderShort } ); Bugzilla::BugMail::Send( $found_id, { changer => $SenderShort } );
......
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