]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 339382: Make Bugzilla::Field use Bugzilla::Object
authormkanat%bugzilla.org <>
Wed, 26 Jul 2006 06:20:01 +0000 (06:20 +0000)
committermkanat%bugzilla.org <>
Wed, 26 Jul 2006 06:20:01 +0000 (06:20 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=LpSolit, a=myk

Bugzilla.pm
Bugzilla/Bug.pm
Bugzilla/BugMail.pm
Bugzilla/DB/Schema.pm
Bugzilla/Field.pm
Bugzilla/Search.pm
checksetup.pl
collectstats.pl
customfield.pl
editusers.cgi
sanitycheck.cgi

index c1503592861ee7d1bf0341f630b2805677e2c802..0ffa1d1b9fecc7e587dd9f6897af43a0b88d0196 100644 (file)
@@ -302,12 +302,13 @@ sub switch_to_main_db {
 sub get_fields {
     my $class = shift;
     my $criteria = shift;
-    return Bugzilla::Field::match($criteria);
+    return @{Bugzilla::Field->match($criteria)};
 }
 
 sub custom_field_names {
     # Get a list of custom fields and convert it into a list of their names.
-    return map($_->{name}, Bugzilla::Field::match({ custom=>1, obsolete=>0 }));
+    return map($_->{name}, 
+               @{Bugzilla::Field->match({ custom=>1, obsolete=>0 })});
 }
 
 sub request_cache {
index 64da19af493a36e7065d47d9f1fa1aeab4691701..ba69932e90d9b9ed84b51b7f39dd1ae36488f433 100755 (executable)
@@ -876,7 +876,7 @@ sub GetBugActivity {
           FROM bugs_activity
                $suppjoins
      LEFT JOIN fielddefs
-            ON bugs_activity.fieldid = fielddefs.fieldid
+            ON bugs_activity.fieldid = fielddefs.id
     INNER JOIN profiles
             ON profiles.userid = bugs_activity.who
          WHERE bugs_activity.bug_id = ?
index 3597b3f4653aa26f1f1a9f7dd3af6c2fe0786fc8..1b2fb5429cc9fea5b78afbe19e12b4c60331c729 100644 (file)
@@ -224,7 +224,7 @@ sub ProcessOneBug {
                    bugs_activity.added, bugs_activity.attach_id, fielddefs.name
               FROM bugs_activity
         INNER JOIN fielddefs
-                ON fielddefs.fieldid = bugs_activity.fieldid
+                ON fielddefs.id = bugs_activity.fieldid
         INNER JOIN profiles
                 ON profiles.userid = bugs_activity.who
              WHERE bugs_activity.bug_id = ?
@@ -277,7 +277,7 @@ sub ProcessOneBug {
         INNER JOIN dependencies
                 ON bugs_activity.bug_id = dependencies.dependson
         INNER JOIN fielddefs
-                ON fielddefs.fieldid = bugs_activity.fieldid
+                ON fielddefs.id = bugs_activity.fieldid
              WHERE dependencies.blocked = ?
                AND (fielddefs.name = 'bug_status'
                     OR fielddefs.name = 'resolution')
index 94e457dd0906d727c593f627652d2cf118ce6b0d..5396a3d20a2da219b2e928c51c78356a996e7347 100644 (file)
@@ -451,7 +451,7 @@ use constant ABSTRACT_SCHEMA => {
 
     fielddefs => {
         FIELDS => [
-            fieldid     => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1,
+            id          => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1,
                             PRIMARYKEY => 1},
             name        => {TYPE => 'varchar(64)', NOTNULL => 1},
             type        => {TYPE => 'INT2', NOTNULL => 1,
index e964141d48b978d6e3686b004a7674264973dd9b..e870ec01d6907bcaa2d073f69e1d0b42ea9974cd 100644 (file)
@@ -38,18 +38,18 @@ Bugzilla::Field - a particular piece of information about bugs
   use Bugzilla::Field;
 
   # Display information about non-obsolete custom fields.
-  # Bugzilla->get_fields() is a wrapper around Bugzilla::Field::match(),
+  # Bugzilla->get_fields() is a wrapper around Bugzilla::Field->match(),
   # so both methods take the same arguments.
-  print Dumper(Bugzilla::Field::match({ obsolete => 1, custom => 1 }));
+  print Dumper(Bugzilla::Field->match({ obsolete => 1, custom => 1 }));
 
   # Create a custom field.
   my $field = Bugzilla::Field::create("hilarity", "Hilarity");
-  print "$field->{description} is a custom field\n";
+  print $field->description . " is a custom field\n";
 
   # Instantiate a Field object for an existing field.
-  my $field = new Bugzilla::Field('qacontact_accessible');
-  if ($field->{obsolete}) {
-      print "$field->{description} is obsolete\n";
+  my $field = new Bugzilla::Field({name => 'qacontact_accessible'});
+  if ($field->obsolete) {
+      print $field->description . " is obsolete\n";
   }
 
   # Validation Routines
@@ -63,21 +63,28 @@ of information that Bugzilla stores about bugs.
 
 This package also provides functions for dealing with CGI form fields.
 
+C<Bugzilla::Field> is an implementation of L<Bugzilla::Object>, and
+so provides all of the methods available in L<Bugzilla::Object>,
+in addition to what is documented here.
+
 =cut
 
 package Bugzilla::Field;
 
 use strict;
 
-use base qw(Exporter);
+use base qw(Exporter Bugzilla::Object);
 @Bugzilla::Field::EXPORT = qw(check_field get_field_id get_legal_field_values);
 
 use Bugzilla::Util;
 use Bugzilla::Constants;
 use Bugzilla::Error;
 
+use constant DB_TABLE   => 'fielddefs';
+use constant LIST_ORDER => 'sortkey, name';
+
 use constant DB_COLUMNS => (
-    'fieldid AS id',
+    'id',
     'name',
     'description',
     'type',
@@ -86,52 +93,18 @@ use constant DB_COLUMNS => (
     'enter_bug',
 );
 
-our $columns = join(", ", DB_COLUMNS);
-
-sub new {
-    my $invocant = shift;
-    my $name = shift;
-    my $self = shift || Bugzilla->dbh->selectrow_hashref(
-                            "SELECT $columns FROM fielddefs WHERE name = ?",
-                            undef,
-                            $name
-                        );
-    bless($self, $invocant);
-    return $self;
-}
-
 =pod
 
 =head2 Instance Properties
 
 =over
 
-=item C<id>
-
-the unique identifier for the field;
-
-=back
-
-=cut
-
-sub id { return $_[0]->{id} }
-
-=over
-
 =item C<name>
 
 the name of the field in the database; begins with "cf_" if field
 is a custom field, but test the value of the boolean "custom" property
 to determine if a given field is a custom field;
 
-=back
-
-=cut
-
-sub name { return $_[0]->{name} }
-
-=over
-
 =item C<description>
 
 a short string describing the field; displayed to Bugzilla users
@@ -242,7 +215,7 @@ sub create {
               );
     $sth->execute($name, $desc, $sortkey, $type, $custom);
 
-    return new Bugzilla::Field($name);
+    return new Bugzilla::Field({name => $name});
 }
 
 
@@ -262,14 +235,14 @@ Params:    C<$criteria> - hash reference - the criteria to match against.
            Note: Bugzilla->get_fields() and Bugzilla->custom_field_names
            wrap this method for most callers.
 
-Returns:   a list of field objects.
+Returns:   A reference to an array of C<Bugzilla::Field> objects.
 
 =back
 
 =cut
 
 sub match {
-    my ($criteria) = @_;
+    my ($class, $criteria) = @_;
   
     my @terms;
     if (defined $criteria->{name}) {
@@ -286,13 +259,10 @@ sub match {
     }
     my $where = (scalar(@terms) > 0) ? "WHERE " . join(" AND ", @terms) : "";
   
-    my $records = Bugzilla->dbh->selectall_arrayref(
-                      "SELECT $columns FROM fielddefs $where ORDER BY sortkey",
-                      { Slice => {}}
-                  );
-    # Generate a array of field objects from the array of field records.
-    my @fields = map( new Bugzilla::Field(undef, $_), @$records );
-    return @fields;
+    my $ids = Bugzilla->dbh->selectcol_arrayref(
+        "SELECT id FROM fielddefs $where", {Slice => {}});
+
+    return $class->new_from_list($ids);
 }
 
 =pod
@@ -371,7 +341,7 @@ sub check_field {
         return 0 if $no_warn; # We don't want an error to be thrown; return.
         trick_taint($name);
 
-        my $field = new Bugzilla::Field($name);
+        my $field = new Bugzilla::Field({ name => $name });
         my $field_desc = $field ? $field->description : $name;
         ThrowCodeError('illegal_field', { field => $field_desc });
     }
@@ -401,7 +371,7 @@ sub get_field_id {
     my $dbh = Bugzilla->dbh;
 
     trick_taint($name);
-    my $id = $dbh->selectrow_array('SELECT fieldid FROM fielddefs
+    my $id = $dbh->selectrow_array('SELECT id FROM fielddefs
                                     WHERE name = ?', undef, $name);
 
     ThrowCodeError('invalid_field_name', {field => $name}) unless $id;
index bdf764f368ad5d6fa235dee7f180e7945c09a64a..673deaa3044815bdd842637bc9578481a2cb60aa 100644 (file)
@@ -1276,7 +1276,7 @@ sub init {
 
     # get a list of field names to verify the user-submitted chart fields against
     %chartfields = @{$dbh->selectcol_arrayref(
-        q{SELECT name, fieldid FROM fielddefs}, { Columns=>[1,2] })};
+        q{SELECT name, id FROM fielddefs}, { Columns=>[1,2] })};
 
     $row = 0;
     for ($chart=-1 ;
index bb6e4624592c2a2a10929c9c37d4215c3d4d10a6..5c2d889f4af7c41f866677b698253de57fc41ad5 100755 (executable)
@@ -1627,7 +1627,7 @@ my $headernum = 1;
 sub AddFDef {
     my ($name, $description, $mailhead) = (@_);
 
-    my $sth = $dbh->prepare("SELECT fieldid FROM fielddefs " .
+    my $sth = $dbh->prepare("SELECT id FROM fielddefs " .
                             "WHERE name = ?");
     $sth->execute($name);
     my ($fieldid) = ($sth->fetchrow_array());
@@ -1640,12 +1640,16 @@ sub AddFDef {
         $dbh->do(q{UPDATE fielddefs
                       SET name = ?, description = ?,
                           mailhead = ?, sortkey = ?
-                    WHERE fieldid = ?}, undef,
+                    WHERE id = ?}, undef,
                  $name, $description, $mailhead, $headernum, $fieldid);
     }
     $headernum++;
 }
 
+# Change the name of the fieldid column to id, so that fielddefs
+# can use Bugzilla::Object easily. We have to do this up here, because
+# otherwise adding these field definitions will fail.
+$dbh->bz_rename_column('fielddefs', 'fieldid', 'id');
 
 # Note that all of these entries are unconditional, from when get_field_id
 # used to create an entry if it wasn't found. New fielddef columns should
@@ -1718,7 +1722,7 @@ my $new_field_name = 'days_elapsed';
 my $field_description = 'Days since bug changed';
 
 my ($old_field_id, $old_field_name) =
-    $dbh->selectrow_array('SELECT fieldid, name
+    $dbh->selectrow_array('SELECT id, name
                            FROM fielddefs
                            WHERE description = ?',
                            undef, $field_description);
@@ -1765,7 +1769,7 @@ if ($old_field_id && ($old_field_name ne $new_field_name)) {
     # Now that saved searches have been fixed, we can fix the field name.
     print "Fixing the 'fielddefs' table...\n";
     print "New field name: " . $new_field_name . "\n";
-    $dbh->do('UPDATE fielddefs SET name = ? WHERE fieldid = ?',
+    $dbh->do('UPDATE fielddefs SET name = ? WHERE id = ?',
               undef, ($new_field_name, $old_field_id));
 }
 AddFDef($new_field_name, $field_description, 0);
@@ -2107,13 +2111,13 @@ if ($dbh->bz_column_info('bugs_activity', 'field')) {
     while (my ($f) = ($sth->fetchrow_array())) {
         my $q = $dbh->quote($f);
         my $s2 =
-            $dbh->prepare("SELECT fieldid FROM fielddefs WHERE name = $q");
+            $dbh->prepare("SELECT id FROM fielddefs WHERE name = $q");
         $s2->execute();
         my ($id) = ($s2->fetchrow_array());
         if (!$id) {
             $dbh->do("INSERT INTO fielddefs (name, description) VALUES " .
                      "($q, $q)");
-            $id = $dbh->bz_last_key('fielddefs', 'fieldid');
+            $id = $dbh->bz_last_key('fielddefs', 'id');
         }
         $dbh->do("UPDATE bugs_activity SET fieldid = $id WHERE field = $q");
     }
@@ -2546,10 +2550,10 @@ if ($dbh->bz_column_info('bugs_activity', 'oldvalue')) {
     $dbh->bz_add_column("bugs_activity", "removed", {TYPE => "TINYTEXT"});
     $dbh->bz_add_column("bugs_activity", "added", {TYPE => "TINYTEXT"});
 
-    # Need to get fieldid's for the fields that have multiple values
+    # Need to get field id's for the fields that have multiple values
     my @multi = ();
     foreach my $f ("cc", "dependson", "blocked", "keywords") {
-        my $sth = $dbh->prepare("SELECT fieldid " .
+        my $sth = $dbh->prepare("SELECT id " .
                                 "FROM fielddefs " .
                                 "WHERE name = '$f'");
         $sth->execute();
@@ -2960,13 +2964,13 @@ if ($dbh->bz_column_info("profiles", "groupset")) {
     # Replace old activity log groupset records with lists of names of groups.
     # Start by defining the bug_group field and getting its id.
     AddFDef("bug_group", "Group", 0);
-    $sth = $dbh->prepare("SELECT fieldid " .
+    $sth = $dbh->prepare("SELECT id " .
                            "FROM fielddefs " .
                           "WHERE name = " . $dbh->quote('bug_group'));
     $sth->execute();
     my ($bgfid) = $sth->fetchrow_array;
     # Get the field id for the old groupset field
-    $sth = $dbh->prepare("SELECT fieldid " .
+    $sth = $dbh->prepare("SELECT id " .
                            "FROM fielddefs " .
                           "WHERE name = " . $dbh->quote('groupset'));
     $sth->execute();
@@ -3108,10 +3112,10 @@ if ($dbh->bz_table_info("attachstatuses")
     
     # Get IDs for the old attachment status and new flag fields.
     my ($old_field_id) = $dbh->selectrow_array(
-        "SELECT fieldid FROM fielddefs WHERE name='attachstatusdefs.name'")
+        "SELECT id FROM fielddefs WHERE name='attachstatusdefs.name'")
         || 0;
     
-    $sth = $dbh->prepare("SELECT fieldid FROM fielddefs " . 
+    $sth = $dbh->prepare("SELECT id FROM fielddefs " . 
                          "WHERE name='flagtypes.name'");
     $sth->execute();
     my $new_field_id = $sth->fetchrow_arrayref()->[0];
index 808badea9562616835eda6bc1aa6f6bc3114846f..1672f679acbf3145dac3a85b07897fc727a21a8f 100755 (executable)
@@ -79,7 +79,7 @@ my $old_resolutions =
     $dbh->selectcol_arrayref('SELECT bugs_activity.added
                                 FROM bugs_activity
                           INNER JOIN fielddefs
-                                  ON fielddefs.fieldid = bugs_activity.fieldid
+                                  ON fielddefs.id = bugs_activity.fieldid
                            LEFT JOIN resolution
                                   ON resolution.value = bugs_activity.added
                                WHERE fielddefs.name = ?
@@ -90,7 +90,7 @@ my $old_resolutions =
                               SELECT bugs_activity.removed
                                 FROM bugs_activity
                           INNER JOIN fielddefs
-                                  ON fielddefs.fieldid = bugs_activity.fieldid
+                                  ON fielddefs.id = bugs_activity.fieldid
                            LEFT JOIN resolution
                                   ON resolution.value = bugs_activity.removed
                                WHERE fielddefs.name = ?
@@ -449,7 +449,7 @@ FIN
             $query = qq{SELECT bugs_activity.removed 
                           FROM bugs_activity 
                     INNER JOIN fielddefs 
-                            ON bugs_activity.fieldid = fielddefs.fieldid 
+                            ON bugs_activity.fieldid = fielddefs.id 
                          WHERE fielddefs.name = ? 
                            AND bugs_activity.bug_id = ? 
                            AND bugs_activity.bug_when >= } . 
index 2821425c7ece5bc0fc6e0a461ca86cc95549f30d..033ac517a1886990880acbf63e93a096a549dffc 100755 (executable)
@@ -75,7 +75,7 @@ $name =~ /^cf_/
   or $name = "cf_" . $name;
 
 # Exit gracefully if there is already a field with the given name.
-if (scalar(Bugzilla::Field::match({ name=>$name })) > 0) {
+if ( new Bugzilla::Field({name => $name}) ) {
     print "There is already a field named $name.  Please choose " .
           "a different name.\n";
     exit;
index 9a4bfd5c0d1cbf7e4eb8bfa6c3a71cf84a9bf703..4d72923919c7c9091d6ff3f31c55259d4a92e0bb 100755 (executable)
@@ -755,7 +755,7 @@ if ($action eq 'search') {
                 profiles_activity.newvalue AS added
          FROM profiles_activity
          INNER JOIN profiles ON profiles_activity.who = profiles.userid
-         INNER JOIN fielddefs ON fielddefs.fieldid = profiles_activity.fieldid
+         INNER JOIN fielddefs ON fielddefs.id = profiles_activity.fieldid
          WHERE profiles_activity.userid = ?
          ORDER BY profiles_activity.profiles_when",
         {'Slice' => {}},
index aeeee5ea93e6dfa5939d981c03b78f7a9cc28165..85b6f5fa2d12932071d3f4c67ae1d1e67dae599b 100755 (executable)
@@ -391,7 +391,7 @@ CrossCheck('classifications', 'id',
 CrossCheck("keyworddefs", "id",
            ["keywords", "keywordid"]);
 
-CrossCheck("fielddefs", "fieldid",
+CrossCheck("fielddefs", "id",
            ["bugs_activity", "fieldid"],
            ['profiles_activity', 'fieldid']);