]>
Commit | Line | Data |
---|---|---|
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 | ||
3ffc5f4f | 51 | RT::ScripAction - RT Action object |
84fb5b46 MKG |
52 | |
53 | =head1 DESCRIPTION | |
54 | ||
3ffc5f4f MKG |
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. | |
84fb5b46 MKG |
58 | |
59 | =cut | |
60 | ||
61 | ||
62 | package RT::ScripAction; | |
63 | ||
64 | use strict; | |
65 | use warnings; | |
66 | ||
67 | use base 'RT::Record'; | |
68 | ||
84fb5b46 | 69 | |
3ffc5f4f | 70 | sub Table {'ScripActions'} |
84fb5b46 MKG |
71 | |
72 | use RT::Template; | |
73 | ||
74 | sub _Accessible { | |
75 | my $self = shift; | |
3ffc5f4f 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 | ||
3ffc5f4f MKG |
90 | =head1 METHODS |
91 | ||
84fb5b46 MKG |
92 | =head2 Create |
93 | ||
3ffc5f4f | 94 | Takes a hash. Creates a new Action entry. |
84fb5b46 MKG |
95 | |
96 | =cut | |
97 | ||
98 | sub Create { | |
99 | my $self = shift; | |
100 | #TODO check these args and do smart things. | |
101 | return($self->SUPER::Create(@_)); | |
102 | } | |
103 | ||
104 | sub Delete { | |
105 | my $self = shift; | |
84fb5b46 MKG |
106 | return (0, "ScripAction->Delete not implemented"); |
107 | } | |
108 | ||
109 | ||
110 | =head2 Load IDENTIFIER | |
111 | ||
112 | Loads an action by its Name. | |
113 | ||
114 | Returns: Id, Error Message | |
115 | ||
116 | =cut | |
117 | ||
118 | sub Load { | |
119 | my $self = shift; | |
120 | my $identifier = shift; | |
3ffc5f4f | 121 | |
84fb5b46 | 122 | if (!$identifier) { |
3ffc5f4f MKG |
123 | return wantarray ? (0, $self->loc('Input error')) : 0; |
124 | } | |
125 | ||
84fb5b46 MKG |
126 | my ($ok, $msg); |
127 | if ($identifier !~ /\D/) { | |
3ffc5f4f | 128 | ($ok, $msg) = $self->SUPER::Load($identifier); |
84fb5b46 MKG |
129 | } |
130 | else { | |
3ffc5f4f | 131 | ($ok, $msg) = $self->LoadByCol('Name', $identifier); |
84fb5b46 MKG |
132 | } |
133 | ||
134 | if (@_) { | |
3ffc5f4f MKG |
135 | RT->Deprecated( |
136 | Arguments => "Template as second argument", | |
137 | Remove => "4.4", | |
138 | ); | |
139 | $self->{'Template'} = shift; | |
84fb5b46 MKG |
140 | } |
141 | ||
3ffc5f4f | 142 | return wantarray ? ($ok, $msg) : $ok; |
84fb5b46 MKG |
143 | } |
144 | ||
145 | ||
146 | =head2 LoadAction HASH | |
147 | ||
3ffc5f4f | 148 | Takes a hash consisting of TicketObj and TransactionObj. Loads an RT::Action:: module. |
84fb5b46 MKG |
149 | |
150 | =cut | |
151 | ||
152 | sub LoadAction { | |
153 | my $self = shift; | |
3ffc5f4f 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; | |
84fb5b46 | 173 | |
3ffc5f4f | 174 | $type->require or die "Require of $type action module failed.\n$@\n"; |
84fb5b46 | 175 | |
3ffc5f4f MKG |
176 | return $self->{'Action'} = $type->new( |
177 | %args, | |
178 | Argument => $self->Argument, | |
179 | CurrentUser => $self->CurrentUser, | |
180 | ScripActionObj => $self, | |
181 | ); | |
182 | } | |
84fb5b46 | 183 | |
84fb5b46 | 184 | |
3ffc5f4f | 185 | =head2 TemplateObj |
84fb5b46 | 186 | |
3ffc5f4f | 187 | Return this action's template object. Deprecated. |
84fb5b46 MKG |
188 | |
189 | =cut | |
190 | ||
191 | sub TemplateObj { | |
192 | my $self = shift; | |
3ffc5f4f MKG |
193 | RT->Deprecated( |
194 | Remove => "4.4", | |
195 | ); | |
196 | ||
84fb5b46 | 197 | if ( !$self->{'TemplateObj'} ) { |
3ffc5f4f | 198 | return undef unless $self->{Template}; |
84fb5b46 | 199 | $self->{'TemplateObj'} = RT::Template->new( $self->CurrentUser ); |
3ffc5f4f | 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 |
220 | sub Prepare { |
221 | my $self = shift; | |
222 | $self->{_Message_ID} = 0; | |
3ffc5f4f | 223 | return $self->Action->Prepare( @_ ); |
84fb5b46 MKG |
224 | } |
225 | ||
226 | sub Commit { | |
227 | my $self = shift; | |
3ffc5f4f | 228 | return $self->Action->Commit( @_ ); |
84fb5b46 MKG |
229 | } |
230 | ||
231 | sub Describe { | |
232 | my $self = shift; | |
3ffc5f4f | 233 | return $self->Action->Describe( @_ ); |
84fb5b46 MKG |
234 | } |
235 | ||
236 | =head2 Action | |
237 | ||
238 | Return the actual RT::Action object for this scrip. | |
239 | ||
240 | =cut | |
241 | ||
242 | sub Action { | |
243 | my $self = shift; | |
3ffc5f4f | 244 | return $self->{'Action'}; |
84fb5b46 MKG |
245 | } |
246 | ||
84fb5b46 MKG |
247 | =head2 id |
248 | ||
249 | Returns the current value of id. | |
250 | (In the database, id is stored as int(11).) | |
251 | ||
252 | ||
84fb5b46 MKG |
253 | =head2 Name |
254 | ||
255 | Returns 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 |
260 | Set Name to VALUE. |
261 | Returns (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 | ||
267 | Returns 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 |
272 | Set Description to VALUE. |
273 | Returns (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 | ||
279 | Returns 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 |
284 | Set ExecModule to VALUE. |
285 | Returns (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 | ||
291 | Returns 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 |
296 | Set Argument to VALUE. |
297 | Returns (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 | ||
303 | Returns the current value of Creator. | |
304 | (In the database, Creator is stored as int(11).) | |
305 | ||
84fb5b46 MKG |
306 | =head2 Created |
307 | ||
308 | Returns the current value of Created. | |
309 | (In the database, Created is stored as datetime.) | |
310 | ||
84fb5b46 MKG |
311 | =head2 LastUpdatedBy |
312 | ||
313 | Returns the current value of LastUpdatedBy. | |
314 | (In the database, LastUpdatedBy is stored as int(11).) | |
315 | ||
84fb5b46 MKG |
316 | =head2 LastUpdated |
317 | ||
318 | Returns the current value of LastUpdated. | |
319 | (In the database, LastUpdated is stored as datetime.) | |
320 | ||
84fb5b46 MKG |
321 | =cut |
322 | ||
323 | ||
84fb5b46 MKG |
324 | sub _CoreAccessible { |
325 | { | |
326 | ||
327 | id => | |
3ffc5f4f | 328 | {read => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => ''}, |
84fb5b46 | 329 | Name => |
3ffc5f4f | 330 | {read => 1, write => 1, sql_type => 12, length => 200, is_blob => 0, is_numeric => 0, type => 'varchar(200)', default => ''}, |
84fb5b46 | 331 | Description => |
3ffc5f4f | 332 | {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varchar(255)', default => ''}, |
84fb5b46 | 333 | ExecModule => |
3ffc5f4f | 334 | {read => 1, write => 1, sql_type => 12, length => 60, is_blob => 0, is_numeric => 0, type => 'varchar(60)', default => ''}, |
84fb5b46 | 335 | Argument => |
3ffc5f4f | 336 | {read => 1, write => 1, sql_type => 12, length => 255, is_blob => 0, is_numeric => 0, type => 'varbinary(255)', default => ''}, |
84fb5b46 | 337 | Creator => |
3ffc5f4f | 338 | {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'}, |
84fb5b46 | 339 | Created => |
3ffc5f4f | 340 | {read => 1, auto => 1, sql_type => 11, length => 0, is_blob => 0, is_numeric => 0, type => 'datetime', default => ''}, |
84fb5b46 | 341 | LastUpdatedBy => |
3ffc5f4f | 342 | {read => 1, auto => 1, sql_type => 4, length => 11, is_blob => 0, is_numeric => 1, type => 'int(11)', default => '0'}, |
84fb5b46 | 343 | LastUpdated => |
3ffc5f4f | 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 | ||
3ffc5f4f MKG |
349 | sub 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 |
358 | RT::Base->_ImportOverlays(); |
359 | ||
360 | 1; |