[Rt-devel] PATCH: Link symmetry

Todd Chapman todd at chaka.net
Fri Nov 4 17:21:12 EST 2005


OK gang,

Here is my stab at fixing the asymmetrical link
transaction problem. Added a couple of tests
and everything passes. See any problems?

(attached)

-Todd

-------------- next part --------------
Index: lib/RT/Ticket_Overlay.pm
===================================================================
--- lib/RT/Ticket_Overlay.pm	(revision 4013)
+++ lib/RT/Ticket_Overlay.pm	(working copy)
@@ -2501,8 +2501,8 @@
         $direction='Base';
     }
 
-    if ( $val ) {
-	my $remote_uri = RT::URI->new( $RT::SystemUser );
+    if ( ! $args{'Silent'} ) {
+	my $remote_uri = RT::URI->new( $self->CurrentUser );
     	$remote_uri->FromURI( $remote_link );
 
         my ( $Trans, $Msg, $TransObj ) = $self->_NewTransaction(
@@ -2512,8 +2512,22 @@
             TimeTaken => 0
         );
 
+        if ( $remote_uri->IsLocal ) {
+
+            my $OtherObj = $remote_uri->Object;
+            my ( $val, $Msg ) = $OtherObj->_NewTransaction(Type  => 'DeleteLink',
+                                                           Field => $direction eq 'Target' ? $LINKDIRMAP{$args{'Type'}}->{Base}
+                                                                                           : $LINKDIRMAP{$args{'Type'}}->{Target},
+                                                           OldValue => $self->URI,
+                                                           ActtivateScrips => $RT::LinkTransactionsRun2Scrips,
+                                                           TimeTaken => 0 );
+        }
+
         return ( $Trans, $Msg );
     }
+    else {
+        return ( $val, $Msg );
+    }
 }
 
 # }}}
@@ -2568,6 +2582,20 @@
 ($id,$msg) =$ticket->AddLink(Type => 'RefersTo', Target => -1);
 ok(!$id,$msg);
 
+my $transactions = $ticket2->Transactions;
+$transactions->Limit( FIELD => 'Type', VALUE => 'AddLink' );
+ok( $transactions->Count == 1, "Transaction found in other ticket" );
+ok( $transactions->First->Field eq 'ReferredToBy');
+ok( $transactions->First->NewValue eq $ticket->URI );
+
+($id,$msg) =$ticket->DeleteLink(Type => 'RefersTo', Target => $ticket2->id);
+ok($id,$msg);
+$transactions = $ticket2->Transactions;
+$transactions->Limit( FIELD => 'Type', VALUE => 'DeleteLink' );
+ok( $transactions->Count == 1, "Transaction found in other ticket" );
+ok( $transactions->First->Field eq 'ReferredToBy');
+ok( $transactions->First->OldValue eq $ticket->URI );
+
 =end testing 
 
 =cut
@@ -2653,11 +2681,8 @@
     }
 
     # Don't write the transaction if we're doing this on create
-    if ( $args{'Silent'} ) {
-        return ( $val, $Msg );
-    }
-    else {
-	my $remote_uri = RT::URI->new( $RT::SystemUser );
+    if ( ! $args{'Silent'} ) {
+	my $remote_uri = RT::URI->new( $self->CurrentUser );
     	$remote_uri->FromURI( $remote_link );
 
         #Write the transaction
@@ -2666,8 +2691,22 @@
 				   Field => $LINKDIRMAP{$args{'Type'}}->{$direction},
 				   NewValue =>  $remote_uri->URI || $remote_link,
 				   TimeTaken => 0 );
+
+        if ( $remote_uri->IsLocal ) {
+
+            my $OtherObj = $remote_uri->Object;
+            my ( $val, $Msg ) = $OtherObj->_NewTransaction(Type  => 'AddLink',
+                                                           Field => $direction eq 'Target' ? $LINKDIRMAP{$args{'Type'}}->{Base} 
+                                                                                           : $LINKDIRMAP{$args{'Type'}}->{Target},
+                                                           NewValue => $self->URI,
+                                                           ActtivateScrips => $RT::LinkTransactionsRun2Scrips,
+                                                           TimeTaken => 0 );
+        }
         return ( $val, $Msg );
     }
+    else {
+        return ( $val, $Msg );
+    }
 
 }
 
Index: etc/RT_Config.pm.in
===================================================================
--- etc/RT_Config.pm.in	(revision 4013)
+++ etc/RT_Config.pm.in	(working copy)
@@ -468,6 +468,11 @@
 @ActiveStatus = qw(new open stalled) unless @ActiveStatus;
 @InactiveStatus = qw(resolved rejected deleted) unless @InactiveStatus;
 
+# Backward compatability setting. Add/Delete Link used to record one
+# transaction and run one scrip. Set this value to 1 if you want
+# both link transactions to have a scrip run.
+Set($LinkTransactionsRun2Scrips , 0);
+
 # }}}
 
 


More information about the Rt-devel mailing list