import of rt 3.0.4
[freeside.git] / rt / lib / RT / ScripAction_Overlay.pm
1 # BEGIN LICENSE BLOCK
2
3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4
5 # (Except where explictly superceded by other copyright notices)
6
7 # This work is made available to you under the terms of Version 2 of
8 # the GNU General Public License. A copy of that license should have
9 # been provided with this software, but in any event can be snarfed
10 # from www.gnu.org.
11
12 # This work is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16
17 # Unless otherwise specified, all modifications, corrections or
18 # extensions to this work which alter its source code become the
19 # property of Best Practical Solutions, LLC when submitted for
20 # inclusion in the work.
21
22
23 # END LICENSE BLOCK
24 =head1 NAME
25
26   RT::ScripAction - RT Action object
27
28 =head1 SYNOPSIS
29
30   use RT::ScripAction;
31
32
33 =head1 DESCRIPTION
34
35 This module should never be called directly by client code. it's an internal module which
36 should only be accessed through exported APIs in other modules.
37
38
39 =begin testing
40
41 ok (require RT::ScripAction);
42
43 =end testing
44
45 =head1 METHODS
46
47 =cut
48
49 use strict;
50 no warnings qw(redefine);
51
52 # {{{  sub _Init 
53 sub _Init  {
54     my $self = shift; 
55     $self->{'table'} = "ScripActions";
56     return ($self->SUPER::_Init(@_));
57 }
58 # }}}
59
60 # {{{ sub _Accessible 
61 sub _Accessible  {
62     my $self = shift;
63     my %Cols = ( Name  => 'read',
64                  Description => 'read',
65                  ExecModule  => 'read',
66                  Argument  => 'read',
67                  Creator => 'read/auto',
68                  Created => 'read/auto',
69                  LastUpdatedBy => 'read/auto',
70                  LastUpdated => 'read/auto'
71        );
72     return($self->SUPER::_Accessible(@_, %Cols));
73 }
74 # }}}
75
76 # {{{ sub Create 
77 =head2 Create
78   
79  Takes a hash. Creates a new Action entry.
80  should be better documented.
81 =cut
82
83 sub Create  {
84     my $self = shift;
85     #TODO check these args and do smart things.
86     return($self->SUPER::Create(@_));
87 }
88 # }}}
89
90 # {{{ sub Delete 
91 sub Delete  {
92     my $self = shift;
93     
94     return (0, "ScripAction->Delete not implemented");
95 }
96 # }}}
97
98 # {{{ sub Load 
99 sub Load  {
100     my $self = shift;
101     my $identifier = shift;
102     
103     if (!$identifier) {
104         return (0, $self->loc('Input error'));
105     }       
106     
107     if ($identifier !~ /\D/) {
108         $self->SUPER::Load($identifier);
109     }
110     else {
111         $self->LoadByCol('Name', $identifier);
112         
113     }
114
115     if (@_) {
116         # Set the template Id to the passed in template    
117         my $template = shift;
118         
119         $self->{'Template'} = $template;
120     }
121     return ($self->loc('[_1] ScripAction loaded', $self->Id));
122 }
123 # }}}
124
125 # {{{ sub LoadAction 
126
127 =head2 LoadAction HASH
128
129   Takes a hash consisting of TicketObj and TransactionObj.  Loads an RT::Action:: module.
130
131 =cut
132
133 sub LoadAction  {
134     my $self = shift;
135     my %args = ( TransactionObj => undef,
136                  TicketObj => undef,
137                  @_ );
138     
139     #TODO: Put this in an eval  
140     $self->ExecModule =~ /^(\w+)$/;
141     my $module = $1;
142     my $type = "RT::Action::". $module;
143  
144     eval "require $type" || die "Require of $type failed.\n$@\n";
145     
146     $self->{'Action'}  = $type->new ( 'ScripActionObj' => $self, 
147                                       'TicketObj' => $args{'TicketObj'},
148                                       'ScripObj' => $args{'ScripObj'},
149                                       'TransactionObj' => $args{'TransactionObj'},
150                                       'TemplateObj' => $self->TemplateObj,
151                                       'Argument' => $self->Argument,
152                                     );
153 }
154 # }}}
155
156 # {{{ sub TemplateObj
157
158 =head2 TemplateObj
159
160 Return this action\'s template object
161
162 =cut
163
164 sub TemplateObj {
165     my $self = shift;
166     return undef unless $self->{Template};
167     if (!$self->{'TemplateObj'})  {
168         require RT::Template;
169         $self->{'TemplateObj'} = RT::Template->new($self->CurrentUser);
170         $self->{'TemplateObj'}->LoadById($self->{'Template'});
171         
172     }
173     
174     return ($self->{'TemplateObj'});
175 }
176 # }}}
177
178 # The following methods call the action object
179
180 # {{{ sub Prepare 
181
182 sub Prepare  {
183     my $self = shift;
184     return ($self->{'Action'}->Prepare());
185   
186 }
187 # }}}
188
189 # {{{ sub Commit 
190 sub Commit  {
191     my $self = shift;
192     return($self->{'Action'}->Commit());
193     
194     
195 }
196 # }}}
197
198 # {{{ sub Describe 
199 sub Describe  {
200     my $self = shift;
201     return ($self->{'Action'}->Describe());
202     
203 }
204 # }}}
205
206 # {{{ sub DESTROY
207 sub DESTROY {
208     my $self=shift;
209     $self->{'Action'} = undef;
210     $self->{'TemplateObj'} = undef;
211 }
212 # }}}
213
214
215 1;
216
217