1 # {{{ BEGIN BPS TAGGED BLOCK
5 # This software is Copyright (c) 1996-2004 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
48 RT::Scrips - a collection of RT Scrip objects
62 ok (require RT::Scrips);
69 no warnings qw(redefine);
71 # {{{ sub LimitToQueue
75 Takes a queue id (numerical) as its only argument. Makes sure that
76 Scopes it pulls out apply to this queue (or another that you've selected with
77 another call to this method
85 $self->Limit (ENTRYAGGREGATOR => 'OR',
93 # {{{ sub LimitToGlobal
98 Scopes it pulls out apply to all queues (or another that you've selected with
99 another call to this method or LimitToQueue
107 $self->Limit (ENTRYAGGREGATOR => 'OR',
118 return(new RT::Scrip($self->CurrentUser));
126 Returns the next scrip that this user can see.
134 my $Scrip = $self->SUPER::Next();
135 if ((defined($Scrip)) and (ref($Scrip))) {
137 if ($Scrip->CurrentUserHasRight('ShowScrips')) {
141 #If the user doesn't have the right to show this scrip
143 return($self->Next());
146 #if there never was any scrip
156 Run through the relevant scrips.
163 my %args = ( TicketObj => undef,
165 Transaction => undef,
166 TransactionObj => undef,
171 $self->Prepare(%args);
178 Commit all of this object's prepared scrips
186 foreach my $scrip (@{$self->Prepared}) {
188 $scrip->Commit( TicketObj => $self->{'TicketObj'},
189 TransactionObj => $self->{'TransactionObj'} );
196 Only prepare the scrips, returning an array of the scrips we're interested in
197 in order of preparation, not execution
203 my %args = ( TicketObj => undef,
205 Transaction => undef,
206 TransactionObj => undef,
211 #We're really going to need a non-acled ticket for the scrips to work
212 $self->_SetupSourceObjects( TicketObj => $args{'TicketObj'},
213 Ticket => $args{'Ticket'},
214 TransactionObj => $args{'TransactionObj'},
215 Transaction => $args{'Transaction'} );
218 $self->_FindScrips( Stage => $args{'Stage'}, Type => $args{'Type'} );
221 #Iterate through each script and check it's applicability.
222 while ( my $scrip = $self->Next() ) {
225 unless ( $scrip->IsApplicable(
226 TicketObj => $self->{'TicketObj'},
227 TransactionObj => $self->{'TransactionObj'}
230 #If it's applicable, prepare and commit it
232 unless ( $scrip->Prepare( TicketObj => $self->{'TicketObj'},
233 TransactionObj => $self->{'TransactionObj'}
235 push @{$self->{'prepared_scrips'}}, $scrip;
239 return (@{$self->Prepared});
245 Returns an arrayref of the scrips this object has prepared
252 return ($self->{'prepared_scrips'} || []);
256 # {{{ sup _SetupSourceObjects
257 =head2 _SetupSourceObjects { TicketObj , Ticket, Transaction, TransactionObj }
259 Setup a ticket and transaction for this Scrip collection to work with as it runs through the
260 relevant scrips. (Also to figure out which scrips apply)
267 sub _SetupSourceObjects {
273 Transaction => undef,
274 TransactionObj => undef,
277 if ( ( $self->{'TicketObj'} = $args{'TicketObj'} ) ) {
278 $self->{'TicketObj'}->CurrentUser( $self->CurrentUser );
281 $self->{'TicketObj'} = RT::Ticket->new( $self->CurrentUser );
282 $self->{'TicketObj'}->Load( $args{'Ticket'} )
283 || $RT::Logger->err("$self couldn't load ticket $args{'Ticket'}\n");
286 if ( ( $self->{'TransactionObj'} = $args{'TransactionObj'} ) ) {
287 $self->{'TransactionObj'}->CurrentUser( $self->CurrentUser );
290 $self->{'TransactionObj'} = RT::Transaction->new( $self->CurrentUser );
291 $self->{'TransactionObj'}->Load( $args{'Transaction'} )
292 || $RT::Logger->err( "$self couldn't load transaction $args{'Transaction'}\n");
298 # {{{ sub _FindScrips;
302 Find only the apropriate scrips for whatever we're doing now
314 $self->LimitToQueue( $self->{'TicketObj'}->QueueObj->Id )
315 ; #Limit it to $Ticket->QueueObj->Id
316 $self->LimitToGlobal()
317 unless $self->{'TicketObj'}->QueueObj->Disabled; # or to "global"
319 $self->Limit( FIELD => "Stage", VALUE => $args{'Stage'} );
321 my $ConditionsAlias = $self->NewAlias('ScripConditions');
325 FIELD1 => 'ScripCondition',
326 ALIAS2 => $ConditionsAlias,
330 #We only want things where the scrip applies to this sort of transaction
332 ALIAS => $ConditionsAlias,
333 FIELD => 'ApplicableTransTypes',
335 VALUE => $args{'Type'},
336 ENTRYAGGREGATOR => 'OR',
340 # Or where the scrip applies to any transaction
342 ALIAS => $ConditionsAlias,
343 FIELD => 'ApplicableTransTypes',
346 ENTRYAGGREGATOR => 'OR',
349 $RT::Logger->debug("Found ".$self->Count. " scrips");