]>
Commit | Line | Data |
---|---|---|
84fb5b46 MKG |
1 | # BEGIN BPS TAGGED BLOCK {{{ |
2 | # | |
3 | # COPYRIGHT: | |
4 | # | |
5 | # This software is Copyright (c) 1996-2012 Best Practical Solutions, LLC | |
6 | # <sales@bestpractical.com> | |
7 | # | |
8 | # (Except where explicitly superseded by other copyright notices) | |
9 | # | |
10 | # | |
11 | # LICENSE: | |
12 | # | |
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 | |
16 | # from www.gnu.org. | |
17 | # | |
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. | |
22 | # | |
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., 51 Franklin Street, Fifth Floor, Boston, MA | |
26 | # 02110-1301 or visit their web page on the internet at | |
27 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. | |
28 | # | |
29 | # | |
30 | # CONTRIBUTION SUBMISSION POLICY: | |
31 | # | |
32 | # (The following paragraph is not intended to limit the rights granted | |
33 | # to you to modify and distribute this software under the terms of | |
34 | # the GNU General Public License and is only of importance to you if | |
35 | # you choose to contribute your changes and enhancements to the | |
36 | # community by submitting them to Best Practical Solutions, LLC.) | |
37 | # | |
38 | # By intentionally submitting any modifications, corrections or | |
39 | # derivatives to this work, or any other work intended for use with | |
40 | # Request Tracker, to Best Practical Solutions, LLC, you confirm that | |
41 | # you are the copyright holder for those contributions and you grant | |
42 | # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, | |
43 | # royalty-free, perpetual, license to use, copy, create derivative | |
44 | # works based on those contributions, and sublicense and distribute | |
45 | # those contributions and any derivatives thereof. | |
46 | # | |
47 | # END BPS TAGGED BLOCK }}} | |
48 | ||
49 | =head1 NAME | |
50 | ||
51 | RT::Scrip - an RT Scrip object | |
52 | ||
53 | =head1 SYNOPSIS | |
54 | ||
55 | use RT::Scrip; | |
56 | ||
57 | =head1 DESCRIPTION | |
58 | ||
59 | ||
60 | =head1 METHODS | |
61 | ||
62 | ||
63 | =cut | |
64 | ||
65 | ||
66 | package RT::Scrip; | |
67 | ||
68 | use strict; | |
69 | use warnings; | |
70 | ||
71 | ||
72 | use RT::Queue; | |
73 | use RT::Template; | |
74 | use RT::ScripCondition; | |
75 | use RT::ScripAction; | |
76 | use base 'RT::Record'; | |
77 | ||
78 | sub Table {'Scrips'} | |
79 | ||
80 | # {{{ sub Create | |
81 | ||
82 | =head2 Create | |
83 | ||
84 | Creates a new entry in the Scrips table. Takes a paramhash with: | |
85 | ||
86 | Queue => 0, | |
87 | Description => undef, | |
88 | Template => undef, | |
89 | ScripAction => undef, | |
90 | ScripCondition => undef, | |
91 | CustomPrepareCode => undef, | |
92 | CustomCommitCode => undef, | |
93 | CustomIsApplicableCode => undef, | |
94 | ||
95 | ||
96 | ||
97 | ||
98 | Returns (retval, msg); | |
99 | retval is 0 for failure or scrip id. msg is a textual description of what happened. | |
100 | ||
101 | =cut | |
102 | ||
103 | sub Create { | |
104 | my $self = shift; | |
105 | my %args = ( | |
106 | Queue => 0, | |
107 | Template => 0, # name or id | |
108 | ScripAction => 0, # name or id | |
109 | ScripCondition => 0, # name or id | |
110 | Stage => 'TransactionCreate', | |
111 | Description => undef, | |
112 | CustomPrepareCode => undef, | |
113 | CustomCommitCode => undef, | |
114 | CustomIsApplicableCode => undef, | |
115 | @_ | |
116 | ); | |
117 | ||
118 | if ($args{CustomPrepareCode} || $args{CustomCommitCode} || $args{CustomIsApplicableCode}) { | |
119 | unless ( $self->CurrentUser->HasRight( Object => $RT::System, | |
120 | Right => 'ExecuteCode' ) ) | |
121 | { | |
122 | return ( 0, $self->loc('Permission Denied') ); | |
123 | } | |
124 | } | |
125 | ||
126 | unless ( $args{'Queue'} ) { | |
127 | unless ( $self->CurrentUser->HasRight( Object => $RT::System, | |
128 | Right => 'ModifyScrips' ) ) | |
129 | { | |
130 | return ( 0, $self->loc('Permission Denied') ); | |
131 | } | |
132 | $args{'Queue'} = 0; # avoid undef sneaking in | |
133 | } | |
134 | else { | |
135 | my $QueueObj = RT::Queue->new( $self->CurrentUser ); | |
136 | $QueueObj->Load( $args{'Queue'} ); | |
137 | unless ( $QueueObj->id ) { | |
138 | return ( 0, $self->loc('Invalid queue') ); | |
139 | } | |
140 | unless ( $QueueObj->CurrentUserHasRight('ModifyScrips') ) { | |
141 | return ( 0, $self->loc('Permission Denied') ); | |
142 | } | |
143 | $args{'Queue'} = $QueueObj->id; | |
144 | } | |
145 | ||
146 | #TODO +++ validate input | |
147 | ||
148 | require RT::ScripAction; | |
149 | return ( 0, $self->loc("Action is mandatory argument") ) | |
150 | unless $args{'ScripAction'}; | |
151 | my $action = RT::ScripAction->new( $self->CurrentUser ); | |
152 | $action->Load( $args{'ScripAction'} ); | |
153 | return ( 0, $self->loc( "Action '[_1]' not found", $args{'ScripAction'} ) ) | |
154 | unless $action->Id; | |
155 | ||
156 | require RT::Template; | |
157 | return ( 0, $self->loc("Template is mandatory argument") ) | |
158 | unless $args{'Template'}; | |
159 | my $template = RT::Template->new( $self->CurrentUser ); | |
160 | $template->Load( $args{'Template'} ); | |
161 | return ( 0, $self->loc( "Template '[_1]' not found", $args{'Template'} ) ) | |
162 | unless $template->Id; | |
163 | ||
164 | require RT::ScripCondition; | |
165 | return ( 0, $self->loc("Condition is mandatory argument") ) | |
166 | unless $args{'ScripCondition'}; | |
167 | my $condition = RT::ScripCondition->new( $self->CurrentUser ); | |
168 | $condition->Load( $args{'ScripCondition'} ); | |
169 | return ( 0, $self->loc( "Condition '[_1]' not found", $args{'ScripCondition'} ) ) | |
170 | unless $condition->Id; | |
171 | ||
172 | my ( $id, $msg ) = $self->SUPER::Create( | |
173 | Queue => $args{'Queue'}, | |
174 | Template => $template->Id, | |
175 | ScripCondition => $condition->id, | |
176 | Stage => $args{'Stage'}, | |
177 | ScripAction => $action->Id, | |
178 | Description => $args{'Description'}, | |
179 | CustomPrepareCode => $args{'CustomPrepareCode'}, | |
180 | CustomCommitCode => $args{'CustomCommitCode'}, | |
181 | CustomIsApplicableCode => $args{'CustomIsApplicableCode'}, | |
182 | ); | |
183 | if ( $id ) { | |
184 | return ( $id, $self->loc('Scrip Created') ); | |
185 | } | |
186 | else { | |
187 | return ( $id, $msg ); | |
188 | } | |
189 | } | |
190 | ||
191 | ||
192 | ||
193 | =head2 Delete | |
194 | ||
195 | Delete this object | |
196 | ||
197 | =cut | |
198 | ||
199 | sub Delete { | |
200 | my $self = shift; | |
201 | ||
202 | unless ( $self->CurrentUserHasRight('ModifyScrips') ) { | |
203 | return ( 0, $self->loc('Permission Denied') ); | |
204 | } | |
205 | ||
206 | return ( $self->SUPER::Delete(@_) ); | |
207 | } | |
208 | ||
209 | ||
210 | ||
211 | =head2 QueueObj | |
212 | ||
213 | Retuns an RT::Queue object with this Scrip's queue | |
214 | ||
215 | =cut | |
216 | ||
217 | sub QueueObj { | |
218 | my $self = shift; | |
219 | ||
220 | if ( !$self->{'QueueObj'} ) { | |
221 | require RT::Queue; | |
222 | $self->{'QueueObj'} = RT::Queue->new( $self->CurrentUser ); | |
223 | $self->{'QueueObj'}->Load( $self->__Value('Queue') ); | |
224 | } | |
225 | return ( $self->{'QueueObj'} ); | |
226 | } | |
227 | ||
228 | ||
229 | ||
230 | =head2 ActionObj | |
231 | ||
232 | Retuns an RT::Action object with this Scrip\'s Action | |
233 | ||
234 | =cut | |
235 | ||
236 | sub ActionObj { | |
237 | my $self = shift; | |
238 | ||
239 | unless ( defined $self->{'ScripActionObj'} ) { | |
240 | require RT::ScripAction; | |
241 | ||
242 | $self->{'ScripActionObj'} = RT::ScripAction->new( $self->CurrentUser ); | |
243 | ||
244 | #TODO: why are we loading Actions with templates like this. | |
245 | # two separate methods might make more sense | |
246 | $self->{'ScripActionObj'}->Load( $self->ScripAction, $self->Template ); | |
247 | } | |
248 | return ( $self->{'ScripActionObj'} ); | |
249 | } | |
250 | ||
251 | ||
252 | ||
253 | =head2 ConditionObj | |
254 | ||
255 | Retuns an L<RT::ScripCondition> object with this Scrip's IsApplicable | |
256 | ||
257 | =cut | |
258 | ||
259 | sub ConditionObj { | |
260 | my $self = shift; | |
261 | ||
262 | my $res = RT::ScripCondition->new( $self->CurrentUser ); | |
263 | $res->Load( $self->ScripCondition ); | |
264 | return $res; | |
265 | } | |
266 | ||
267 | ||
268 | =head2 LoadModules | |
269 | ||
270 | Loads scrip's condition and action modules. | |
271 | ||
272 | =cut | |
273 | ||
274 | sub LoadModules { | |
275 | my $self = shift; | |
276 | ||
277 | $self->ConditionObj->LoadCondition; | |
278 | $self->ActionObj->LoadAction; | |
279 | } | |
280 | ||
281 | ||
282 | =head2 TemplateObj | |
283 | ||
284 | Retuns an RT::Template object with this Scrip\'s Template | |
285 | ||
286 | =cut | |
287 | ||
288 | sub TemplateObj { | |
289 | my $self = shift; | |
290 | ||
291 | unless ( defined $self->{'TemplateObj'} ) { | |
292 | require RT::Template; | |
293 | $self->{'TemplateObj'} = RT::Template->new( $self->CurrentUser ); | |
294 | $self->{'TemplateObj'}->Load( $self->Template ); | |
295 | } | |
296 | return ( $self->{'TemplateObj'} ); | |
297 | } | |
298 | ||
299 | ||
300 | ||
301 | ||
302 | =head2 Apply { TicketObj => undef, TransactionObj => undef} | |
303 | ||
304 | This method instantiates the ScripCondition and ScripAction objects for a | |
305 | single execution of this scrip. it then calls the IsApplicable method of the | |
306 | ScripCondition. | |
307 | If that succeeds, it calls the Prepare method of the | |
308 | ScripAction. If that succeeds, it calls the Commit method of the ScripAction. | |
309 | ||
310 | Usually, the ticket and transaction objects passed to this method | |
311 | should be loaded by the SuperUser role | |
312 | ||
313 | =cut | |
314 | ||
315 | ||
316 | # XXX TODO : This code appears to be obsoleted in favor of similar code in Scrips->Apply. | |
317 | # Why is this here? Is it still called? | |
318 | ||
319 | sub Apply { | |
320 | my $self = shift; | |
321 | my %args = ( TicketObj => undef, | |
322 | TransactionObj => undef, | |
323 | @_ ); | |
324 | ||
325 | $RT::Logger->debug("Now applying scrip ".$self->Id . " for transaction ".$args{'TransactionObj'}->id); | |
326 | ||
327 | my $ApplicableTransactionObj = $self->IsApplicable( TicketObj => $args{'TicketObj'}, | |
328 | TransactionObj => $args{'TransactionObj'} ); | |
329 | unless ( $ApplicableTransactionObj ) { | |
330 | return undef; | |
331 | } | |
332 | ||
333 | if ( $ApplicableTransactionObj->id != $args{'TransactionObj'}->id ) { | |
334 | $RT::Logger->debug("Found an applicable transaction ".$ApplicableTransactionObj->Id . " in the same batch with transaction ".$args{'TransactionObj'}->id); | |
335 | } | |
336 | ||
337 | #If it's applicable, prepare and commit it | |
338 | $RT::Logger->debug("Now preparing scrip ".$self->Id . " for transaction ".$ApplicableTransactionObj->id); | |
339 | unless ( $self->Prepare( TicketObj => $args{'TicketObj'}, | |
340 | TransactionObj => $ApplicableTransactionObj ) | |
341 | ) { | |
342 | return undef; | |
343 | } | |
344 | ||
345 | $RT::Logger->debug("Now commiting scrip ".$self->Id . " for transaction ".$ApplicableTransactionObj->id); | |
346 | unless ( $self->Commit( TicketObj => $args{'TicketObj'}, | |
347 | TransactionObj => $ApplicableTransactionObj) | |
348 | ) { | |
349 | return undef; | |
350 | } | |
351 | ||
352 | $RT::Logger->debug("We actually finished scrip ".$self->Id . " for transaction ".$ApplicableTransactionObj->id); | |
353 | return (1); | |
354 | ||
355 | } | |
356 | ||
357 | ||
358 | ||
359 | =head2 IsApplicable | |
360 | ||
361 | Calls the Condition object\'s IsApplicable method | |
362 | ||
363 | Upon success, returns the applicable Transaction object. | |
364 | Otherwise, undef is returned. | |
365 | ||
366 | If the Scrip is in the TransactionCreate Stage (the usual case), only test | |
367 | the associated Transaction object to see if it is applicable. | |
368 | ||
369 | For Scrips in the TransactionBatch Stage, test all Transaction objects | |
370 | created during the Ticket object's lifetime, and returns the first one | |
371 | that is applicable. | |
372 | ||
373 | =cut | |
374 | ||
375 | sub IsApplicable { | |
376 | my $self = shift; | |
377 | my %args = ( TicketObj => undef, | |
378 | TransactionObj => undef, | |
379 | @_ ); | |
380 | ||
381 | my $return; | |
382 | eval { | |
383 | ||
384 | my @Transactions; | |
385 | ||
386 | if ( $self->Stage eq 'TransactionCreate') { | |
387 | # Only look at our current Transaction | |
388 | @Transactions = ( $args{'TransactionObj'} ); | |
389 | } | |
390 | elsif ( $self->Stage eq 'TransactionBatch') { | |
391 | # Look at all Transactions in this Batch | |
392 | @Transactions = @{ $args{'TicketObj'}->TransactionBatch || [] }; | |
393 | } | |
394 | else { | |
395 | $RT::Logger->error( "Unknown Scrip stage:" . $self->Stage ); | |
396 | return (undef); | |
397 | } | |
398 | my $ConditionObj = $self->ConditionObj; | |
399 | foreach my $TransactionObj ( @Transactions ) { | |
400 | # in TxnBatch stage we can select scrips that are not applicable to all txns | |
401 | my $txn_type = $TransactionObj->Type; | |
402 | next unless( $ConditionObj->ApplicableTransTypes =~ /(?:^|,)(?:Any|\Q$txn_type\E)(?:,|$)/i ); | |
403 | # Load the scrip's Condition object | |
404 | $ConditionObj->LoadCondition( | |
405 | ScripObj => $self, | |
406 | TicketObj => $args{'TicketObj'}, | |
407 | TransactionObj => $TransactionObj, | |
408 | ); | |
409 | ||
410 | if ( $ConditionObj->IsApplicable() ) { | |
411 | # We found an application Transaction -- return it | |
412 | $return = $TransactionObj; | |
413 | last; | |
414 | } | |
415 | } | |
416 | }; | |
417 | ||
418 | if ($@) { | |
419 | $RT::Logger->error( "Scrip IsApplicable " . $self->Id . " died. - " . $@ ); | |
420 | return (undef); | |
421 | } | |
422 | ||
423 | return ($return); | |
424 | ||
425 | } | |
426 | ||
427 | ||
428 | ||
429 | =head2 Prepare | |
430 | ||
431 | Calls the action object's prepare method | |
432 | ||
433 | =cut | |
434 | ||
435 | sub Prepare { | |
436 | my $self = shift; | |
437 | my %args = ( TicketObj => undef, | |
438 | TransactionObj => undef, | |
439 | @_ ); | |
440 | ||
441 | my $return; | |
442 | eval { | |
443 | $self->ActionObj->LoadAction( ScripObj => $self, | |
444 | TicketObj => $args{'TicketObj'}, | |
445 | TransactionObj => $args{'TransactionObj'}, | |
446 | ); | |
447 | ||
448 | $return = $self->ActionObj->Prepare(); | |
449 | }; | |
450 | if ($@) { | |
451 | $RT::Logger->error( "Scrip Prepare " . $self->Id . " died. - " . $@ ); | |
452 | return (undef); | |
453 | } | |
454 | unless ($return) { | |
455 | } | |
456 | return ($return); | |
457 | } | |
458 | ||
459 | ||
460 | ||
461 | =head2 Commit | |
462 | ||
463 | Calls the action object's commit method | |
464 | ||
465 | =cut | |
466 | ||
467 | sub Commit { | |
468 | my $self = shift; | |
469 | my %args = ( TicketObj => undef, | |
470 | TransactionObj => undef, | |
471 | @_ ); | |
472 | ||
473 | my $return; | |
474 | eval { | |
475 | $return = $self->ActionObj->Commit(); | |
476 | }; | |
477 | ||
478 | #Searchbuilder caching isn't perfectly coherent. got to reload the ticket object, since it | |
479 | # may have changed | |
480 | $args{'TicketObj'}->Load( $args{'TicketObj'}->Id ); | |
481 | ||
482 | if ($@) { | |
483 | $RT::Logger->error( "Scrip Commit " . $self->Id . " died. - " . $@ ); | |
484 | return (undef); | |
485 | } | |
486 | ||
487 | # Not destroying or weakening hte Action and Condition here could cause a | |
488 | # leak | |
489 | ||
490 | return ($return); | |
491 | } | |
492 | ||
493 | ||
494 | ||
495 | ||
496 | ||
497 | # does an acl check and then passes off the call | |
498 | sub _Set { | |
499 | my $self = shift; | |
500 | my %args = ( | |
501 | Field => undef, | |
502 | Value => undef, | |
503 | @_, | |
504 | ); | |
505 | ||
506 | unless ( $self->CurrentUserHasRight('ModifyScrips') ) { | |
507 | $RT::Logger->debug( | |
508 | "CurrentUser can't modify Scrips for " . $self->Queue . "\n" ); | |
509 | return ( 0, $self->loc('Permission Denied') ); | |
510 | } | |
511 | ||
512 | ||
513 | if (exists $args{Value}) { | |
514 | if ($args{Field} eq 'CustomIsApplicableCode' || $args{Field} eq 'CustomPrepareCode' || $args{Field} eq 'CustomCommitCode') { | |
515 | unless ( $self->CurrentUser->HasRight( Object => $RT::System, | |
516 | Right => 'ExecuteCode' ) ) { | |
517 | return ( 0, $self->loc('Permission Denied') ); | |
518 | } | |
519 | } | |
520 | elsif ($args{Field} eq 'Queue') { | |
521 | if ($args{Value}) { | |
522 | # moving to another queue | |
523 | my $queue = RT::Queue->new( $self->CurrentUser ); | |
524 | $queue->Load($args{Value}); | |
525 | unless ($queue->Id and $queue->CurrentUserHasRight('ModifyScrips')) { | |
526 | return ( 0, $self->loc('Permission Denied') ); | |
527 | } | |
528 | } else { | |
529 | # moving to global | |
530 | unless ($self->CurrentUser->HasRight( Object => RT->System, Right => 'ModifyScrips' )) { | |
531 | return ( 0, $self->loc('Permission Denied') ); | |
532 | } | |
533 | } | |
534 | } | |
535 | elsif ($args{Field} eq 'Template') { | |
536 | my $template = RT::Template->new( $self->CurrentUser ); | |
537 | $template->Load($args{Value}); | |
538 | unless ($template->Id and $template->CurrentUserCanRead) { | |
539 | return ( 0, $self->loc('Permission Denied') ); | |
540 | } | |
541 | } | |
542 | } | |
543 | ||
dab09ea8 | 544 | return $self->SUPER::_Set(@_); |
84fb5b46 MKG |
545 | } |
546 | ||
547 | ||
548 | # does an acl check and then passes off the call | |
549 | sub _Value { | |
550 | my $self = shift; | |
551 | ||
552 | unless ( $self->CurrentUserHasRight('ShowScrips') ) { | |
553 | $RT::Logger->debug( "CurrentUser can't modify Scrips for " | |
554 | . $self->__Value('Queue') | |
555 | . "\n" ); | |
556 | return (undef); | |
557 | } | |
558 | ||
559 | return $self->__Value(@_); | |
560 | } | |
561 | ||
562 | ||
563 | ||
564 | =head2 CurrentUserHasRight | |
565 | ||
566 | Helper menthod for HasRight. Presets Principal to CurrentUser then | |
567 | calls HasRight. | |
568 | ||
569 | =cut | |
570 | ||
571 | sub CurrentUserHasRight { | |
572 | my $self = shift; | |
573 | my $right = shift; | |
574 | return ( $self->HasRight( Principal => $self->CurrentUser->UserObj, | |
575 | Right => $right ) ); | |
576 | ||
577 | } | |
578 | ||
579 | ||
580 | ||
581 | =head2 HasRight | |
582 | ||
583 | Takes a param-hash consisting of "Right" and "Principal" Principal is | |
584 | an RT::User object or an RT::CurrentUser object. "Right" is a textual | |
585 | Right string that applies to Scrips. | |
586 | ||
587 | =cut | |
588 | ||
589 | sub HasRight { | |
590 | my $self = shift; | |
591 | my %args = ( Right => undef, | |
592 | Principal => undef, | |
593 | @_ ); | |
594 | ||
595 | if ( $self->SUPER::_Value('Queue') ) { | |
596 | return $args{'Principal'}->HasRight( | |
597 | Right => $args{'Right'}, | |
598 | Object => $self->QueueObj | |
599 | ); | |
600 | } | |
601 | else { | |
602 | return $args{'Principal'}->HasRight( | |
603 | Object => $RT::System, | |
604 | Right => $args{'Right'}, | |
605 | ); | |
606 | } | |
607 | } | |
608 | ||
609 | ||
610 | ||
611 | =head2 CompileCheck | |
612 | ||
613 | This routine compile-checks the custom prepare, commit, and is-applicable code | |
614 | to see if they are syntactically valid Perl. We eval them in a codeblock to | |
615 | avoid actually executing the code. | |
616 | ||
617 | If one of the fields has a compile error, only the first is reported. | |
618 | ||
619 | Returns an (ok, message) pair. | |
620 | ||
621 | =cut | |
622 | ||
623 | sub CompileCheck { | |
624 | my $self = shift; | |
625 | ||
626 | for my $method (qw/CustomPrepareCode CustomCommitCode CustomIsApplicableCode/) { | |
627 | my $code = $self->$method; | |
628 | next if !defined($code); | |
629 | ||
630 | do { | |
631 | no strict 'vars'; | |
632 | eval "sub { $code }"; | |
633 | }; | |
634 | next if !$@; | |
635 | ||
636 | my $error = $@; | |
637 | return (0, $self->loc("Couldn't compile [_1] codeblock '[_2]': [_3]", $method, $code, $error)); | |
638 | } | |
639 | } | |
640 | ||
641 | ||
642 | =head2 SetScripAction | |
643 | ||
644 | =cut | |
645 | ||
646 | sub SetScripAction { | |
647 | my $self = shift; | |
648 | my $value = shift; | |
649 | ||
650 | return ( 0, $self->loc("Action is mandatory argument") ) unless $value; | |
651 | ||
652 | require RT::ScripAction; | |
653 | my $action = RT::ScripAction->new( $self->CurrentUser ); | |
654 | $action->Load($value); | |
655 | return ( 0, $self->loc( "Action '[_1]' not found", $value ) ) | |
656 | unless $action->Id; | |
657 | ||
658 | return $self->_Set( Field => 'ScripAction', Value => $action->Id ); | |
659 | } | |
660 | ||
661 | =head2 SetScripCondition | |
662 | ||
663 | =cut | |
664 | ||
665 | sub SetScripCondition { | |
666 | my $self = shift; | |
667 | my $value = shift; | |
668 | ||
669 | return ( 0, $self->loc("Condition is mandatory argument") ) | |
670 | unless $value; | |
671 | ||
672 | require RT::ScripCondition; | |
673 | my $condition = RT::ScripCondition->new( $self->CurrentUser ); | |
674 | $condition->Load($value); | |
675 | ||
676 | return ( 0, $self->loc( "Condition '[_1]' not found", $value ) ) | |
677 | unless $condition->Id; | |
678 | ||
679 | return $self->_Set( Field => 'ScripCondition', Value => $condition->Id ); | |
680 | } | |
681 | ||
682 | =head2 SetTemplate | |
683 | ||
684 | =cut | |
685 | ||
686 | sub SetTemplate { | |
687 | my $self = shift; | |
688 | my $value = shift; | |
689 | ||
690 | return ( 0, $self->loc("Template is mandatory argument") ) unless $value; | |
691 | ||
692 | require RT::Template; | |
693 | my $template = RT::Template->new( $self->CurrentUser ); | |
694 | $template->Load($value); | |
695 | return ( 0, $self->loc( "Template '[_1]' not found", $value ) ) | |
696 | unless $template->Id; | |
697 | ||
698 | return $self->_Set( Field => 'Template', Value => $template->Id ); | |
699 | } | |
700 | ||
701 | 1; | |
702 | ||
703 | ||
704 | ||
705 | ||
706 | ||
707 | ||
708 | =head2 id | |
709 | ||
710 | Returns the current value of id. | |
711 | (In the database, id is stored as int(11).) | |
712 | ||
713 | ||
714 | =cut | |
715 | ||
716 | ||
717 | =head2 Description | |
718 | ||
719 | Returns the current value of Description. | |
720 | (In the database, Description is stored as varchar(255).) | |
721 | ||
722 | ||
723 | ||
724 | =head2 SetDescription VALUE | |
725 | ||
726 | ||
727 | Set Description to VALUE. | |
728 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
729 | (In the database, Description will be stored as a varchar(255).) | |
730 | ||
731 | ||
732 | =cut | |
733 | ||
734 | ||
735 | =head2 ScripCondition | |
736 | ||
737 | Returns the current value of ScripCondition. | |
738 | (In the database, ScripCondition is stored as int(11).) | |
739 | ||
740 | ||
741 | ||
742 | =head2 SetScripCondition VALUE | |
743 | ||
744 | ||
745 | Set ScripCondition to VALUE. | |
746 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
747 | (In the database, ScripCondition will be stored as a int(11).) | |
748 | ||
749 | ||
750 | =cut | |
751 | ||
752 | ||
753 | =head2 ScripConditionObj | |
754 | ||
755 | Returns the ScripCondition Object which has the id returned by ScripCondition | |
756 | ||
757 | ||
758 | =cut | |
759 | ||
760 | sub ScripConditionObj { | |
761 | my $self = shift; | |
762 | my $ScripCondition = RT::ScripCondition->new($self->CurrentUser); | |
763 | $ScripCondition->Load($self->__Value('ScripCondition')); | |
764 | return($ScripCondition); | |
765 | } | |
766 | ||
767 | =head2 ScripAction | |
768 | ||
769 | Returns the current value of ScripAction. | |
770 | (In the database, ScripAction is stored as int(11).) | |
771 | ||
772 | ||
773 | ||
774 | =head2 SetScripAction VALUE | |
775 | ||
776 | ||
777 | Set ScripAction to VALUE. | |
778 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
779 | (In the database, ScripAction will be stored as a int(11).) | |
780 | ||
781 | ||
782 | =cut | |
783 | ||
784 | ||
785 | =head2 ScripActionObj | |
786 | ||
787 | Returns the ScripAction Object which has the id returned by ScripAction | |
788 | ||
789 | ||
790 | =cut | |
791 | ||
792 | sub ScripActionObj { | |
793 | my $self = shift; | |
794 | my $ScripAction = RT::ScripAction->new($self->CurrentUser); | |
795 | $ScripAction->Load($self->__Value('ScripAction')); | |
796 | return($ScripAction); | |
797 | } | |
798 | ||
799 | =head2 ConditionRules | |
800 | ||
801 | Returns the current value of ConditionRules. | |
802 | (In the database, ConditionRules is stored as text.) | |
803 | ||
804 | ||
805 | ||
806 | =head2 SetConditionRules VALUE | |
807 | ||
808 | ||
809 | Set ConditionRules to VALUE. | |
810 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
811 | (In the database, ConditionRules will be stored as a text.) | |
812 | ||
813 | ||
814 | =cut | |
815 | ||
816 | ||
817 | =head2 ActionRules | |
818 | ||
819 | Returns the current value of ActionRules. | |
820 | (In the database, ActionRules is stored as text.) | |
821 | ||
822 | ||
823 | ||
824 | =head2 SetActionRules VALUE | |
825 | ||
826 | ||
827 | Set ActionRules to VALUE. | |
828 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
829 | (In the database, ActionRules will be stored as a text.) | |
830 | ||
831 | ||
832 | =cut | |
833 | ||
834 | ||
835 | =head2 CustomIsApplicableCode | |
836 | ||
837 | Returns the current value of CustomIsApplicableCode. | |
838 | (In the database, CustomIsApplicableCode is stored as text.) | |
839 | ||
840 | ||
841 | ||
842 | =head2 SetCustomIsApplicableCode VALUE | |
843 | ||
844 | ||
845 | Set CustomIsApplicableCode to VALUE. | |
846 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
847 | (In the database, CustomIsApplicableCode will be stored as a text.) | |
848 | ||
849 | ||
850 | =cut | |
851 | ||
852 | ||
853 | =head2 CustomPrepareCode | |
854 | ||
855 | Returns the current value of CustomPrepareCode. | |
856 | (In the database, CustomPrepareCode is stored as text.) | |
857 | ||
858 | ||
859 | ||
860 | =head2 SetCustomPrepareCode VALUE | |
861 | ||
862 | ||
863 | Set CustomPrepareCode to VALUE. | |
864 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
865 | (In the database, CustomPrepareCode will be stored as a text.) | |
866 | ||
867 | ||
868 | =cut | |
869 | ||
870 | ||
871 | =head2 CustomCommitCode | |
872 | ||
873 | Returns the current value of CustomCommitCode. | |
874 | (In the database, CustomCommitCode is stored as text.) | |
875 | ||
876 | ||
877 | ||
878 | =head2 SetCustomCommitCode VALUE | |
879 | ||
880 | ||
881 | Set CustomCommitCode to VALUE. | |
882 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
883 | (In the database, CustomCommitCode will be stored as a text.) | |
884 | ||
885 | ||
886 | =cut | |
887 | ||
888 | ||
889 | =head2 Stage | |
890 | ||
891 | Returns the current value of Stage. | |
892 | (In the database, Stage is stored as varchar(32).) | |
893 | ||
894 | ||
895 | ||
896 | =head2 SetStage VALUE | |
897 | ||
898 | ||
899 | Set Stage to VALUE. | |
900 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
901 | (In the database, Stage will be stored as a varchar(32).) | |
902 | ||
903 | ||
904 | =cut | |
905 | ||
906 | ||
907 | =head2 Queue | |
908 | ||
909 | Returns the current value of Queue. | |
910 | (In the database, Queue is stored as int(11).) | |
911 | ||
912 | ||
913 | ||
914 | =head2 SetQueue VALUE | |
915 | ||
916 | ||
917 | Set Queue to VALUE. | |
918 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
919 | (In the database, Queue will be stored as a int(11).) | |
920 | ||
921 | ||
922 | =cut | |
923 | ||
924 | ||
925 | =head2 Template | |
926 | ||
927 | Returns the current value of Template. | |
928 | (In the database, Template is stored as int(11).) | |
929 | ||
930 | ||
931 | ||
932 | =head2 SetTemplate VALUE | |
933 | ||
934 | ||
935 | Set Template to VALUE. | |
936 | Returns (1, 'Status message') on success and (0, 'Error Message') on failure. | |
937 | (In the database, Template will be stored as a int(11).) | |
938 | ||
939 | ||
940 | =cut | |
941 | ||
942 | ||
943 | =head2 Creator | |
944 | ||
945 | Returns the current value of Creator. | |
946 | (In the database, Creator is stored as int(11).) | |
947 | ||
948 | ||
949 | =cut | |
950 | ||
951 | ||
952 | =head2 Created | |
953 | ||
954 | Returns the current value of Created. | |
955 | (In the database, Created is stored as datetime.) | |
956 | ||
957 | ||
958 | =cut | |
959 | ||
960 | ||
961 | =head2 LastUpdatedBy | |
962 | ||
963 | Returns the current value of LastUpdatedBy. | |
964 | (In the database, LastUpdatedBy is stored as int(11).) | |
965 | ||
966 | ||
967 | =cut | |
968 | ||
969 | ||
970 | =head2 LastUpdated | |
971 | ||
972 | Returns the current value of LastUpdated. | |
973 | (In the database, LastUpdated is stored as datetime.) | |
974 | ||
975 | ||
976 | =cut | |
977 | ||
978 | ||
979 | ||
980 | sub _CoreAccessible { | |
981 | { | |
982 | ||
983 | id => | |
984 | {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''}, | |
985 | Description => | |
986 | {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''}, | |
987 | ScripCondition => | |
988 | {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'}, | |
989 | ScripAction => | |
990 | {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'}, | |
991 | ConditionRules => | |
992 | {read => 1, write => 1, sql_type => -4, length => 0, is_blob => 1, is_numeric => 0, type => 'text', default => ''}, | |
993 | ActionRules => | |
994 | {read => 1, write => 1, sql_type => -4, length => 0, is_blob => 1, is_numeric => 0, type => 'text', default => ''}, | |
995 | CustomIsApplicableCode => | |
996 | {read => 1, write => 1, sql_type => -4, length => 0, is_blob => 1, is_numeric => 0, type => 'text', default => ''}, | |
997 | CustomPrepareCode => | |
998 | {read => 1, write => 1, sql_type => -4, length => 0, is_blob => 1, is_numeric => 0, type => 'text', default => ''}, | |
999 | CustomCommitCode => | |
1000 | {read => 1, write => 1, sql_type => -4, length => 0, is_blob => 1, is_numeric => 0, type => 'text', default => ''}, | |
1001 | Stage => | |
1002 | {read => 1, write => 1, sql_type => 12, length => 32, is_blob => 0, is_numeric => 0, type => 'varchar(32)', default => ''}, | |
1003 | Queue => | |
1004 | {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'}, | |
1005 | Template => | |
1006 | {read => 1, write => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'}, | |
1007 | Creator => | |
1008 | {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'}, | |
1009 | Created => | |
1010 | {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''}, | |
1011 | LastUpdatedBy => | |
1012 | {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'}, | |
1013 | LastUpdated => | |
1014 | {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''}, | |
1015 | ||
1016 | } | |
1017 | }; | |
1018 | ||
1019 | RT::Base->_ImportOverlays(); | |
1020 | ||
1021 | 1; |