#! /bin/sh /usr/share/dpatch/dpatch-run
## 05_Bugzilla_User.pm.dpatch by Alexis Sukrieh <sukria@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Provide the sub `update_user()' for updating an existing user in the database.

@DPATCH@
diff -urNad bugzilla-2.22~/Bugzilla/User.pm bugzilla-2.22/Bugzilla/User.pm
--- bugzilla-2.22~/Bugzilla/User.pm	2006-10-04 08:12:54.000000000 +0200
+++ bugzilla-2.22/Bugzilla/User.pm	2006-10-04 08:15:38.000000000 +0200
@@ -154,6 +154,48 @@
     return $self;
 }
 
+# Debian patch for updating an existing user in the database.
+sub update_user ($$$;$$) {
+    my ($userid, $username, $realname, $password, $disabledtext) = (@_);
+    my $dbh = Bugzilla->dbh;
+
+    $disabledtext ||= '';
+
+    # If not specified, generate a new random password for the user.
+    $password ||= &::GenerateRandomPassword();
+    my $cryptpassword = bz_crypt($password);
+
+    # XXX - These should be moved into ValidateNewUser or CheckEmailSyntax
+    #       At the least, they shouldn't be here. They're safe for now, though.
+    trick_taint($username);
+    trick_taint($realname);
+
+    # fetch the user in the profiles table
+    my $sth = $dbh->prepare("SELECT * from profiles where userid=?");
+    $sth->execute($userid);
+    my $row = $sth->fetchrow_hashref();
+
+    if (! $row->{userid}) {
+        return undef;
+    }
+    
+    # Update the user record into the database.
+    $dbh->do("UPDATE profiles set
+                    login_name=?, 
+                    realname=?, 
+                    cryptpassword=?, 
+                    disabledtext=?,
+                    refreshed_when='1901-01-01 00:00:00'
+              WHERE
+                    userid=?",
+             undef, 
+             ($username, $realname, $cryptpassword, $disabledtext, $userid));
+
+    # Return the password to the calling code so it can be included
+    # in an email sent to the user.
+    return $password;
+}
+
 # Accessors for user attributes
 sub id { $_[0]->{id}; }
 sub login { $_[0]->{login}; }
