~ubuntu-branches/ubuntu/oneiric/request-tracker3.8/oneiric-updates

« back to all changes in this revision

Viewing changes to bin/rt-crontool.in

  • Committer: Bazaar Package Importer
  • Author(s): Dominic Hargreaves, Dominic Hargreaves, Christian Perrier
  • Date: 2009-06-16 21:46:59 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090616214659-5ji9k1n3qyc2br3n
Tags: 3.8.4-1
[ Dominic Hargreaves ]
* Add missing comma in Depends (fixes FTBFS on etch)
* Update debconf translations: pt.po, ja.po, sv.po, it.po, cs.po, ru.po
  (Closes: #519885, #519922, #520603, #520759, #521199, #521926)
* Document preference for not using SQLite in production
  (Closes: #512750)

[ Christian Perrier ]
* Debconf templates and debian/control reviewed by the debian-l10n-
  english team as part of the Smith review project.
  (Closes: #522367, #520959)
* [Debconf translation updates]
  - Japanese. Closes: #522896
  - German. Closes: #520958
  - Portuguese. Closes: #523481
  - Galician. Closes: #524256
  - Galician. Closes: #524256
  - Spanish. Closes: #524449
  - Italian. Closes: #524715
  - Russian. Closes: #524894
  - Swedish. Closes: #525171
  - French. Closes: #525281

[ Dominic Hargreaves ]
* Don't tell dbconfig to comment out unused variables, since this
  breaks MySQL and Postgres database configuration (Closes: #523090)
* Update Standards-Version (no changes)
* Switch dependency on sysklogd to rsyslog (Closes: #526914)
* New upstream release; includes
  - Minor security fix (Closes: #533069)
  - Add missing Postgres index (Closes: #512653)
* Patch webmux.pl to provide a better error message when the wrong
  major version of RT is in @INC (for example in a mod_perl context).
  (Closes: #518692)
* Add some more example Exim 4 configuration (Closes: #238345)
* Don't apply database ACLs in databases managed by dbconfig-common.
* Remove unused ACL patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
#Clean out all the nasties from the environment
86
86
CleanEnv();
87
87
 
 
88
my ( $search, $condition, $action, $search_arg, $condition_arg, $action_arg,
 
89
     $template, $template_id, $transaction, $transaction_type, $help, $log, $verbose );
 
90
GetOptions(
 
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,
 
101
    "log=s"              => \$log,
 
102
    "verbose|v"          => \$verbose,
 
103
    "help"               => \$help,
 
104
);
 
105
 
88
106
# Load the config file
89
107
RT::LoadConfig();
90
108
 
 
109
# adjust logging to the screen according to options
 
110
RT->Config->Set( LogToScreen => $log ) if $log;
 
111
 
91
112
#Connect to the database and get RT::SystemUser and RT::Nobody loaded
92
113
RT::Init();
93
114
 
94
115
#Get the current user all loaded
95
116
my $CurrentUser = GetCurrentUser();
96
117
 
 
118
# show help even if there is no current user
 
119
help() if $help;
 
120
 
97
121
unless ( $CurrentUser->Id ) {
98
122
    print loc("No RT user found. Please consult your RT administrator.\n");
99
123
    exit(1);
100
124
}
101
125
 
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,
113
 
            "help"               => \$help,
114
 
            "verbose|v"          => \$verbose );
115
 
 
116
 
help() if $help or not $search or not $action;
 
126
help() unless $search && $action;
117
127
 
118
128
$transaction = lc( $transaction||'' );
119
129
if ( $transaction && $transaction !~ /^(first|all|last)$/i ) {
121
131
    exit 1;
122
132
}
123
133
 
 
134
if ( $template && $template_id ) {
 
135
    print STDERR loc("--template-id is deprecated argument and can not be used with --template");
 
136
    exit 1;
 
137
}
 
138
elsif ( $template_id ) {
 
139
# don't warn
 
140
    $template = $template_id;
 
141
}
 
142
 
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);
128
147
 
129
 
# load template if specified
130
 
my $template_obj;
131
 
if ($template_id) {
132
 
    $template_obj = RT::Template->new($CurrentUser);
133
 
    $template_obj->Load($template_id);
134
 
}
135
148
my $void_scrip = RT::Scrip->new( $CurrentUser );
136
149
my $void_scrip_action = RT::ScripAction->new( $CurrentUser );
137
150
 
154
167
while ( my $ticket = $tickets->Next() ) {
155
168
    print $ticket->Id() . ": " if ($verbose);
156
169
 
 
170
    my $template_obj = get_template( $ticket );
 
171
 
157
172
    if ( $transaction ) {
158
173
        my $txns = get_transactions($ticket);
159
174
        my $found = 0;
160
175
        while ( my $txn = $txns->Next ) {
161
176
            print loc("Using transaction #[_1]...", $txn->id)
162
177
                if $verbose;
163
 
            process($ticket, $txn);
 
178
            process($ticket, $txn, $template_obj);
164
179
            $found = 1;
165
180
        }
166
181
        print loc("Couldn't find suitable transaction, skipping")
169
184
        print loc("Processing without transaction, some conditions and actions may fail. Consider using --transaction argument")
170
185
            if $verbose;
171
186
 
172
 
        process($ticket);
 
187
        process($ticket, undef, $template_obj);
173
188
    }
174
189
}
175
190
 
176
191
sub process {
177
192
    my $ticket = shift;
178
193
    my $transaction = shift;
 
194
    my $template_obj = shift;
179
195
 
180
196
    # perform some more advanced check
181
197
    if ($condition) {
241
257
    return $txns;
242
258
}
243
259
 
 
260
=head2 get_template
 
261
 
 
262
Takes a ticket and returns a template according to command line options.
 
263
 
 
264
=cut
 
265
 
 
266
{ my $cache = undef;
 
267
sub get_template {
 
268
    my $ticket = shift;
 
269
    return undef unless $template;
 
270
 
 
271
    unless ( $template =~ /\D/ ) {
 
272
        # by id
 
273
        return $cache if $cache;
 
274
 
 
275
        my $cache = RT::Template->new( $RT::SystemUser );
 
276
        $cache->Load( $template );
 
277
        die "Failed to load template '$template'"
 
278
            unless $cache->id;
 
279
        return $cache;
 
280
    }
 
281
 
 
282
    my $queue = $ticket->Queue;
 
283
    return $cache->{ $queue } if $cache->{ $queue };
 
284
 
 
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"
 
290
            unless $res->id;
 
291
    }
 
292
    return $cache->{ $queue } = $res;
 
293
} }
 
294
 
244
295
# {{{ load_module 
245
296
 
246
297
=head2 load_module
300
351
      . loc( "[_1] - An argument to pass to [_2]", "--action-arg", "--action" )
301
352
      . "\n";
302
353
    print "     "
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" )
304
355
      . "\n";
305
356
    print "     "
306
357
      . loc( "[_1] - Specify if you want to use either 'first', 'last' or 'all' transactions", "--transaction" )
309
360
      . loc( "[_1] - Specify the comma separated list of transactions' types you want to use", "--transaction-type" )
310
361
      . "\n";
311
362
    print "     "
 
363
      . loc( "[_1] - Adjust LogToScreen config option", "--log" ) . "\n";
 
364
    print "     "
312
365
      . loc( "[_1] - Output status updates to STDOUT", "--verbose" ) . "\n";
313
366
    print "\n";
314
367
    print "\n";