--- Bugzilla.pm.old	2009-05-12 18:28:21.000000000 +0100
+++ Bugzilla.pm	2009-06-30 18:34:00.000000000 +0100
@@ -97,6 +97,15 @@ sub is_version_up_to_2_22 {
     }
 }
 
+sub is_version_up_to_3_00 {
+    my $self = shift;
+
+    if ( $self->{ version_type } eq "up_to_3_00" ) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
 
 
 # There are various ways to talk to Bugzilla. The Bugzilla API as
@@ -371,28 +380,18 @@ sub bug_status_map {
             $status_map->{ $status } = {};
             $status_map->{ $status }->{ name } = $status;
             $status_map->{ $status }->{ accepts_data_as_resolution } = 0;
-            $status_map->{ $status }->{ active } = 0; #Bugzilla::Bug::is_open_state( $status );
+	    
+	    my $bug_status = new Bugzilla::Status( { name => $status } );
+	    $status_map->{ $status }->{ active } = $bug_status->is_open();
             $status_map->{ $status }->{ possible_resolution_states } = [];
+
+	    foreach my $bug_status_change_to ( @{ $bug_status->can_change_to() } ) {
+		unshift( @{ $status_map->{ $status }->{ possible_resolution_states } }, $bug_status_change_to->name() ); 
+	    }
+
             $status_map->{ $status }->{ possible_resolutions } = [];
         }
         
-        $status_map->{ 'NEW'      }->{ possible_resolution_states } = [ 'ASSIGNED', 'RESOLVED' ];
-        
-        $status_map->{ 'ASSIGNED' }->{ active } = 1;
-        $status_map->{ 'ASSIGNED' }->{ accepts_data_as_resolution } = 1;
-        # ASSIGNED -> ASSIGNED for reassignment to other user
-        $status_map->{ 'ASSIGNED' }->{ possible_resolution_states } = [ 'ASSIGNED', 'RESOLVED' ];
-        
-        $status_map->{ 'REOPENED' }->{ active } = 1;
-        $status_map->{ 'REOPENED' }->{ possible_resolution_states } = [ 'ASSIGNED', 'RESOLVED' ];
-        
-        # RESOLVED -> RESOLVED for resolution change only
-        $status_map->{ 'RESOLVED' }->{ possible_resolution_states } = [ 'RESOLVED', 'REOPENED' ];
-        
-        $status_map->{ 'VERIFIED' }->{ possible_resolution_states } = [ 'REOPENED' ];
-        $status_map->{ 'CLOSED'   }->{ possible_resolution_states } = [ 'REOPENED' ];
-        
-        
         my $resolution_values = Bugzilla::Field::get_legal_field_values('resolution');
         my $pos = Bugzilla::Util::lsearch($resolution_values, '');
         if ($pos >= 0) {
@@ -442,8 +441,14 @@ sub set_version_type {
 	    } else {
 		$self->{ version_type } = $BUGTRACKER_VERSION_NOT_SUPPORTED;
 	    }
-	} elsif ( $major == 3 && $minor == 0 ) {
-	    $self->{version_type} = $BUGTRACKER_VERSION_LATEST;
+	} elsif ( $major == 3 ) {
+	    if ( $minor == 0 ) {
+		$self->{ version_type } = "up_to_3_00";
+	    } elsif ( $minor == 2 ) {
+	    	$self->{version_type} = $BUGTRACKER_VERSION_LATEST;
+	    } else {
+		$self->{ version_type } = $BUGTRACKER_VERSION_NOT_SUPPORTED;
+	    }
 	} else {
 	    $self->{ version_type } = $BUGTRACKER_VERSION_NOT_SUPPORTED;
 	}
@@ -508,7 +513,7 @@ sub integration_add_comment {
 	    # 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" ;
 	}
-    } elsif ( $self->is_version_up_to_2_22() || $self->is_version_latest() ) {
+    } elsif ( $self->is_version_up_to_2_22() || $self->is_version_up_to_3_00() ) {
 	# AppendComment was fixed in Bugzilla 2.22. Should use the
 	# native version
 	my $userid = Bugzilla::User::login_to_id( $username );
@@ -521,9 +526,24 @@ sub integration_add_comment {
 	    # 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" ;
 	}
+    } elsif ( $self->is_version_latest() ) {
+		#
+		# Bugzilla 3.2.3
+		#
+	
+		Bugzilla->usage_mode( 'USAGE_MODE_EMAIL' );
+	
+	    my $userid = Bugzilla::User->new( { name => $username } );
+		Bugzilla->set_user($userid);
+	
+		my $current_bug = new Bugzilla::Bug( $bugid );
+		$current_bug->add_comment( $comment );
+		$current_bug->update();
+	
+		return 0;	
     } else {
-	AppendComment( $bugid, $username, $comment );
-	return 0;
+		AppendComment( $bugid, $username, $comment );
+		return 0;
     }
 }
 
@@ -548,169 +568,40 @@ sub integration_change_bug_resolution {
 
     if ( $self->is_version_latest() ) {
 
+	my $dbh = Bugzilla->dbh;
         my $privileges_are_required = 0; #Set within check_can_change_field, not used at the moment
         my $bug = new Bugzilla::Bug($bugid);
         my $user = Bugzilla::User->new( { name => $username } );
         Bugzilla->set_user($user);
         
-        my $dbh = Bugzilla->dbh;
-        my $sql = "UPDATE bugs SET ";
         my $has_changed = 0;
         my @params = ();
+        
         if(!defined $status) {
             $status = "none";
-        } else {
-            $status = lc $status;
         }
         
-        my $assignee = undef;
-        my $dupe_id = undef;
-
         if ( $status =~ /^none$/ )  {
-
             return ( 1, "Undefined status '$status' for bug '$bugid'.\n");
+        } 
 
-        } elsif ( $status =~ /^assigned$/ )  {
-
-            if( defined($resolution) && ('' ne $resolution) ) {
-
-                # Reassign to given assignee
-                $assignee = $dbh->selectrow_array( "SELECT userid FROM profiles WHERE " .
-                                                   $dbh->sql_istrcmp('login_name', '?'), undef, $resolution);
-                                    
-                if( $assignee == 0) {
-                    return ( 1, "Unknown assignee '$resolution'.\n");
-                }
-                    
-                my %data = { 'knob' => 'reassign' }; #Needed by check_can_change_field for correctness
-                if(!$bug->check_can_change_field('assigned_to', $bug->assigned_to, $assignee, \$privileges_are_required, \%data)) {
-                    return ( 1, "Missing permission to reassign bug.\n");
-                }
-                    
-                $sql .= "bug_status=?";
-                push(@params, 'NEW'); # NOT ASSIGNED, this would break bz workflow
-                $sql .= ", assigned_to = ?";
-                push(@params, $assignee);
-                    
-            } 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");
-                }
-                    
-                $sql .= "bug_status=?";
-                push(@params, 'ASSIGNED');
-            }
-            $has_changed = 1;
-
-        } elsif ( $status =~ /^reopened$/ )  {
-            
-            if(!$bug->check_can_change_field('bug_status', $bug->bug_status, uc $status, \$privileges_are_required)) {
-                return ( 1, "Missing permission to reopen bug.\n");
-            }
-            $sql .= "bug_status=?";
-            push(@params, uc $status);
-            $sql .= ", resolution=?";
-            push(@params, "");
-            $has_changed = 1;
-        } elsif ( $status =~ /^resolved$/ )  {
-
-            $resolution = lc $resolution;
-
-            if(!$bug->check_can_change_field('bug_status', $bug->bug_status, uc $status, \$privileges_are_required)) {
-                return ( 1, "Missing permission to resolve bug.\n");
-            }
-                
-            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") {
-
-                $dupe_id = $resolution_data;
-                my $reporter = $dbh->selectrow_array( "SELECT reporter FROM bugs WHERE bug_id = ?", undef, $dupe_id);
-                my $reporter_user = Bugzilla::User->new($reporter);
-                if (!$reporter_user->can_see_bug($dupe_id)) {
-                    # We don't want to be verbose to the user here, because he doesn't have the permissions
-                    return ( 1, "Error while setting status of bug '$bugid' to 'resolved duplicate $resolution_data'.\n");
-                }
-            }
-                
-            $sql .= "remaining_time = 0"; #Must reset time in this case, is also done in bugzilla's process_bug.cgi
-            $sql .= ", bug_status=?";
-            push(@params, uc $status);
-            $sql .= ", resolution=?";
-            push(@params, uc $resolution);
-            $has_changed = 1;
-        } else {
-            return ( 1, "Unknown status '$status' for bug '$bugid'.\n");
-        }
-        
-
-        my $dbh = Bugzilla->dbh;
-        # Lock database tables, avoid mid-air collisions
-        $dbh->bz_lock_tables('bugs WRITE', 'bugs_activity WRITE', 'duplicates WRITE', 'longdescs WRITE', 'fielddefs READ', 'profiles READ');
-        my $timestamp = $dbh->selectrow_array("SELECT NOW()"); # use same timestamp for all modifications
-        
-        $sql .= " WHERE bug_id = ?";
-        push(@params, $bugid);
-
-        if ($has_changed == 1) {
-
-            my $result = $dbh->do($sql, undef, @params);
-
-            if($result) {
-                
-                if ($resolution ne 'duplicate') {
-                    # Remove if previous resolution was duplicate
-                    $dbh->do( "DELETE FROM duplicates WHERE dupe = ?", undef, $bugid);
-
-                } else {
-                    # Remove previous one if dupe has changed
-                    $dbh->do( "DELETE FROM duplicates WHERE dupe = ?", undef, $bugid);
-                    
-                    if($dbh->do( "INSERT INTO duplicates VALUES (?, ?)", undef, $dupe_id, $bugid)) {
-                        # Simulate bugzilla behavior when marking as duplicate
-                        Bugzilla::Bug::AppendComment($bugid, $user->id, "", 0, $timestamp, 0, Bugzilla::Constants->CMT_DUPE_OF, $dupe_id);
-                        Bugzilla::Bug::AppendComment($dupe_id, $user->id, "", 0, $timestamp, 0, Bugzilla::Constants->CMT_HAS_DUPE, $bugid);
-                    }
-                }
-                
-                # Finally add values to bug's activity log
-                my $bug2 = new Bugzilla::Bug($bugid);
-                if( defined($assignee) && ( $bug->assigned_to->id != $bug2->assigned_to->id)) {
-                    my $old_value = Bugzilla::User::user_id_to_login($bug->assigned_to->id);
-                    my $new_value = Bugzilla::User::user_id_to_login($bug2->assigned_to->id);
-                    Bugzilla::Bug::LogActivityEntry($bugid, 'assigned_to', $old_value, $new_value, $user->id, $timestamp);
-                }
-                if($bug->bug_status ne $bug2->bug_status) {
-                    Bugzilla::Bug::LogActivityEntry($bugid, 'bug_status', $bug->bug_status, $bug2->bug_status, $user->id, $timestamp);
-                  }
-                if($bug->resolution ne $bug2->resolution) {
-                    Bugzilla::Bug::LogActivityEntry($bugid, 'resolution', $bug->resolution, $bug2->resolution, $user->id, $timestamp);
-                  }
-                
-            } else {
-                $dbh->bz_unlock_tables();
-                return ( 1, "Error while updating the status resolution of bug 'bugid'.\n");
-            }
-        }
-        $dbh->bz_unlock_tables();
+		$bug->set_status( $status, { resolution => $resolution } );
+			
+		# $dbh->bz_start_transaction();
+		my $timestamp = $dbh->selectrow_array(q{SELECT NOW()});
+		my $changes = $bug->update($timestamp);
+		# dbh->bz_commit_transaction();
+	
+		$has_changed = 1;
         
-        if($has_changed == 1){
+        if ( $has_changed == 1 ) {
             return 0;
         } else {
             return ( 1, "Changing bug resolution for bug '$bugid' wasn't successful. Nothing changed.\n");
         }
+
     }
+
     return ( 1, "Changing bug resolution is not yet implemented in this version of Bugzilla.\n");
 }
 
