+ # Cache existing ScripCondition, ScripAction, and Template IDs.
+ # Complicated because we don't want to just step on multiple IDs
+ # with the same name.
+ my $cachify = sub {
+ my ($class, $hash) = @_;
+ my $search = $class->new($CurrentUser);
+ $search->UnLimit;
+ while ( my $item = $search->Next ) {
+ my $ids = $hash->{lc($item->Name)} ||= [];
+ if ( $item->Creator == 1 ) { # RT::SystemUser
+ unshift @$ids, $item->Id;
+ }
+ else {
+ push @$ids, $item->Id;
+ }
+ }
+ };
+
+ my (%condition, %action, %template);
+ &$cachify('RT::ScripConditions', \%condition);
+ &$cachify('RT::ScripActions', \%action);
+ &$cachify('RT::Templates', \%template);
+ # $condition{name} = [ ids... ]
+ # with the id of the system-created object first, if there is one
+
+ # ScripConditions
+ my $ScripCondition = RT::ScripCondition->new($CurrentUser);
+ foreach my $sc (@ScripConditions) {
+ # $sc: Name, Description, ApplicableTransTypes, ExecModule, Argument
+ next if exists( $condition{ lc($sc->{Name}) } );
+ my ($val, $msg) = $ScripCondition->Create( %$sc );
+ die $msg if !$val;
+ $condition{ lc($ScripCondition->Name) } = [ $ScripCondition->Id ];
+ }