Commit 9d6205cd authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 399163: Bugzilla/*.pm should use transactions for database interaction -…

Bug 399163: Bugzilla/*.pm should use transactions for database interaction - Patch by Emmanuel Seyman <eseyman@linagora.com> r/a=mkanat
parent 0dadaed4
......@@ -738,12 +738,7 @@ sub remove_from_db {
# Also, the attach_data table uses attachments.attach_id as a foreign
# key, and so indirectly depends on a bug deletion too.
$dbh->bz_lock_tables('attachments WRITE', 'bug_group_map WRITE',
'bugs WRITE', 'bugs_activity WRITE', 'cc WRITE',
'dependencies WRITE', 'duplicates WRITE',
'flags WRITE', 'keywords WRITE',
'longdescs WRITE', 'votes WRITE',
'attach_data WRITE');
$dbh->bz_start_transaction();
$dbh->do("DELETE FROM bug_group_map WHERE bug_id = ?", undef, $bug_id);
$dbh->do("DELETE FROM bugs_activity WHERE bug_id = ?", undef, $bug_id);
......@@ -754,7 +749,6 @@ sub remove_from_db {
undef, ($bug_id, $bug_id));
$dbh->do("DELETE FROM flags WHERE bug_id = ?", undef, $bug_id);
$dbh->do("DELETE FROM keywords WHERE bug_id = ?", undef, $bug_id);
$dbh->do("DELETE FROM longdescs WHERE bug_id = ?", undef, $bug_id);
$dbh->do("DELETE FROM votes WHERE bug_id = ?", undef, $bug_id);
# The attach_data table doesn't depend on bugs.bug_id directly.
......@@ -771,7 +765,9 @@ sub remove_from_db {
$dbh->do("DELETE FROM attachments WHERE bug_id = ?", undef, $bug_id);
$dbh->do("DELETE FROM bugs WHERE bug_id = ?", undef, $bug_id);
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
$dbh->do("DELETE FROM longdescs WHERE bug_id = ?", undef, $bug_id);
# Now this bug no longer exists
$self->DESTROY;
......
......@@ -659,8 +659,9 @@ sub _populate_longdescs {
" for each 50.\n\n";
local $| = 1;
$dbh->bz_lock_tables('bugs write', 'longdescs write', 'profiles write',
'bz_schema WRITE');
# On MySQL, longdescs doesn't benefit from transactions, but this
# doesn't hurt.
$dbh->bz_start_transaction();
$dbh->do('DELETE FROM longdescs');
......@@ -722,7 +723,7 @@ sub _populate_longdescs {
print "\n\n";
$dbh->bz_drop_column('bugs', 'long_desc');
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
} # main if
}
......@@ -740,8 +741,7 @@ sub _update_bugs_activity_field_to_fieldid {
[qw(fieldid)]);
print "Populating new bugs_activity.fieldid field...\n";
$dbh->bz_lock_tables('bugs_activity WRITE', 'fielddefs WRITE');
$dbh->bz_start_transaction();
my $ids = $dbh->selectall_arrayref(
'SELECT DISTINCT fielddefs.id, bugs_activity.field
......@@ -760,7 +760,7 @@ sub _update_bugs_activity_field_to_fieldid {
$dbh->do("UPDATE bugs_activity SET fieldid = ? WHERE field = ?",
undef, $id, $field);
}
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
$dbh->bz_drop_column('bugs_activity', 'field');
}
......
......@@ -97,13 +97,12 @@ sub create {
Bugzilla->login(LOGIN_REQUIRED);
my $dbh = Bugzilla->dbh;
$class->check_required_create_fields(@_);
$dbh->bz_start_transaction();
my $params = $class->run_create_validators(@_);
# Right now you can only create a Saved Search for the current user.
$params->{userid} = Bugzilla->user->id;
$dbh->bz_lock_tables('namedqueries WRITE',
'namedqueries_link_in_footer WRITE');
my $lif = delete $params->{link_in_footer};
my $obj = $class->insert_create_data($params);
if ($lif) {
......@@ -111,7 +110,7 @@ sub create {
(user_id, namedquery_id) VALUES (?,?)',
undef, $params->{userid}, $obj->id);
}
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
return $obj;
}
......
......@@ -170,7 +170,7 @@ sub writeToDatabase {
my $self = shift;
my $dbh = Bugzilla->dbh;
$dbh->bz_lock_tables('series_categories WRITE', 'series WRITE');
$dbh->bz_start_transaction();
my $category_id = getCategoryID($self->{'category'});
my $subcategory_id = getCategoryID($self->{'subcategory'});
......@@ -209,7 +209,7 @@ sub writeToDatabase {
|| ThrowCodeError("missing_series_id", { 'series' => $self });
}
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
}
# Check whether a series with this name, category and subcategory exists in
......
......@@ -171,12 +171,10 @@ sub issue_session_token {
sub CleanTokenTable {
my $dbh = Bugzilla->dbh;
$dbh->bz_lock_tables('tokens WRITE');
$dbh->do('DELETE FROM tokens
WHERE ' . $dbh->sql_to_days('NOW()') . ' - ' .
$dbh->sql_to_days('issuedate') . ' >= ?',
undef, MAX_TOKEN_AGE);
$dbh->bz_unlock_tables();
}
sub GenerateUniqueToken {
......@@ -301,9 +299,7 @@ sub delete_token {
return unless defined $token;
trick_taint($token);
$dbh->bz_lock_tables('tokens WRITE');
$dbh->do("DELETE FROM tokens WHERE token = ?", undef, $token);
$dbh->bz_unlock_tables();
}
# Given a token, makes sure it comes from the currently logged in user
......@@ -364,14 +360,14 @@ sub _create_token {
trick_taint($tokentype);
trick_taint($eventdata);
$dbh->bz_lock_tables('tokens WRITE');
$dbh->bz_start_transaction();
my $token = GenerateUniqueToken();
$dbh->do("INSERT INTO tokens (userid, issuedate, token, tokentype, eventdata)
VALUES (?, NOW(), ?, ?, ?)", undef, ($userid, $token, $tokentype, $eventdata));
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
if (wantarray) {
my (undef, $token_ts, undef) = GetTokenData($token);
......
......@@ -1583,9 +1583,7 @@ sub create {
my $class = ref($invocant) || $invocant;
my $dbh = Bugzilla->dbh;
$dbh->bz_lock_tables('profiles WRITE', 'profiles_activity WRITE',
'user_group_map WRITE', 'email_setting WRITE', 'groups READ',
'tokens READ', 'fielddefs READ');
$dbh->bz_start_transaction();
my $user = $class->SUPER::create(@_);
......@@ -1622,7 +1620,7 @@ sub create {
VALUES (?, ?, NOW(), ?, NOW())',
undef, ($user->id, $who, $creation_date_fieldid));
$dbh->bz_unlock_tables();
$dbh->bz_commit_transaction();
# Return the newly created user account.
return $user;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment