import rt 2.0.14
[freeside.git] / rt / lib / RT / ScripAction.pm
1 # Copyright 1999-2000 Jesse Vincent <jesse@fsck.com>
2 # Released under the terms of the GNU Public License
3 # $Header: /home/cvs/cvsroot/freeside/rt/lib/RT/ScripAction.pm,v 1.1 2002-08-12 06:17:07 ivan Exp $
4
5 =head1 NAME
6
7   RT::ScripAction - RT Action object
8
9 =head1 SYNOPSIS
10
11   use RT::ScripAction;
12
13
14 =head1 DESCRIPTION
15
16 This module should never be called directly by client code. it's an internal module which
17 should only be accessed through exported APIs in other modules.
18
19
20 =begin testing
21
22 ok (require RT::TestHarness);
23 ok (require RT::ScripAction);
24
25 =end testing
26
27 =head1 METHODS
28
29 =cut
30
31 package RT::ScripAction;
32 use RT::Record;
33 @ISA= qw(RT::Record);
34
35 # {{{  sub _Init 
36 sub _Init  {
37     my $self = shift; 
38     $self->{'table'} = "ScripActions";
39     return ($self->SUPER::_Init(@_));
40 }
41 # }}}
42
43 # {{{ sub _Accessible 
44 sub _Accessible  {
45     my $self = shift;
46     my %Cols = ( Name  => 'read',
47                  Description => 'read',
48                  ExecModule  => 'read',
49                  Argument  => 'read',
50                  Creator => 'read/auto',
51                  Created => 'read/auto',
52                  LastUpdatedBy => 'read/auto',
53                  LastUpdated => 'read/auto'
54        );
55     return($self->SUPER::_Accessible(@_, %Cols));
56 }
57 # }}}
58
59 # {{{ sub Create 
60 =head2 Create
61   
62  Takes a hash. Creates a new Action entry.
63  should be better documented.
64 =cut
65
66 sub Create  {
67     my $self = shift;
68     #TODO check these args and do smart things.
69     return($self->SUPER::Create(@_));
70 }
71 # }}}
72
73 # {{{ sub Delete 
74 sub Delete  {
75     my $self = shift;
76     
77     return (0, "ScripAction->Delete not implemented");
78 }
79 # }}}
80
81 # {{{ sub Load 
82 sub Load  {
83     my $self = shift;
84     my $identifier = shift;
85     
86     if (!$identifier) {
87         return (0, 'Input error');
88     }       
89     
90     if ($identifier !~ /\D/) {
91         $self->SUPER::LoadById($identifier);
92     }
93     else {
94         $self->LoadByCol('Name', $identifier);
95         
96     }
97
98     if (@_) {
99         # Set the template Id to the passed in template    
100         my $template = shift;
101         
102         $self->{'Template'} = $template;
103     }
104     return ($self->Id, 'ScripAction loaded');
105 }
106 # }}}
107
108 # {{{ sub LoadAction 
109
110 =head2 LoadAction HASH
111
112   Takes a hash consisting of TicketObj and TransactionObj.  Loads an RT::Action:: module.
113
114 =cut
115
116 sub LoadAction  {
117     my $self = shift;
118     my %args = ( TransactionObj => undef,
119                  TicketObj => undef,
120                  @_ );
121     
122     #TODO: Put this in an eval  
123     $self->ExecModule =~ /^(\w+)$/;
124     my $module = $1;
125     my $type = "RT::Action::". $module;
126  
127     $RT::Logger->debug("now requiring $type\n"); 
128     eval "require $type" || die "Require of $type failed.\n$@\n";
129     
130     $self->{'Action'}  = $type->new ( 'ScripActionObj' => $self, 
131                                       'TicketObj' => $args{'TicketObj'},
132                                       'TransactionObj' => $args{'TransactionObj'},
133                                       'TemplateObj' => $self->TemplateObj,
134                                       'Argument' => $self->Argument,
135                                     );
136 }
137 # }}}
138
139 # {{{ sub TemplateObj
140
141 =head2 TemplateObj
142
143 Return this action\'s template object
144
145 =cut
146
147 sub TemplateObj {
148     my $self = shift;
149     return undef unless $self->{Template};
150     if (!$self->{'TemplateObj'})  {
151         require RT::Template;
152         $self->{'TemplateObj'} = RT::Template->new($self->CurrentUser);
153         $self->{'TemplateObj'}->LoadById($self->{'Template'});
154         
155     }
156     
157     return ($self->{'TemplateObj'});
158 }
159 # }}}
160
161 # The following methods call the action object
162
163 # {{{ sub Prepare 
164
165 sub Prepare  {
166     my $self = shift;
167     return ($self->{'Action'}->Prepare());
168   
169 }
170 # }}}
171
172 # {{{ sub Commit 
173 sub Commit  {
174     my $self = shift;
175     return($self->{'Action'}->Commit());
176     
177     
178 }
179 # }}}
180
181 # {{{ sub Describe 
182 sub Describe  {
183     my $self = shift;
184     return ($self->{'Action'}->Describe());
185     
186 }
187 # }}}
188
189 # {{{ sub DESTROY
190 sub DESTROY {
191     my $self=shift;
192     $self->{'Action'} = undef;
193     $self->{'TemplateObj'} = undef;
194 }
195 # }}}
196
197
198 1;
199
200