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