summaryrefslogtreecommitdiffstats
path: root/editversions.cgi
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2005-07-19 09:05:10 +0200
committerlpsolit%gmail.com <>2005-07-19 09:05:10 +0200
commit534173a0d5d06a945cd48da84815e4f003ebf727 (patch)
tree17c8d114e1d3eb194be1aaab9fe0a2a958d94374 /editversions.cgi
parent0b6e85450a54b205afcda501b78d2dd2982d269e (diff)
downloadbugzilla-534173a0d5d06a945cd48da84815e4f003ebf727.tar.gz
bugzilla-534173a0d5d06a945cd48da84815e4f003ebf727.tar.xz
Bug 300532: Update editversions.cgi to use routines from Version.pm and Product.pm - Patch by Tiago R. Mello <timello@async.com.br> r=LpSolit a=myk
Diffstat (limited to 'editversions.cgi')
-rwxr-xr-xeditversions.cgi246
1 files changed, 69 insertions, 177 deletions
diff --git a/editversions.cgi b/editversions.cgi
index 8d3f4dc8b..a7ced7df3 100755
--- a/editversions.cgi
+++ b/editversions.cgi
@@ -37,82 +37,21 @@ require "globals.pl";
use Bugzilla::Constants;
use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::User;
+use Bugzilla::Product;
+use Bugzilla::Version;
use vars qw($template $vars);
my $cgi = Bugzilla->cgi;
my $dbh = Bugzilla->dbh;
-# 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?
- SendSQL("SELECT name
- FROM products
- WHERE name = " . SqlQuote($prod));
- return FetchOneColumn();
-}
-
-sub CheckProduct ($)
-{
- my $prod = shift;
-
- # do we have a product?
- unless ($prod) {
- ThrowUserError('product_not_specified');
- }
-
- unless (TestProduct $prod) {
- ThrowUserError('product_doesnt_exist',
- {'product' => $prod});
- }
-}
-
-sub TestVersion ($$)
-{
- my ($prod,$ver) = @_;
-
- # does the product exist?
- 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();
-}
-
-sub CheckVersion ($$)
-{
- my ($prod, $ver) = @_;
-
- # do we have the version?
- unless ($ver) {
- ThrowUserError('version_not_specified');
- }
-
- CheckProduct($prod);
-
- unless (TestVersion $prod, $ver) {
- ThrowUserError('version_not_valid',
- {'product' => $prod,
- 'version' => $ver});
- }
-}
-
-
#
# Preliminary checks:
#
Bugzilla->login(LOGIN_REQUIRED);
-print Bugzilla->cgi->header();
+print $cgi->header();
UserInGroup("editcomponents")
|| ThrowUserError("auth_failure", {group => "editcomponents",
@@ -122,34 +61,17 @@ UserInGroup("editcomponents")
#
# often used variables
#
-my $product = trim($cgi->param('product') || '');
-my $version = trim($cgi->param('version') || '');
-my $action = trim($cgi->param('action') || '');
-
+my $product_name = trim($cgi->param('product') || '');
+my $version_name = trim($cgi->param('version') || '');
+my $action = trim($cgi->param('action') || '');
#
-# product = '' -> Show nice list of versions
+# product = '' -> Show nice list of products
#
-unless ($product) {
-
- my @products = ();
-
- SendSQL("SELECT products.name, products.description
- FROM products
- ORDER BY products.name");
-
- while ( MoreSQLData() ) {
- my ($product, $description) = FetchSQLData();
-
- my $prod = {};
-
- $prod->{'name'} = $product;
- $prod->{'description'} = $description;
-
- push(@products, $prod);
- }
+unless ($product_name) {
+ my @products = Bugzilla::Product::get_all_products();
$vars->{'products'} = \@products;
$template->process("admin/versions/select-product.html.tmpl",
$vars)
@@ -158,33 +80,17 @@ unless ($product) {
exit;
}
+my $product = Bugzilla::Product::check_product($product_name);
+
#
# action='' -> Show nice list of versions
#
unless ($action) {
+ my @versions =
+ Bugzilla::Version::get_versions_by_product($product->id);
- CheckProduct($product);
- my $product_id = get_product_id($product);
- my @versions = ();
-
- SendSQL("SELECT value
- FROM versions
- WHERE product_id = $product_id
- ORDER BY value");
-
- while ( MoreSQLData() ) {
- my $name = FetchOneColumn();
-
- my $version = {};
-
- $version->{'name'} = $name;
-
- push(@versions, $version);
-
- }
-
- $vars->{'product'} = $product;
+ $vars->{'product'} = $product->name;
$vars->{'versions'} = \@versions;
$template->process("admin/versions/list.html.tmpl",
$vars)
@@ -204,10 +110,7 @@ unless ($action) {
if ($action eq 'add') {
- CheckProduct($product);
- my $product_id = get_product_id($product);
-
- $vars->{'product'} = $product;
+ $vars->{'product'} = $product->name;
$template->process("admin/versions/create.html.tmpl",
$vars)
|| ThrowTemplateError($template->error());
@@ -223,33 +126,26 @@ if ($action eq 'add') {
if ($action eq 'new') {
- CheckProduct($product);
- my $product_id = get_product_id($product);
-
# Cleanups and valididy checks
+ $version_name || ThrowUserError('version_blank_name');
- unless ($version) {
- ThrowUserError('version_blank_name',
- {'name' => $version});
- }
-
- if (TestVersion($product,$version)) {
+ my $version = new Bugzilla::Version($product->id, $version_name);
+ if ($version) {
ThrowUserError('version_already_exists',
- {'name' => $version,
- 'product' => $product});
+ {'name' => $version->name,
+ 'product' => $product->name});
}
# Add the new version
- SendSQL("INSERT INTO versions ( " .
- "value, product_id" .
- " ) VALUES ( " .
- SqlQuote($version) . ", $product_id)");
+ trick_taint($version_name);
+ $dbh->do("INSERT INTO versions (value, product_id)
+ VALUES (?, ?)", undef, ($version_name, $product->id));
# Make versioncache flush
unlink "$datadir/versioncache";
- $vars->{'name'} = $version;
- $vars->{'product'} = $product;
+ $vars->{'name'} = $version_name;
+ $vars->{'product'} = $product->name;
$template->process("admin/versions/created.html.tmpl",
$vars)
|| ThrowTemplateError($template->error());
@@ -268,18 +164,13 @@ if ($action eq 'new') {
if ($action eq 'del') {
- CheckVersion($product, $version);
- my $product_id = get_product_id($product);
-
- SendSQL("SELECT count(bug_id)
- FROM bugs
- WHERE product_id = $product_id
- AND version = " . SqlQuote($version));
- my $bugs = FetchOneColumn() || 0;
+ my $version = Bugzilla::Version::check_version($product,
+ $version_name);
+ my $bugs = $version->bug_count;
$vars->{'bug_count'} = $bugs;
- $vars->{'name'} = $version;
- $vars->{'product'} = $product;
+ $vars->{'name'} = $version->name;
+ $vars->{'product'} = $product->name;
$template->process("admin/versions/confirm-delete.html.tmpl",
$vars)
|| ThrowTemplateError($template->error());
@@ -294,29 +185,24 @@ if ($action eq 'del') {
#
if ($action eq 'delete') {
- CheckVersion($product, $version);
- my $product_id = get_product_id($product);
- trick_taint($version);
-
- my $nb_bugs =
- $dbh->selectrow_array("SELECT COUNT(bug_id) FROM bugs
- WHERE product_id = ? AND version = ?",
- undef, ($product_id, $version));
+ my $version = Bugzilla::Version::check_version($product,
+ $version_name);
# The version cannot be removed if there are bugs
# associated with it.
- if ($nb_bugs) {
- ThrowUserError("version_has_bugs", { nb => $nb_bugs });
+ if ($version->bug_count) {
+ ThrowUserError("version_has_bugs",
+ { nb => $version->bug_count });
}
$dbh->do("DELETE FROM versions WHERE product_id = ? AND value = ?",
- undef, ($product_id, $version));
+ undef, ($product->id, $version->name));
unlink "$datadir/versioncache";
- $vars->{'name'} = $version;
- $vars->{'product'} = $product;
+ $vars->{'name'} = $version->name;
+ $vars->{'product'} = $product->name;
$template->process("admin/versions/deleted.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
@@ -333,11 +219,11 @@ if ($action eq 'delete') {
if ($action eq 'edit') {
- CheckVersion($product,$version);
- my $product_id = get_product_id($product);
+ my $version = Bugzilla::Version::check_version($product,
+ $version_name);
- $vars->{'name'} = $version;
- $vars->{'product'} = $product;
+ $vars->{'name'} = $version->name;
+ $vars->{'product'} = $product->name;
$template->process("admin/versions/edit.html.tmpl",
$vars)
@@ -354,10 +240,11 @@ if ($action eq 'edit') {
if ($action eq 'update') {
- my $versionold = trim($cgi->param('versionold') || '');
-
- CheckVersion($product,$versionold);
- my $product_id = get_product_id($product);
+ $version_name || ThrowUserError('version_not_specified');
+ my $version_old_name = trim($cgi->param('versionold') || '');
+ my $version_old =
+ Bugzilla::Version::check_version($product,
+ $version_old_name);
# Note that the order of this tests is important. If you change
# them, be sure to test for WHERE='$version' or WHERE='$versionold'
@@ -366,23 +253,28 @@ if ($action eq 'update') {
'versions WRITE',
'products READ');
- if ($version ne $versionold) {
- unless ($version) {
- ThrowUserError('version_blank_name');
- }
- if (TestVersion($product,$version)) {
+ if ($version_name ne $version_old->name) {
+
+ my $version = new Bugzilla::Version($product->id,
+ $version_name);
+
+ if ($version) {
ThrowUserError('version_already_exists',
- {'name' => $version,
- 'product' => $product});
+ {'name' => $version->name,
+ 'product' => $product->name});
}
- SendSQL("UPDATE bugs
- SET version=" . SqlQuote($version) . "
- WHERE version=" . SqlQuote($versionold) . "
- AND product_id = $product_id");
- SendSQL("UPDATE versions
- SET value = " . SqlQuote($version) . "
- WHERE product_id = $product_id
- AND value = " . SqlQuote($versionold));
+
+ trick_taint($version_name);
+ $dbh->do("UPDATE bugs
+ SET version = ?
+ WHERE version = ? AND product_id = ?", undef,
+ ($version_name, $version_old->name, $product->id));
+
+ $dbh->do("UPDATE versions
+ SET value = ?
+ WHERE product_id = ? AND value = ?", undef,
+ ($version_name, $product->id, $version_old->name));
+
unlink "$datadir/versioncache";
$vars->{'updated_name'} = 1;
@@ -390,8 +282,8 @@ if ($action eq 'update') {
$dbh->bz_unlock_tables();
- $vars->{'name'} = $version;
- $vars->{'product'} = $product;
+ $vars->{'name'} = $version_name;
+ $vars->{'product'} = $product->name;
$template->process("admin/versions/updated.html.tmpl",
$vars)
|| ThrowTemplateError($template->error());