]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 399163: Bugzilla/*.pm should use transactions for database interaction - Patch...
authorlpsolit%gmail.com <>
Mon, 19 Nov 2007 02:20:53 +0000 (02:20 +0000)
committerlpsolit%gmail.com <>
Mon, 19 Nov 2007 02:20:53 +0000 (02:20 +0000)
Bugzilla/Bug.pm
Bugzilla/Install/DB.pm
Bugzilla/Search/Saved.pm
Bugzilla/Series.pm
Bugzilla/Token.pm
Bugzilla/User.pm

index e79a7a1caf17489a77064360e1bb7b286cd82075..eaf6a9a83ebd981228a6292e7e0d74b7e08b4712 100755 (executable)
@@ -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;
index 327487cd9549a1a22b83996d7122550de88148fc..9934e058fb9645dc3a5efa14611815f87b064a75 100644 (file)
@@ -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');
     }
index bcc72cffec2cacfde2683f3dd19412066827704c..3484eb3bce39e9f25672504e1701fade0f36bf76 100644 (file)
@@ -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;
 }
index d6fd7a08a3ff155e761a6d5b4263c7720db0367c..a99c442fe7e0a10038257abdd46df45beab5a132 100644 (file)
@@ -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
index 7db6b91651378a94f70fcae8f0ccd85e7e50a108..2f911fca13f07c41abc92e10f6d415536529cf2b 100644 (file)
@@ -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);
index 7cd1910c42051363f93c90603d2df8bcac1bee1f..bd2a65ae0cc69aa3ab2d4a12c885906a19a59665 100644 (file)
@@ -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;