]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 338793: Remove DBID_to_name() from globals.pl - Patch by Frédéric Buclin <LpSolit...
authorlpsolit%gmail.com <>
Tue, 20 Jun 2006 00:30:23 +0000 (00:30 +0000)
committerlpsolit%gmail.com <>
Tue, 20 Jun 2006 00:30:23 +0000 (00:30 +0000)
Bugzilla/BugMail.pm
Bugzilla/User.pm
contrib/bug_email.pl
editproducts.cgi
globals.pl
process_bug.cgi

index af0bf9027424bbc63f2dd2b5bd528aa2a9ac6cf4..2c6f6af3e3a7388450a8fdda815a664f5d2af069 100644 (file)
@@ -186,10 +186,10 @@ sub ProcessOneBug {
     # Convert to names, for later display
     $values{'changer'} = $changer;
     $values{'changername'} = Bugzilla::User->new_from_login($changer)->name;
-    $values{'assigned_to'} = &::DBID_to_name($values{'assigned_to'});
-    $values{'reporter'} = &::DBID_to_name($values{'reporter'});
+    $values{'assigned_to'} = user_id_to_login($values{'assigned_to'});
+    $values{'reporter'} = user_id_to_login($values{'reporter'});
     if ($values{'qa_contact'}) {
-        $values{'qa_contact'} = &::DBID_to_name($values{'qa_contact'});
+        $values{'qa_contact'} = user_id_to_login($values{'qa_contact'});
     }
     $values{'cc'} = join(', ', @cc_login_names);
     $values{'estimated_time'} = format_time_decimal($values{'estimated_time'});
@@ -635,7 +635,7 @@ sub sendMail {
     }
     push @headerrel, 'None' if !scalar(@headerrel);
     push @watchingrel, 'None' if !scalar(@watchingrel);
-    push @watchingrel, map { &::DBID_to_name($_) } @$watchingRef;
+    push @watchingrel, map { user_id_to_login($_) } @$watchingRef;
     $substs{"reasonsheader"} = join(" ", @headerrel);
     $substs{"reasonswatchheader"} = join(" ", @watchingrel);
 
index 7bafd688a1f4312723fd4276dd4235f471f60fda..c26f64332f5f94d1d950ef75662d3da63c7650c2 100644 (file)
@@ -51,7 +51,7 @@ use Bugzilla::Field;
 
 use base qw(Exporter);
 @Bugzilla::User::EXPORT = qw(insert_new_user is_available_username
-    login_to_id validate_password
+    login_to_id user_id_to_login validate_password
     UserInGroup
     USER_MATCH_MULTIPLE USER_MATCH_FAILED USER_MATCH_SUCCESS
     MATCH_SKIP_CONFIRM
@@ -1416,6 +1416,17 @@ sub login_to_id {
     }
 }
 
+sub user_id_to_login {
+    my $user_id = shift;
+    my $dbh = Bugzilla->dbh;
+
+    return '' unless ($user_id && detaint_natural($user_id));
+
+    my $login = $dbh->selectrow_array('SELECT login_name FROM profiles
+                                       WHERE userid = ?', undef, $user_id);
+    return $login || '';
+}
+
 sub validate_password {
     my ($password, $matchpassword) = @_;
 
@@ -1841,6 +1852,12 @@ of a user, but you don't want the full weight of Bugzilla::User.
 However, consider using a Bugzilla::User object instead of this function
 if you need more information about the user than just their ID.
 
+=item C<user_id_to_login($user_id)>
+
+Returns the login name of the user account for the given user ID. If no
+valid user ID is given or the user has no entry in the profiles table,
+we return an empty string.
+
 =item C<validate_password($passwd1, $passwd2)>
 
 Returns true if a password is valid (i.e. meets Bugzilla's
index 66a87d038886d8884b5c9fb6e07ba5e4f398da77..546c08dc562e94853112106f10322ad85aabf436 100755 (executable)
@@ -38,7 +38,7 @@
 #
 # You need to work with bug_email.pl the MIME::Parser installed.
 # 
-# $Id: bug_email.pl,v 1.40 2006/06/19 16:25:02 vladd%bugzilla.org Exp $
+# $Id: bug_email.pl,v 1.41 2006/06/19 17:30:24 lpsolit%gmail.com Exp $
 ###############################################################
 
 # 02/12/2000 (SML)
@@ -1081,7 +1081,7 @@ END
         
         $val = $Control{ $field };
       
-        $val = DBID_to_name( $val ) if( $field =~ /reporter|assigned_to|qa_contact/ );
+        $val = user_id_to_login( $val ) if( $field =~ /reporter|assigned_to|qa_contact/ );
       
         $tmp_reply .= sprintf( "     \@%-15s = %-15s\n", $field, $val );
 
index ea7430755583b7c7db659eccfe3c8792b98e53c4..b21ceb8fd8a7bae91c879700e3f4c50153750afb 100755 (executable)
@@ -44,6 +44,7 @@ use Bugzilla::Product;
 use Bugzilla::Classification;
 use Bugzilla::Milestone;
 use Bugzilla::Group;
+use Bugzilla::User;
 
 # Shut up misguided -w warnings about "used only once".  "use vars" just
 # doesn't work for me.
@@ -907,7 +908,7 @@ if ($action eq 'update') {
                 foreach my $msg (@$msgs) {
                     MessageToMTA($msg);
                 }
-                my $name = DBID_to_name($who);
+                my $name = user_id_to_login($who);
 
                 push(@toomanyvotes_list,
                      {id => $id, name => $name});
@@ -960,7 +961,7 @@ if ($action eq 'update') {
                     foreach my $msg (@$msgs) {
                         MessageToMTA($msg);
                     }
-                    my $name = DBID_to_name($who);
+                    my $name = user_id_to_login($who);
 
                     push(@toomanytotalvotes_list,
                          {id => $bug_id, name => $name});
index b4c71a28e788fc1dc133cc44abc6a75e501dcbd2..a1e87eec25eee6618a3eb914e4515d3e2ec43a10 100644 (file)
@@ -138,28 +138,6 @@ sub GetVersionTable {
     $::VersionTableLoaded = 1;
 }
 
-sub DBID_to_name {
-    my ($id) = (@_);
-    return "__UNKNOWN__" if !defined $id;
-    # $id should always be a positive integer
-    if ($id =~ m/^([1-9][0-9]*)$/) {
-        $id = $1;
-    } else {
-        $::cachedNameArray{$id} = "__UNKNOWN__";
-    }
-    if (!defined $::cachedNameArray{$id}) {
-        PushGlobalSQLState();
-        SendSQL("SELECT login_name FROM profiles WHERE userid = $id");
-        my $r = FetchOneColumn();
-        PopGlobalSQLState();
-        if (!defined $r || $r eq "") {
-            $r = "__UNKNOWN__";
-        }
-        $::cachedNameArray{$id} = $r;
-    }
-    return $::cachedNameArray{$id};
-}
-
 # Returns a list of all the legal values for a field that has a
 # list of legal values, like rep_platform or resolution.
 sub get_legal_field_values {
index 3541650f343e0d78a3d63ed65ebc07de2aa86c94..ca72015a2789938b7be9e2302ac15afe2bc23bd4 100755 (executable)
@@ -1587,8 +1587,8 @@ foreach my $id (@idlist) {
                 $vars->{'field'} = 'component';
             } elsif ($col eq 'assigned_to' || $col eq 'qa_contact') {
                 # Display the assignee or QA contact email address
-                $vars->{'oldvalue'} = DBID_to_name($oldhash{$col});
-                $vars->{'newvalue'} = DBID_to_name($formhash{$col});
+                $vars->{'oldvalue'} = user_id_to_login($oldhash{$col});
+                $vars->{'newvalue'} = user_id_to_login($formhash{$col});
                 $vars->{'field'} = $col;
             } else {
                 $vars->{'oldvalue'} = $oldhash{$col};
@@ -2085,16 +2085,16 @@ foreach my $id (@idlist) {
             # the old assignee can be notified
             #
             if ($col eq 'assigned_to') {
-                $old = ($old) ? DBID_to_name($old) : "";
-                $new = ($new) ? DBID_to_name($new) : "";
+                $old = ($old) ? user_id_to_login($old) : "";
+                $new = ($new) ? user_id_to_login($new) : "";
                 $origOwner = $old;
             }
 
             # ditto for the old qa contact
             #
             if ($col eq 'qa_contact') {
-                $old = ($old) ? DBID_to_name($old) : "";
-                $new = ($new) ? DBID_to_name($new) : "";
+                $old = ($old) ? user_id_to_login($old) : "";
+                $new = ($new) ? user_id_to_login($new) : "";
                 $origQaContact = $old;
             }
 
@@ -2154,7 +2154,7 @@ foreach my $id (@idlist) {
                 || !$cgi->param('confirm_add_duplicate')) {
             # The reporter is oblivious to the existence of the new bug and is permitted access
             # ... add 'em to the cc (and record activity)
-            LogActivityEntry($duplicate,"cc","",DBID_to_name($reporter),
+            LogActivityEntry($duplicate,"cc","",user_id_to_login($reporter),
                              $whoid,$timestamp);
             $dbh->do(q{INSERT INTO cc (who, bug_id) VALUES (?, ?)},
                      undef, $reporter, $duplicate);