From d3f8bf365e5b93f58497a25e07fde7ce30884f9d Mon Sep 17 00:00:00 2001 From: "mkanat%kerio.com" <> Date: Fri, 18 Feb 2005 05:57:26 +0000 Subject: Bug 280503: Replace "LOCK/UNLOCK TABLES" with Bugzilla::DB function call Patch By Tomas Kopal r=mkanat,a=myk --- Bugzilla/Token.pm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'Bugzilla/Token.pm') diff --git a/Bugzilla/Token.pm b/Bugzilla/Token.pm index 90efe99bd..9caf91ab2 100644 --- a/Bugzilla/Token.pm +++ b/Bugzilla/Token.pm @@ -52,13 +52,14 @@ my $maxtokenage = 3; sub IssueEmailChangeToken { my ($userid, $old_email, $new_email) = @_; + my $dbh = Bugzilla->dbh; my $token_ts = time(); my $issuedate = time2str("%Y-%m-%d %H:%M", $token_ts); # Generate a unique token and insert it into the tokens table. # We have to lock the tokens table before generating the token, # since the database must be queried for token uniqueness. - &::SendSQL("LOCK TABLES tokens WRITE"); + $dbh->bz_lock_tables('tokens WRITE'); my $token = GenerateUniqueToken(); my $quotedtoken = &::SqlQuote($token); my $quoted_emails = &::SqlQuote($old_email . ":" . $new_email); @@ -72,7 +73,7 @@ sub IssueEmailChangeToken { tokentype , eventdata ) VALUES ( $userid , '$issuedate' , $quotedtoken , 'emailnew' , $quoted_emails )"); - &::SendSQL("UNLOCK TABLES"); + $dbh->bz_unlock_tables(); # Mail the user the token along with instructions for using it. @@ -110,6 +111,8 @@ sub IssuePasswordToken { my ($loginname) = @_; + my $dbh = Bugzilla->dbh; + # Retrieve the user's ID from the database. my $quotedloginname = &::SqlQuote($loginname); &::SendSQL("SELECT profiles.userid, tokens.issuedate FROM profiles @@ -129,13 +132,13 @@ sub IssuePasswordToken { # Generate a unique token and insert it into the tokens table. # We have to lock the tokens table before generating the token, # since the database must be queried for token uniqueness. - &::SendSQL("LOCK TABLES tokens WRITE"); + $dbh->bz_lock_tables('tokens WRITE'); my $token = GenerateUniqueToken(); my $quotedtoken = &::SqlQuote($token); my $quotedipaddr = &::SqlQuote($::ENV{'REMOTE_ADDR'}); &::SendSQL("INSERT INTO tokens ( userid , issuedate , token , tokentype , eventdata ) VALUES ( $userid , NOW() , $quotedtoken , 'password' , $quotedipaddr )"); - &::SendSQL("UNLOCK TABLES"); + $dbh->bz_unlock_tables(); # Mail the user the token along with instructions for using it. @@ -158,10 +161,11 @@ sub IssuePasswordToken { sub CleanTokenTable { - &::SendSQL("LOCK TABLES tokens WRITE"); + my $dbh = Bugzilla->dbh; + $dbh->bz_lock_tables('tokens WRITE'); &::SendSQL("DELETE FROM tokens WHERE TO_DAYS(NOW()) - TO_DAYS(issuedate) >= " . $maxtokenage); - &::SendSQL("UNLOCK TABLES"); + $dbh->bz_unlock_tables(); } @@ -198,6 +202,8 @@ sub Cancel { my ($token, $cancelaction) = @_; + my $dbh = Bugzilla->dbh; + # Quote the token for inclusion in SQL statements. my $quotedtoken = &::SqlQuote($token); @@ -232,9 +238,9 @@ sub Cancel { Bugzilla::BugMail::MessageToMTA($message); # Delete the token from the database. - &::SendSQL("LOCK TABLES tokens WRITE"); + $dbh->bz_lock_tables('tokens WRITE'); &::SendSQL("DELETE FROM tokens WHERE token = $quotedtoken"); - &::SendSQL("UNLOCK TABLES"); + $dbh->bz_unlock_tables(); } sub DeletePasswordTokens { -- cgit v1.2.3-24-g4f1b