]> git.uio.no Git - usit-rt.git/blob - lib/RT/ScripAction.pm
Putting 4.2.0 on top of 4.0.17
[usit-rt.git] / lib / RT / ScripAction.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2 #
3 # COPYRIGHT:
4 #
5 # This software is Copyright (c) 1996-2013 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::ScripAction - RT Action object
52
53 =head1 DESCRIPTION
54
55 This module should never be called directly by client code. it's an
56 internal module which should only be accessed through exported APIs
57 in other modules.
58
59 =cut
60
61
62 package RT::ScripAction;
63
64 use strict;
65 use warnings;
66
67 use base 'RT::Record';
68
69 sub Table {'ScripActions'}
70
71 use RT::Template;
72
73 sub _Accessible  {
74     my $self = shift;
75     my %Cols = (
76         Name  => 'read',
77         Description => 'read',
78         ExecModule  => 'read',
79         Argument  => 'read',
80         Creator => 'read/auto',
81         Created => 'read/auto',
82         LastUpdatedBy => 'read/auto',
83         LastUpdated => 'read/auto'
84     );
85     return($self->SUPER::_Accessible(@_, %Cols));
86 }
87
88
89 =head1 METHODS
90
91 =head2 Create
92
93 Takes a hash. Creates a new Action entry.
94
95 =cut
96
97 sub Create  {
98     my $self = shift;
99     #TODO check these args and do smart things.
100     return($self->SUPER::Create(@_));
101 }
102
103 sub Delete  {
104     my $self = shift;
105     return (0, "ScripAction->Delete not implemented");
106 }
107
108
109 =head2 Load IDENTIFIER
110
111 Loads an action by its Name.
112
113 Returns: Id, Error Message
114
115 =cut
116
117 sub Load  {
118     my $self = shift;
119     my $identifier = shift;
120
121     if (!$identifier) {
122         return wantarray ? (0, $self->loc('Input error')) : 0;
123     }
124
125     my ($ok, $msg);
126     if ($identifier !~ /\D/) {
127         ($ok, $msg) = $self->SUPER::Load($identifier);
128     }
129     else {
130         ($ok, $msg) = $self->LoadByCol('Name', $identifier);
131     }
132
133     if (@_) {
134         RT->Deprecated(
135             Arguments => "Template as second argument",
136             Remove    => "4.4",
137         );
138         $self->{'Template'} = shift;
139     }
140
141     return wantarray ? ($ok, $msg) : $ok;
142 }
143
144
145 =head2 LoadAction HASH
146
147 Takes a hash consisting of TicketObj and TransactionObj.  Loads an RT::Action:: module.
148
149 =cut
150
151 sub LoadAction  {
152     my $self = shift;
153     my %args = (
154         TransactionObj => undef,
155         TicketObj => undef,
156         ScripObj => undef,
157         @_
158     );
159
160     # XXX: this whole block goes with TemplateObj method
161     unless ( @_ && exists $args{'TemplateObj'} ) {
162         local $self->{_TicketObj} = $args{TicketObj};
163         $args{'TemplateObj'} = $self->TemplateObj;
164     }
165     else {
166         $self->{'TemplateObj'} = $args{'TemplateObj'};
167     }
168
169     $self->ExecModule =~ /^(\w+)$/;
170     my $module = $1;
171     my $type = "RT::Action::". $module;
172
173     eval "require $type" || die "Require of $type failed.\n$@\n";
174
175     return $self->{'Action'} = $type->new(
176         %args,
177         Argument       => $self->Argument,
178         CurrentUser    => $self->CurrentUser,
179         ScripActionObj => $self,
180     );
181 }
182
183
184 =head2 TemplateObj
185
186 Return this action's template object.  Deprecated.
187
188 =cut
189
190 sub TemplateObj {
191     my $self = shift;
192     RT->Deprecated(
193         Remove => "4.4",
194     );
195
196     return undef unless $self->{Template};
197     if ( !$self->{'TemplateObj'} ) {
198         $self->{'TemplateObj'} = RT::Template->new( $self->CurrentUser );
199         $self->{'TemplateObj'}->Load( $self->{'Template'} );
200
201         if ( ( $self->{'TemplateObj'}->__Value('Queue') == 0 )
202             && $self->{'_TicketObj'} ) {
203             my $tmptemplate = RT::Template->new( $self->CurrentUser );
204             my ( $ok, $err ) = $tmptemplate->LoadQueueTemplate(
205                 Queue => $self->{'_TicketObj'}->QueueObj->id,
206                 Name  => $self->{'TemplateObj'}->Name);
207
208             if ( $tmptemplate->id ) {
209                 # found the queue-specific template with the same name
210                 $self->{'TemplateObj'} = $tmptemplate;
211             }
212         }
213
214     }
215
216     return ( $self->{'TemplateObj'} );
217 }
218
219 sub Prepare  {
220     my $self = shift;
221     $self->{_Message_ID} = 0;
222     return $self->Action->Prepare( @_ );
223 }
224
225 sub Commit  {
226     my $self = shift;
227     return $self->Action->Commit( @_ );
228 }
229
230 sub Describe  {
231     my $self = shift;
232     return $self->Action->Describe( @_ );
233 }
234
235 =head2 Action
236
237 Return the actual RT::Action object for this scrip.
238
239 =cut
240
241 sub Action {
242     my $self = shift;
243     return $self->{'Action'};
244 }
245
246 =head2 id
247
248 Returns the current value of id.
249 (In the database, id is stored as int(11).)
250
251
252 =head2 Name
253
254 Returns the current value of Name.
255 (In the database, Name is stored as varchar(200).)
256
257 =head2 SetName VALUE
258
259 Set Name to VALUE.
260 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
261 (In the database, Name will be stored as a varchar(200).)
262
263
264 =head2 Description
265
266 Returns the current value of Description.
267 (In the database, Description is stored as varchar(255).)
268
269 =head2 SetDescription VALUE
270
271 Set Description to VALUE.
272 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
273 (In the database, Description will be stored as a varchar(255).)
274
275
276 =head2 ExecModule
277
278 Returns the current value of ExecModule.
279 (In the database, ExecModule is stored as varchar(60).)
280
281 =head2 SetExecModule VALUE
282
283 Set ExecModule to VALUE.
284 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
285 (In the database, ExecModule will be stored as a varchar(60).)
286
287
288 =head2 Argument
289
290 Returns the current value of Argument.
291 (In the database, Argument is stored as varbinary(255).)
292
293 =head2 SetArgument VALUE
294
295 Set Argument to VALUE.
296 Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
297 (In the database, Argument will be stored as a varbinary(255).)
298
299
300 =head2 Creator
301
302 Returns the current value of Creator.
303 (In the database, Creator is stored as int(11).)
304
305 =head2 Created
306
307 Returns the current value of Created.
308 (In the database, Created is stored as datetime.)
309
310 =head2 LastUpdatedBy
311
312 Returns the current value of LastUpdatedBy.
313 (In the database, LastUpdatedBy is stored as int(11).)
314
315 =head2 LastUpdated
316
317 Returns the current value of LastUpdated.
318 (In the database, LastUpdated is stored as datetime.)
319
320 =cut
321
322
323 sub _CoreAccessible {
324     {
325
326         id =>
327                 {read => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
328         Name =>
329                 {read => 1, write => 1, sql_type => 12, length => 200,  is_blob => 0,  is_numeric => 0,  type => 'varchar(200)', default => ''},
330         Description =>
331                 {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varchar(255)', default => ''},
332         ExecModule =>
333                 {read => 1, write => 1, sql_type => 12, length => 60,  is_blob => 0,  is_numeric => 0,  type => 'varchar(60)', default => ''},
334         Argument =>
335                 {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varbinary(255)', default => ''},
336         Creator =>
337                 {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
338         Created =>
339                 {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
340         LastUpdatedBy =>
341                 {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
342         LastUpdated =>
343                 {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
344
345  }
346 };
347
348 sub PreInflate {
349     my $class = shift;
350     my ($importer, $uid, $data) = @_;
351
352     $class->SUPER::PreInflate( $importer, $uid, $data );
353
354     return not $importer->SkipBy( "Name", $class, $uid, $data );
355 }
356
357 RT::Base->_ImportOverlays();
358
359 1;