Putting 4.2.0 on top of 4.0.17
[usit-rt.git] / lib / RT / ScripAction.pm
CommitLineData
84fb5b46
MKG
1# BEGIN BPS TAGGED BLOCK {{{
2#
3# COPYRIGHT:
4#
403d7b0b 5# This software is Copyright (c) 1996-2013 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
69sub Table {'ScripActions'}
70
84fb5b46
MKG
71use RT::Template;
72
73sub _Accessible {
74 my $self = shift;
af59614d
MKG
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 );
84fb5b46
MKG
85 return($self->SUPER::_Accessible(@_, %Cols));
86}
87
88
af59614d
MKG
89=head1 METHODS
90
84fb5b46
MKG
91=head2 Create
92
af59614d 93Takes a hash. Creates a new Action entry.
84fb5b46
MKG
94
95=cut
96
97sub Create {
98 my $self = shift;
99 #TODO check these args and do smart things.
100 return($self->SUPER::Create(@_));
101}
102
103sub Delete {
104 my $self = shift;
84fb5b46
MKG
105 return (0, "ScripAction->Delete not implemented");
106}
107
108
109=head2 Load IDENTIFIER
110
111Loads an action by its Name.
112
113Returns: Id, Error Message
114
115=cut
116
117sub Load {
118 my $self = shift;
119 my $identifier = shift;
af59614d 120
84fb5b46 121 if (!$identifier) {
af59614d
MKG
122 return wantarray ? (0, $self->loc('Input error')) : 0;
123 }
124
84fb5b46
MKG
125 my ($ok, $msg);
126 if ($identifier !~ /\D/) {
af59614d 127 ($ok, $msg) = $self->SUPER::Load($identifier);
84fb5b46
MKG
128 }
129 else {
af59614d 130 ($ok, $msg) = $self->LoadByCol('Name', $identifier);
84fb5b46
MKG
131 }
132
133 if (@_) {
af59614d
MKG
134 RT->Deprecated(
135 Arguments => "Template as second argument",
136 Remove => "4.4",
137 );
138 $self->{'Template'} = shift;
84fb5b46
MKG
139 }
140
af59614d 141 return wantarray ? ($ok, $msg) : $ok;
84fb5b46
MKG
142}
143
144
145=head2 LoadAction HASH
146
af59614d 147Takes a hash consisting of TicketObj and TransactionObj. Loads an RT::Action:: module.
84fb5b46
MKG
148
149=cut
150
151sub LoadAction {
152 my $self = shift;
af59614d
MKG
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 }
84fb5b46 168
84fb5b46
MKG
169 $self->ExecModule =~ /^(\w+)$/;
170 my $module = $1;
171 my $type = "RT::Action::". $module;
af59614d 172
84fb5b46 173 eval "require $type" || die "Require of $type failed.\n$@\n";
af59614d
MKG
174
175 return $self->{'Action'} = $type->new(
176 %args,
177 Argument => $self->Argument,
178 CurrentUser => $self->CurrentUser,
179 ScripActionObj => $self,
180 );
84fb5b46
MKG
181}
182
183
184=head2 TemplateObj
185
af59614d 186Return this action's template object. Deprecated.
84fb5b46
MKG
187
188=cut
189
190sub TemplateObj {
191 my $self = shift;
af59614d
MKG
192 RT->Deprecated(
193 Remove => "4.4",
194 );
195
84fb5b46
MKG
196 return undef unless $self->{Template};
197 if ( !$self->{'TemplateObj'} ) {
198 $self->{'TemplateObj'} = RT::Template->new( $self->CurrentUser );
af59614d 199 $self->{'TemplateObj'}->Load( $self->{'Template'} );
84fb5b46
MKG
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
84fb5b46
MKG
219sub Prepare {
220 my $self = shift;
221 $self->{_Message_ID} = 0;
af59614d 222 return $self->Action->Prepare( @_ );
84fb5b46
MKG
223}
224
225sub Commit {
226 my $self = shift;
af59614d 227 return $self->Action->Commit( @_ );
84fb5b46
MKG
228}
229
230sub Describe {
231 my $self = shift;
af59614d 232 return $self->Action->Describe( @_ );
84fb5b46
MKG
233}
234
235=head2 Action
236
237Return the actual RT::Action object for this scrip.
238
239=cut
240
241sub Action {
242 my $self = shift;
af59614d 243 return $self->{'Action'};
84fb5b46
MKG
244}
245
84fb5b46
MKG
246=head2 id
247
248Returns the current value of id.
249(In the database, id is stored as int(11).)
250
251
84fb5b46
MKG
252=head2 Name
253
254Returns the current value of Name.
255(In the database, Name is stored as varchar(200).)
256
84fb5b46
MKG
257=head2 SetName VALUE
258
84fb5b46
MKG
259Set Name to VALUE.
260Returns (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
84fb5b46
MKG
264=head2 Description
265
266Returns the current value of Description.
267(In the database, Description is stored as varchar(255).)
268
84fb5b46
MKG
269=head2 SetDescription VALUE
270
84fb5b46
MKG
271Set Description to VALUE.
272Returns (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
84fb5b46
MKG
276=head2 ExecModule
277
278Returns the current value of ExecModule.
279(In the database, ExecModule is stored as varchar(60).)
280
84fb5b46
MKG
281=head2 SetExecModule VALUE
282
84fb5b46
MKG
283Set ExecModule to VALUE.
284Returns (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
84fb5b46
MKG
288=head2 Argument
289
290Returns the current value of Argument.
291(In the database, Argument is stored as varbinary(255).)
292
84fb5b46
MKG
293=head2 SetArgument VALUE
294
84fb5b46
MKG
295Set Argument to VALUE.
296Returns (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
84fb5b46
MKG
300=head2 Creator
301
302Returns the current value of Creator.
303(In the database, Creator is stored as int(11).)
304
84fb5b46
MKG
305=head2 Created
306
307Returns the current value of Created.
308(In the database, Created is stored as datetime.)
309
84fb5b46
MKG
310=head2 LastUpdatedBy
311
312Returns the current value of LastUpdatedBy.
313(In the database, LastUpdatedBy is stored as int(11).)
314
84fb5b46
MKG
315=head2 LastUpdated
316
317Returns the current value of LastUpdated.
318(In the database, LastUpdated is stored as datetime.)
319
84fb5b46
MKG
320=cut
321
322
84fb5b46
MKG
323sub _CoreAccessible {
324 {
325
326 id =>
af59614d 327 {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''},
84fb5b46 328 Name =>
af59614d 329 {read => 1, write => 1, sql_type => 12, length => 200, is_blob => 0, is_numeric => 0, type => 'varchar(200)', default => ''},
84fb5b46 330 Description =>
af59614d 331 {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''},
84fb5b46 332 ExecModule =>
af59614d 333 {read => 1, write => 1, sql_type => 12, length => 60, is_blob => 0, is_numeric => 0, type => 'varchar(60)', default => ''},
84fb5b46 334 Argument =>
af59614d 335 {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varbinary(255)', default => ''},
84fb5b46 336 Creator =>
af59614d 337 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
84fb5b46 338 Created =>
af59614d 339 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
84fb5b46 340 LastUpdatedBy =>
af59614d 341 {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'},
84fb5b46 342 LastUpdated =>
af59614d 343 {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''},
84fb5b46
MKG
344
345 }
346};
347
af59614d
MKG
348sub 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
84fb5b46
MKG
357RT::Base->_ImportOverlays();
358
3591;