2004-05-23 07:22:32 +00:00
|
|
|
|
#!/usr/bin/perl -wT
|
1999-10-12 23:00:35 +00:00
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
|
#
|
1999-11-01 23:33:56 +00:00
|
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
|
# the License at http://www.mozilla.org/MPL/
|
|
|
|
|
#
|
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
|
# rights and limitations under the License.
|
|
|
|
|
#
|
|
|
|
|
# The Original Code is mozilla.org code.
|
|
|
|
|
#
|
|
|
|
|
# The Initial Developer of the Original Code is Holger
|
|
|
|
|
# Schurig. Portions created by Holger Schurig are
|
|
|
|
|
# Copyright (C) 1999 Holger Schurig. All
|
|
|
|
|
# Rights Reserved.
|
|
|
|
|
#
|
|
|
|
|
# Contributor(s): Holger Schurig <holgerschurig@nikocity.de>
|
2005-01-16 13:48:25 +00:00
|
|
|
|
# Terry Weissman <terry@mozilla.org>
|
|
|
|
|
# Gavin Shelley <bugzilla@chimpychompy.org>
|
2005-04-06 00:19:56 +00:00
|
|
|
|
# Fr<46>d<EFBFBD>ric Buclin <LpSolit@gmail.com>
|
1999-10-12 23:00:35 +00:00
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# Direct any questions on this source code to
|
|
|
|
|
#
|
|
|
|
|
# Holger Schurig <holgerschurig@nikocity.de>
|
|
|
|
|
|
|
|
|
|
use strict;
|
2002-04-29 19:32:29 +00:00
|
|
|
|
use lib ".";
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
require "CGI.pl";
|
|
|
|
|
require "globals.pl";
|
|
|
|
|
|
2004-03-27 03:51:44 +00:00
|
|
|
|
use Bugzilla::Constants;
|
2003-11-22 03:50:42 +00:00
|
|
|
|
use Bugzilla::Config qw(:DEFAULT $datadir);
|
2005-03-15 22:10:14 +00:00
|
|
|
|
use Bugzilla::User;
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2005-01-16 13:48:25 +00:00
|
|
|
|
use vars qw($template $vars);
|
|
|
|
|
|
|
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-02-17 21:57:27 +00:00
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
# TestProduct: just returns if the specified product does exists
|
|
|
|
|
# CheckProduct: same check, optionally emit an error text
|
|
|
|
|
# TestVersion: just returns if the specified product/version combination exists
|
|
|
|
|
# CheckVersion: same check, optionally emit an error text
|
|
|
|
|
|
|
|
|
|
sub TestProduct ($)
|
|
|
|
|
{
|
|
|
|
|
my $prod = shift;
|
|
|
|
|
|
|
|
|
|
# does the product exist?
|
2002-08-12 05:43:05 +00:00
|
|
|
|
SendSQL("SELECT name
|
1999-10-12 23:00:35 +00:00
|
|
|
|
FROM products
|
2005-01-16 13:48:25 +00:00
|
|
|
|
WHERE name = " . SqlQuote($prod));
|
1999-10-12 23:00:35 +00:00
|
|
|
|
return FetchOneColumn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub CheckProduct ($)
|
|
|
|
|
{
|
|
|
|
|
my $prod = shift;
|
|
|
|
|
|
|
|
|
|
# do we have a product?
|
|
|
|
|
unless ($prod) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
ThrowUserError('product_not_specified');
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unless (TestProduct $prod) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
ThrowUserError('product_doesnt_exist',
|
|
|
|
|
{'product' => $prod});
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub TestVersion ($$)
|
|
|
|
|
{
|
|
|
|
|
my ($prod,$ver) = @_;
|
|
|
|
|
|
|
|
|
|
# does the product exist?
|
2005-01-16 13:48:25 +00:00
|
|
|
|
SendSQL("SELECT products.name, value
|
2002-08-12 05:43:05 +00:00
|
|
|
|
FROM versions, products
|
2005-01-16 13:48:25 +00:00
|
|
|
|
WHERE versions.product_id = products.id
|
|
|
|
|
AND products.name = " . SqlQuote($prod) . "
|
|
|
|
|
AND value = " . SqlQuote($ver));
|
1999-10-12 23:00:35 +00:00
|
|
|
|
return FetchOneColumn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub CheckVersion ($$)
|
|
|
|
|
{
|
2005-01-16 13:48:25 +00:00
|
|
|
|
my ($prod, $ver) = @_;
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
# do we have the version?
|
|
|
|
|
unless ($ver) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
ThrowUserError('version_not_specified');
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CheckProduct($prod);
|
|
|
|
|
|
2005-01-16 13:48:25 +00:00
|
|
|
|
unless (TestVersion $prod, $ver) {
|
|
|
|
|
ThrowUserError('version_not_valid',
|
|
|
|
|
{'product' => $prod,
|
|
|
|
|
'version' => $ver});
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Preliminary checks:
|
|
|
|
|
#
|
|
|
|
|
|
2004-03-27 03:51:44 +00:00
|
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2003-05-05 01:15:38 +00:00
|
|
|
|
print Bugzilla->cgi->header();
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2005-01-27 19:50:25 +00:00
|
|
|
|
UserInGroup("editcomponents")
|
|
|
|
|
|| ThrowUserError("auth_failure", {group => "editcomponents",
|
|
|
|
|
action => "edit",
|
|
|
|
|
object => "versions"});
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# often used variables
|
|
|
|
|
#
|
2004-03-27 20:07:25 +00:00
|
|
|
|
my $product = trim($cgi->param('product') || '');
|
|
|
|
|
my $version = trim($cgi->param('version') || '');
|
|
|
|
|
my $action = trim($cgi->param('action') || '');
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# product = '' -> Show nice list of versions
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
unless ($product) {
|
|
|
|
|
|
2005-01-16 13:48:25 +00:00
|
|
|
|
my @products = ();
|
|
|
|
|
|
|
|
|
|
SendSQL("SELECT products.name, products.description
|
1999-10-12 23:00:35 +00:00
|
|
|
|
FROM products
|
2002-08-12 05:43:05 +00:00
|
|
|
|
ORDER BY products.name");
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
while ( MoreSQLData() ) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
my ($product, $description) = FetchSQLData();
|
|
|
|
|
|
|
|
|
|
my $prod = {};
|
|
|
|
|
|
|
|
|
|
$prod->{'name'} = $product;
|
|
|
|
|
$prod->{'description'} = $description;
|
|
|
|
|
|
|
|
|
|
push(@products, $prod);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-16 13:48:25 +00:00
|
|
|
|
$vars->{'products'} = \@products;
|
|
|
|
|
$template->process("admin/versions/select-product.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='' -> Show nice list of versions
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
unless ($action) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
CheckProduct($product);
|
2002-08-12 05:43:05 +00:00
|
|
|
|
my $product_id = get_product_id($product);
|
2005-01-16 13:48:25 +00:00
|
|
|
|
my @versions = ();
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2002-08-12 05:43:05 +00:00
|
|
|
|
SendSQL("SELECT value
|
|
|
|
|
FROM versions
|
2005-01-16 13:48:25 +00:00
|
|
|
|
WHERE product_id = $product_id
|
1999-10-12 23:00:35 +00:00
|
|
|
|
ORDER BY value");
|
|
|
|
|
|
|
|
|
|
while ( MoreSQLData() ) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
my $name = FetchOneColumn();
|
|
|
|
|
|
|
|
|
|
my $version = {};
|
|
|
|
|
|
|
|
|
|
$version->{'name'} = $name;
|
|
|
|
|
|
|
|
|
|
push(@versions, $version);
|
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-01-16 13:48:25 +00:00
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
$vars->{'versions'} = \@versions;
|
|
|
|
|
$template->process("admin/versions/list.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='add' -> present form for parameters for new version
|
|
|
|
|
#
|
|
|
|
|
# (next action will be 'new')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'add') {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
CheckProduct($product);
|
2002-08-12 05:43:05 +00:00
|
|
|
|
my $product_id = get_product_id($product);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2005-01-16 13:48:25 +00:00
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
$template->process("admin/versions/create.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='new' -> add version entered in the 'action=add' screen
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'new') {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
CheckProduct($product);
|
2002-08-12 05:43:05 +00:00
|
|
|
|
my $product_id = get_product_id($product);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
# Cleanups and valididy checks
|
|
|
|
|
|
|
|
|
|
unless ($version) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
ThrowUserError('version_blank_name',
|
|
|
|
|
{'name' => $version});
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
if (TestVersion($product,$version)) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
ThrowUserError('version_already_exists',
|
|
|
|
|
{'name' => $version,
|
|
|
|
|
'product' => $product});
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Add the new version
|
|
|
|
|
SendSQL("INSERT INTO versions ( " .
|
2005-01-16 13:48:25 +00:00
|
|
|
|
"value, product_id" .
|
|
|
|
|
" ) VALUES ( " .
|
|
|
|
|
SqlQuote($version) . ", $product_id)");
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
# Make versioncache flush
|
2003-11-22 03:50:42 +00:00
|
|
|
|
unlink "$datadir/versioncache";
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2005-01-16 13:48:25 +00:00
|
|
|
|
$vars->{'name'} = $version;
|
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
$template->process("admin/versions/created.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='del' -> ask if user really wants to delete
|
|
|
|
|
#
|
|
|
|
|
# (next action would be 'delete')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'del') {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
CheckVersion($product, $version);
|
2002-08-12 05:43:05 +00:00
|
|
|
|
my $product_id = get_product_id($product);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2002-08-12 05:43:05 +00:00
|
|
|
|
SendSQL("SELECT count(bug_id)
|
1999-10-12 23:00:35 +00:00
|
|
|
|
FROM bugs
|
2002-08-12 05:43:05 +00:00
|
|
|
|
WHERE product_id = $product_id
|
|
|
|
|
AND version = " . SqlQuote($version));
|
2005-01-16 13:48:25 +00:00
|
|
|
|
my $bugs = FetchOneColumn() || 0;
|
|
|
|
|
|
|
|
|
|
$vars->{'bug_count'} = $bugs;
|
|
|
|
|
$vars->{'name'} = $version;
|
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
$template->process("admin/versions/confirm-delete.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='delete' -> really delete the version
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'delete') {
|
2005-04-06 00:19:56 +00:00
|
|
|
|
CheckVersion($product, $version);
|
2002-08-12 05:43:05 +00:00
|
|
|
|
my $product_id = get_product_id($product);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2005-04-06 00:19:56 +00:00
|
|
|
|
trick_taint($version);
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
2005-04-06 00:19:56 +00:00
|
|
|
|
my $nb_bugs =
|
|
|
|
|
$dbh->selectrow_array("SELECT COUNT(bug_id) FROM bugs
|
|
|
|
|
WHERE product_id = ? AND version = ?",
|
|
|
|
|
undef, ($product_id, $version));
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
2005-04-06 00:19:56 +00:00
|
|
|
|
# The version cannot be removed if there are bugs
|
|
|
|
|
# associated with it.
|
|
|
|
|
if ($nb_bugs) {
|
|
|
|
|
ThrowUserError("version_has_bugs", { nb => $nb_bugs });
|
1999-12-17 03:41:13 +00:00
|
|
|
|
}
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2005-04-06 00:19:56 +00:00
|
|
|
|
$dbh->do("DELETE FROM versions WHERE product_id = ? AND value = ?",
|
|
|
|
|
undef, ($product_id, $version));
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2003-11-22 03:50:42 +00:00
|
|
|
|
unlink "$datadir/versioncache";
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
|
|
|
|
$vars->{'name'} = $version;
|
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
|
2005-04-06 00:19:56 +00:00
|
|
|
|
$template->process("admin/versions/deleted.html.tmpl", $vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
1999-10-12 23:00:35 +00:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='edit' -> present the edit version form
|
|
|
|
|
#
|
|
|
|
|
# (next action would be 'update')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'edit') {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
CheckVersion($product,$version);
|
2002-08-12 05:43:05 +00:00
|
|
|
|
my $product_id = get_product_id($product);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2005-01-16 13:48:25 +00:00
|
|
|
|
$vars->{'name'} = $version;
|
|
|
|
|
$vars->{'product'} = $product;
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
2005-01-16 13:48:25 +00:00
|
|
|
|
$template->process("admin/versions/edit.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='update' -> update the version
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'update') {
|
|
|
|
|
|
2004-03-27 20:07:25 +00:00
|
|
|
|
my $versionold = trim($cgi->param('versionold') || '');
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
CheckVersion($product,$versionold);
|
2002-08-12 05:43:05 +00:00
|
|
|
|
my $product_id = get_product_id($product);
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
# Note that the order of this tests is important. If you change
|
|
|
|
|
# them, be sure to test for WHERE='$version' or WHERE='$versionold'
|
|
|
|
|
|
2005-02-17 21:57:27 +00:00
|
|
|
|
$dbh->bz_lock_tables('bugs WRITE',
|
|
|
|
|
'versions WRITE',
|
|
|
|
|
'products READ');
|
1999-10-12 23:00:35 +00:00
|
|
|
|
|
|
|
|
|
if ($version ne $versionold) {
|
|
|
|
|
unless ($version) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
ThrowUserError('version_blank_name');
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
if (TestVersion($product,$version)) {
|
2005-01-16 13:48:25 +00:00
|
|
|
|
ThrowUserError('version_already_exists',
|
|
|
|
|
{'name' => $version,
|
|
|
|
|
'product' => $product});
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
SendSQL("UPDATE bugs
|
2005-02-08 16:51:03 +00:00
|
|
|
|
SET version=" . SqlQuote($version) . "
|
1999-10-12 23:00:35 +00:00
|
|
|
|
WHERE version=" . SqlQuote($versionold) . "
|
2002-08-12 05:43:05 +00:00
|
|
|
|
AND product_id = $product_id");
|
1999-10-12 23:00:35 +00:00
|
|
|
|
SendSQL("UPDATE versions
|
2005-01-16 13:48:25 +00:00
|
|
|
|
SET value = " . SqlQuote($version) . "
|
2002-08-12 05:43:05 +00:00
|
|
|
|
WHERE product_id = $product_id
|
2005-01-16 13:48:25 +00:00
|
|
|
|
AND value = " . SqlQuote($versionold));
|
2003-11-22 03:50:42 +00:00
|
|
|
|
unlink "$datadir/versioncache";
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
|
|
|
|
$vars->{'updated_name'} = 1;
|
1999-10-12 23:00:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-17 21:57:27 +00:00
|
|
|
|
$dbh->bz_unlock_tables();
|
2005-01-16 13:48:25 +00:00
|
|
|
|
|
|
|
|
|
$vars->{'name'} = $version;
|
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
$template->process("admin/versions/updated.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
1999-10-12 23:00:35 +00:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# No valid action found
|
|
|
|
|
#
|
2005-02-16 16:35:54 +00:00
|
|
|
|
ThrowUserError('no_valid_action', {'field' => "version"});
|