[Rt-commit] r17087 - rt/3.8/trunk/lib/RT

clkao at bestpractical.com clkao at bestpractical.com
Wed Dec 3 08:53:58 EST 2008


Author: clkao
Date: Wed Dec  3 08:53:57 2008
New Revision: 17087

Modified:
   rt/3.8/trunk/lib/RT/Record.pm

Log:
Refactor AllDependedOnBy so we have AllDependsOn as well.

Modified: rt/3.8/trunk/lib/RT/Record.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Record.pm	(original)
+++ rt/3.8/trunk/lib/RT/Record.pm	Wed Dec  3 08:53:57 2008
@@ -1095,27 +1095,54 @@
 
 sub AllDependedOnBy {
     my $self = shift;
-    my $dep = $self->DependedOnBy;
+    return $self->_AllLinkedTickets( LinkType => 'DependsOn',
+                                     Direction => 'Target', @_ );
+}
+
+=head2 AllDependsOn
+
+Returns an array of RT::Ticket objects which this ticket (directly or
+indirectly) depends on; takes an optional 'Type' argument in the param
+hash, which will limit returned tickets to that type, as well as cause
+tickets with that type to serve as 'leaf' nodes that stops the
+recursive dependency search.
+
+=cut
+
+sub AllDependsOn {
+    my $self = shift;
+    return $self->_AllLinkedTickets( LinkType => 'DependsOn',
+                                     Direction => 'Base', @_ );
+}
+
+sub _AllLinkedTickets {
+    my $self = shift;
+
     my %args = (
+        LinkType  => undef,
+        Direction => undef,
         Type   => undef,
 	_found => {},
 	_top   => 1,
         @_
     );
 
+    my $dep = $self->_Links( $args{Direction}, $args{LinkType});
     while (my $link = $dep->Next()) {
-	next unless ($link->BaseURI->IsLocal());
-	next if $args{_found}{$link->BaseObj->Id};
+        my $uri = $args{Direction} eq 'Target' ? $link->BaseURI : $link->TargetURI;
+	next unless ($uri->IsLocal());
+        my $obj = $args{Direction} eq 'Target' ? $link->BaseObj : $link->TargetObj;
+	next if $args{_found}{$obj->Id};
 
 	if (!$args{Type}) {
-	    $args{_found}{$link->BaseObj->Id} = $link->BaseObj;
-	    $link->BaseObj->AllDependedOnBy( %args, _top => 0 );
+	    $args{_found}{$obj->Id} = $obj;
+	    $obj->_AllLinkedTickets( %args, _top => 0 );
 	}
-	elsif ($link->BaseObj->Type eq $args{Type}) {
-	    $args{_found}{$link->BaseObj->Id} = $link->BaseObj;
+	elsif ($obj->Type eq $args{Type}) {
+	    $args{_found}{$obj->Id} = $obj;
 	}
 	else {
-	    $link->BaseObj->AllDependedOnBy( %args, _top => 0 );
+	    $obj->_AllLinkedTickets( %args, _top => 0 );
 	}
     }
 


More information about the Rt-commit mailing list