From 6e29c7cd06afac55962dac20421bddbf17954906 Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Fri, 8 Jul 2005 04:03:03 +0000 Subject: Bug 289580: Templatize the 'confirm delete' bit of editproducts.cgi - Patch by Tiago R. Mello r=LpSolit a=justdave --- editproducts.cgi | 289 +++++++++++++++++++++---------------------------------- 1 file changed, 112 insertions(+), 177 deletions(-) (limited to 'editproducts.cgi') diff --git a/editproducts.cgi b/editproducts.cgi index 229aa64d2..9d81f176c 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -139,16 +139,21 @@ sub CheckClassificationProduct ($$) { my $cl = shift; my $prod = shift; + my $dbh = Bugzilla->dbh; CheckClassification($cl); CheckProduct($prod); - # does the classification exist? - SendSQL("SELECT products.name - FROM products,classifications - WHERE products.name=" . SqlQuote($prod) . - " AND classifications.name=" . SqlQuote($cl)); - my $res = FetchOneColumn(); + trick_taint($prod); + trick_taint($cl); + + my $query = q{SELECT products.name + FROM products + INNER JOIN classifications + ON products.classification_id = classifications.id + WHERE products.name = ? + AND classifications.name = ?}; + my $res = $dbh->selectrow_array($query, undef, ($prod, $cl)); unless ($res) { print "Sorry, classification->product '$cl'->'$prod' does not exist."; @@ -157,6 +162,26 @@ sub CheckClassificationProduct ($$) } } +sub CheckClassificationProductNew ($$) +{ + my ($cl, $prod) = @_; + my $dbh = Bugzilla->dbh; + + CheckClassificationNew($cl); + + my ($res) = $dbh->selectrow_array(q{ + SELECT products.name + FROM products + INNER JOIN classifications + ON products.classification_id = classifications.id + WHERE products.name = ? AND classifications.name = ?}, + undef, ($prod, $cl)); + + unless ($res) { + ThrowUserError('classification_doesnt_exist_for_product', + { product => $prod, classification => $cl }); + } +} # # Displays the form to edit a products parameters @@ -604,180 +629,93 @@ if ($action eq 'new') { # if ($action eq 'del') { - PutHeader("Delete product"); - CheckProduct($product); - my $classification_id=1; - if (Param('useclassification')) { - CheckClassificationProduct($classification,$product); - $classification_id = get_classification_id($classification); - } - - # display some data about the product - SendSQL("SELECT classifications.description, - products.id, products.description, milestoneurl, disallownew - FROM products,classifications - WHERE products.name=" . SqlQuote($product) . - " AND classifications.id=" . SqlQuote($classification_id)); - my ($class_description, $product_id, $prod_description, $milestoneurl, $disallownew) = FetchSQLData(); - my $milestonelink = $milestoneurl ? "$milestoneurl" - : "missing"; - $prod_description ||= "description missing"; - $class_description ||= "description missing"; - $disallownew = $disallownew ? 'closed' : 'open'; - print "\n"; - print "\n"; - print " \n"; - print " \n"; - - if (Param('useclassification')) { - print "\n"; - print " \n"; - print " \n"; - - print "\n"; - print " \n"; - print " \n"; + if (!$product) { + ThrowUserError('product_not_specified'); } - print "\n"; - print " \n"; - print " \n"; - - print "\n"; - print " \n"; - print " \n"; - - if (Param('usetargetmilestone')) { - print "\n"; - print " \n"; - print " \n"; - } - - - print "\n"; - print " \n"; - print " \n"; + my $product_id = get_product_id($product); + $product_id || ThrowUserError('product_doesnt_exist', + {product => $product}); - print "\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n
PartValue
Classification:$classification
Description:$class_description
Product:$product
Description:$prod_description
Milestone URL:$milestonelink
Closed for bugs:$disallownew
Components:"; - SendSQL("SELECT name,description - FROM components - WHERE product_id=$product_id"); - if (MoreSQLData()) { - print ""; - while ( MoreSQLData() ) { - my ($component, $description) = FetchSQLData(); - $description ||= "description missing"; - print ""; - print "\n"; - } - print "
$component:$description
\n"; - } else { - print "missing"; - } + my $classification_id = 1; - print "
Versions:"; - SendSQL("SELECT value - FROM versions - WHERE product_id=$product_id - ORDER BY value"); - if (MoreSQLData()) { - my $br = 0; - while ( MoreSQLData() ) { - my ($version) = FetchSQLData(); - print "
" if $br; - print $version; - $br = 1; - } - } else { - print "missing"; + if (Param('useclassification')) { + CheckClassificationProductNew($classification, $product); + $classification_id = get_classification_id($classification); + $vars->{'classification'} = $classification; } - # - # Adding listing for associated target milestones - matthew@zeroknowledge.com - # + # Extract some data about the product + my $query = q{SELECT classifications.description, + products.description, + products.milestoneurl, + products.disallownew + FROM products + INNER JOIN classifications + ON products.classification_id = classifications.id + WHERE products.id = ?}; + + my ($class_description, + $prod_description, + $milestoneurl, + $disallownew) = $dbh->selectrow_array($query, undef, + $product_id); + + $vars->{'class_description'} = $class_description; + $vars->{'product_id'} = $product_id; + $vars->{'prod_description'} = $prod_description; + $vars->{'milestoneurl'} = $milestoneurl; + $vars->{'disallownew'} = $disallownew; + $vars->{'product_name'} = $product; + + $vars->{'components'} = $dbh->selectall_arrayref(q{ + SELECT name, description FROM components + WHERE product_id = ? ORDER BY name}, {'Slice' => {}}, + $product_id); + + $vars->{'versions'} = $dbh->selectcol_arrayref(q{ + SELECT value FROM versions + WHERE product_id = ? ORDER BY value}, undef, + $product_id); + + # Adding listing for associated target milestones - + # matthew@zeroknowledge.com if (Param('usetargetmilestone')) { - print "
Edit milestones:"; - SendSQL("SELECT value - FROM milestones - WHERE product_id=$product_id - ORDER BY sortkey,value"); - if(MoreSQLData()) { - my $br = 0; - while ( MoreSQLData() ) { - my ($milestone) = FetchSQLData(); - print "
" if $br; - print $milestone; - $br = 1; - } - } else { - print "missing"; - } - } - - print "
Bugs:"; - SendSQL("SELECT count(bug_id), product_id - FROM bugs " . - $dbh->sql_group_by('product_id') . " - HAVING product_id = $product_id"); - my $bugs = FetchOneColumn(); - print $bugs || 'none'; - - - print "
"; - - print "

Confirmation

\n"; - - if ($bugs) { - if (!Param("allowbugdeletion")) { - print "Sorry, there are $bugs bugs outstanding for this product. -You must reassign those bugs to another product before you can delete this -one."; - PutTrailer($localtrailer); - exit; - } - print "
\n", - "There are bugs entered for this product! When you delete this ", - "product, ALL stored bugs and their history will be ", - "deleted too.\n", - "
\n"; + $vars->{'milestones'} = $dbh->selectcol_arrayref(q{ + SELECT value FROM milestones + WHERE product_id = ? + ORDER BY sortkey, value}, undef, $product_id); } - print "

Do you really want to delete this product?

\n"; - print "

\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "
"; - - PutTrailer($localtrailer); + ($vars->{'bug_count'}) = $dbh->selectrow_array(q{ + SELECT COUNT(*) FROM bugs WHERE product_id = ?}, + undef, $product_id) || 0; + + $template->process("admin/products/confirm-delete.html.tmpl", $vars) + || ThrowTemplateError($template->error()); exit; } - - # # action='delete' -> really delete the product # if ($action eq 'delete') { - CheckProduct($product); + + if (!$product) { + ThrowUserError('product_not_specified'); + } + my $product_id = get_product_id($product); + $product_id || ThrowUserError('product_doesnt_exist', + {product => $product}); + + $vars->{'product'} = $product; - my $bug_ids = - $dbh->selectcol_arrayref("SELECT bug_id FROM bugs WHERE product_id = ?", - undef, $product_id); + my $bug_ids = $dbh->selectcol_arrayref(q{ + SELECT bug_id FROM bugs + WHERE product_id = ?}, undef, $product_id); my $nb_bugs = scalar(@$bug_ids); if ($nb_bugs) { @@ -790,47 +728,44 @@ if ($action eq 'delete') { else { ThrowUserError("product_has_bugs", { nb => $nb_bugs }); } + $vars->{'nb_bugs'} = $nb_bugs; } - PutHeader("Deleting product"); - print "All references to deleted bugs removed.

\n" if $nb_bugs; - $dbh->bz_lock_tables('products WRITE', 'components WRITE', 'versions WRITE', 'milestones WRITE', 'group_control_map WRITE', 'flaginclusions WRITE', 'flagexclusions WRITE'); - $dbh->do("DELETE FROM components WHERE product_id = ?", undef, $product_id); - print "Components deleted.
\n"; + $dbh->do("DELETE FROM components WHERE product_id = ?", + undef, $product_id); - $dbh->do("DELETE FROM versions WHERE product_id = ?", undef, $product_id); - print "Versions deleted.
\n"; + $dbh->do("DELETE FROM versions WHERE product_id = ?", + undef, $product_id); - $dbh->do("DELETE FROM milestones WHERE product_id = ?", undef, $product_id); - print "Milestones deleted.

\n"; + $dbh->do("DELETE FROM milestones WHERE product_id = ?", + undef, $product_id); $dbh->do("DELETE FROM group_control_map WHERE product_id = ?", undef, $product_id); - print "Group controls deleted.
\n"; $dbh->do("DELETE FROM flaginclusions WHERE product_id = ?", undef, $product_id); + $dbh->do("DELETE FROM flagexclusions WHERE product_id = ?", undef, $product_id); - print "Flag inclusions and exclusions deleted.

\n"; - - $dbh->do("DELETE FROM products WHERE id = ?", undef, $product_id); - print "Product '$product' deleted.

\n"; + + $dbh->do("DELETE FROM products WHERE id = ?", + undef, $product_id); $dbh->bz_unlock_tables(); unlink "$datadir/versioncache"; - PutTrailer($localtrailer); + + $template->process("admin/products/deleted.html.tmpl", $vars) + || ThrowTemplateError($template->error()); exit; } - - # # action='edit' -> present the 'edit product' form # If a product is given with no action associated with it, then edit it. -- cgit v1.2.3-24-g4f1b