summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Field.pm
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2005-09-06 05:41:20 +0200
committerlpsolit%gmail.com <>2005-09-06 05:41:20 +0200
commit3223b9f1872063b0c1ba864880449e40c68d590d (patch)
tree53446ca60ec5aafe33236b979f24a8d57dc009a7 /Bugzilla/Field.pm
parentd14f5d4e1330aa4efee97b7b83381619980a6819 (diff)
downloadbugzilla-3223b9f1872063b0c1ba864880449e40c68d590d.tar.gz
bugzilla-3223b9f1872063b0c1ba864880449e40c68d590d.tar.xz
Bug 304745: Move GetFieldID() out of globals.pl - Patch by Frédéric Buclin <LpSolit@gmail.com> r=wicked a=justdave
Diffstat (limited to 'Bugzilla/Field.pm')
-rw-r--r--Bugzilla/Field.pm31
1 files changed, 29 insertions, 2 deletions
diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm
index 26265ac3d..09c4731ac 100644
--- a/Bugzilla/Field.pm
+++ b/Bugzilla/Field.pm
@@ -20,7 +20,8 @@ package Bugzilla::Field;
use strict;
use base qw(Exporter);
-@Bugzilla::Field::EXPORT = qw(check_form_field check_form_field_defined);
+@Bugzilla::Field::EXPORT = qw(check_form_field check_form_field_defined
+ get_field_id);
use Bugzilla::Util;
use Bugzilla::Error;
@@ -52,6 +53,22 @@ sub check_form_field_defined {
}
}
+sub get_field_id {
+ my ($name) = @_;
+ my $dbh = Bugzilla->dbh;
+
+ trick_taint($name);
+ my $id = $dbh->selectrow_array('SELECT fieldid FROM fielddefs
+ WHERE name = ?', undef, $name);
+
+ ThrowCodeError('invalid_field_name', {field => $name}) unless $id;
+ return $id
+}
+
+1;
+
+__END__
+
=head1 NAME
Bugzilla::Field - Useful routines for fields manipulation
@@ -63,7 +80,7 @@ Bugzilla::Field - Useful routines for fields manipulation
# Validation Routines
check_form_field($cgi, $fieldname, \@legal_values);
check_form_field_defined($cgi, $fieldname);
-
+ $fieldid = get_field_id($fieldname);
=head1 DESCRIPTION
@@ -101,4 +118,14 @@ Params: $cgi - a CGI object
Returns: nothing
+=item C<get_field_id($fieldname)>
+
+Description: Returns the ID of the specified field name and throws
+ an error if this field does not exist.
+
+Params: $fieldname - a field name
+
+Returns: the corresponding field ID or an error if the field name
+ does not exist.
+
=back