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>
|
|
|
|
#
|
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);
|
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) {
|
|
|
|
&::ThrowUserError('product_not_specified');
|
2000-03-21 19:47:06 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
# Does it exist in the DB?
|
|
|
|
unless (TestProduct $product) {
|
|
|
|
&::ThrowUserError('product_doesnt_exist',
|
|
|
|
{'product' => $product});
|
2000-03-21 19:47:06 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2002-08-12 09:43:05 +04:00
|
|
|
FROM milestones, products
|
2004-09-11 10:48:14 +04:00
|
|
|
WHERE milestones.product_id = products.id
|
|
|
|
AND products.name = ?
|
|
|
|
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');
|
|
|
|
exit;
|
|
|
|
}
|
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});
|
|
|
|
exit;
|
2000-03-21 19:47:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Preliminary checks:
|
|
|
|
#
|
|
|
|
|
2004-03-27 06:51:44 +03:00
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
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
|
|
|
|
|
|
|
unless (UserInGroup("editcomponents")) {
|
2004-09-11 10:48:14 +04:00
|
|
|
ThrowUserError('auth_cant_edit_milestones');
|
2000-03-21 19:47:06 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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});
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length($milestone) > 20) {
|
|
|
|
ThrowUserError('milestone_name_too_long',
|
|
|
|
{'name' => $milestone});
|
2000-03-21 19:47:06 +03:00
|
|
|
exit;
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
# Need to store in case detaint_natural() clears the sortkey
|
|
|
|
my $stored_sortkey = $sortkey;
|
2004-06-11 21:03:50 +04:00
|
|
|
if (!detaint_natural($sortkey)) {
|
2004-09-11 10:48:14 +04:00
|
|
|
ThrowUserError('milestone_sortkey_invalid',
|
|
|
|
{'name' => $milestone,
|
|
|
|
'sortkey' => $stored_sortkey});
|
2003-09-25 23:59:44 +04:00
|
|
|
exit;
|
|
|
|
}
|
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
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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') {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
2000-03-21 19:47:06 +03: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('SELECT count(bug_id), product_id, target_milestone
|
|
|
|
FROM bugs
|
|
|
|
GROUP BY product_id, target_milestone
|
|
|
|
HAVING product_id = ?
|
|
|
|
AND target_milestone = ?');
|
|
|
|
|
|
|
|
trick_taint($milestone);
|
|
|
|
$vars->{'bug_count'} = $dbh->selectrow_array($sth,
|
|
|
|
undef,
|
|
|
|
$product_id,
|
|
|
|
$milestone) || 0;
|
|
|
|
|
|
|
|
$sth = $dbh->prepare('SELECT defaultmilestone
|
|
|
|
FROM products
|
|
|
|
WHERE id = ?');
|
|
|
|
|
|
|
|
$vars->{'default_milestone'} = $dbh->selectrow_array($sth,
|
|
|
|
undef,
|
|
|
|
$product_id) || '';
|
|
|
|
|
|
|
|
$vars->{'name'} = $milestone;
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
$template->process("admin/milestones/confirm-delete.html.tmpl",
|
|
|
|
$vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-23 21:23:14 +03:00
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='delete' -> really delete the milestone
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'delete') {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
2000-03-21 19:47:06 +03: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
|
|
|
# lock the tables before we start to change everything:
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
$dbh->do('LOCK TABLES attachments WRITE,
|
|
|
|
bugs WRITE,
|
|
|
|
bugs_activity WRITE,
|
|
|
|
milestones WRITE,
|
|
|
|
dependencies WRITE');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
# According to MySQL doc I cannot do a DELETE x.* FROM x JOIN Y,
|
|
|
|
# so I have to iterate over bugs and delete all the indivial entries
|
|
|
|
# in bugs_activies and attachments.
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
# Detaint this here, as we may need it if deleting bugs, but will
|
|
|
|
# definitely need it detainted whhen we actually delete the
|
|
|
|
# milestone itself
|
|
|
|
trick_taint($milestone);
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
if (Param("allowbugdeletion")) {
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
my $deleted_bug_count = 0;
|
|
|
|
|
|
|
|
my $sth = $dbh->prepare_cached('SELECT bug_id
|
|
|
|
FROM bugs
|
|
|
|
WHERE product_id = ?
|
|
|
|
AND target_milestone = ?');
|
|
|
|
|
|
|
|
my $data = $dbh->selectall_arrayref($sth,
|
|
|
|
undef,
|
|
|
|
$product_id,
|
|
|
|
$milestone);
|
|
|
|
|
|
|
|
foreach my $aref (@$data) {
|
|
|
|
|
|
|
|
my ($bugid) = @$aref;
|
|
|
|
|
|
|
|
$dbh->do('DELETE FROM attachments WHERE bug_id = ?',
|
|
|
|
undef,
|
|
|
|
$bugid);
|
|
|
|
$dbh->do('DELETE FROM bugs_activity WHERE bug_id = ?',
|
|
|
|
undef,
|
|
|
|
$bugid);
|
|
|
|
$dbh->do('DELETE FROM dependencies WHERE blocked = ?',
|
|
|
|
undef,
|
|
|
|
$bugid);
|
|
|
|
|
|
|
|
$deleted_bug_count++;
|
2000-03-21 19:47:06 +03:00
|
|
|
}
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
$vars->{'deleted_bug_count'} = $deleted_bug_count;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
# Deleting the rest is easier:
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
$dbh->do('DELETE FROM bugs
|
|
|
|
WHERE product_id = ?
|
|
|
|
AND target_milestone = ?',
|
|
|
|
undef,
|
|
|
|
$product_id,
|
|
|
|
$milestone);
|
2000-03-21 19:47:06 +03:00
|
|
|
}
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
$dbh->do('DELETE FROM milestones
|
|
|
|
WHERE product_id = ?
|
|
|
|
AND value = ?',
|
|
|
|
undef,
|
|
|
|
$product_id,
|
|
|
|
$milestone);
|
|
|
|
|
|
|
|
$dbh->do('UNLOCK TABLES');
|
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
|
|
|
|
|
|
|
|
|
|
|
$vars->{'name'} = $milestone;
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
$template->process("admin/milestones/deleted.html.tmpl",
|
|
|
|
$vars)
|
|
|
|
|| 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});
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
|
|
|
$dbh->do("LOCK TABLES bugs WRITE,
|
|
|
|
milestones WRITE,
|
|
|
|
products WRITE");
|
2000-03-21 19:47:06 +03:00
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
# Need to store because detaint_natural() will delete this if
|
|
|
|
# invalid
|
|
|
|
my $stored_sortkey = $sortkey;
|
2001-04-06 20:47:49 +04:00
|
|
|
if ($sortkey != $sortkeyold) {
|
2004-06-16 17:45:37 +04:00
|
|
|
if (!detaint_natural($sortkey)) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
$dbh->do('UNLOCK TABLES');
|
|
|
|
ThrowUserError('milestone_sortkey_invalid',
|
|
|
|
{'name' => $milestone,
|
|
|
|
'sortkey' => $stored_sortkey});
|
|
|
|
|
2004-06-16 17:45:37 +04:00
|
|
|
exit;
|
|
|
|
}
|
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
|
|
|
$dbh->do('UNLOCK TABLES');
|
|
|
|
ThrowUserError('milestone_blank_name');
|
2000-03-21 19:47:06 +03:00
|
|
|
exit;
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
if (TestMilestone($product, $milestone)) {
|
|
|
|
$dbh->do('UNLOCK TABLES');
|
|
|
|
ThrowUserError('milestone_already_exists',
|
|
|
|
{'name' => $milestone,
|
|
|
|
'product' => $product});
|
2000-03-21 19:47:06 +03:00
|
|
|
exit;
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
trick_taint($milestone);
|
|
|
|
trick_taint($milestoneold);
|
|
|
|
|
|
|
|
$dbh->do('UPDATE bugs
|
|
|
|
SET target_milestone = ?,
|
|
|
|
delta_ts = delta_ts
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
$dbh->do('UNLOCK TABLES');
|
|
|
|
|
|
|
|
$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
|
|
|
|
#
|
2004-09-11 10:48:14 +04:00
|
|
|
ThrowUserError('milestone_no_action');
|