");
if ($Search) {
my $load_module = sub {
my $modname = $_[0];
$modname =~ s{::}{/}g;
require "$modname.pm" or die (
loc( "Failed to load module [_1]. ([_2])", $_[0], $@ ) . "\n"
);
};
$m->print(loc("Starting..."), "
");
eval {
$load_module->($Search);
$load_module->($Action) if $Action;
$load_module->($Condition) if $Condition;
if ($TemplateId and !$TemplateObj) {
$TemplateObj = RT::Template->new($RT::Nobody);
$TemplateObj->LoadById($TemplateId);
}
my $tickets = RT::Tickets->new($RT::SystemUser);
my $search = $Search->new( TicketsObj => $tickets, Argument => $SearchArg );
$search->Prepare;
my $tickets_found = $search->TicketsObj;
#for each ticket we've found
while ( my $ticket = $tickets_found->Next ) {
$m->print("
" . $ticket->Id . ": ") if $Verbose;
$m->print(loc("Checking...")) if $Verbose;
# perform some more advanced check
if ($Condition) {
my $ConditionObj = $Condition->new(
TicketObj => $ticket,
Argument => $ConditionArg
);
# if the condition doesn't apply, get out of here
next unless ( $ConditionObj->IsApplicable );
$m->print(loc("Condition matches...")) if $Verbose;
}
if ($Action) {
#prepare our action
my $ActionObj = $Action->new(
TicketObj => $ticket,
TemplateObj => $TemplateObj,
Argument => $ActionArg
);
#if our preparation, move onto the next ticket
next unless ( $ActionObj->Prepare );
$m->print(loc("Action prepared...")) if $Verbose;
#commit our action.
next unless ( $ActionObj->Commit );
$m->print(loc("Action committed.")) if $Verbose;
}
}
};
$m->print('