2004-05-23 11:22:32 +04:00
|
|
|
|
#!/usr/bin/perl -wT
|
2000-03-21 19:47:06 +03:00
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# This is a script to edit the target milestones. It is largely a copy of
|
|
|
|
|
# the editversions.cgi script, since the two fields were set up in a
|
|
|
|
|
# very similar fashion.
|
|
|
|
|
#
|
|
|
|
|
# (basically replace each occurance of 'milestone' with 'version', and
|
|
|
|
|
# you'll have the original script)
|
|
|
|
|
#
|
|
|
|
|
# Matt Masson <matthew@zeroknowledge.com>
|
|
|
|
|
#
|
2004-09-11 10:48:14 +04:00
|
|
|
|
# Contributors : Gavin Shelley <bugzilla@chimpychompy.org>
|
2005-04-06 04:19:56 +04:00
|
|
|
|
# Fr<46>d<EFBFBD>ric Buclin <LpSolit@gmail.com>
|
2004-09-11 10:48:14 +04:00
|
|
|
|
#
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use strict;
|
2002-04-29 23:32:29 +04:00
|
|
|
|
use lib ".";
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
require "CGI.pl";
|
|
|
|
|
require "globals.pl";
|
|
|
|
|
|
2004-03-27 06:51:44 +03:00
|
|
|
|
use Bugzilla::Constants;
|
2003-11-22 06:50:42 +03:00
|
|
|
|
use Bugzilla::Config qw(:DEFAULT $datadir);
|
2005-03-16 01:10:14 +03:00
|
|
|
|
use Bugzilla::User;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
use vars qw($template $vars);
|
|
|
|
|
|
|
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
# TestProduct: just returns if the specified product does exists
|
|
|
|
|
# CheckProduct: same check, optionally emit an error text
|
|
|
|
|
# TestMilestone: just returns if the specified product/version combination exists
|
|
|
|
|
# CheckMilestone: same check, optionally emit an error text
|
|
|
|
|
|
|
|
|
|
sub TestProduct ($)
|
|
|
|
|
{
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $product = shift;
|
|
|
|
|
|
|
|
|
|
trick_taint($product);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
# does the product exist?
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
my $sth = $dbh->prepare_cached("SELECT name
|
|
|
|
|
FROM products
|
|
|
|
|
WHERE name = ?");
|
|
|
|
|
$sth->execute($product);
|
|
|
|
|
|
|
|
|
|
my ($row) = $sth->fetchrow_array;
|
|
|
|
|
|
|
|
|
|
$sth->finish;
|
|
|
|
|
|
|
|
|
|
return $row;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub CheckProduct ($)
|
|
|
|
|
{
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $product = shift;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
# do we have a product?
|
2004-09-11 10:48:14 +04:00
|
|
|
|
unless ($product) {
|
2005-03-05 03:18:48 +03:00
|
|
|
|
ThrowUserError('product_not_specified');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
# Does it exist in the DB?
|
|
|
|
|
unless (TestProduct $product) {
|
2005-03-05 03:18:48 +03:00
|
|
|
|
ThrowUserError('product_doesnt_exist',
|
|
|
|
|
{'product' => $product});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub TestMilestone ($$)
|
|
|
|
|
{
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my ($product, $milestone) = @_;
|
|
|
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
# does the product exist?
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $sth = $dbh->prepare_cached("
|
|
|
|
|
SELECT products.name, value
|
2005-04-05 01:52:06 +04:00
|
|
|
|
FROM milestones
|
|
|
|
|
INNER JOIN products
|
|
|
|
|
ON milestones.product_id = products.id
|
|
|
|
|
WHERE products.name = ?
|
2004-09-11 10:48:14 +04:00
|
|
|
|
AND value = ?");
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
trick_taint($product);
|
|
|
|
|
trick_taint($milestone);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$sth->execute($product, $milestone);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my ($db_milestone) = $sth->fetchrow_array();
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$sth->finish();
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
return $db_milestone;
|
|
|
|
|
}
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
sub CheckMilestone ($$)
|
2000-03-21 19:47:06 +03:00
|
|
|
|
{
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my ($product, $milestone) = @_;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
# do we have the milestone and product combination?
|
|
|
|
|
unless ($milestone) {
|
|
|
|
|
ThrowUserError('milestone_not_specified');
|
|
|
|
|
}
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
CheckProduct($product);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
unless (TestMilestone $product, $milestone) {
|
|
|
|
|
ThrowUserError('milestone_not_valid',
|
|
|
|
|
{'product' => $product,
|
|
|
|
|
'milestone' => $milestone});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-03 23:41:23 +04:00
|
|
|
|
sub CheckSortkey ($$)
|
|
|
|
|
{
|
|
|
|
|
my ($milestone, $sortkey) = @_;
|
|
|
|
|
# Keep a copy in case detaint_signed() clears the sortkey
|
|
|
|
|
my $stored_sortkey = $sortkey;
|
|
|
|
|
|
|
|
|
|
if (!detaint_signed($sortkey) || $sortkey < -32768 || $sortkey > 32767) {
|
|
|
|
|
ThrowUserError('milestone_sortkey_invalid',
|
|
|
|
|
{'name' => $milestone,
|
|
|
|
|
'sortkey' => $stored_sortkey});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $sortkey;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
#
|
|
|
|
|
# Preliminary checks:
|
|
|
|
|
#
|
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
my $user = Bugzilla->login(LOGIN_REQUIRED);
|
|
|
|
|
my $whoid = $user->id;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2003-05-05 05:15:38 +04:00
|
|
|
|
print Bugzilla->cgi->header();
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-01-16 17:07:31 +03:00
|
|
|
|
UserInGroup("editcomponents")
|
|
|
|
|
|| ThrowUserError("auth_failure", {group => "editcomponents",
|
|
|
|
|
action => "edit",
|
|
|
|
|
object => "milestones"});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# often used variables
|
|
|
|
|
#
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $product = trim($cgi->param('product') || '');
|
|
|
|
|
my $milestone = trim($cgi->param('milestone') || '');
|
|
|
|
|
my $sortkey = trim($cgi->param('sortkey') || '0');
|
|
|
|
|
my $action = trim($cgi->param('action') || '');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# product = '' -> Show nice list of milestones
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
unless ($product) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
my @products = ();
|
|
|
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
|
|
|
|
|
my $sth = $dbh->prepare_cached('SELECT products.name, products.description
|
|
|
|
|
FROM products
|
|
|
|
|
ORDER BY products.name');
|
|
|
|
|
|
|
|
|
|
my $data = $dbh->selectall_arrayref($sth);
|
|
|
|
|
|
|
|
|
|
foreach my $aref (@$data) {
|
|
|
|
|
|
|
|
|
|
my $prod = {};
|
|
|
|
|
|
|
|
|
|
my ($name, $description) = @$aref;
|
|
|
|
|
|
|
|
|
|
$prod->{'name'} = $name;
|
|
|
|
|
$prod->{'description'} = $description;
|
|
|
|
|
|
|
|
|
|
push(@products, $prod);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$vars->{'products'} = \@products;
|
|
|
|
|
$template->process("admin/milestones/select-product.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='' -> Show nice list of milestones
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
unless ($action) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
CheckProduct($product);
|
2002-08-12 09:43:05 +04:00
|
|
|
|
my $product_id = get_product_id($product);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my @milestones = ();
|
|
|
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
|
|
|
|
|
my $sth = $dbh->prepare_cached('SELECT value, sortkey
|
|
|
|
|
FROM milestones
|
|
|
|
|
WHERE product_id = ?
|
|
|
|
|
ORDER BY sortkey, value');
|
|
|
|
|
|
|
|
|
|
my $data = $dbh->selectall_arrayref($sth,
|
|
|
|
|
undef,
|
|
|
|
|
$product_id);
|
|
|
|
|
|
|
|
|
|
foreach my $aref (@$data) {
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $milestone = {};
|
|
|
|
|
my ($name, $sortkey) = @$aref;
|
|
|
|
|
|
|
|
|
|
$milestone->{'name'} = $name;
|
|
|
|
|
$milestone->{'sortkey'} = $sortkey;
|
|
|
|
|
|
|
|
|
|
push(@milestones, $milestone);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
$vars->{'milestones'} = \@milestones;
|
|
|
|
|
$template->process("admin/milestones/list.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='add' -> present form for parameters for new milestone
|
|
|
|
|
#
|
|
|
|
|
# (next action will be 'new')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'add') {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
CheckProduct($product);
|
2002-08-12 09:43:05 +04:00
|
|
|
|
my $product_id = get_product_id($product);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
$template->process("admin/milestones/create.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='new' -> add milestone entered in the 'action=add' screen
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'new') {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
CheckProduct($product);
|
2002-08-12 09:43:05 +04:00
|
|
|
|
my $product_id = get_product_id($product);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
# Cleanups and valididy checks
|
|
|
|
|
unless ($milestone) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
ThrowUserError('milestone_blank_name',
|
|
|
|
|
{'name' => $milestone});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (length($milestone) > 20) {
|
|
|
|
|
ThrowUserError('milestone_name_too_long',
|
|
|
|
|
{'name' => $milestone});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-05-03 23:41:23 +04:00
|
|
|
|
$sortkey = CheckSortkey($milestone, $sortkey);
|
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
if (TestMilestone($product, $milestone)) {
|
|
|
|
|
ThrowUserError('milestone_already_exists',
|
|
|
|
|
{'name' => $milestone,
|
|
|
|
|
'product' => $product});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Add the new milestone
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
trick_taint($milestone);
|
|
|
|
|
$dbh->do('INSERT INTO milestones ( value, product_id, sortkey )
|
|
|
|
|
VALUES ( ?, ?, ? )',
|
|
|
|
|
undef,
|
|
|
|
|
$milestone,
|
|
|
|
|
$product_id,
|
|
|
|
|
$sortkey);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
# Make versioncache flush
|
2003-11-22 06:50:42 +03:00
|
|
|
|
unlink "$datadir/versioncache";
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$vars->{'name'} = $milestone;
|
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
$template->process("admin/milestones/created.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='del' -> ask if user really wants to delete
|
|
|
|
|
#
|
|
|
|
|
# (next action would be 'delete')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'del') {
|
|
|
|
|
CheckMilestone($product, $milestone);
|
2002-08-12 09:43:05 +04:00
|
|
|
|
my $product_id = get_product_id($product);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$vars->{'default_milestone'} =
|
|
|
|
|
$dbh->selectrow_array('SELECT defaultmilestone
|
|
|
|
|
FROM products WHERE id = ?',
|
|
|
|
|
undef, $product_id);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
trick_taint($milestone);
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$vars->{'name'} = $milestone;
|
|
|
|
|
$vars->{'product'} = $product;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
# The default milestone cannot be deleted.
|
|
|
|
|
if ($vars->{'default_milestone'} eq $milestone) {
|
|
|
|
|
ThrowUserError("milestone_is_default", $vars);
|
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$vars->{'bug_count'} =
|
|
|
|
|
$dbh->selectrow_array("SELECT COUNT(bug_id) FROM bugs
|
|
|
|
|
WHERE product_id = ? AND target_milestone = ?",
|
|
|
|
|
undef, ($product_id, $milestone)) || 0;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$template->process("admin/milestones/confirm-delete.html.tmpl", $vars)
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='delete' -> really delete the milestone
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'delete') {
|
2005-04-06 04:19:56 +04:00
|
|
|
|
CheckMilestone($product, $milestone);
|
2002-08-12 09:43:05 +04:00
|
|
|
|
my $product_id = get_product_id($product);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
my $default_milestone =
|
|
|
|
|
$dbh->selectrow_array("SELECT defaultmilestone
|
|
|
|
|
FROM products WHERE id = ?",
|
|
|
|
|
undef, $product_id);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
trick_taint($milestone);
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$vars->{'name'} = $milestone;
|
|
|
|
|
$vars->{'product'} = $product;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
# The default milestone cannot be deleted.
|
|
|
|
|
if ($milestone eq $default_milestone) {
|
|
|
|
|
ThrowUserError("milestone_is_default", $vars);
|
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
# We don't want to delete bugs when deleting a milestone.
|
|
|
|
|
# Bugs concerned are reassigned to the default milestone.
|
|
|
|
|
my $bug_ids =
|
|
|
|
|
$dbh->selectcol_arrayref("SELECT bug_id FROM bugs
|
|
|
|
|
WHERE product_id = ? AND target_milestone = ?",
|
|
|
|
|
undef, ($product_id, $milestone));
|
|
|
|
|
|
|
|
|
|
my $nb_bugs = scalar(@$bug_ids);
|
|
|
|
|
if ($nb_bugs) {
|
|
|
|
|
my $timestamp = $dbh->selectrow_array("SELECT NOW()");
|
|
|
|
|
foreach my $bug_id (@$bug_ids) {
|
|
|
|
|
$dbh->do("UPDATE bugs SET target_milestone = ?,
|
|
|
|
|
delta_ts = ? WHERE bug_id = ?",
|
|
|
|
|
undef, ($default_milestone, $timestamp, $bug_id));
|
|
|
|
|
# We have to update the 'bugs_activity' table too.
|
|
|
|
|
LogActivityEntry($bug_id, 'target_milestone', $milestone,
|
|
|
|
|
$default_milestone, $whoid, $timestamp);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$vars->{'bug_count'} = $nb_bugs;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$dbh->do("DELETE FROM milestones WHERE product_id = ? AND value = ?",
|
|
|
|
|
undef, ($product_id, $milestone));
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2003-11-22 06:50:42 +03:00
|
|
|
|
unlink "$datadir/versioncache";
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$template->process("admin/milestones/deleted.html.tmpl", $vars)
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='edit' -> present the edit milestone form
|
|
|
|
|
#
|
|
|
|
|
# (next action would be 'update')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'edit') {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
CheckMilestone($product, $milestone);
|
2002-08-12 09:43:05 +04:00
|
|
|
|
my $product_id = get_product_id($product);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $sth = $dbh->prepare_cached('SELECT sortkey
|
|
|
|
|
FROM milestones
|
|
|
|
|
WHERE product_id = ?
|
|
|
|
|
AND value = ?');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
trick_taint($milestone);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$vars->{'sortkey'} = $dbh->selectrow_array($sth,
|
|
|
|
|
undef,
|
|
|
|
|
$product_id,
|
|
|
|
|
$milestone) || 0;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$vars->{'name'} = $milestone;
|
|
|
|
|
$vars->{'product'} = $product;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$template->process("admin/milestones/edit.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='update' -> update the milestone
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'update') {
|
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $milestoneold = trim($cgi->param('milestoneold') || '');
|
|
|
|
|
my $sortkeyold = trim($cgi->param('sortkeyold') || '0');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
CheckMilestone($product, $milestoneold);
|
2002-08-12 09:43:05 +04:00
|
|
|
|
my $product_id = get_product_id($product);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
if (length($milestone) > 20) {
|
|
|
|
|
ThrowUserError('milestone_name_too_long',
|
|
|
|
|
{'name' => $milestone});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
|
2005-02-18 00:57:27 +03:00
|
|
|
|
$dbh->bz_lock_tables('bugs WRITE',
|
|
|
|
|
'milestones WRITE',
|
|
|
|
|
'products WRITE');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-05-03 23:41:23 +04:00
|
|
|
|
if ($sortkey ne $sortkeyold) {
|
|
|
|
|
$sortkey = CheckSortkey($milestone, $sortkey);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
trick_taint($milestoneold);
|
|
|
|
|
|
|
|
|
|
$dbh->do('UPDATE milestones SET sortkey = ?
|
|
|
|
|
WHERE product_id = ?
|
|
|
|
|
AND value = ?',
|
|
|
|
|
undef,
|
|
|
|
|
$sortkey,
|
|
|
|
|
$product_id,
|
|
|
|
|
$milestoneold);
|
|
|
|
|
|
2003-11-22 06:50:42 +03:00
|
|
|
|
unlink "$datadir/versioncache";
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$vars->{'updated_sortkey'} = 1;
|
|
|
|
|
$vars->{'sortkey'} = $sortkey;
|
2001-04-06 20:47:49 +04:00
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
if ($milestone ne $milestoneold) {
|
|
|
|
|
unless ($milestone) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
ThrowUserError('milestone_blank_name');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
if (TestMilestone($product, $milestone)) {
|
|
|
|
|
ThrowUserError('milestone_already_exists',
|
|
|
|
|
{'name' => $milestone,
|
|
|
|
|
'product' => $product});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
trick_taint($milestone);
|
|
|
|
|
trick_taint($milestoneold);
|
|
|
|
|
|
|
|
|
|
$dbh->do('UPDATE bugs
|
2005-02-08 19:51:03 +03:00
|
|
|
|
SET target_milestone = ?
|
2004-09-11 10:48:14 +04:00
|
|
|
|
WHERE target_milestone = ?
|
|
|
|
|
AND product_id = ?',
|
|
|
|
|
undef,
|
|
|
|
|
$milestone,
|
|
|
|
|
$milestoneold,
|
|
|
|
|
$product_id);
|
|
|
|
|
|
|
|
|
|
$dbh->do("UPDATE milestones
|
|
|
|
|
SET value = ?
|
|
|
|
|
WHERE product_id = ?
|
|
|
|
|
AND value = ?",
|
|
|
|
|
undef,
|
|
|
|
|
$milestone,
|
|
|
|
|
$product_id,
|
|
|
|
|
$milestoneold);
|
|
|
|
|
|
|
|
|
|
$dbh->do("UPDATE products
|
|
|
|
|
SET defaultmilestone = ?
|
|
|
|
|
WHERE id = ?
|
|
|
|
|
AND defaultmilestone = ?",
|
|
|
|
|
undef,
|
|
|
|
|
$milestone,
|
|
|
|
|
$product_id,
|
|
|
|
|
$milestoneold);
|
|
|
|
|
|
2003-11-22 06:50:42 +03:00
|
|
|
|
unlink "$datadir/versioncache";
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
$vars->{'updated_name'} = 1;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-18 00:57:27 +03:00
|
|
|
|
$dbh->bz_unlock_tables();
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
$vars->{'name'} = $milestone;
|
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
$template->process("admin/milestones/updated.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# No valid action found
|
|
|
|
|
#
|
2005-02-16 19:35:54 +03:00
|
|
|
|
ThrowUserError('no_valid_action', {'field' => "target_milestone"});
|