[rt-users] Order of actions on ticket

Schultz, Eric ESchultz at corp.untd.com
Fri Jan 12 16:22:10 EST 2007


> Also, according to the BP Wiki (but not tested by me), scrips are 
> executed in alphanumeric order according to the description. 
> This was a 
> huge surprise to me when I read it a couple of days ago :-) 
> So you might 
> be able to order the scrips by putting numbers in front of them or 
> something.

>From what I can tell, this is purely rumor.  At least, before 3.6.x - I
haven't looked at that code yet.  But certainly not true for 3.4.x or
3.5.x.  The Prepare subroutine in lib/RT/Scrips_Overlay.pm calls
_FindScrips(), which simply gets all of the scrips from the database in
the order in which the database returns them to you.  Whatever you get
from doing a straight query against the backend, you'll get in RT.  They
aren't even ordered by Scrip.id, which I had hoped for.

However, I have modified the Prepare subroutine in
lib/RT/Scrips_Overlay.pm to do just that - ordering by Description.  It
was actually a fairly trivial change.  Here's a patch against the 3.4.3
tree, if I am not mistaken (else, it's 3.4.1 - my production code is
based on that version with selected changes from later versions).

# begin patch -------------------------
@@ -220,9 +220,15 @@

     $self->_FindScrips( Stage => $args{'Stage'}, Type => $args{'Type'}
);

+    my %sorted_scrips = ();
+    while (my $scrip = $self->Next()) {
+       $sorted_scrips{ $scrip->Description() } = $scrip;
+    }

     #Iterate through each script and check it's applicability.
-    while ( my $scrip = $self->Next() ) {
+    foreach my $scripid (sort keys %sorted_scrips) {
+
+       my $scrip = $sorted_scrips{$scripid};

         next
           unless ( $scrip->IsApplicable(
# end patch ---------------------------

In other words, all I did was use a hash to sort the scrips as I stepped
through each one with a while loop, then replaced the while loop with a
foreach.  I had thought about doing a numeric sort (with {$a <=> $b}),
but I figure people can put zeroes in front of their numbers for
sorting.  Enjoy!

Eric Schultz
United Online



More information about the rt-users mailing list