Bug 303705: Eliminate deprecated Bugzilla::DB routines from editkeywords.cgi - Patch by Fr�d�ric Buclin <LpSolit@gmail.com> r=jouni a=justdave

This commit is contained in:
lpsolit%gmail.com 2005-09-04 18:35:05 +00:00
Родитель 5953c746f2
Коммит 775e3488e1
1 изменённых файлов: 60 добавлений и 75 удалений

Просмотреть файл

@ -25,6 +25,7 @@ use lib ".";
require "globals.pl"; require "globals.pl";
use Bugzilla;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Config qw(:DEFAULT $datadir); use Bugzilla::Config qw(:DEFAULT $datadir);
use Bugzilla::User; use Bugzilla::User;
@ -46,6 +47,12 @@ sub Validate {
if ($description eq "") { if ($description eq "") {
ThrowUserError("keyword_blank_description"); ThrowUserError("keyword_blank_description");
} }
# It is safe to detaint these values as they are only
# used in placeholders.
trick_taint($name);
$_[0] = $name;
trick_taint($description);
$_[1] = $description;
} }
@ -55,7 +62,7 @@ sub Validate {
Bugzilla->login(LOGIN_REQUIRED); Bugzilla->login(LOGIN_REQUIRED);
print Bugzilla->cgi->header(); print $cgi->header();
UserInGroup("editkeywords") UserInGroup("editkeywords")
|| ThrowUserError("auth_failure", {group => "editkeywords", || ThrowUserError("auth_failure", {group => "editkeywords",
@ -69,29 +76,18 @@ $vars->{'action'} = $action;
if ($action eq "") { if ($action eq "") {
my @keywords; my @keywords;
SendSQL("SELECT keyworddefs.id, keyworddefs.name, keyworddefs.description, $vars->{'keywords'} =
COUNT(keywords.bug_id) $dbh->selectall_arrayref('SELECT keyworddefs.id, keyworddefs.name,
FROM keyworddefs LEFT JOIN keywords keyworddefs.description,
ON keyworddefs.id = keywords.keywordid " . COUNT(keywords.bug_id) AS bug_count
$dbh->sql_group_by('keyworddefs.id', FROM keyworddefs
'keyworddefs.name, keyworddefs.description') . " LEFT JOIN keywords
ORDER BY keyworddefs.name"); ON keyworddefs.id = keywords.keywordid ' .
$dbh->sql_group_by('id', 'name, description') . '
ORDER BY keyworddefs.name', {'Slice' => {}});
while (MoreSQLData()) { print $cgi->header();
my ($id, $name, $description, $bugs) = FetchSQLData(); $template->process("admin/keywords/list.html.tmpl", $vars)
my $keyword = {};
$keyword->{'id'} = $id;
$keyword->{'name'} = $name;
$keyword->{'description'} = $description;
$keyword->{'bug_count'} = $bugs;
push(@keywords, $keyword);
}
print Bugzilla->cgi->header();
$vars->{'keywords'} = \@keywords;
$template->process("admin/keywords/list.html.tmpl",
$vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
@ -99,10 +95,9 @@ if ($action eq "") {
if ($action eq 'add') { if ($action eq 'add') {
print Bugzilla->cgi->header(); print $cgi->header();
$template->process("admin/keywords/create.html.tmpl", $template->process("admin/keywords/create.html.tmpl", $vars)
$vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
@ -119,10 +114,11 @@ if ($action eq 'new') {
my $description = trim($cgi->param('description') || ''); my $description = trim($cgi->param('description') || '');
Validate($name, $description); Validate($name, $description);
SendSQL("SELECT id FROM keyworddefs WHERE name = " . SqlQuote($name));
if (FetchOneColumn()) { my $id = $dbh->selectrow_array('SELECT id FROM keyworddefs
WHERE name = ?', undef, $name);
if ($id) {
$vars->{'name'} = $name; $vars->{'name'} = $name;
ThrowUserError("keyword_already_exists"); ThrowUserError("keyword_already_exists");
} }
@ -133,12 +129,12 @@ if ($action eq 'new') {
# rarely enough, and there really aren't ever going to be that many # rarely enough, and there really aren't ever going to be that many
# keywords anyway. # keywords anyway.
SendSQL("SELECT id FROM keyworddefs ORDER BY id"); my $existing_ids =
$dbh->selectcol_arrayref('SELECT id FROM keyworddefs ORDER BY id');
my $newid = 1; my $newid = 1;
while (MoreSQLData()) { foreach my $oldid (@$existing_ids) {
my $oldid = FetchOneColumn();
if ($oldid > $newid) { if ($oldid > $newid) {
last; last;
} }
@ -146,18 +142,17 @@ if ($action eq 'new') {
} }
# Add the new keyword. # Add the new keyword.
SendSQL("INSERT INTO keyworddefs (id, name, description) VALUES ($newid, " . $dbh->do('INSERT INTO keyworddefs
SqlQuote($name) . "," . (id, name, description) VALUES (?, ?, ?)',
SqlQuote($description) . ")"); undef, ($newid, $name, $description));
# Make versioncache flush # Make versioncache flush
unlink "$datadir/versioncache"; unlink "$datadir/versioncache";
print Bugzilla->cgi->header(); print $cgi->header();
$vars->{'name'} = $name; $vars->{'name'} = $name;
$template->process("admin/keywords/created.html.tmpl", $template->process("admin/keywords/created.html.tmpl", $vars)
$vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
@ -176,30 +171,27 @@ if ($action eq 'edit') {
detaint_natural($id); detaint_natural($id);
# get data of keyword # get data of keyword
SendSQL("SELECT name,description my ($name, $description) =
FROM keyworddefs $dbh->selectrow_array('SELECT name, description FROM keyworddefs
WHERE id=$id"); WHERE id = ?', undef, $id);
my ($name, $description) = FetchSQLData();
if (!$name) { if (!$name) {
$vars->{'id'} = $id; $vars->{'id'} = $id;
ThrowCodeError("invalid_keyword_id", $vars); ThrowCodeError("invalid_keyword_id", $vars);
} }
SendSQL("SELECT count(*) my $bugs = $dbh->selectrow_array('SELECT COUNT(*) FROM keywords
FROM keywords WHERE keywordid = ?',
WHERE keywordid = $id"); undef, $id);
my $bugs = '';
$bugs = FetchOneColumn() if MoreSQLData();
$vars->{'keyword_id'} = $id; $vars->{'keyword_id'} = $id;
$vars->{'name'} = $name; $vars->{'name'} = $name;
$vars->{'description'} = $description; $vars->{'description'} = $description;
$vars->{'bug_count'} = $bugs; $vars->{'bug_count'} = $bugs;
print Bugzilla->cgi->header(); print $cgi->header();
$template->process("admin/keywords/edit.html.tmpl", $template->process("admin/keywords/edit.html.tmpl", $vars)
$vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
@ -219,27 +211,24 @@ if ($action eq 'update') {
Validate($name, $description); Validate($name, $description);
SendSQL("SELECT id FROM keyworddefs WHERE name = " . SqlQuote($name)); my $tmp = $dbh->selectrow_array('SELECT id FROM keyworddefs
WHERE name = ?', undef, $name);
my $tmp = FetchOneColumn();
if ($tmp && $tmp != $id) { if ($tmp && $tmp != $id) {
$vars->{'name'} = $name; $vars->{'name'} = $name;
ThrowUserError("keyword_already_exists", $vars); ThrowUserError("keyword_already_exists", $vars);
} }
SendSQL("UPDATE keyworddefs SET name = " . SqlQuote($name) . $dbh->do('UPDATE keyworddefs SET name = ?, description = ?
", description = " . SqlQuote($description) . WHERE id = ?', undef, ($name, $description, $id));
" WHERE id = $id");
# Make versioncache flush # Make versioncache flush
unlink "$datadir/versioncache"; unlink "$datadir/versioncache";
print Bugzilla->cgi->header(); print $cgi->header();
$vars->{'name'} = $name; $vars->{'name'} = $name;
$template->process("admin/keywords/rebuild-cache.html.tmpl", $template->process("admin/keywords/rebuild-cache.html.tmpl", $vars)
$vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
@ -250,42 +239,38 @@ if ($action eq 'delete') {
my $id = $cgi->param('id'); my $id = $cgi->param('id');
detaint_natural($id); detaint_natural($id);
SendSQL("SELECT name FROM keyworddefs WHERE id=$id"); my $name = $dbh->selectrow_array('SELECT name FROM keyworddefs
my $name = FetchOneColumn(); WHERE id= ?', undef, $id);
if (!$cgi->param('reallydelete')) { if (!$cgi->param('reallydelete')) {
SendSQL("SELECT count(*) my $bugs = $dbh->selectrow_array('SELECT COUNT(*) FROM keywords
FROM keywords WHERE keywordid = ?',
WHERE keywordid = $id"); undef, $id);
my $bugs = FetchOneColumn();
if ($bugs) { if ($bugs) {
$vars->{'bug_count'} = $bugs; $vars->{'bug_count'} = $bugs;
$vars->{'keyword_id'} = $id; $vars->{'keyword_id'} = $id;
$vars->{'name'} = $name; $vars->{'name'} = $name;
print Bugzilla->cgi->header(); print $cgi->header();
$template->process("admin/keywords/confirm-delete.html.tmpl", $template->process("admin/keywords/confirm-delete.html.tmpl", $vars)
$vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} }
} }
SendSQL("DELETE FROM keywords WHERE keywordid = $id"); $dbh->do('DELETE FROM keywords WHERE keywordid = ?', undef, $id);
SendSQL("DELETE FROM keyworddefs WHERE id = $id"); $dbh->do('DELETE FROM keyworddefs WHERE id = ?', undef, $id);
# Make versioncache flush # Make versioncache flush
unlink "$datadir/versioncache"; unlink "$datadir/versioncache";
print Bugzilla->cgi->header(); print $cgi->header();
$vars->{'name'} = $name; $vars->{'name'} = $name;
$template->process("admin/keywords/rebuild-cache.html.tmpl", $template->process("admin/keywords/rebuild-cache.html.tmpl", $vars)
$vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;