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