--- Bugzilla.pm.bak_0.26.17	2010-03-08 17:43:30.000000000 +0200
+++ Bugzilla.pm	2010-04-04 23:15:32.000000000 +0300
@@ -565,19 +565,35 @@
 	}
     } else {
         # Since Bugzilla 3.1.3 AppendComment has been replaced by add_comment
-	my $userid = Bugzilla::User::login_to_id( $username );
-	if ( $userid > 0 ) {
-            my $bug = Bugzilla::Bug->check($bugid);
+        
+        my $dbh = Bugzilla->dbh;
+        my @ret_list = eval {
+        my $userid = Bugzilla::User::login_to_id( $username );
+        if ( $userid > 0 ) {
+            $dbh->bz_start_transaction();
             my $user = new Bugzilla::User($userid);
             Bugzilla->set_user($user);
+            my $bug = Bugzilla::Bug->check($bugid);
             $bug->add_comment($comment, {isprivate => 0, work_time => 0, type => Bugzilla::Constants->CMT_NORMAL, extra_data => ""} );
             $bug->update();
-	    return 0;
+            $dbh->bz_commit_transaction();
+            return 0;
         } else {
-	    # This should never happen. Each user should have a
-	    # corresponding userid in the database schema
-	    return 1, "Login '$username' could not be converted to an id in Bugzilla. Is username mapping setup correctly in daemon.conf ?\n" ;
+            # This should never happen. Each user should have a
+            # corresponding userid in the database schema
+            return 1, "Login '$username' could not be converted to an id in Bugzilla. Is username mapping setup correctly in daemon.conf ?\n" ;
         }
+        }; # eval
+        if ($@) {
+            my $err = $@; 
+            log_daemon_warn( undef, $err );
+            $dbh->bz_rollback_transaction() if $dbh->bz_in_transaction();
+            return 1, "Error while adding bug comment: $err";
+        }
+        else {
+            return @ret_list;
+        }
+        
     }
 }
 
@@ -606,7 +622,7 @@
          $self->is_version_up_to_2_22() ) {
         # Changing bug resolutions is not supported for earlier versions of Bugzilla
         return ( 1, "Changing bug resolution is not implemented in this version of Bugzilla.\n");
-    } elsif ( $self->is_version_up_to_3_1_2() || $self->is_version_latest() ) {
+    } elsif ( $self->is_version_up_to_3_1_2() ) {
 
         my $privileges_are_required = 0; #Set within check_can_change_field, not used at the moment
         my $bug = new Bugzilla::Bug($bugid);
@@ -784,6 +800,110 @@
         } else {
             return ( 1, "Changing bug resolution for bug '$bugid' wasn't successful. Nothing changed.\n");
         }
+    } elsif ( $self->is_version_latest() ) {
+        
+        my $dbh = Bugzilla->dbh;
+        
+        # Run in eval block to catch bugzilla exceptions
+        my @ret_list = eval {
+        my $privileges_are_required = 0; #Set within check_can_change_field, not used at the moment
+        my $user = Bugzilla::User->new( { name => $username } );
+        Bugzilla->set_user($user);
+        my $bug = Bugzilla::Bug->check($bugid);
+        
+        my $has_changed = 0;
+        
+        if(!defined $status) {
+            $status = "none";
+        } else {
+            $status = lc $status;
+        }
+        
+        my $new_status = undef;
+        my $resolution_params = {};
+        
+        
+        if ( $status =~ /^none$/ )  {
+
+            return ( 1, "Undefined status '$status' for bug '$bugid'.\n");
+
+        } elsif ( $status =~ /^assigned$/ )  {
+
+            if( defined($resolution) && ('' ne $resolution) ) {
+
+                # Reassign to given assignee
+                my $assignee_user = Bugzilla::User->new( {name => $resolution} );
+                if( !defined($assignee_user) ) {
+                    return ( 1, "Unknown assignee '$resolution'.\n");
+                }
+                
+                $bug->set_assigned_to($assignee_user);
+                $new_status = "NEW";
+            } else {
+                
+                # Accepting bug
+                if($bug->assigned_to->id == 0) {
+                    return ( 1, "Bug '$bugid' was never confirmed. Can't change status to 'ASSIGNED'.\n");
+                }
+                
+                if($bug->assigned_to->id != $user->id) {
+                    return ( 1, "You cannot accept a bug if you aren't the assignee. Bug '$bugid' is assigned to '" . $bug->assigned_to->login . "'\n");
+                }
+                
+                $new_status = uc $status;
+            }
+            $has_changed = 1;
+
+        } elsif ( $status =~ /^reopened$/ )  {
+            
+            $new_status = uc $status;
+            
+            $has_changed = 1;
+        } elsif ( $status =~ /^resolved$/ )  {
+
+            $resolution = lc $resolution;
+            
+            if((!defined $resolution) || ('' eq $resolution)) {
+                return ( 1, "Undefined resolution for status '$status'.\n");
+            }
+                
+            if($resolution eq "moved") {
+                # Should never happen, anyway leave it here
+                return ( 1, "Movement of bugs isn't supported.\n");
+            }
+            elsif ($resolution eq "duplicate") {
+                $resolution_params->{dupe_of} = $resolution_data;
+            }
+            
+            $resolution_params->{resolution} = uc $resolution;
+            $new_status = uc $status;
+            
+            $has_changed = 1;
+        } else {
+            return ( 1, "Unknown status '$status' for bug '$bugid'.\n");
+        }
+        
+        if($has_changed == 1) {
+            $dbh->bz_start_transaction();
+            $bug->set_status($new_status, $resolution_params);
+            $bug->update();
+            $dbh->bz_commit_transaction();
+            
+            return 0;
+        } else {
+            return ( 1, "Changing bug resolution for bug '$bugid' wasn't successful. Nothing changed.\n");
+        }
+        }; # eval
+        if ($@) {
+            my $err = $@;
+            log_daemon_warn( undef, $err );
+            $dbh->bz_rollback_transaction() if $dbh->bz_in_transaction();
+            return 1, "Error while changing bug resolution: $err";
+        }
+        else {
+            return @ret_list;
+        }
+    
     } else {
         # Changing bug resolutions is not supported for earlier versions of Bugzilla
         return ( 1, "Changing bug resolution is not yet implemented in this version of Bugzilla.\n");
