Bug 43600 - Convert products/components to use ids instead of names.

Initial attempt by jake@bugzilla.org, updated by me r=joel, preed
parent 17b301e7
......@@ -111,13 +111,16 @@ sub initBug {
my $query = "
select
bugs.bug_id, alias, product, version, rep_platform, op_sys, bug_status,
resolution, priority, bug_severity, component, assigned_to, reporter,
bugs.bug_id, alias, products.name, version, rep_platform, op_sys, bug_status,
resolution, priority, bug_severity, components.name, assigned_to, reporter,
bug_file_loc, short_desc, target_milestone, qa_contact,
status_whiteboard, date_format(creation_ts,'%Y-%m-%d %H:%i'),
groupset, delta_ts, sum(votes.count)
from bugs left join votes using(bug_id)
from bugs left join votes using(bug_id),
products, components
where bugs.bug_id = $bug_id
AND products.id = bugs.product_id
AND components.id = bugs.component_id
group by bugs.bug_id";
&::SendSQL(&::SelectVisible($query, $user_id, $usergroupset));
......
......@@ -111,13 +111,16 @@ sub initBug {
my $query = "
select
bugs.bug_id, alias, product, version, rep_platform, op_sys, bug_status,
resolution, priority, bug_severity, component, assigned_to, reporter,
bugs.bug_id, alias, products.name, version, rep_platform, op_sys, bug_status,
resolution, priority, bug_severity, components.name, assigned_to, reporter,
bug_file_loc, short_desc, target_milestone, qa_contact,
status_whiteboard, date_format(creation_ts,'%Y-%m-%d %H:%i'),
groupset, delta_ts, sum(votes.count)
from bugs left join votes using(bug_id)
from bugs left join votes using(bug_id),
products, components
where bugs.bug_id = $bug_id
AND products.id = bugs.product_id
AND components.id = bugs.component_id
group by bugs.bug_id";
&::SendSQL(&::SelectVisible($query, $user_id, $usergroupset));
......
......@@ -66,13 +66,29 @@ sub init {
my @andlist;
# First, deal with all the old hard-coded non-chart-based poop.
unshift(@supptables,
("profiles map_assigned_to",
"profiles map_reporter",
"LEFT JOIN profiles map_qa_contact ON bugs.qa_contact = map_qa_contact.userid"));
unshift(@wherepart,
("bugs.assigned_to = map_assigned_to.userid",
"bugs.reporter = map_reporter.userid"));
if (&::lsearch($fieldsref, 'map_assigned_to.login_name') >= 0) {
push @supptables, "profiles AS map_assigned_to";
push @wherepart, "bugs.assigned_to = map_assigned_to.userid";
}
if (&::lsearch($fieldsref, 'map_reporter.login_name') >= 0) {
push @supptables, "profiles AS map_reporter";
push @wherepart, "bugs.assigned_to = map_reporter.userid";
}
if (&::lsearch($fieldsref, 'map_qa_contact.login_name') >= 0) {
push @supptables, "LEFT JOIN profiles map_qa_contact ON bugs.qa_contact = map_qa_contact.userid";
}
if (&::lsearch($fieldsref, 'map_products.name') >= 0) {
push @supptables, "products AS map_products";
push @wherepart, "bugs.product_id = map_products.id";
}
if (&::lsearch($fieldsref, 'map_components.name') >= 0) {
push @supptables, "components AS map_components";
push @wherepart, "bugs.component_id = map_components.id";
}
my $minvotes;
if (defined $F{'votes'}) {
......@@ -108,6 +124,18 @@ sub init {
}
}
if ($F{'product'}) {
push(@supptables, "products products_");
push(@wherepart, "products_.id = bugs.product_id");
push(@specialchart, ["products_.name", "anyexact", $F{'product'}]);
}
if ($F{'component'}) {
push(@supptables, "components components_");
push(@wherepart, "components_.id = bugs.component_id");
push(@specialchart, ["components_.name", "anyexact", $F{'component'}]);
}
if ($F{'keywords'}) {
my $t = $F{'keywords_type'};
if (!$t || $t eq "or") {
......@@ -248,7 +276,7 @@ sub init {
my @funcdefs =
(
"^(assigned_to|reporter)," => sub {
push(@supptables, "profiles map_$f");
push(@supptables, "profiles AS map_$f");
push(@wherepart, "bugs.$f = map_$f.userid");
$f = "map_$f.login_name";
},
......@@ -391,6 +419,20 @@ sub init {
$f = "(to_days(now()) - to_days(bugs.delta_ts))";
},
"^component,(?!changed)" => sub {
my $table = "components_$chartid";
push(@supptables, "components $table");
push(@wherepart, "bugs.component_id = $table.id");
$f = $ff = "$table.name";
},
"^product,(?!changed)" => sub {
my $table = "products_$chartid";
push(@supptables, "products $table");
push(@wherepart, "bugs.product_id = $table.id");
$f = $ff = "$table.name";
},
"^keywords," => sub {
&::GetVersionTable();
my @list;
......
......@@ -947,7 +947,7 @@ sub CheckIfVotedConfirmed {
SendSQL("SELECT bugs.votes, bugs.bug_status, products.votestoconfirm, " .
" bugs.everconfirmed " .
"FROM bugs, products " .
"WHERE bugs.bug_id = $id AND products.product = bugs.product");
"WHERE bugs.bug_id = $id AND products.product_id = bugs.product_id");
my ($votes, $status, $votestoconfirm, $everconfirmed) = (FetchSQLData());
if ($votes >= $votestoconfirm && $status eq $::unconfirmedstate) {
SendSQL("UPDATE bugs SET bug_status = 'NEW', everconfirmed = 1 " .
......
......@@ -252,7 +252,7 @@ sub validateStatuses
FROM attachments, bugs, attachstatusdefs
WHERE attachments.attach_id = $::FORM{'id'}
AND attachments.bug_id = bugs.bug_id
AND attachstatusdefs.product = bugs.product");
AND attachstatusdefs.product_id = bugs.product_id");
my @statusdefs;
push(@statusdefs, FetchSQLData()) while MoreSQLData();
PopGlobalSQLState();
......@@ -573,7 +573,7 @@ sub edit
SendSQL("SELECT id, name
FROM attachstatusdefs, bugs
WHERE bug_id = $bugid
AND attachstatusdefs.product = bugs.product
AND attachstatusdefs.product_id = bugs.product_id
ORDER BY sortkey");
while ( MoreSQLData() )
{
......
......@@ -77,19 +77,27 @@ sub show_bug {
# Populate the bug hash with the info we get directly from the DB.
my $query = "
SELECT bugs.bug_id, alias, product, version, rep_platform,
SELECT bugs.bug_id, alias, products.name, version, rep_platform,
op_sys, bug_status, resolution, priority,
bug_severity, component, assigned_to, reporter,
bug_severity, components.name, assigned_to, reporter,
bug_file_loc, short_desc, target_milestone,
qa_contact, status_whiteboard,
date_format(creation_ts,'%Y-%m-%d %H:%i'),
groupset, delta_ts, sum(votes.count)
FROM bugs LEFT JOIN votes USING(bug_id)
FROM bugs LEFT JOIN votes USING(bug_id), products, components
WHERE bugs.bug_id = $id
AND bugs.product_id = products.id
AND bugs.component_id = components.id
GROUP BY bugs.bug_id";
SendSQL($query);
# The caller is meant to have checked this. Abort here so that
# we don't get obscure SQL errors, below
if (!MoreSQLData()) {
ThrowCodeError("No data when fetching bug $id");
}
my $value;
my @row = FetchSQLData();
foreach my $field ("bug_id", "alias", "product", "version", "rep_platform",
......
......@@ -397,8 +397,8 @@ DefineColumn("resolution" , "bugs.resolution" , "Result"
DefineColumn("summary" , "bugs.short_desc" , "Summary" );
DefineColumn("summaryfull" , "bugs.short_desc" , "Summary" );
DefineColumn("status_whiteboard" , "bugs.status_whiteboard" , "Status Summary" );
DefineColumn("component" , "bugs.component" , "Component" );
DefineColumn("product" , "bugs.product" , "Product" );
DefineColumn("component" , "map_components.name" , "Component" );
DefineColumn("product" , "map_products.name" , "Product" );
DefineColumn("version" , "bugs.version" , "Version" );
DefineColumn("os" , "bugs.op_sys" , "OS" );
DefineColumn("target_milestone" , "bugs.target_milestone" , "Target Milestone" );
......@@ -561,7 +561,7 @@ if ($order) {
# change it to order by the sortkey of the target_milestone first.
if ($db_order =~ /bugs.target_milestone/) {
$db_order =~ s/bugs.target_milestone/ms_order.sortkey,ms_order.value/;
$query =~ s/\sWHERE\s/ LEFT JOIN milestones ms_order ON ms_order.value = bugs.target_milestone AND ms_order.product = bugs.product WHERE /;
$query =~ s/\sWHERE\s/ LEFT JOIN milestones ms_order ON ms_order.value = bugs.target_milestone AND ms_order.product_id = bugs.product_id WHERE /;
}
# If we are sorting by votes, sort in descending order if no explicit
......
......@@ -67,6 +67,9 @@ sub collect_stats {
my $dir = shift;
my $product = shift;
my $when = localtime (time);
my $product_id = get_product_id($product) unless $product eq '-All-';
die "Unknown product $product" unless ($product_id or $product eq '-All-');
# NB: Need to mangle the product for the filename, but use the real
# product name in the query
......@@ -82,7 +85,7 @@ sub collect_stats {
if( $product eq "-All-" ) {
SendSQL("select count(bug_status) from bugs where bug_status='$status'");
} else {
SendSQL("select count(bug_status) from bugs where bug_status='$status' and product='$product'");
SendSQL("select count(bug_status) from bugs where bug_status='$status' and product_id=$product_id");
}
push @row, FetchOneColumn();
......@@ -92,7 +95,7 @@ sub collect_stats {
if( $product eq "-All-" ) {
SendSQL("select count(resolution) from bugs where resolution='$resolution'");
} else {
SendSQL("select count(resolution) from bugs where resolution='$resolution' and product='$product'");
SendSQL("select count(resolution) from bugs where resolution='$resolution' and product_id=$product_id");
}
push @row, FetchOneColumn();
......
......@@ -37,7 +37,7 @@
#
# You need to work with bug_email.pl the MIME::Parser installed.
#
# $Id: bug_email.pl,v 1.10 2002/07/25 01:47:19 justdave%syndicomm.com Exp $
# $Id: bug_email.pl,v 1.11 2002/08/12 05:43:05 bbaetz%student.usyd.edu.au Exp $
###############################################################
# 02/12/2000 (SML)
......@@ -196,7 +196,7 @@ sub CheckPermissions {
sub CheckProduct {
my $Product = shift;
SendSQL("select product from products where product='$Product'");
SendSQL("select name from products where name = " . SqlQuote($Product));
my $Result = FetchOneColumn();
if (lc($Result) eq lc($Product)) {
return $Result;
......@@ -211,7 +211,7 @@ sub CheckComponent {
my $Product = shift;
my $Component = shift;
SendSQL("select value from components where program=" . SqlQuote($Product) . " and value=" . SqlQuote($Component) . "");
SendSQL("select components.name from components, products where components.product_id = products.id AND products.name=" . SqlQuote($Product) . " and components.name=" . SqlQuote($Component));
my $Result = FetchOneColumn();
if (lc($Result) eq lc($Component)) {
return $Result;
......@@ -226,7 +226,7 @@ sub CheckVersion {
my $Product = shift;
my $Version = shift;
SendSQL("select value from versions where program=" . SqlQuote($Product) . " and value=" . SqlQuote($Version) . "");
SendSQL("select value from versions, products where versions.product_id = products.id AND products.name=" . SqlQuote($Product) . " and value=" . SqlQuote($Version));
my $Result = FetchOneColumn();
if (lc($Result) eq lc($Version)) {
return $Result;
......@@ -840,9 +840,9 @@ if (! CheckPermissions("CreateBugs", $SenderShort ) ) {
# Set QA
if (Param("useqacontact")) {
SendSQL("select initialqacontact from components where program=" .
SendSQL("select initialqacontact from components, products where components.product_id = products.id AND products.name=" .
SqlQuote($Control{'product'}) .
" and value=" . SqlQuote($Control{'component'}));
" and components.name=" . SqlQuote($Control{'component'}));
$Control{'qacontact'} = FetchOneColumn();
}
......@@ -863,7 +863,7 @@ if ( $Product eq "" ) {
$Text .= "Valid products are:\n\t";
SendSQL("select product from products");
SendSQL("select name from products ORDER BY name");
@all_products = FetchAllSQLData();
$Text .= join( "\n\t", @all_products ) . "\n\n";
$Text .= horLine();
......@@ -903,7 +903,7 @@ if ( $Component eq "" ) {
foreach my $prod ( @all_products ) {
$Text .= "\nValid components for product `$prod' are: \n\t";
SendSQL("select value from components where program=" . SqlQuote( $prod ) . "");
SendSQL("SELECT components.name FROM components, products WHERE components.product_id=products.id AND products.name = " . SqlQuote($prod));
@val_components = FetchAllSQLData();
$Text .= join( "\n\t", @val_components ) . "\n";
......@@ -936,9 +936,10 @@ if ( defined($Control{'assigned_to'})
&& $Control{'assigned_to'} !~ /^\s*$/ ) {
$Control{'assigned_to'} = DBname_to_id($Control{'assigned_to'});
} else {
SendSQL("select initialowner from components where program=" .
SendSQL("select initialowner from components, products where " .
" components.product_id=products.id AND products.name=" .
SqlQuote($Control{'product'}) .
" and value=" . SqlQuote($Control{'component'}));
" and components.name=" . SqlQuote($Control{'component'}));
$Control{'assigned_to'} = FetchOneColumn();
}
......@@ -982,7 +983,7 @@ if ( $Version eq "" ) {
foreach my $prod ( @all_products ) {
$Text .= "Valid versions for product " . SqlQuote( $prod ) . " are: \n\t";
SendSQL("select value from versions where program=" . SqlQuote( $prod ) . "");
SendSQL("select value from versions, products where versions.product_id=products.id AND products.name=" . SqlQuote( $prod ));
@all_versions = FetchAllSQLData();
$anz_versions = @all_versions;
$Text .= join( "\n\t", @all_versions ) . "\n" ;
......@@ -1176,11 +1177,20 @@ END
my $query = "insert into bugs (\n" . join(",\n", @used_fields ) .
", bug_status, creation_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 $val;
foreach my $field (@used_fields) {
if( $field eq "groupset" ) {
$query .= $Control{$field} . ",\n";
} elsif ( $field eq 'product' ) {
$query .= get_product_id($Control{$field}) . ",\n";
} elsif ( $field eq 'component' ) {
$query .= get_component_id(get_product_id($Control{'product'}),
$Control{$field}) . ",\n";
} else {
$query .= SqlQuote($Control{$field}) . ",\n";
}
......@@ -1210,8 +1220,8 @@ END
my $ever_confirmed = 0;
my $state = SqlQuote("UNCONFIRMED");
SendSQL("SELECT votestoconfirm FROM products WHERE product = " .
SqlQuote($Control{'product'}) . ";");
SendSQL("SELECT votestoconfirm FROM products WHERE name = " .
SqlQuote($Control{'product'}));
if (!FetchOneColumn()) {
$ever_confirmed = 1;
$state = SqlQuote("NEW");
......
......@@ -23,6 +23,7 @@
use vars qw(
%FORM
%legal_product
$userid
);
......@@ -85,9 +86,9 @@ my $product = $::FORM{'product'};
# which could enable people guessing product names to determine
# whether or not certain products exist in Bugzilla, even if they
# cannot get any other information about that product.
grep($product eq $_ , @::legal_product)
|| DisplayError("The product name is invalid.")
&& exit;
my $product_id = get_product_id($product);
ThrowUserError("The product name is invalid.") unless $product_id;
# Make sure the user is authorized to access this product.
if (Param("usebuggroups") && GroupExists($product)) {
......@@ -102,9 +103,9 @@ if (Param("usebuggroups") && GroupExists($product)) {
######################################################################
my @components;
SendSQL("SELECT value, initialowner, initialqacontact, description FROM " .
"components WHERE program = " . SqlQuote($product) . " ORDER BY " .
"value");
SendSQL("SELECT name, initialowner, initialqacontact, description FROM " .
"components WHERE product_id = $product_id ORDER BY " .
"name");
while (MoreSQLData()) {
my ($name, $initialowner, $initialqacontact, $description) =
FetchSQLData();
......
......@@ -62,6 +62,15 @@ my $product = formvalue("product");
my $sortvisible = formvalue("sortvisible");
my @buglist = (split(/[:,]/, formvalue("bug_id")));
my $product_id;
if ($product) {
$product_id = get_product_id($product);
if (!$product_id) {
ThrowUserError("The product <tt>" . html_quote($product) .
"</tt> does not exist");
}
}
# Small backwards-compatibility hack, dated 2002-04-10.
$sortby = "count" if $sortby eq "dup_count";
......@@ -143,16 +152,17 @@ if (scalar(%count)) {
# WONTFIX. We want to see VERIFIED INVALID and WONTFIX because common
# "bugs" which aren't bugs end up in this state.
my $query = "
SELECT bugs.bug_id, component, bug_severity, op_sys, target_milestone,
short_desc, bug_status, resolution
FROM bugs
WHERE (bug_status != 'CLOSED')
AND ((bug_status = 'VERIFIED' AND resolution IN ('INVALID', 'WONTFIX'))
SELECT bugs.bug_id, components.name, bug_severity, op_sys,
target_milestone, short_desc, bug_status, resolution
FROM bugs, components
WHERE (bugs.component_id = components.id)
AND (bug_status != 'CLOSED')
AND ((bug_status = 'VERIFIED' AND resolution IN ('INVALID', 'WONTFIX'))
OR (bug_status != 'VERIFIED'))
AND bugs.bug_id IN (" . join(", ", keys %count) . ")";
# Limit to a single product if requested
$query .= (" AND product = " . SqlQuote($product)) if $product;
# Limit to a single product if requested
$query .= (" AND bugs.product_id = " . $product_id) if $product_id;
SendSQL(SelectVisible($query,
$userid,
......
......@@ -155,7 +155,7 @@ sub validateSortKey
sub validateProduct
{
# Retrieve a list of products.
SendSQL("SELECT product FROM products");
SendSQL("SELECT name FROM products");
my @products;
push(@products, FetchSQLData()) while MoreSQLData();
......@@ -180,11 +180,13 @@ sub list
# Retrieve a list of attachment status flags and create an array of hashes
# in which each hash contains the data for one flag.
SendSQL("SELECT id, name, description, sortkey, product, count(statusid)
FROM attachstatusdefs LEFT JOIN attachstatuses
ON attachstatusdefs.id=attachstatuses.statusid
GROUP BY id
ORDER BY sortkey");
SendSQL("SELECT attachstatusdefs.id, attachstatusdefs.name, " .
"attachstatusdefs.description, attachstatusdefs.sortkey, products.name, " .
"count(attachstatusdefs.id) " .
"FROM attachstatusdefs, products " .
"WHERE products.id = attachstatusdefs.product_id " .
"GROUP BY id " .
"ORDER BY attachstatusdefs.sortkey");
my @statusdefs;
while ( MoreSQLData() )
{
......@@ -212,7 +214,7 @@ sub create
# Display a form for creating a new attachment status flag.
# Retrieve a list of products to which the attachment status may apply.
SendSQL("SELECT product FROM products");
SendSQL("SELECT name FROM products");
my @products;
push(@products, FetchSQLData()) while MoreSQLData();
......@@ -236,14 +238,13 @@ sub insert
# in a SQL statement.
my $name = SqlQuote($::FORM{'name'});
my $desc = SqlQuote($::FORM{'desc'});
my $product = SqlQuote($::FORM{'product'});
my $product_id = get_product_id($::FORM{'product'});
SendSQL("LOCK TABLES attachstatusdefs WRITE");
SendSQL("SELECT MAX(id) FROM attachstatusdefs");
my $id = FetchSQLData() || 0;
$id++;
SendSQL("INSERT INTO attachstatusdefs (id, name, description, sortkey, product)
VALUES ($id, $name, $desc, $::FORM{'sortkey'}, $product)");
my $id = FetchSQLData() + 1;
SendSQL("INSERT INTO attachstatusdefs (id, name, description, sortkey, product_id)
VALUES ($id, $name, $desc, $::FORM{'sortkey'}, $product_id)");
SendSQL("UNLOCK TABLES");
# Display the "administer attachment status flags" page
......@@ -257,8 +258,11 @@ sub edit
# Display a form for editing an existing attachment status flag.
# Retrieve the definition from the database.
SendSQL("SELECT name, description, sortkey, product
FROM attachstatusdefs WHERE id = $::FORM{'id'}");
SendSQL("SELECT attachstatusdefs.name, attachstatusdefs.description, " .
" attachstatusdefs.sortkey, products.name " .
"FROM attachstatusdefs, products " .
"WHERE attachstatusdefs.product_id = products.id " .
" AND attachstatusdefs.id = $::FORM{'id'}");
my ($name, $desc, $sortkey, $product) = FetchSQLData();
# Define the variables and functions that will be passed to the UI template.
......
......@@ -422,7 +422,7 @@ this box. It is <B>strongly</B> suggested that you review the bugs in this
group before checking the box.<P>
";
}
SendSQL("SELECT product FROM products WHERE product=" . SqlQuote($name));
SendSQL("SELECT name FROM products WHERE name=" . SqlQuote($name));
if (MoreSQLData()) {
$cantdelete = 1;
print "
......@@ -489,7 +489,7 @@ if ($action eq 'delete') {
$cantdelete = 1;
}
}
SendSQL("SELECT product FROM products WHERE product=" . SqlQuote($name));
SendSQL("SELECT name FROM products WHERE name=" . SqlQuote($name));
if (FetchOneColumn()) {
if (!defined $::FORM{'unbind'}) {
$cantdelete = 1;
......
......@@ -33,9 +33,9 @@ sub TestProduct ($)
my $prod = shift;
# does the product exist?
SendSQL("SELECT product
SendSQL("SELECT name
FROM products
WHERE product=" . SqlQuote($prod));
WHERE name=" . SqlQuote($prod));
return FetchOneColumn();
}
......@@ -62,9 +62,9 @@ sub TestMilestone ($$)
my ($prod,$mile) = @_;
# does the product exist?
SendSQL("SELECT product,value
FROM milestones
WHERE product=" . SqlQuote($prod) . " and value=" . SqlQuote($mile));
SendSQL("SELECT products.name, value
FROM milestones, products
WHERE milestones.product_id=products.id AND products.name=" . SqlQuote($prod) . " and value=" . SqlQuote($mile));
return FetchOneColumn();
}
......@@ -183,10 +183,10 @@ if ($milestone) {
unless ($product) {
PutHeader("Select product");
SendSQL("SELECT products.product,products.description,'xyzzy'
SendSQL("SELECT products.name,products.description,'xyzzy'
FROM products
GROUP BY products.product
ORDER BY products.product");
GROUP BY products.name
ORDER BY products.name");
print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n";
print " <TH ALIGN=\"left\">Edit milestones of ...</TH>\n";
print " <TH ALIGN=\"left\">Description</TH>\n";
......@@ -216,10 +216,11 @@ unless ($product) {
unless ($action) {
PutHeader("Select milestone for $product");
CheckProduct($product);
my $product_id = get_product_id($product);
SendSQL("SELECT value,sortkey
FROM milestones
WHERE product=" . SqlQuote($product) . "
WHERE product_id=$product_id
ORDER BY sortkey,value");
print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n";
......@@ -259,6 +260,7 @@ unless ($action) {
if ($action eq 'add') {
PutHeader("Add milestone for $product");
CheckProduct($product);
my $product_id = get_product_id($product);
#print "This page lets you add a new milestone to a $::bugzilla_name tracked product.\n";
......@@ -287,6 +289,7 @@ if ($action eq 'add') {
if ($action eq 'new') {
PutHeader("Adding new milestone for $product");
CheckProduct($product);
my $product_id = get_product_id($product);
# Cleanups and valididy checks
......@@ -305,10 +308,9 @@ if ($action eq 'new') {
# Add the new milestone
SendSQL("INSERT INTO milestones ( " .
"value, product, sortkey" .
"value, product_id, sortkey" .
" ) VALUES ( " .
SqlQuote($milestone) . "," .
SqlQuote($product) . ", $sortkey)");
SqlQuote($milestone) . ", $product_id, $sortkey)");
# Make versioncache flush
unlink "data/versioncache";
......@@ -330,16 +332,17 @@ if ($action eq 'new') {
if ($action eq 'del') {
PutHeader("Delete milestone of $product");
CheckMilestone($product, $milestone);
my $product_id = get_product_id($product);
SendSQL("SELECT count(bug_id),product,target_milestone
SendSQL("SELECT count(bug_id), product_id, target_milestone
FROM bugs
GROUP BY product,target_milestone
HAVING product=" . SqlQuote($product) . "
GROUP BY product_id, target_milestone
HAVING product_id=$product_id
AND target_milestone=" . SqlQuote($milestone));
my $bugs = FetchOneColumn();
SendSQL("SELECT defaultmilestone FROM products " .
"WHERE product=" . SqlQuote($product));
"WHERE id=$product_id");
my $defaultmilestone = FetchOneColumn();
print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0>\n";
......@@ -405,6 +408,7 @@ one.";
if ($action eq 'delete') {
PutHeader("Deleting milestone of $product");
CheckMilestone($product,$milestone);
my $product_id = get_product_id($product);
# lock the tables before we start to change everything:
......@@ -422,7 +426,7 @@ if ($action eq 'delete') {
SendSQL("SELECT bug_id
FROM bugs
WHERE product=" . SqlQuote($product) . "
WHERE product_id=$product_id
AND target_milestone=" . SqlQuote($milestone));
while (MoreSQLData()) {
my $bugid = FetchOneColumn();
......@@ -439,13 +443,13 @@ if ($action eq 'delete') {
# Deleting the rest is easier:
SendSQL("DELETE FROM bugs
WHERE product=" . SqlQuote($product) . "
WHERE product_id=$product_id
AND target_milestone=" . SqlQuote($milestone));
print "Bugs deleted.<BR>\n";
}
SendSQL("DELETE FROM milestones
WHERE product=" . SqlQuote($product) . "
WHERE product_id=$product_id
AND value=" . SqlQuote($milestone));
print "Milestone deleted.<P>\n";
SendSQL("UNLOCK TABLES");
......@@ -466,9 +470,10 @@ if ($action eq 'delete') {
if ($action eq 'edit') {
PutHeader("Edit milestone of $product");
CheckMilestone($product,$milestone);
my $product_id = get_product_id($product);
SendSQL("SELECT sortkey FROM milestones WHERE product=" .
SqlQuote($product) . " AND value = " . SqlQuote($milestone));
SendSQL("SELECT sortkey FROM milestones WHERE product_id=$product_id " .
" AND value = " . SqlQuote($milestone));
my $sortkey = FetchOneColumn();
print "<FORM METHOD=POST ACTION=editmilestones.cgi>\n";
......@@ -506,6 +511,7 @@ if ($action eq 'update') {
my $sortkeyold = trim($::FORM{sortkeyold} || '0');
CheckMilestone($product,$milestoneold);
my $product_id = get_product_id($product);
SendSQL("LOCK TABLES bugs WRITE,
milestones WRITE,
......@@ -535,14 +541,14 @@ if ($action eq 'update') {
SET target_milestone=" . SqlQuote($milestone) . ",
delta_ts=delta_ts
WHERE target_milestone=" . SqlQuote($milestoneold) . "
AND product=" . SqlQuote($product));
AND product_id=$product_id");
SendSQL("UPDATE milestones
SET value=" . SqlQuote($milestone) . "
WHERE product=" . SqlQuote($product) . "
WHERE product_id=$product_id
AND value=" . SqlQuote($milestoneold));
SendSQL("UPDATE products " .
"SET defaultmilestone = " . SqlQuote($milestone) .
"WHERE product = " . SqlQuote($product) .
" WHERE id = $product_id" .
" AND defaultmilestone = " . SqlQuote($milestoneold));
unlink "data/versioncache";
print "Updated milestone.<BR>\n";
......
......@@ -579,9 +579,10 @@ if ($action eq 'del') {
# Check if the user is an initialowner
my $nodelete = '';
SendSQL("SELECT program, value
FROM components
WHERE initialowner=" . DBname_to_id($user));
SendSQL("SELECT products.name, components.name " .
"FROM products, components " .
"WHERE products.id = components.product_id " .
" AND initialowner=" . DBname_to_id($user));
$found = 0;
while (MoreSQLData()) {
if ($found) {
......@@ -603,9 +604,10 @@ if ($action eq 'del') {
# Check if the user is an initialqacontact
SendSQL("SELECT program, value
FROM components
WHERE initialqacontact=" . DBname_to_id($user));
SendSQL("SELECT products.name, components.name " .
"FROM products, components " .
"WHERE products.id = components.id " .
" AND initialqacontact=" . DBname_to_id($user));
$found = 0;
while (MoreSQLData()) {
if ($found) {
......
......@@ -46,9 +46,9 @@ sub TestProduct ($)
my $prod = shift;
# does the product exist?
SendSQL("SELECT product
SendSQL("SELECT name
FROM products
WHERE product=" . SqlQuote($prod));
WHERE name=" . SqlQuote($prod));
return FetchOneColumn();
}
......@@ -75,9 +75,9 @@ sub TestVersion ($$)
my ($prod,$ver) = @_;
# does the product exist?
SendSQL("SELECT program,value
FROM versions
WHERE program=" . SqlQuote($prod) . " and value=" . SqlQuote($ver));
SendSQL("SELECT products.name,value
FROM versions, products
WHERE versions.product_id=products.id AND products.name=" . SqlQuote($prod) . " and value=" . SqlQuote($ver));
return FetchOneColumn();
}
......@@ -191,10 +191,10 @@ if ($version) {
unless ($product) {
PutHeader("Select product");
SendSQL("SELECT products.product,products.description,'xyzzy'
SendSQL("SELECT products.name,products.description,'xyzzy'
FROM products
GROUP BY products.product
ORDER BY products.product");
GROUP BY products.name
ORDER BY products.name");
print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n";
print " <TH ALIGN=\"left\">Edit versions of ...</TH>\n";
print " <TH ALIGN=\"left\">Description</TH>\n";
......@@ -217,8 +217,6 @@ unless ($product) {
exit;
}
#
# action='' -> Show nice list of versions
#
......@@ -226,24 +224,11 @@ unless ($product) {
unless ($action) {
PutHeader("Select version of $product");
CheckProduct($product);
my $product_id = get_product_id($product);
=for me
# Das geht nicht wie vermutet. Ich bekomme nicht alle Versionen
# angezeigt! Schade. Ich wrde gerne sehen, wieviel Bugs pro
# Version angegeben sind ...
SendSQL("SELECT value,program,COUNT(bug_id)
FROM versions LEFT JOIN bugs
ON program=product AND value=version
WHERE program=" . SqlQuote($product) . "
GROUP BY value");
=cut
SendSQL("SELECT value,program
FROM versions
WHERE program=" . SqlQuote($product) . "
SendSQL("SELECT value
FROM versions
WHERE product_id=$product_id
ORDER BY value");
print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0><TR BGCOLOR=\"#6666FF\">\n";
......@@ -252,8 +237,7 @@ unless ($action) {
print " <TH ALIGN=\"left\">Action</TH>\n";
print "</TR>";
while ( MoreSQLData() ) {
my ($version,$dummy,$bugs) = FetchSQLData();
$bugs ||= 'none';
my $version = FetchOneColumn();
print "<TR>\n";
print " <TD VALIGN=\"top\"><A HREF=\"editversions.cgi?product=", url_quote($product), "&version=", url_quote($version), "&action=edit\"><B>$version</B></A></TD>\n";
#print " <TD VALIGN=\"top\">$bugs</TD>\n";
......@@ -281,6 +265,7 @@ unless ($action) {
if ($action eq 'add') {
PutHeader("Add version of $product");
CheckProduct($product);
my $product_id = get_product_id($product);
#print "This page lets you add a new version to a bugzilla-tracked product.\n";
......@@ -309,6 +294,7 @@ if ($action eq 'add') {
if ($action eq 'new') {
PutHeader("Adding new version");
CheckProduct($product);
my $product_id = get_product_id($product);
# Cleanups and valididy checks
......@@ -327,10 +313,9 @@ if ($action eq 'new') {
# Add the new version
SendSQL("INSERT INTO versions ( " .
"value, program" .
"value, product_id" .
" ) VALUES ( " .
SqlQuote($version) . "," .
SqlQuote($product) . ")");
SqlQuote($version) . ", $product_id)");
# Make versioncache flush
unlink "data/versioncache";
......@@ -352,12 +337,12 @@ if ($action eq 'new') {
if ($action eq 'del') {
PutHeader("Delete version of $product");
CheckVersion($product, $version);
my $product_id = get_product_id($product);
SendSQL("SELECT count(bug_id),product,version
SendSQL("SELECT count(bug_id)
FROM bugs
GROUP BY product,version
HAVING product=" . SqlQuote($product) . "
AND version=" . SqlQuote($version));
WHERE product_id = $product_id
AND version = " . SqlQuote($version));
my $bugs = FetchOneColumn();
print "<TABLE BORDER=1 CELLPADDING=4 CELLSPACING=0>\n";
......@@ -416,6 +401,7 @@ one.";
if ($action eq 'delete') {
PutHeader("Deleting version of $product");
CheckVersion($product,$version);
my $product_id = get_product_id($product);
# lock the tables before we start to change everything:
......@@ -433,7 +419,7 @@ if ($action eq 'delete') {
SendSQL("SELECT bug_id
FROM bugs
WHERE product=" . SqlQuote($product) . "
WHERE product_id=$product_id
AND version=" . SqlQuote($version));
while (MoreSQLData()) {
my $bugid = FetchOneColumn();
......@@ -450,13 +436,13 @@ if ($action eq 'delete') {
# Deleting the rest is easier:
SendSQL("DELETE FROM bugs
WHERE product=" . SqlQuote($product) . "
WHERE product_id = $product_id
AND version=" . SqlQuote($version));
print "Bugs deleted.<BR>\n";
}
SendSQL("DELETE FROM versions
WHERE program=" . SqlQuote($product) . "
WHERE product_id = $product_id
AND value=" . SqlQuote($version));
print "Version deleted.<P>\n";
SendSQL("UNLOCK TABLES");
......@@ -477,6 +463,7 @@ if ($action eq 'delete') {
if ($action eq 'edit') {
PutHeader("Edit version of $product");
CheckVersion($product,$version);
my $product_id = get_product_id($product);
print "<FORM METHOD=POST ACTION=editversions.cgi>\n";
print "<TABLE BORDER=0 CELLPADDING=4 CELLSPACING=0><TR>\n";
......@@ -510,12 +497,14 @@ if ($action eq 'update') {
my $versionold = trim($::FORM{versionold} || '');
CheckVersion($product,$versionold);
my $product_id = get_product_id($product);
# Note that the order of this tests is important. If you change
# them, be sure to test for WHERE='$version' or WHERE='$versionold'
SendSQL("LOCK TABLES bugs WRITE,
versions WRITE");
versions WRITE,
products READ");
if ($version ne $versionold) {
unless ($version) {
......@@ -534,10 +523,10 @@ if ($action eq 'update') {
SET version=" . SqlQuote($version) . ",
delta_ts = delta_ts
WHERE version=" . SqlQuote($versionold) . "
AND product=" . SqlQuote($product));
AND product_id = $product_id");
SendSQL("UPDATE versions
SET value=" . SqlQuote($version) . "
WHERE program=" . SqlQuote($product) . "
WHERE product_id = $product_id
AND value=" . SqlQuote($versionold));
unlink "data/versioncache";
print "Updated version.<BR>\n";
......
......@@ -239,7 +239,9 @@ if (lsearch(\@::enterable_products, $product) == -1) {
DisplayError("'" . html_quote($product) . "' is not a valid product.");
exit;
}
my $product_id = get_product_id($product);
if (0 == @{$::components{$product}}) {
my $error = "Sorry; there needs to be at least one component for this " .
"product in order to create a new bug. ";
......@@ -261,8 +263,8 @@ elsif (1 == @{$::components{$product}}) {
}
my @components;
SendSQL("SELECT value, description FROM components " .
"WHERE program = " . SqlQuote($product) . " ORDER BY value");
SendSQL("SELECT name, description FROM components " .
"WHERE product_id = $product_id ORDER BY name");
while (MoreSQLData()) {
my ($name, $description) = FetchSQLData();
......@@ -315,7 +317,7 @@ if (exists $::COOKIE{"VERSION-$product"} &&
my @status = "NEW";
if (UserInGroup("editbugs") || UserInGroup("canconfirm")) {
SendSQL("SELECT votestoconfirm FROM products WHERE product = " .
SendSQL("SELECT votestoconfirm FROM products WHERE name = " .
SqlQuote($product));
push(@status, $unconfirmedstate) if (FetchOneColumn());
}
......
......@@ -434,7 +434,10 @@ sub GenerateArrayCode {
sub GenerateVersionTable {
SendSQL("select value, program from versions order by value");
SendSQL("SELECT versions.value, products.name " .
"FROM versions, products " .
"WHERE products.id = versions.product_id " .
"ORDER BY versions.value");
my @line;
my %varray;
my %carray;
......@@ -446,7 +449,10 @@ sub GenerateVersionTable {
push @{$::versions{$p1}}, $v;
$varray{$v} = 1;
}
SendSQL("select value, program from components order by value");
SendSQL("SELECT components.name, products.name " .
"FROM components, products " .
"WHERE products.id = components.product_id " .
"ORDER BY components.name");
while (@line = FetchSQLData()) {
my ($c,$p) = (@line);
if (!defined $::components{$p}) {
......@@ -464,7 +470,7 @@ sub GenerateVersionTable {
# about them anyway.
my $mpart = $dotargetmilestone ? ", milestoneurl" : "";
SendSQL("select product, description, votesperuser, disallownew$mpart from products ORDER BY product");
SendSQL("select name, description, votesperuser, disallownew$mpart from products ORDER BY name");
while (@line = FetchSQLData()) {
my ($p, $d, $votesperuser, $dis, $u) = (@line);
$::proddesc{$p} = $d;
......@@ -546,7 +552,10 @@ sub GenerateVersionTable {
if ($dotargetmilestone) {
# reading target milestones in from the database - matthew@zeroknowledge.com
SendSQL("SELECT value, product FROM milestones ORDER BY sortkey, value");
SendSQL("SELECT milestones.value, products.name " .
"FROM milestones, products " .
"WHERE products.id = milestones.product_id " .
"ORDER BY milestones.sortkey, milestones.value");
my @line;
my %tmarray;
@::legal_target_milestone = ();
......@@ -943,6 +952,49 @@ sub DBNameToIdAndCheck {
registered for a Bugzilla account.");
}
sub get_product_id {
my ($prod) = @_;
PushGlobalSQLState();
SendSQL("SELECT id FROM products WHERE name = " . SqlQuote($prod));
my ($prod_id) = FetchSQLData();
PopGlobalSQLState();
return $prod_id;
}
sub get_product_name {
my ($prod_id) = @_;
die "non-numeric prod_id '$prod_id' passed to get_product_name"
unless ($prod_id =~ /^\d+$/);
PushGlobalSQLState();
SendSQL("SELECT name FROM products WHERE id = $prod_id");
my ($prod) = FetchSQLData();
PopGlobalSQLState();
return $prod;
}
sub get_component_id {
my ($prod_id, $comp) = @_;
die "non-numeric prod_id '$prod_id' passed to get_component_id"
unless ($prod_id =~ /^\d+$/);
PushGlobalSQLState();
SendSQL("SELECT id FROM components " .
"WHERE product_id = $prod_id AND name = " . SqlQuote($comp));
my ($comp_id) = FetchSQLData();
PopGlobalSQLState();
return $comp_id;
}
sub get_component_name {
my ($comp_id) = @_;
die "non-numeric comp_id '$comp_id' passed to get_component_name"
unless ($comp_id =~ /^\d+$/);
PushGlobalSQLState();
SendSQL("SELECT name FROM components WHERE id = $comp_id");
my ($comp) = FetchSQLData();
PopGlobalSQLState();
return $comp;
}
# Use trick_taint() when you know that there is no way that the data
# in a scalar can be tainted, but taint mode still bails on it.
# WARNING!! Using this routine on data that really could be tainted
......@@ -1330,7 +1382,7 @@ sub RemoveVotes {
"FROM profiles " .
"LEFT JOIN votes ON profiles.userid = votes.who " .
"LEFT JOIN bugs USING(bug_id) " .
"LEFT JOIN products USING(product)" .
"LEFT JOIN products ON products.id = bugs.product_id " .
"WHERE votes.bug_id = $id " .
$whopart);
my @list;
......
......@@ -570,9 +570,10 @@ for (my $k=1 ; $k <= $bugqty ; $k++) {
push (@values, SqlQuote($qa_contact));
push (@query, "qa_contact");
} else {
SendSQL("select initialqacontact from components where program=" .
SqlQuote($product[0]) .
" and value=" . SqlQuote($component[0]) );
SendSQL("SELECT initialqacontact FROM components, products "
"WHERE components.product_id = products.id" .
" AND products.name = " . SqlQuote($product[0]) .
" AND components.name = " . SqlQuote($component[0]) );
$qa_contact = FetchOneColumn();
push (@values, SqlQuote(DBname_to_id($qa_contact)) );
push (@query, "qa_contact");
......
......@@ -41,7 +41,7 @@ GetVersionTable();
my $generic_query = "
SELECT
bugs.bug_id,
bugs.product,
products.name,
bugs.version,
bugs.rep_platform,
bugs.op_sys,
......@@ -49,7 +49,7 @@ my $generic_query = "
bugs.resolution,
bugs.priority,
bugs.bug_severity,
bugs.component,
components.name,
assign.login_name,
report.login_name,
bugs.bug_file_loc,
......@@ -58,8 +58,9 @@ my $generic_query = "
bugs.qa_contact,
bugs.status_whiteboard,
bugs.keywords
FROM bugs,profiles assign,profiles report
WHERE assign.userid = bugs.assigned_to AND report.userid = bugs.reporter";
FROM bugs,profiles assign,profiles report, products, components
WHERE assign.userid = bugs.assigned_to AND report.userid = bugs.reporter
AND bugs.product_id=products.id AND bugs.component_id=components.id";
my $buglist = $::FORM{'buglist'} ||
$::FORM{'bug_id'} ||
......
......@@ -70,6 +70,11 @@ $template->process("$template_name.txt.tmpl", $vars, \$comment)
ValidateComment($comment);
my $product = $::FORM{'product'};
my $product_id = get_product_id($product);
if (!$product_id) {
ThrowUserError("Sorry, the product <tt>" . html_quote($product) .
"</tt> does not exist");
}
# Set cookies
my $cookiepath = Param("cookiepath");
......@@ -100,10 +105,11 @@ if(Param("usebuggroupsentry") && GroupExists($product)) {
}
}
if (!$::FORM{'component'}) {
my $component_id = get_component_id($product_id, $::FORM{component});
if (!$component_id) {
DisplayError("You must choose a component that corresponds to this bug.
If necessary, just guess.");
exit;
exit;
}
if (!defined $::FORM{'short_desc'} || trim($::FORM{'short_desc'}) eq "") {
......@@ -121,20 +127,20 @@ my $sql_component = SqlQuote($::FORM{'component'});
# Default assignee is the component owner.
if ($::FORM{'assigned_to'} eq "") {
SendSQL("SELECT initialowner FROM components " .
"WHERE program=$sql_product AND value=$sql_component");
"WHERE id = $component_id");
$::FORM{'assigned_to'} = FetchOneColumn();
} else {
$::FORM{'assigned_to'} = DBNameToIdAndCheck(trim($::FORM{'assigned_to'}));
}
my @bug_fields = ("product", "version", "rep_platform",
my @bug_fields = ("version", "rep_platform",
"bug_severity", "priority", "op_sys", "assigned_to",
"bug_status", "bug_file_loc", "short_desc", "component",
"bug_status", "bug_file_loc", "short_desc",
"target_milestone");
if (Param("useqacontact")) {
SendSQL("SELECT initialqacontact FROM components " .
"WHERE program=$sql_product AND value=$sql_component");
"WHERE id = $component_id");
my $qa_contact = FetchOneColumn();
if (defined $qa_contact && $qa_contact != 0) {
$::FORM{'qa_contact'} = $qa_contact;
......@@ -155,14 +161,14 @@ if (exists $::FORM{'bug_status'}) {
if (!exists $::FORM{'bug_status'}) {
$::FORM{'bug_status'} = $::unconfirmedstate;
SendSQL("SELECT votestoconfirm FROM products WHERE product=$sql_product");
SendSQL("SELECT votestoconfirm FROM products WHERE id = $product_id");
if (!FetchOneColumn()) {
$::FORM{'bug_status'} = "NEW";
}
}
if (!exists $::FORM{'target_milestone'}) {
SendSQL("SELECT defaultmilestone FROM products WHERE product=$sql_product");
SendSQL("SELECT defaultmilestone FROM products WHERE name=$sql_product");
$::FORM{'target_milestone'} = FetchOneColumn();
}
......@@ -200,6 +206,11 @@ if (exists $::FORM{'bug_status'}
$::FORM{'everconfirmed'} = 1;
}
$::FORM{'product_id'} = $product_id;
push(@used_fields, "product_id");
$::FORM{component_id} = $component_id;
push(@used_fields, "component_id");
my %ccids;
my @cc;
......
......@@ -174,7 +174,8 @@ sub CheckonComment( $ ) {
# and make the user verify the version, component, target milestone,
# and bug groups if so.
if ( $::FORM{'id'} ) {
SendSQL("SELECT product FROM bugs WHERE bug_id = $::FORM{'id'}");
SendSQL("SELECT name FROM products, bugs " .
"WHERE products.id = bugs.product_id AND bug_id = $::FORM{'id'}");
$::oldproduct = FetchSQLData();
}
if ((($::FORM{'id'} && $::FORM{'product'} ne $::oldproduct)
......@@ -503,8 +504,8 @@ if($::usergroupset ne '0') {
}
foreach my $field ("rep_platform", "priority", "bug_severity",
"summary", "component", "bug_file_loc", "short_desc",
"product", "version", "op_sys",
"summary", "bug_file_loc", "short_desc",
"version", "op_sys",
"target_milestone", "status_whiteboard") {
if (defined $::FORM{$field}) {
if ($::FORM{$field} ne $::dontchange) {
......@@ -514,6 +515,41 @@ foreach my $field ("rep_platform", "priority", "bug_severity",
}
}
my $prod_id; # Remember, can't use this for mass changes
if ($::FORM{'product'} ne $::dontchange) {
$prod_id = get_product_id($::FORM{'product'});
if (! $prod_id) {
DisplayError("The <tt>" . html_quote($::FORM{'product'}) .
"</tt> product doesn't exist.");
exit;
}
DoComma();
$::query .= "product_id = $prod_id";
} else {
SendSQL("SELECT DISTINCT product_id FROM bugs WHERE bug_id IN (" .
join(',', @idlist) . ") LIMIT 2");
$prod_id = FetchOneColumn();
$prod_id = undef if (FetchOneColumn());
}
my $comp_id; # Remember, can't use this for mass changes
if ($::FORM{'component'} ne $::dontchange) {
if (!defined $prod_id) {
ThrowUserError("You cannot change the component from a list of bugs " .
"covering more than one product");
}
$comp_id = get_component_id($prod_id,
$::FORM{'component'});
if (! $comp_id) {
DisplayError("The <tt>" . html_quote($::FORM{'component'}) .
"</tt> component doesn't exist in the <tt>" .
html_quote($::FORM{'product'}) . "</tt> product");
exit;
}
DoComma();
$::query .= "component_id = $comp_id";
}
# If this installation uses bug aliases, and the user is changing the alias,
# add this change to the query.
if (Param("usebugaliases") && defined($::FORM{'alias'})) {
......@@ -708,17 +744,15 @@ SWITCH: for ($::FORM{'knob'}) {
DoConfirm();
}
ChangeStatus('NEW');
SendSQL("select initialowner from components where program=" .
SqlQuote($::FORM{'product'}) . " and value=" .
SqlQuote($::FORM{'component'}));
SendSQL("SELECT initialowner FROM components " .
"WHERE components.id = $comp_id");
my $newid = FetchOneColumn();
my $newname = DBID_to_name($newid);
DoComma();
$::query .= "assigned_to = $newid";
if (Param("useqacontact")) {
SendSQL("select initialqacontact from components where program=" .
SqlQuote($::FORM{'product'}) .
" and value=" . SqlQuote($::FORM{'component'}));
SendSQL("SELECT initialqacontact FROM components " .
"WHERE components.id = $comp_id");
my $qacontact = FetchOneColumn();
if (defined $qacontact && $qacontact != 0) {
DoComma();
......@@ -923,8 +957,9 @@ foreach my $id (@idlist) {
SendSQL("LOCK TABLES bugs $write, bugs_activity $write, cc $write, " .
"cc AS selectVisible_cc $write, " .
"profiles $write, dependencies $write, votes $write, " .
"products READ, components READ, " .
"keywords $write, longdescs $write, fielddefs $write, " .
"keyworddefs READ, groups READ, attachments READ, products READ");
"keyworddefs READ, groups READ, attachments READ");
my @oldvalues = SnapShotBug($id);
my %oldhash;
my $i = 0;
......@@ -1270,6 +1305,19 @@ foreach my $id (@idlist) {
}
if ($old ne $new) {
# Products and components are now stored in the DB using ID's
# We need to translate this to English before logging it
if ($col eq 'product_id') {
$old = get_product_name($old);
$new = get_product_name($new);
$col = 'product';
}
if ($col eq 'component_id') {
$old = get_component_name($old);
$new = get_component_name($new);
$col = 'component';
}
# save off the old value for passing to processmail so the old
# owner can be notified
#
......
......@@ -660,7 +660,7 @@ print qq{
};
SendSQL("SELECT product,description FROM products ORDER BY product");
SendSQL("SELECT name, description FROM products ORDER BY name");
while (MoreSQLData()) {
my ($product, $productdesc) = FetchSQLData();
......@@ -725,7 +725,11 @@ components and their associated products:
foreach $product (@products)
{
SendSQL("SELECT value,description FROM components WHERE program=" . SqlQuote($product) . " ORDER BY value");
SendSQL("SELECT components.name, components.description " .
"FROM components, products " .
"WHERE components.product_id = products.id" .
" AND products.name = " . SqlQuote($product) .
"ORDER BY name");
while (MoreSQLData()) {
......
......@@ -263,6 +263,7 @@ $when<p>
FIN
# Build up $query string
my $prod_table = ($FORM{'product'} ne "-All-") ? ", products" : "";
my $query;
$query = <<FIN;
select
......@@ -272,12 +273,13 @@ select
unix_timestamp(date_format(bugs.creation_ts, '%Y-%m-%d %h:%m:%s'))
from bugs,
profiles assign
profiles assign $prod_table
where bugs.assigned_to = assign.userid
FIN
if ($FORM{'product'} ne "-All-" ) {
$query .= "and bugs.product=".SqlQuote($FORM{'product'});
$query .= "and products.id = bugs.product_id\n";
$query .= "and products.name=".SqlQuote($FORM{'product'});
}
$query .= "AND bugs.bug_status IN ('NEW', 'ASSIGNED', 'REOPENED')";
......@@ -641,11 +643,11 @@ sub bybugs {
sub most_doomed_for_milestone {
my $when = localtime (time);
my $ms = "M" . Param("curmilestone");
my $product_id = get_product_id($FORM{'product'}) unless $FORM{'product'} eq '-All-';
print "<center>\n<h1>";
if( $FORM{'product'} ne "-All-" ) {
SendSQL("SELECT defaultmilestone FROM products WHERE product = " .
SqlQuote($FORM{'product'}));
SendSQL("SELECT defaultmilestone FROM products WHERE id = $product_id");
$ms = FetchOneColumn();
print "Most Doomed for $ms ($FORM{'product'})";
} else {
......@@ -661,7 +663,7 @@ sub most_doomed_for_milestone {
my $query;
$query = "select distinct assigned_to from bugs where target_milestone=\"$ms\"";
if ($FORM{'product'} ne "-All-" ) {
$query .= "and bugs.product=".SqlQuote($FORM{'product'});
$query .= "and bugs.product_id=$product_id ";
}
$query .= <<FIN;
and
......@@ -687,7 +689,7 @@ FIN
foreach $person (@people) {
my $query = "select count(bug_id) from bugs,profiles where target_milestone=\"$ms\" and userid=assigned_to and userid=\"$person\"";
if( $FORM{'product'} ne "-All-" ) {
$query .= "and bugs.product=".SqlQuote($FORM{'product'});
$query .= "and bugs.product_id=$product_id ";
}
$query .= <<FIN;
and
......
......@@ -203,15 +203,15 @@ CrossCheck("profiles", "userid",
["watch", "watcher"],
["watch", "watched"],
["tokens", "userid"],
["components", "initialowner", "value"],
["components", "initialqacontact", "value", ["0"]]);
["components", "initialowner", "name"],
["components", "initialqacontact", "name", ["0"]]);
CrossCheck("products", "product",
["bugs", "product", "bug_id"],
["components", "program", "value"],
["milestones", "product", "value"],
["versions", "program", "value"],
["attachstatusdefs", "product", "name"]);
CrossCheck("products", "id",
["bugs", "product_id", "bug_id"],
["components", "product_id", "name"],
["milestones", "product_id", "value"],
["versions", "product_id", "value"],
["attachstatusdefs", "product_id", "name"]);
###########################################################################
# Perform group checks
......@@ -239,17 +239,17 @@ while (@row = FetchSQLData()) {
Status("Checking version/products");
SendSQL("select distinct product, version from bugs");
SendSQL("select distinct product_id, version from bugs");
while (@row = FetchSQLData()) {
my @copy = @row;
push(@checklist, \@copy);
}
foreach my $ref (@checklist) {
my ($product, $version) = (@$ref);
SendSQL("select count(*) from versions where program = " . SqlQuote($product) . " and value = " . SqlQuote($version));
my ($product_id, $version) = (@$ref);
SendSQL("select count(*) from versions where product_id = $product_id and value = " . SqlQuote($version));
if (FetchOneColumn() != 1) {
Alert("Bug(s) found with invalid product/version: $product/$version");
Alert("Bug(s) found with invalid product ID/version: $product_id/$version");
}
}
......@@ -257,17 +257,17 @@ foreach my $ref (@checklist) {
Status("Checking milestone/products");
@checklist = ();
SendSQL("select distinct product, target_milestone from bugs");
SendSQL("select distinct product_id, target_milestone from bugs");
while (@row = FetchSQLData()) {
my @copy = @row;
push(@checklist, \@copy);
}
foreach my $ref (@checklist) {
my ($product, $milestone) = (@$ref);
SendSQL("SELECT count(*) FROM milestones WHERE product = " . SqlQuote($product) . " AND value = " . SqlQuote($milestone));
my ($product_id, $milestone) = (@$ref);
SendSQL("SELECT count(*) FROM milestones WHERE product_id = $product_id AND value = " . SqlQuote($milestone));
if(FetchOneColumn() != 1) {
Alert("Bug(s) found with invalid product/milestone: $product/$milestone");
Alert("Bug(s) found with invalid product ID/milestone: $product_id/$milestone");
}
}
......@@ -275,17 +275,17 @@ foreach my $ref (@checklist) {
Status("Checking default milestone/products");
@checklist = ();
SendSQL("select product, defaultmilestone from products");
SendSQL("select id, defaultmilestone from products");
while (@row = FetchSQLData()) {
my @copy = @row;
push(@checklist, \@copy);
}
foreach my $ref (@checklist) {
my ($product, $milestone) = (@$ref);
SendSQL("SELECT count(*) FROM milestones WHERE product = " . SqlQuote($product) . " AND value = " . SqlQuote($milestone));
my ($product_id, $milestone) = (@$ref);
SendSQL("SELECT count(*) FROM milestones WHERE product_id = $product_id AND value = " . SqlQuote($milestone));
if(FetchOneColumn() != 1) {
Alert("Product(s) found with invalid default milestone: $product/$milestone");
Alert("Product(s) found with invalid default milestone: $product_id/$milestone");
}
}
......@@ -293,19 +293,17 @@ foreach my $ref (@checklist) {
Status("Checking components/products");
@checklist = ();
SendSQL("select distinct product, component from bugs");
SendSQL("select distinct product_id, component_id from bugs");
while (@row = FetchSQLData()) {
my @copy = @row;
push(@checklist, \@copy);
}
foreach my $ref (@checklist) {
my ($product, $component) = (@$ref);
SendSQL("select count(*) from components where program = " . SqlQuote($product) . " and value = " . SqlQuote($component));
my ($product_id, $component_id) = (@$ref);
SendSQL("select count(*) from components where product_id = $product_id and id = $component_id");
if (FetchOneColumn() != 1) {
my $link = "buglist.cgi?product=" . url_quote($product) .
"&component=" . url_quote($component);
Alert(qq{Bug(s) found with invalid product/component: $product/$component (<a href="$link">bug list</a>)});
Alert(qq{Bug(s) found with invalid product/component ID: $product_id/$component_id});
}
}
......@@ -601,7 +599,7 @@ Status("Checking votes/everconfirmed");
@badbugs = ();
SendSQL("SELECT bug_id FROM bugs, products " .
"WHERE bugs.product = products.product " .
"WHERE bugs.product_id = products.id " .
"AND bug_status = " . SqlQuote($::unconfirmedstate) . ' ' .
"AND votestoconfirm <= votes " .
"ORDER BY bug_id");
......
......@@ -153,7 +153,7 @@ sub show_user {
# we can do it all in one query.
my %maxvotesperbug;
if($canedit) {
SendSQL("SELECT products.product, products.maxvotesperbug
SendSQL("SELECT products.name, products.maxvotesperbug
FROM products");
while (MoreSQLData()) {
my ($prod, $max) = FetchSQLData();
......@@ -173,10 +173,11 @@ sub show_user {
SendSQL("SELECT votes.bug_id, votes.count, bugs.short_desc,
bugs.bug_status
FROM votes, bugs
FROM votes, bugs, products
WHERE votes.who = $who
AND votes.bug_id = bugs.bug_id
AND bugs.product = " . SqlQuote($product) .
AND bugs.product_id = products.id
AND products.name = " . SqlQuote($product) .
"ORDER BY votes.bug_id");
while (MoreSQLData()) {
......@@ -270,9 +271,9 @@ sub record_votes {
# If the user is voting for bugs, make sure they aren't overstuffing
# the ballot box.
if (scalar(@buglist)) {
SendSQL("SELECT bugs.bug_id, bugs.product, products.maxvotesperbug
SendSQL("SELECT bugs.bug_id, products.name, products.maxvotesperbug
FROM bugs, products
WHERE products.product = bugs.product
WHERE products.id = bugs.product_id
AND bugs.bug_id IN (" . join(", ", @buglist) . ")");
my %prodcount;
......
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