rt 4.2.16
[freeside.git] / rt / lib / RT / ScripCondition.pm
1 # BEGIN BPS TAGGED BLOCK {{{
2 #
3 # COPYRIGHT:
4 #
5 # This software is Copyright (c) 1996-2019 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::ScripCondition - RT scrip conditional
52
53 =head1 SYNOPSIS
54
55   use RT::ScripCondition;
56
57
58 =head1 DESCRIPTION
59
60 This module should never be called directly by client code. it's an internal module which
61 should only be accessed through exported APIs in other modules.
62
63
64
65 =head1 METHODS
66
67 =cut
68
69
70 package RT::ScripCondition;
71
72 use strict;
73 use warnings;
74
75
76 use base 'RT::Record';
77
78
79 sub Table {'ScripConditions'}
80
81
82 sub _Accessible  {
83     my $self = shift;
84     my %Cols = ( Name  => 'read',
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                );
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
105 sub Create  {
106     my $self = shift;
107     return($self->SUPER::Create(@_));
108 }
109
110
111 =head2 Delete
112
113 No API available for deleting things just yet.
114
115 =cut
116
117 sub Delete  {
118     my $self = shift;
119     return(0, $self->loc('Unimplemented'));
120 }
121
122
123 =head2 Load IDENTIFIER
124
125 Loads a condition takes a name or ScripCondition id.
126
127 =cut
128
129 sub Load  {
130     my $self = shift;
131     my $identifier = shift;
132
133     unless (defined $identifier) {
134         return (undef);
135     }
136
137     if ($identifier !~ /\D/) {
138         return ($self->SUPER::LoadById($identifier));
139     }
140     else {
141         return ($self->LoadByCol('Name', $identifier));
142     }
143 }
144
145
146 =head2 LoadCondition  HASH
147
148 takes a hash which has the following elements:  TransactionObj and TicketObj.
149 Loads the Condition module in question.
150
151 =cut
152
153
154 sub LoadCondition  {
155     my $self = shift;
156     my %args = ( TransactionObj => undef,
157                  TicketObj => undef,
158                  @_ );
159
160     #TODO: Put this in an eval
161     $self->ExecModule =~ /^(\w+)$/;
162     my $module = $1;
163     my $type = "RT::Condition::". $module;
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                                        );
175 }
176
177
178
179
180 =head2 Describe 
181
182 Helper method to call the condition module's Describe method.
183
184 =cut
185
186 sub Describe  {
187     my $self = shift;
188     return ($self->{'Condition'}->Describe());
189     
190 }
191
192
193 =head2 IsApplicable
194
195 Helper method to call the condition module's IsApplicable method.
196
197 =cut
198
199 sub IsApplicable  {
200     my $self = shift;
201     return ($self->{'Condition'}->IsApplicable());
202     
203 }
204
205
206
207 =head2 id
208
209 Returns 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
218 Returns the current value of Name.
219 (In the database, Name is stored as varchar(200).)
220
221
222
223 =head2 SetName VALUE
224
225
226 Set Name to VALUE.
227 Returns (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
236 Returns the current value of Description.
237 (In the database, Description is stored as varchar(255).)
238
239
240
241 =head2 SetDescription VALUE
242
243
244 Set Description to VALUE.
245 Returns (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
254 Returns the current value of ExecModule.
255 (In the database, ExecModule is stored as varchar(60).)
256
257
258
259 =head2 SetExecModule VALUE
260
261
262 Set ExecModule to VALUE.
263 Returns (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
272 Returns the current value of Argument.
273 (In the database, Argument is stored as varbinary(255).)
274
275
276
277 =head2 SetArgument VALUE
278
279
280 Set Argument to VALUE.
281 Returns (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
290 Returns the current value of ApplicableTransTypes.
291 (In the database, ApplicableTransTypes is stored as varchar(60).)
292
293
294
295 =head2 SetApplicableTransTypes VALUE
296
297
298 Set ApplicableTransTypes to VALUE.
299 Returns (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
308 Returns 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
317 Returns the current value of Created.
318 (In the database, Created is stored as datetime.)
319
320
321 =cut
322
323
324 =head2 LastUpdatedBy
325
326 Returns 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
335 Returns the current value of LastUpdated.
336 (In the database, LastUpdated is stored as datetime.)
337
338
339 =cut
340
341
342
343 sub _CoreAccessible {
344     {
345
346         id =>
347                 {read => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => ''},
348         Name =>
349                 {read => 1, write => 1, sql_type => 12, length => 200,  is_blob => 0,  is_numeric => 0,  type => 'varchar(200)', default => ''},
350         Description =>
351                 {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varchar(255)', default => ''},
352         ExecModule =>
353                 {read => 1, write => 1, sql_type => 12, length => 60,  is_blob => 0,  is_numeric => 0,  type => 'varchar(60)', default => ''},
354         Argument =>
355                 {read => 1, write => 1, sql_type => 12, length => 255,  is_blob => 0,  is_numeric => 0,  type => 'varbinary(255)', default => ''},
356         ApplicableTransTypes =>
357                 {read => 1, write => 1, sql_type => 12, length => 60,  is_blob => 0,  is_numeric => 0,  type => 'varchar(60)', default => ''},
358         Creator =>
359                 {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
360         Created =>
361                 {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
362         LastUpdatedBy =>
363                 {read => 1, auto => 1, sql_type => 4, length => 11,  is_blob => 0,  is_numeric => 1,  type => 'int(11)', default => '0'},
364         LastUpdated =>
365                 {read => 1, auto => 1, sql_type => 11, length => 0,  is_blob => 0,  is_numeric => 0,  type => 'datetime', default => ''},
366
367  }
368 };
369
370 sub 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
379 sub __DependsOn {
380     my $self = shift;
381     my %args = (
382         Shredder => undef,
383         Dependencies => undef,
384         @_,
385     );
386     my $deps = $args{'Dependencies'};
387
388 # Scrips
389     my $objs = RT::Scrips->new( $self->CurrentUser );
390     $objs->Limit( FIELD => 'ScripCondition', VALUE => $self->Id );
391     $deps->_PushDependencies(
392         BaseObject => $self,
393         Flags => RT::Shredder::Constants::DEPENDS_ON,
394         TargetObjects => $objs,
395         Shredder => $args{'Shredder'}
396     );
397
398     return $self->SUPER::__DependsOn( %args );
399 }
400
401 RT::Base->_ImportOverlays();
402
403 1;