85
85
#Clean out all the nasties from the environment
88
my ( $search, $condition, $action, $search_arg, $condition_arg, $action_arg,
89
$template, $template_id, $transaction, $transaction_type, $help, $log, $verbose );
91
"search=s" => \$search,
92
"search-arg=s" => \$search_arg,
93
"condition=s" => \$condition,
94
"condition-arg=s" => \$condition_arg,
95
"action-arg=s" => \$action_arg,
96
"action=s" => \$action,
97
"template=s" => \$template,
98
"template-id=s" => \$template_id,
99
"transaction=s" => \$transaction,
100
"transaction-type=s" => \$transaction_type,
102
"verbose|v" => \$verbose,
88
106
# Load the config file
109
# adjust logging to the screen according to options
110
RT->Config->Set( LogToScreen => $log ) if $log;
91
112
#Connect to the database and get RT::SystemUser and RT::Nobody loaded
94
115
#Get the current user all loaded
95
116
my $CurrentUser = GetCurrentUser();
118
# show help even if there is no current user
97
121
unless ( $CurrentUser->Id ) {
98
122
print loc("No RT user found. Please consult your RT administrator.\n");
102
my ( $search, $condition, $action, $search_arg, $condition_arg, $action_arg,
103
$template_id, $transaction, $transaction_type, $help, $verbose );
104
GetOptions( "search=s" => \$search,
105
"search-arg=s" => \$search_arg,
106
"condition=s" => \$condition,
107
"condition-arg=s" => \$condition_arg,
108
"action-arg=s" => \$action_arg,
109
"action=s" => \$action,
110
"template-id=s" => \$template_id,
111
"transaction=s" => \$transaction,
112
"transaction-type=s" => \$transaction_type,
114
"verbose|v" => \$verbose );
116
help() if $help or not $search or not $action;
126
help() unless $search && $action;
118
128
$transaction = lc( $transaction||'' );
119
129
if ( $transaction && $transaction !~ /^(first|all|last)$/i ) {
134
if ( $template && $template_id ) {
135
print STDERR loc("--template-id is deprecated argument and can not be used with --template");
138
elsif ( $template_id ) {
140
$template = $template_id;
124
143
# We _must_ have a search object
125
144
load_module($search);
126
145
load_module($action) if ($action);
127
146
load_module($condition) if ($condition);
129
# load template if specified
132
$template_obj = RT::Template->new($CurrentUser);
133
$template_obj->Load($template_id);
135
148
my $void_scrip = RT::Scrip->new( $CurrentUser );
136
149
my $void_scrip_action = RT::ScripAction->new( $CurrentUser );
154
167
while ( my $ticket = $tickets->Next() ) {
155
168
print $ticket->Id() . ": " if ($verbose);
170
my $template_obj = get_template( $ticket );
157
172
if ( $transaction ) {
158
173
my $txns = get_transactions($ticket);
160
175
while ( my $txn = $txns->Next ) {
161
176
print loc("Using transaction #[_1]...", $txn->id)
163
process($ticket, $txn);
178
process($ticket, $txn, $template_obj);
166
181
print loc("Couldn't find suitable transaction, skipping")
262
Takes a ticket and returns a template according to command line options.
269
return undef unless $template;
271
unless ( $template =~ /\D/ ) {
273
return $cache if $cache;
275
my $cache = RT::Template->new( $RT::SystemUser );
276
$cache->Load( $template );
277
die "Failed to load template '$template'"
282
my $queue = $ticket->Queue;
283
return $cache->{ $queue } if $cache->{ $queue };
285
my $res = RT::Template->new( $RT::SystemUser );
286
$res->LoadQueueTemplate( Queue => $queue, Name => $template );
287
unless ( $res->id ) {
288
$res->LoadGlobalTemplate( $template );
289
die "Failed to load template '$template', either for queue #$queue or global"
292
return $cache->{ $queue } = $res;
244
295
# {{{ load_module
246
297
=head2 load_module
300
351
. loc( "[_1] - An argument to pass to [_2]", "--action-arg", "--action" )
303
. loc( "[_1] - Specify id of the template you want to use", "--template-id" )
354
. loc( "[_1] - Specify name or id of template(s) you want to use", "--template" )
306
357
. loc( "[_1] - Specify if you want to use either 'first', 'last' or 'all' transactions", "--transaction" )