1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2005 Best Practical Solutions, LLC
6 # <jesse@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 # CONTRIBUTION SUBMISSION POLICY:
30 # (The following paragraph is not intended to limit the rights granted
31 # to you to modify and distribute this software under the terms of
32 # the GNU General Public License and is only of importance to you if
33 # you choose to contribute your changes and enhancements to the
34 # community by submitting them to Best Practical Solutions, LLC.)
36 # By intentionally submitting any modifications, corrections or
37 # derivatives to this work, or any other work intended for use with
38 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
39 # you are the copyright holder for those contributions and you grant
40 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
41 # royalty-free, perpetual, license to use, copy, create derivative
42 # works based on those contributions, and sublicense and distribute
43 # those contributions and any derivatives thereof.
45 # END BPS TAGGED BLOCK }}}
49 RT::Scrips - a collection of RT Scrip objects
63 ok (require RT::Scrips);
73 no warnings qw(redefine);
75 # {{{ sub LimitToQueue
79 Takes a queue id (numerical) as its only argument. Makes sure that
80 Scopes it pulls out apply to this queue (or another that you've selected with
81 another call to this method
89 $self->Limit (ENTRYAGGREGATOR => 'OR',
97 # {{{ sub LimitToGlobal
102 Scopes it pulls out apply to all queues (or another that you've selected with
103 another call to this method or LimitToQueue
111 $self->Limit (ENTRYAGGREGATOR => 'OR',
122 return(new RT::Scrip($self->CurrentUser));
130 Returns the next scrip that this user can see.
138 my $Scrip = $self->SUPER::Next();
139 if ((defined($Scrip)) and (ref($Scrip))) {
141 if ($Scrip->CurrentUserHasRight('ShowScrips')) {
145 #If the user doesn't have the right to show this scrip
147 return($self->Next());
150 #if there never was any scrip
160 Run through the relevant scrips.
167 my %args = ( TicketObj => undef,
169 Transaction => undef,
170 TransactionObj => undef,
175 $self->Prepare(%args);
182 Commit all of this object's prepared scrips
190 foreach my $scrip (@{$self->Prepared}) {
192 $scrip->Commit( TicketObj => $self->{'TicketObj'},
193 TransactionObj => $self->{'TransactionObj'} );
200 Only prepare the scrips, returning an array of the scrips we're interested in
201 in order of preparation, not execution
207 my %args = ( TicketObj => undef,
209 Transaction => undef,
210 TransactionObj => undef,
215 #We're really going to need a non-acled ticket for the scrips to work
216 $self->_SetupSourceObjects( TicketObj => $args{'TicketObj'},
217 Ticket => $args{'Ticket'},
218 TransactionObj => $args{'TransactionObj'},
219 Transaction => $args{'Transaction'} );
222 $self->_FindScrips( Stage => $args{'Stage'}, Type => $args{'Type'} );
225 #Iterate through each script and check it's applicability.
226 while ( my $scrip = $self->Next() ) {
229 unless ( $scrip->IsApplicable(
230 TicketObj => $self->{'TicketObj'},
231 TransactionObj => $self->{'TransactionObj'}
234 #If it's applicable, prepare and commit it
236 unless ( $scrip->Prepare( TicketObj => $self->{'TicketObj'},
237 TransactionObj => $self->{'TransactionObj'}
239 push @{$self->{'prepared_scrips'}}, $scrip;
243 return (@{$self->Prepared});
249 Returns an arrayref of the scrips this object has prepared
256 return ($self->{'prepared_scrips'} || []);
260 # {{{ sup _SetupSourceObjects
262 =head2 _SetupSourceObjects { TicketObj , Ticket, Transaction, TransactionObj }
264 Setup a ticket and transaction for this Scrip collection to work with as it runs through the
265 relevant scrips. (Also to figure out which scrips apply)
272 sub _SetupSourceObjects {
278 Transaction => undef,
279 TransactionObj => undef,
282 if ( ( $self->{'TicketObj'} = $args{'TicketObj'} ) ) {
283 $self->{'TicketObj'}->CurrentUser( $self->CurrentUser );
286 $self->{'TicketObj'} = RT::Ticket->new( $self->CurrentUser );
287 $self->{'TicketObj'}->Load( $args{'Ticket'} )
288 || $RT::Logger->err("$self couldn't load ticket $args{'Ticket'}\n");
291 if ( ( $self->{'TransactionObj'} = $args{'TransactionObj'} ) ) {
292 $self->{'TransactionObj'}->CurrentUser( $self->CurrentUser );
295 $self->{'TransactionObj'} = RT::Transaction->new( $self->CurrentUser );
296 $self->{'TransactionObj'}->Load( $args{'Transaction'} )
297 || $RT::Logger->err( "$self couldn't load transaction $args{'Transaction'}\n");
303 # {{{ sub _FindScrips;
307 Find only the apropriate scrips for whatever we're doing now
319 $self->LimitToQueue( $self->{'TicketObj'}->QueueObj->Id )
320 ; #Limit it to $Ticket->QueueObj->Id
321 $self->LimitToGlobal();
324 $self->Limit( FIELD => "Stage", VALUE => $args{'Stage'} );
326 my $ConditionsAlias = $self->NewAlias('ScripConditions');
330 FIELD1 => 'ScripCondition',
331 ALIAS2 => $ConditionsAlias,
335 #We only want things where the scrip applies to this sort of transaction
336 # TransactionBatch stage can define list of transaction
337 foreach( split /\s*,\s*/, ($args{'Type'} || '') ) {
339 ALIAS => $ConditionsAlias,
340 FIELD => 'ApplicableTransTypes',
343 ENTRYAGGREGATOR => 'OR',
347 # Or where the scrip applies to any transaction
349 ALIAS => $ConditionsAlias,
350 FIELD => 'ApplicableTransTypes',
353 ENTRYAGGREGATOR => 'OR',
356 $RT::Logger->debug("Found ".$self->Count. " scrips");