[Rt-commit] r8383 - in rt/branches/3.7-EXPERIMENTAL-TUNIS: lib/RT

thayes at bestpractical.com thayes at bestpractical.com
Thu Aug 2 12:08:38 EDT 2007


Author: thayes
Date: Thu Aug  2 12:08:38 2007
New Revision: 8383

Modified:
   rt/branches/3.7-EXPERIMENTAL-TUNIS/   (props changed)
   rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm

Log:
 r8568 at toth:  toth | 2007-08-02 12:08:13 -0400
 * Changed locking methods to work based on lock type priorities
 


Modified: rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm
==============================================================================
--- rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm	(original)
+++ rt/branches/3.7-EXPERIMENTAL-TUNIS/lib/RT/Ticket.pm	Thu Aug  2 12:08:38 2007
@@ -227,7 +227,7 @@
 	return($Queue);
 }
 
-
+my @Types = qw(Auto Take Hard);
 
 sub Locked {
     my $ticket =shift;
@@ -236,11 +236,19 @@
 
 sub Lock {
     my $ticket = shift;
-    my $type = shift;
+    my $type = shift || 'Auto';
 
-    if ( $ticket->Locked() ) {
-        return undef;
+    if ( my $lock = $ticket->Locked() ) {
+    	my $LockType = $lock->Content->{'Type'};
+    	my $priority;
+    	my $LockPriority;
+		for(my $i = 0; $i < scalar @Types; $i++) {
+			$priority = $i if $Types[$i] eq $type;
+			$LockPriority = $i if $Types[$i] eq $LockType;
+		}
+		return undef if $priority <= $LockPriority;
     } else {
+    	$ticket->Unlock();	#Remove any existing locks (because this one has greater priority)
         $ticket->SetAttribute(
             Name    => 'RT_Lock',
             Content => {
@@ -255,13 +263,20 @@
 
 sub Unlock {
     my $ticket = shift;
-    my $type = shift;
+    my $type = shift || 'Auto';
 
     my $lock = $ticket->RT::Ticket::Locked();
     return undef unless $lock;
     return undef unless $lock->Content->{User} ==  $ticket->CurrentUser->id;
-    return undef if $lock->Content->{'Type'} eq 'Hard' && !($type eq 'Hard');
-    return undef if $lock->Content->{'Type'} eq 'IR' && !($type eq 'IR');
+    
+    my $LockType = $lock->Content->{'Type'};
+    my $priority;
+	my $LockPriority;
+	for(my $i = 0; $i < scalar @Types; $i++) {
+		$priority = $i if $Types[$i] eq $type;
+		$LockPriority = $i if $Types[$i] eq $LockType;
+	}
+	return undef if $priority < $LockPriority;
     $ticket->DeleteAttribute('RT_Lock');
 }
 


More information about the Rt-commit mailing list