summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authormkanat%kerio.com <>2005-02-18 06:57:26 +0100
committermkanat%kerio.com <>2005-02-18 06:57:26 +0100
commitd3f8bf365e5b93f58497a25e07fde7ce30884f9d (patch)
treeba45ba2aa22039ecd440ca4c5c7fa421eb158456 /Bugzilla
parentf95d1faba79c94bcf3bf936334d6bb10e03c93b2 (diff)
downloadbugzilla-d3f8bf365e5b93f58497a25e07fde7ce30884f9d.tar.gz
bugzilla-d3f8bf365e5b93f58497a25e07fde7ce30884f9d.tar.xz
Bug 280503: Replace "LOCK/UNLOCK TABLES" with Bugzilla::DB function call
Patch By Tomas Kopal <Tomas.Kopal@altap.cz> r=mkanat,a=myk
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Constants.pm6
-rw-r--r--Bugzilla/DB.pm4
-rw-r--r--Bugzilla/Error.pm3
-rw-r--r--Bugzilla/Series.pm4
-rw-r--r--Bugzilla/Token.pm22
-rw-r--r--Bugzilla/User.pm9
6 files changed, 30 insertions, 18 deletions
diff --git a/Bugzilla/Constants.pm b/Bugzilla/Constants.pm
index 3ef3cc634..a3e16251c 100644
--- a/Bugzilla/Constants.pm
+++ b/Bugzilla/Constants.pm
@@ -66,6 +66,8 @@ use base qw(Exporter);
DEFAULT_QUERY_NAME
COMMENT_COLS
+
+ UNLOCK_ABORT
);
@Bugzilla::Constants::EXPORT_OK = qw(contenttypes);
@@ -217,4 +219,8 @@ use constant DEFAULT_QUERY_NAME => '(Default query)';
# The column length for displayed (and wrapped) bug comments.
use constant COMMENT_COLS => 80;
+# used by Bugzilla::DB to indicate that tables are being unlocked
+# because of error
+use constant UNLOCK_ABORT => 1;
+
1;
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index 3e3f45c66..d1ecfcb2e 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -501,8 +501,8 @@ formatted SQL command have prefix C<sql_>. All other methods have prefix C<bz_>.
set even without locking tables first without raising an error
to simplify error handling.
Abstract method, should be overriden by database specific code.
- Params: $abort = true (1) if the operation on locked tables failed
- (if transactions are supported, the action will be rolled
+ Params: $abort = UNLOCK_ABORT (true, 1) if the operation on locked tables
+ failed (if transactions are supported, the action will be rolled
back). False (0) or no param if the operation succeeded.
Returns: none
diff --git a/Bugzilla/Error.pm b/Bugzilla/Error.pm
index 96017f368..e86b1c41a 100644
--- a/Bugzilla/Error.pm
+++ b/Bugzilla/Error.pm
@@ -27,6 +27,7 @@ use base qw(Exporter);
@Bugzilla::Error::EXPORT = qw(ThrowCodeError ThrowTemplateError ThrowUserError);
use Bugzilla::Config;
+use Bugzilla::Constants;
use Bugzilla::Util;
use Date::Format;
@@ -37,7 +38,7 @@ sub _throw_error {
$vars->{error} = $error;
- Bugzilla->dbh->do("UNLOCK TABLES") if $unlock_tables;
+ Bugzilla->dbh->bz_unlock_tables(UNLOCK_ABORT) if $unlock_tables;
# If a writable data/errorlog exists, log error details there.
if (-w "data/errorlog") {
diff --git a/Bugzilla/Series.pm b/Bugzilla/Series.pm
index a4bd6654f..53e6fbabf 100644
--- a/Bugzilla/Series.pm
+++ b/Bugzilla/Series.pm
@@ -170,7 +170,7 @@ sub writeToDatabase {
my $self = shift;
my $dbh = Bugzilla->dbh;
- $dbh->do("LOCK TABLES series_categories WRITE, series WRITE");
+ $dbh->bz_lock_tables('series_categories WRITE', 'series WRITE');
my $category_id = getCategoryID($self->{'category'});
my $subcategory_id = getCategoryID($self->{'subcategory'});
@@ -210,7 +210,7 @@ sub writeToDatabase {
|| &::ThrowCodeError("missing_series_id", { 'series' => $self });
}
- $dbh->do("UNLOCK TABLES");
+ $dbh->bz_unlock_tables();
}
# Check whether a series with this name, category and subcategory exists in
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 {
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index 8f5f6a762..67b79f168 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -384,10 +384,9 @@ sub derive_groups {
my $sth;
- $dbh->do(q{LOCK TABLES profiles WRITE,
- user_group_map WRITE,
- group_group_map READ,
- groups READ}) unless $already_locked;
+ $dbh->bz_lock_tables('profiles WRITE', 'user_group_map WRITE',
+ 'group_group_map READ',
+ 'groups READ') unless $already_locked;
# avoid races, we are only up to date as of the BEGINNING of this process
my $time = $dbh->selectrow_array("SELECT NOW()");
@@ -459,7 +458,7 @@ sub derive_groups {
undef,
$time,
$id);
- $dbh->do("UNLOCK TABLES") unless $already_locked;
+ $dbh->bz_unlock_tables() unless $already_locked;
}
sub can_bless {