| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package OpenInteract2::Context; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Context.pm,v 1.87 2005/03/17 14:57:57 sjn Exp $ |
|
4
|
|
|
|
|
|
|
|
|
5
|
85
|
|
|
85
|
|
8835181
|
use strict; |
|
|
85
|
|
|
|
|
309
|
|
|
|
85
|
|
|
|
|
3923
|
|
|
6
|
85
|
|
|
85
|
|
526
|
use base qw( Exporter Class::Accessor::Fast ); |
|
|
85
|
|
|
|
|
188
|
|
|
|
85
|
|
|
|
|
111598
|
|
|
7
|
85
|
|
|
85
|
|
402140
|
use Data::Dumper qw( Dumper ); |
|
|
85
|
|
|
|
|
37420
|
|
|
|
85
|
|
|
|
|
5941
|
|
|
8
|
85
|
|
|
85
|
|
156976
|
use DateTime; |
|
|
85
|
|
|
|
|
19335063
|
|
|
|
85
|
|
|
|
|
4518
|
|
|
9
|
85
|
|
|
85
|
|
5476
|
use Log::Log4perl qw( get_logger ); |
|
|
85
|
|
|
|
|
213241
|
|
|
|
85
|
|
|
|
|
1024
|
|
|
10
|
85
|
|
|
85
|
|
77622
|
use OpenInteract2::Constants qw( :log ); |
|
|
85
|
|
|
|
|
287
|
|
|
|
85
|
|
|
|
|
26203
|
|
|
11
|
85
|
|
|
85
|
|
66171
|
use OpenInteract2::Log qw( uchk ); |
|
|
85
|
|
|
|
|
257
|
|
|
|
85
|
|
|
|
|
8341
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$OpenInteract2::Context::VERSION = sprintf("%d.%02d", q$Revision: 1.87 $ =~ /(\d+)\.(\d+)/); |
|
14
|
|
|
|
|
|
|
|
|
15
|
85
|
|
|
85
|
|
557
|
use constant DEFAULT_TEMP_LIB_DIR => 'templib'; |
|
|
85
|
|
|
|
|
158
|
|
|
|
85
|
|
|
|
|
585249
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my ( $log_spops, $log_act, $log_init ); |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
|
|
0
|
|
|
sub version { return '1.99_06' } |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Exportable deployment URL call -- main, images, static |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my ( $DEPLOY_URL, $DEPLOY_IMAGE_URL, $DEPLOY_STATIC_URL ); |
|
24
|
0
|
|
|
0
|
|
|
sub DEPLOY_URL { return $DEPLOY_URL } |
|
25
|
0
|
|
|
0
|
|
|
sub DEPLOY_IMAGE_URL { return $DEPLOY_IMAGE_URL } |
|
26
|
0
|
|
|
0
|
|
|
sub DEPLOY_STATIC_URL { return $DEPLOY_STATIC_URL } |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my ( $DEFAULT_LANGUAGE_HANDLE ); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# This is the only copy of the context that should be around. We might |
|
31
|
|
|
|
|
|
|
# modify this later so we can have multiple copies of the context |
|
32
|
|
|
|
|
|
|
# around (produced by, say, a ContextFactory), but W(P)AGNI. Note that |
|
33
|
|
|
|
|
|
|
# before accessing the exported variable you should first ensure that |
|
34
|
|
|
|
|
|
|
# it's initialized. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my ( $CTX ); |
|
37
|
0
|
|
|
0
|
|
|
sub CTX { return $CTX } |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
@OpenInteract2::Context::EXPORT_OK = qw( |
|
40
|
|
|
|
|
|
|
CTX DEPLOY_URL DEPLOY_IMAGE_URL DEPLOY_STATIC_URL |
|
41
|
|
|
|
|
|
|
); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
require OpenInteract2::Config; |
|
44
|
|
|
|
|
|
|
require OpenInteract2::Config::Bootstrap; |
|
45
|
|
|
|
|
|
|
require OpenInteract2::DatasourceManager; |
|
46
|
|
|
|
|
|
|
require OpenInteract2::Observer; |
|
47
|
|
|
|
|
|
|
require OpenInteract2::Request; |
|
48
|
|
|
|
|
|
|
require OpenInteract2::Response; |
|
49
|
|
|
|
|
|
|
require OpenInteract2::Action; |
|
50
|
|
|
|
|
|
|
require OpenInteract2::Controller; |
|
51
|
|
|
|
|
|
|
require OpenInteract2::Exception; |
|
52
|
|
|
|
|
|
|
require OpenInteract2::Setup; |
|
53
|
|
|
|
|
|
|
require OpenInteract2::I18N; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my @CORE_FIELDS = qw( bootstrap repository packages cache |
|
56
|
|
|
|
|
|
|
datasource_manager timezone timezone_object setup_class ); |
|
57
|
|
|
|
|
|
|
my @REQUEST_FIELDS = qw( request response controller user group is_logged_in is_admin ); |
|
58
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( @CORE_FIELDS, @REQUEST_FIELDS ); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
######################################## |
|
61
|
|
|
|
|
|
|
# CONSTRUCTOR AND INITIALIZATION |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# $item should be either a hashref of parameters (preferably with one |
|
64
|
|
|
|
|
|
|
# parameter 'website_dir') or an OI2::Config::Bootstrap object |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub create { |
|
67
|
0
|
|
|
0
|
|
|
my ( $class, $item, $params ) = @_; |
|
68
|
0
|
0
|
|
|
|
|
return $CTX if ( $CTX ); |
|
69
|
0
|
|
0
|
|
|
|
$item ||= {}; |
|
70
|
0
|
|
0
|
|
|
|
$params ||= {}; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my ( $website_dir ); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Don't assign this to $CTX until after it's setup! |
|
75
|
0
|
|
|
|
|
|
my $ctx = bless( {}, $class ); |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my ( $bootstrap ); |
|
78
|
0
|
0
|
|
|
|
|
if ( ref $item eq 'OpenInteract2::Config::Bootstrap' ) { |
|
|
|
0
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
$bootstrap = $item; |
|
80
|
0
|
|
|
|
|
|
$website_dir = $bootstrap->website_dir; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
elsif ( $item->{website_dir} ) { |
|
83
|
0
|
|
|
|
|
|
$bootstrap = eval { |
|
84
|
0
|
|
|
|
|
|
OpenInteract2::Config::Bootstrap->new({ |
|
85
|
|
|
|
|
|
|
website_dir => $item->{website_dir} |
|
86
|
|
|
|
|
|
|
}) |
|
87
|
|
|
|
|
|
|
}; |
|
88
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
|
89
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( |
|
90
|
|
|
|
|
|
|
"Cannot create bootstrap object using website ", |
|
91
|
|
|
|
|
|
|
"directory '$item->{website_dir}': $@" ); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
0
|
|
|
|
|
|
$website_dir = $item->{website_dir}; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# this is typically only set from standalone scripts; see POD |
|
97
|
|
|
|
|
|
|
|
|
98
|
0
|
0
|
0
|
|
|
|
if ( $params->{initialize_log} and -d $website_dir ) { |
|
|
|
0
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
OpenInteract2::Log->init_from_website( $website_dir ); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
elsif ( $params->{initialize_log} ) { |
|
102
|
0
|
|
|
|
|
|
OpenInteract2::Log->init_screen; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
0
|
|
|
|
$log_init ||= get_logger( LOG_INIT ); |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if ( $bootstrap ) { |
|
108
|
0
|
|
|
|
|
|
$ctx->bootstrap( $bootstrap ); |
|
109
|
0
|
0
|
|
|
|
|
$log_init->is_debug && |
|
110
|
|
|
|
|
|
|
$log_init->debug( "Assigned bootstrap ok; setting up..." ); |
|
111
|
0
|
|
|
|
|
|
eval { $ctx->setup( $params ) }; |
|
|
0
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
|
113
|
0
|
|
|
|
|
|
my $error = $@; |
|
114
|
0
|
|
|
|
|
|
$CTX = undef; |
|
115
|
0
|
|
|
|
|
|
$log_init->error( "Setup failed to run: $error" ); |
|
116
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( $error ); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
else { |
|
119
|
0
|
0
|
|
|
|
|
$log_init->is_info && $log_init->info( "Setup ran ok" ); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
} |
|
122
|
0
|
|
|
|
|
|
return $CTX = $ctx |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub instance { |
|
127
|
0
|
|
|
0
|
|
|
my ( $class, $no_exception ) = @_; |
|
128
|
0
|
0
|
|
|
|
|
return $CTX if ( $CTX ); |
|
129
|
0
|
0
|
|
|
|
|
if ( $no_exception ) { |
|
130
|
0
|
|
|
|
|
|
return undef; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
OpenInteract2::Exception->throw( |
|
133
|
0
|
|
|
|
|
|
"No context available; first call 'create()'" ); |
|
134
|
|
|
|
|
|
|
} |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Initialize the Context |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub setup { |
|
140
|
0
|
|
|
0
|
|
|
my ( $self, $params ) = @_; |
|
141
|
0
|
|
0
|
|
|
|
$params ||= {}; |
|
142
|
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
my @skip = (); |
|
144
|
0
|
0
|
|
|
|
|
if ( $params->{skip} ) { |
|
145
|
0
|
0
|
|
|
|
|
if ( ref $params->{skip} eq 'ARRAY' ) { |
|
146
|
0
|
|
|
|
|
|
push @skip, @{ $params->{skip} }; |
|
|
0
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
else { |
|
149
|
0
|
|
|
|
|
|
push @skip, $params->{skip}; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
0
|
|
|
|
|
|
$log_init->info( "Will skip setup tasks: ", join( ', ', @skip ) ); |
|
152
|
|
|
|
|
|
|
} |
|
153
|
0
|
|
|
|
|
|
my $bootstrap = $self->bootstrap; |
|
154
|
0
|
0
|
0
|
|
|
|
unless ( $bootstrap and |
|
155
|
|
|
|
|
|
|
ref( $bootstrap ) eq 'OpenInteract2::Config::Bootstrap' ) { |
|
156
|
0
|
|
|
|
|
|
$log_init->error( "Cannot run setup() without bootstrap defined" ); |
|
157
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( |
|
158
|
|
|
|
|
|
|
"Cannot run setup() on context without a valid ", |
|
159
|
|
|
|
|
|
|
"bootstrap configuration object set" ); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# This should call _initialize_singleton() when it's got the |
|
163
|
|
|
|
|
|
|
# context in a decent state... |
|
164
|
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
$log_init->info( "Running setup actions..." ); |
|
166
|
0
|
|
|
|
|
|
OpenInteract2::Setup->run_all_actions( $self, @skip ); |
|
167
|
0
|
|
|
|
|
|
$log_init->info( "Setup actions ran ok, context now initialized" ); |
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
return $self; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Called from OI2::Setup after it's read the server configuration |
|
174
|
|
|
|
|
|
|
sub _initialize_singleton { |
|
175
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
176
|
0
|
|
|
|
|
|
$CTX = $self; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
######################################## |
|
181
|
|
|
|
|
|
|
# CONFIGURATION ASSIGNMENTS |
|
182
|
|
|
|
|
|
|
# |
|
183
|
|
|
|
|
|
|
# These subroutines generally map to some basic system information |
|
184
|
|
|
|
|
|
|
# that can be modified at runtime in addition to the modifications in |
|
185
|
|
|
|
|
|
|
# the configuration. Note: modifications made here should get |
|
186
|
|
|
|
|
|
|
# reflected in the configuration as well. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub server_config { |
|
189
|
0
|
|
|
0
|
|
|
my ( $self, $config ) = @_; |
|
190
|
0
|
0
|
|
|
|
|
if ( $config ) { |
|
191
|
0
|
|
0
|
|
|
|
$log_init ||= get_logger( LOG_INIT ); |
|
192
|
0
|
|
|
|
|
|
$config->{dir}{website} = $self->bootstrap->website_dir; |
|
193
|
0
|
|
|
|
|
|
$config->translate_dirs; |
|
194
|
0
|
|
|
|
|
|
$log_init->info( "Translated server config directories ok" ); |
|
195
|
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
$self->{server_config} = $config; |
|
197
|
0
|
|
|
|
|
|
$self->assign_deploy_url; |
|
198
|
0
|
|
|
|
|
|
$self->assign_deploy_image_url; |
|
199
|
0
|
|
|
|
|
|
$self->assign_deploy_static_url; |
|
200
|
0
|
|
|
|
|
|
$log_init->info( "Assigned constants from server config ok" ); |
|
201
|
|
|
|
|
|
|
} |
|
202
|
0
|
|
|
|
|
|
return $self->{server_config}; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# Where is this app deployed under? |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub assign_deploy_url { |
|
208
|
0
|
|
|
0
|
|
|
my ( $self, $url ) = @_; |
|
209
|
|
|
|
|
|
|
|
|
210
|
0
|
|
0
|
|
|
|
$url ||= $self->server_config->{context_info}{deployed_under}; |
|
211
|
0
|
|
|
|
|
|
$url = $self->_clean_deploy_url( $url ); |
|
212
|
0
|
0
|
0
|
|
|
|
if ( $url and $url !~ m|^/| ) { |
|
213
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( |
|
214
|
|
|
|
|
|
|
"Deployment URL must begin with a '/'. It may not ", |
|
215
|
|
|
|
|
|
|
"be a fully-qualified URL (e.g., 'http://foo.com/') ", |
|
216
|
|
|
|
|
|
|
"and it may not be a purely relative URL (e.g., 'oi')" ); |
|
217
|
|
|
|
|
|
|
} |
|
218
|
0
|
|
|
|
|
|
$DEPLOY_URL = $url; |
|
219
|
0
|
|
|
|
|
|
$self->server_config->{context_info}{deployed_under} = $url; |
|
220
|
0
|
0
|
|
|
|
|
$log_init->is_info && $log_init->info( "Assigned deployment URL '$url'" ); |
|
221
|
0
|
|
|
|
|
|
return $DEPLOY_URL; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub assign_deploy_image_url { |
|
225
|
0
|
|
|
0
|
|
|
my ( $self, $url ) = @_; |
|
226
|
|
|
|
|
|
|
|
|
227
|
0
|
|
0
|
|
|
|
$url ||= $self->server_config->{context_info}{deployed_under_image}; |
|
228
|
0
|
|
|
|
|
|
$url = $self->_clean_deploy_url( $url ); |
|
229
|
0
|
|
|
|
|
|
$DEPLOY_IMAGE_URL = $url; |
|
230
|
0
|
|
|
|
|
|
$self->server_config->{context_info}{deployed_under_image} = $url; |
|
231
|
0
|
0
|
|
|
|
|
$log_init->is_info && |
|
232
|
|
|
|
|
|
|
$log_init->info( "Assigned image deployment URL '$url'" ); |
|
233
|
0
|
|
|
|
|
|
return $DEPLOY_IMAGE_URL; |
|
234
|
|
|
|
|
|
|
} |
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub assign_deploy_static_url { |
|
237
|
0
|
|
|
0
|
|
|
my ( $self, $url ) = @_; |
|
238
|
|
|
|
|
|
|
|
|
239
|
0
|
|
0
|
|
|
|
$url ||= $self->server_config->{context_info}{deployed_under_static}; |
|
240
|
0
|
|
|
|
|
|
$url = $self->_clean_deploy_url( $url ); |
|
241
|
0
|
|
|
|
|
|
$DEPLOY_STATIC_URL = $url; |
|
242
|
0
|
|
|
|
|
|
$self->server_config->{context_info}{deployed_under_static} = $url; |
|
243
|
0
|
0
|
|
|
|
|
$log_init->is_info && |
|
244
|
|
|
|
|
|
|
$log_init->info( "Assigned static deployment URL '$url'" ); |
|
245
|
0
|
|
|
|
|
|
return $DEPLOY_STATIC_URL; |
|
246
|
|
|
|
|
|
|
} |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub _clean_deploy_url { |
|
249
|
0
|
|
|
0
|
|
|
my ( $self, $url ) = @_; |
|
250
|
0
|
0
|
|
|
|
|
return '' unless ( $url ); |
|
251
|
0
|
|
|
|
|
|
$url =~ s/^\s+//; |
|
252
|
0
|
|
|
|
|
|
$url =~ s/\s+$//; |
|
253
|
0
|
|
|
|
|
|
$url =~ s|/$||; |
|
254
|
0
|
|
|
|
|
|
return $url; |
|
255
|
|
|
|
|
|
|
} |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
# What type of requests/responses are we getting/generating? |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
# TODO: get rid of 'context_info' reference; these are strictly |
|
261
|
|
|
|
|
|
|
# assigned by adapter now |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub assign_request_type { |
|
264
|
0
|
|
|
0
|
|
|
my ( $self, $type ) = @_; |
|
265
|
|
|
|
|
|
|
|
|
266
|
0
|
|
0
|
|
|
|
$type ||= $self->server_config->{context_info}{request}; |
|
267
|
0
|
|
|
|
|
|
$self->server_config->{context_info}{request} = $type; |
|
268
|
0
|
|
|
|
|
|
OpenInteract2::Request->set_implementation_type( $type ); |
|
269
|
0
|
0
|
|
|
|
|
$log_init->is_info && |
|
270
|
|
|
|
|
|
|
$log_init->info( "Assigned request type '$type'" ); |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
sub assign_response_type { |
|
275
|
0
|
|
|
0
|
|
|
my ( $self, $type ) = @_; |
|
276
|
|
|
|
|
|
|
|
|
277
|
0
|
|
0
|
|
|
|
$type ||= $self->server_config->{context_info}{response}; |
|
278
|
0
|
|
|
|
|
|
$self->server_config->{context_info}{response} = $type; |
|
279
|
0
|
|
|
|
|
|
OpenInteract2::Response->set_implementation_type( $type ); |
|
280
|
0
|
0
|
|
|
|
|
$log_init->is_info && |
|
281
|
|
|
|
|
|
|
$log_init->info( "Assigned response type '$type'" ); |
|
282
|
|
|
|
|
|
|
} |
|
283
|
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
######################################## |
|
286
|
|
|
|
|
|
|
# DATE FACTORY |
|
287
|
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
sub create_date { |
|
289
|
0
|
|
|
0
|
|
|
my ( $self, $params ) = @_; |
|
290
|
0
|
|
0
|
|
|
|
$params ||= {}; |
|
291
|
0
|
0
|
|
|
|
|
if ( $params->{epoch} ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
292
|
0
|
|
|
|
|
|
return DateTime->from_epoch( |
|
293
|
|
|
|
|
|
|
time_zone => $self->timezone_object, |
|
294
|
|
|
|
|
|
|
epoch => $params->{epoch}, |
|
295
|
|
|
|
|
|
|
); |
|
296
|
|
|
|
|
|
|
} |
|
297
|
|
|
|
|
|
|
elsif ( $params->{last_day_of_month} ) { |
|
298
|
0
|
|
|
|
|
|
delete $params->{last_day_of_month}; |
|
299
|
0
|
|
|
|
|
|
return DateTime->last_day_of_month( |
|
300
|
|
|
|
|
|
|
time_zone => $self->timezone_object, |
|
301
|
0
|
|
|
|
|
|
%{ $params }, |
|
302
|
|
|
|
|
|
|
); |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
elsif ( $params->{year} ) { |
|
305
|
0
|
|
|
|
|
|
return DateTime->new( |
|
306
|
|
|
|
|
|
|
time_zone => $self->timezone_object, |
|
307
|
0
|
|
|
|
|
|
%{ $params } |
|
308
|
|
|
|
|
|
|
); |
|
309
|
|
|
|
|
|
|
} |
|
310
|
|
|
|
|
|
|
else { |
|
311
|
0
|
|
|
|
|
|
return DateTime->now( |
|
312
|
|
|
|
|
|
|
time_zone => $self->timezone_object |
|
313
|
|
|
|
|
|
|
); |
|
314
|
|
|
|
|
|
|
} |
|
315
|
|
|
|
|
|
|
} |
|
316
|
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
######################################## |
|
319
|
|
|
|
|
|
|
# ACTION LOOKUP |
|
320
|
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
sub lookup_action_name { |
|
322
|
0
|
|
|
0
|
|
|
my ( $self, $action_url ) = @_; |
|
323
|
0
|
|
0
|
|
|
|
$log_act ||= get_logger( LOG_ACTION ); |
|
324
|
0
|
0
|
|
|
|
|
unless ( $action_url ) { |
|
325
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( |
|
326
|
|
|
|
|
|
|
"Cannot lookup action without action name without URL" ); |
|
327
|
|
|
|
|
|
|
} |
|
328
|
|
|
|
|
|
|
$log_act->is_debug && |
|
329
|
0
|
0
|
|
|
|
|
$log_act->debug( "Try to find action name for URL '$action_url'" ); |
|
330
|
0
|
|
|
|
|
|
my $server_config = $self->server_config; |
|
331
|
0
|
|
0
|
|
|
|
my $action_name = $server_config->{action_url}{ $action_url } || ''; |
|
332
|
0
|
0
|
|
|
|
|
$log_act->is_debug && |
|
333
|
|
|
|
|
|
|
$log_act->debug( "Found name '$action_name' for URL '$action_url'" ); |
|
334
|
0
|
|
|
|
|
|
return $action_name; |
|
335
|
|
|
|
|
|
|
} |
|
336
|
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
sub lookup_action_info { |
|
339
|
0
|
|
|
0
|
|
|
my ( $self, $action_name ) = @_; |
|
340
|
0
|
|
0
|
|
|
|
$log_act ||= get_logger( LOG_ACTION ); |
|
341
|
0
|
0
|
|
|
|
|
unless ( $action_name ) { |
|
342
|
0
|
|
|
|
|
|
$log_act->error( "No action name given to lookup info; called ", |
|
343
|
|
|
|
|
|
|
"from: ", join( ' | ', caller ) ); |
|
344
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( |
|
345
|
|
|
|
|
|
|
"Cannot lookup action without action name" ); |
|
346
|
|
|
|
|
|
|
} |
|
347
|
|
|
|
|
|
|
|
|
348
|
|
|
|
|
|
|
$log_act->is_debug && |
|
349
|
0
|
0
|
|
|
|
|
$log_act->debug( "Try to find action info for '$action_name'" ); |
|
350
|
0
|
|
|
|
|
|
my $server_config = $self->server_config; |
|
351
|
0
|
|
|
|
|
|
my $action_info = $server_config->{action}{ lc $action_name }; |
|
352
|
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
# Let the caller deal with a not found action rather than assuming |
|
354
|
|
|
|
|
|
|
# we know best. |
|
355
|
|
|
|
|
|
|
|
|
356
|
0
|
0
|
|
|
|
|
unless ( $action_info ) { |
|
357
|
0
|
|
|
|
|
|
my $msg = "Action '$action_name' not found in action table" ; |
|
358
|
0
|
|
|
|
|
|
$log_act->error( $msg ); |
|
359
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( $msg ); |
|
360
|
|
|
|
|
|
|
} |
|
361
|
|
|
|
|
|
|
|
|
362
|
|
|
|
|
|
|
$log_act->is_debug && |
|
363
|
0
|
0
|
|
|
|
|
$log_act->debug( uchk( "Action '%s' is [Class: %s] [Template: %s] ", |
|
364
|
|
|
|
|
|
|
$action_name, $action_info->{class}, |
|
365
|
|
|
|
|
|
|
$action_info->{template} ) ); |
|
366
|
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
# Allow as many redirects as we need |
|
368
|
|
|
|
|
|
|
|
|
369
|
0
|
|
|
|
|
|
my $current_name = $action_name; |
|
370
|
0
|
|
|
|
|
|
while ( my $action_redir = $action_info->{redir} ) { |
|
371
|
0
|
|
|
|
|
|
$action_info = $server_config->{action}{ lc $action_redir }; |
|
372
|
0
|
0
|
|
|
|
|
unless ( $action_info ) { |
|
373
|
0
|
|
|
|
|
|
$log_act->warn( "Failed redirect from '$current_name' to ", |
|
374
|
|
|
|
|
|
|
"'$action_redir': no action defined " ); |
|
375
|
0
|
|
|
|
|
|
return undef; |
|
376
|
|
|
|
|
|
|
} |
|
377
|
|
|
|
|
|
|
$log_act->is_debug && |
|
378
|
0
|
0
|
|
|
|
|
$log_act->debug( "Redirect to '$action_redir'" ); |
|
379
|
0
|
|
|
|
|
|
$current_name = $action_redir; |
|
380
|
|
|
|
|
|
|
} |
|
381
|
0
|
|
|
|
|
|
return $action_info; |
|
382
|
|
|
|
|
|
|
} |
|
383
|
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
sub lookup_action { |
|
386
|
0
|
|
|
0
|
|
|
my ( $self, $action_name, $props ) = @_; |
|
387
|
0
|
|
0
|
|
|
|
$log_act ||= get_logger( LOG_ACTION ); |
|
388
|
0
|
|
|
|
|
|
my $action_info = $self->lookup_action_info( $action_name ); |
|
389
|
0
|
0
|
|
|
|
|
unless ( $action_info ) { |
|
390
|
0
|
|
|
|
|
|
my $msg = "No action found for '$action_name'"; |
|
391
|
0
|
|
|
|
|
|
$log_act->error( $msg ); |
|
392
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( $msg ); |
|
393
|
|
|
|
|
|
|
} |
|
394
|
0
|
|
|
|
|
|
return OpenInteract2::Action->new( $action_info, $props ); |
|
395
|
|
|
|
|
|
|
} |
|
396
|
|
|
|
|
|
|
|
|
397
|
|
|
|
|
|
|
sub lookup_action_none { |
|
398
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
399
|
0
|
|
|
|
|
|
my $action_name = $self->server_config->{action_info}{none}; |
|
400
|
0
|
|
|
|
|
|
return $self->_create_action_from_name( |
|
401
|
|
|
|
|
|
|
$action_name, 'action_info.none' |
|
402
|
|
|
|
|
|
|
); |
|
403
|
|
|
|
|
|
|
} |
|
404
|
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
sub lookup_action_not_found { |
|
406
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
407
|
0
|
|
|
|
|
|
my $action_name = $self->server_config->{action_info}{not_found}; |
|
408
|
0
|
|
|
|
|
|
return $self->_create_action_from_name( |
|
409
|
|
|
|
|
|
|
$action_name, 'action_info.not_found' |
|
410
|
|
|
|
|
|
|
); |
|
411
|
|
|
|
|
|
|
} |
|
412
|
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
sub _create_action_from_name { |
|
414
|
0
|
|
|
0
|
|
|
my ( $self, $name, $key ) = @_; |
|
415
|
0
|
0
|
|
|
|
|
unless ( $name ) { |
|
416
|
0
|
|
|
|
|
|
my $msg = join( '', |
|
417
|
|
|
|
|
|
|
"Check your server configuration -- you must define an ", |
|
418
|
|
|
|
|
|
|
"action number in your server configuration under '$key'" |
|
419
|
|
|
|
|
|
|
); |
|
420
|
0
|
|
0
|
|
|
|
$log_act ||= get_logger( LOG_ACTION ); |
|
421
|
0
|
|
|
|
|
|
$log_act->error( $msg ); |
|
422
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( $msg ); |
|
423
|
|
|
|
|
|
|
} |
|
424
|
0
|
|
|
|
|
|
return $self->lookup_action( $name ); |
|
425
|
|
|
|
|
|
|
} |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
sub lookup_default_action_info { |
|
428
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
429
|
0
|
|
|
|
|
|
return $self->server_config->{action_info}{default}; |
|
430
|
|
|
|
|
|
|
} |
|
431
|
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
######################################## |
|
434
|
|
|
|
|
|
|
# OBJECT CLASS LOOKUP |
|
435
|
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
sub lookup_object { |
|
437
|
0
|
|
|
0
|
|
|
my ( $self, $object_name ) = @_; |
|
438
|
0
|
|
0
|
|
|
|
$log_spops ||= get_logger( LOG_SPOPS ); |
|
439
|
0
|
0
|
|
|
|
|
unless ( $object_name ) { |
|
440
|
0
|
|
|
|
|
|
my $msg = "Cannot lookup object class without object name"; |
|
441
|
0
|
|
|
|
|
|
$log_spops->error( $msg ); |
|
442
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( $msg ); |
|
443
|
|
|
|
|
|
|
} |
|
444
|
0
|
|
|
|
|
|
my $spops_config = $self->spops_config; |
|
445
|
0
|
0
|
|
|
|
|
unless ( $spops_config->{ lc $object_name } ) { |
|
446
|
0
|
|
|
|
|
|
my $msg = "No object class found for '$object_name'"; |
|
447
|
0
|
|
|
|
|
|
$log_spops->error( $msg ); |
|
448
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( $msg ); |
|
449
|
|
|
|
|
|
|
} |
|
450
|
0
|
|
|
|
|
|
my $use_name = lc $object_name; |
|
451
|
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
# 'alias_class' is defined in the common case when we want to |
|
453
|
|
|
|
|
|
|
# generate the persistence class ('class') and then subclass it |
|
454
|
|
|
|
|
|
|
# for our customizations ('alias_class') |
|
455
|
|
|
|
|
|
|
|
|
456
|
0
|
|
0
|
|
|
|
my $object_class = $spops_config->{ $use_name }{alias_class} |
|
457
|
|
|
|
|
|
|
|| $spops_config->{ $use_name }{class}; |
|
458
|
0
|
0
|
|
|
|
|
$log_spops->is_debug && |
|
459
|
|
|
|
|
|
|
$log_spops->debug( "Found class '$object_class' for '$object_name'" ); |
|
460
|
0
|
|
|
|
|
|
return $object_class; |
|
461
|
|
|
|
|
|
|
} |
|
462
|
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
######################################## |
|
465
|
|
|
|
|
|
|
# CONTROLLER LOOKUP |
|
466
|
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
sub lookup_controller_config { |
|
468
|
0
|
|
|
0
|
|
|
my ( $self, $name ) = @_; |
|
469
|
0
|
0
|
|
|
|
|
if ( $name ) { |
|
470
|
0
|
|
|
|
|
|
return $self->server_config->{controller}{ $name }; |
|
471
|
|
|
|
|
|
|
} |
|
472
|
0
|
|
|
|
|
|
return $self->server_config->{controller}; |
|
473
|
|
|
|
|
|
|
} |
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
######################################## |
|
477
|
|
|
|
|
|
|
# FULLTEXT INDEXING LOOKUP |
|
478
|
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
sub lookup_fulltext_config { |
|
480
|
0
|
|
|
0
|
|
|
my ( $self, $name ) = @_; |
|
481
|
0
|
0
|
|
|
|
|
if ( $name ) { |
|
482
|
0
|
|
|
|
|
|
return $self->server_config->{fulltext}{ $name }; |
|
483
|
|
|
|
|
|
|
} |
|
484
|
0
|
|
|
|
|
|
return $self->server_config->{fulltext}; |
|
485
|
|
|
|
|
|
|
} |
|
486
|
|
|
|
|
|
|
|
|
487
|
|
|
|
|
|
|
sub fulltext_indexer { |
|
488
|
0
|
|
|
0
|
|
|
my ( $self, $indexer_name ) = @_; |
|
489
|
0
|
|
0
|
|
|
|
$log_act ||= get_logger( LOG_ACTION ); |
|
490
|
|
|
|
|
|
|
|
|
491
|
0
|
|
|
|
|
|
my $all_config = $self->lookup_fulltext_config; |
|
492
|
0
|
0
|
|
|
|
|
unless ( $indexer_name ) { |
|
493
|
0
|
|
|
|
|
|
$indexer_name = $all_config->{default}; |
|
494
|
0
|
0
|
|
|
|
|
unless ( $indexer_name ) { |
|
495
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( |
|
496
|
|
|
|
|
|
|
"No fulltext indexer defined in server configuration ", |
|
497
|
|
|
|
|
|
|
"key 'fulltext.default'" ); |
|
498
|
|
|
|
|
|
|
} |
|
499
|
|
|
|
|
|
|
} |
|
500
|
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
$log_act->is_debug && |
|
502
|
0
|
0
|
|
|
|
|
$log_act->debug( "Fulltext indexer configured: $indexer_name" ); |
|
503
|
0
|
|
|
|
|
|
my $ft_config = $all_config->{ $indexer_name }; |
|
504
|
0
|
0
|
|
|
|
|
unless ( ref $ft_config eq 'HASH' ) { |
|
505
|
0
|
|
|
|
|
|
OpenInteract2::Exception->throw( |
|
506
|
|
|
|
|
|
|
"Fulltext indexer '$indexer_name' set in server ", |
|
507
|
|
|
|
|
|
|
"configuration key 'fulltext.default' does not ", |
|
508
|
|
|
|
|
|
|
"have corresponding configuration section." ); |
|
509
|
|
|
|
|
|
|
} |
|
510
|
|
|
|
|
|
|
|
|
511
|
0
|
|
|
|
|
|
my $ft_class = $ft_config->{class}; |
|
512
|
0
|
|
|
|
|
|
return $ft_class->new( $ft_config ); |
|
513
|
|
|
|
|
|
|
} |
|
514
|
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
######################################## |
|
517
|
|
|
|
|
|
|
# CONTENT GENERATOR LOOKUP |
|
518
|
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
sub lookup_content_generator_config { |
|
520
|
0
|
|
|
0
|
|
|
my ( $self, $name ) = @_; |
|
521
|
0
|
0
|
|
|
|
|
if ( $name ) { |
|
522
|
0
|
|
|
|
|
|
return $self->server_config->{content_generator}{ $name }; |
|
523
|
|
|
|
|
|
|
} |
|
524
|
0
|
|
|
|
|
|
return $self->server_config->{content_generator}; |
|
525
|
|
|
|
|
|
|
} |
|
526
|
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
######################################## |
|
529
|
|
|
|
|
|
|
# OBSERVERS |
|
530
|
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
sub lookup_observer { |
|
532
|
0
|
|
|
0
|
|
|
my ( $self, $name ) = @_; |
|
533
|
0
|
0
|
|
|
|
|
if ( $name ) { |
|
534
|
0
|
|
|
|
|
|
return $self->{observers}{ $name }; |
|
535
|
|
|
|
|
|
|
} |
|
536
|
0
|
|
|
|
|
|
return $self->{observers}; |
|
537
|
|
|
|
|
|
|
} |
|
538
|
|
|
|
|
|
|
|
|
539
|
|
|
|
|
|
|
sub set_observer_registry { |
|
540
|
0
|
|
|
0
|
|
|
my ( $self, $registry ) = @_; |
|
541
|
0
|
|
|
|
|
|
$self->{observers} = $registry; |
|
542
|
0
|
|
|
|
|
|
return; |
|
543
|
|
|
|
|
|
|
} |
|
544
|
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
sub add_observer { |
|
546
|
0
|
|
|
0
|
|
|
my ( $self, $observer_name, $observer_info ) = @_; |
|
547
|
0
|
|
|
|
|
|
OpenInteract2::Observer->register_observer( |
|
548
|
|
|
|
|
|
|
$observer_name, $observer_info, $self->{observers} ); |
|
549
|
|
|
|
|
|
|
} |
|
550
|
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
sub map_observer { |
|
552
|
0
|
|
|
0
|
|
|
my ( $self, $observer_name, $action_or_name ) = @_; |
|
553
|
0
|
|
|
|
|
|
OpenInteract2::Observer->add_observer_to_action( $observer_name, $action_or_name ); |
|
554
|
|
|
|
|
|
|
} |
|
555
|
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
|
|
557
|
|
|
|
|
|
|
######################################## |
|
558
|
|
|
|
|
|
|
# DIRECTORY/FILE LOOKUPS |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
sub lookup_directory { |
|
561
|
0
|
|
|
0
|
|
|
my ( $self, $dir_name ) = @_; |
|
562
|
0
|
0
|
|
|
|
|
if ( $dir_name ) { |
|
563
|
0
|
|
|
|
|
|
return $self->server_config->{dir}{ $dir_name }; |
|
564
|
|
|
|
|
|
|
} |
|
565
|
0
|
|
|
|
|
|
return $self->server_config->{dir}; |
|
566
|
|
|
|
|
|
|
} |
|
567
|
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
# TODO: What happens if someone specifies a fully-qualified directory? |
|
569
|
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
sub lookup_temp_lib_directory { |
|
571
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
572
|
0
|
|
|
|
|
|
my $bootstrap = $self->bootstrap; |
|
573
|
0
|
|
0
|
|
|
|
my $lib_dir = $bootstrap->temp_lib_dir || DEFAULT_TEMP_LIB_DIR; |
|
574
|
0
|
|
|
|
|
|
return File::Spec->catdir( $bootstrap->website_dir, $lib_dir ); |
|
575
|
|
|
|
|
|
|
} |
|
576
|
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
sub lookup_temp_lib_refresh_filename { |
|
578
|
0
|
|
|
0
|
|
|
return 'refresh.txt'; |
|
579
|
|
|
|
|
|
|
} |
|
580
|
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
sub lookup_override_action_filename { |
|
582
|
0
|
|
|
0
|
|
|
return 'action_override.ini'; |
|
583
|
|
|
|
|
|
|
} |
|
584
|
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
sub lookup_override_spops_filename { |
|
586
|
0
|
|
|
0
|
|
|
return 'spops_override.ini'; |
|
587
|
|
|
|
|
|
|
} |
|
588
|
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
######################################## |
|
591
|
|
|
|
|
|
|
# LOOKUPS, OTHER |
|
592
|
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
sub lookup_session_config { |
|
594
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
595
|
0
|
|
|
|
|
|
return $self->server_config->{session_info}; |
|
596
|
|
|
|
|
|
|
} |
|
597
|
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
sub lookup_login_config { |
|
599
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
600
|
0
|
|
|
|
|
|
return $self->server_config->{login}; |
|
601
|
|
|
|
|
|
|
} |
|
602
|
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
sub lookup_mail_config { |
|
604
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
605
|
0
|
|
|
|
|
|
return $self->server_config->{mail}; |
|
606
|
|
|
|
|
|
|
} |
|
607
|
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
sub lookup_language_config { |
|
609
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
610
|
0
|
|
|
|
|
|
return $self->server_config->{language}; |
|
611
|
|
|
|
|
|
|
} |
|
612
|
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
sub lookup_cache_config { |
|
614
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
615
|
0
|
|
|
|
|
|
return $self->server_config->{cache}; |
|
616
|
|
|
|
|
|
|
} |
|
617
|
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
sub lookup_config_watcher_config { |
|
619
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
620
|
0
|
|
|
|
|
|
return $self->server_config->{config_watcher}; |
|
621
|
|
|
|
|
|
|
} |
|
622
|
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
sub lookup_redirect_config { |
|
624
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
625
|
0
|
|
|
|
|
|
return $self->server_config->{redirect}; |
|
626
|
|
|
|
|
|
|
} |
|
627
|
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
sub lookup_box_config { |
|
629
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
630
|
0
|
|
|
|
|
|
return $self->server_config->{box}; |
|
631
|
|
|
|
|
|
|
} |
|
632
|
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
######################################## |
|
635
|
|
|
|
|
|
|
# CLASS LOOKUP |
|
636
|
|
|
|
|
|
|
|
|
637
|
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
sub lookup_class { |
|
639
|
0
|
|
|
0
|
|
|
my ( $self, $name ) = @_; |
|
640
|
0
|
0
|
|
|
|
|
if ( $name ) { |
|
641
|
0
|
|
|
|
|
|
return $self->server_config->{system_class}{ $name }; |
|
642
|
|
|
|
|
|
|
} |
|
643
|
0
|
|
|
|
|
|
return $self->server_config->{system_class}; |
|
644
|
|
|
|
|
|
|
} |
|
645
|
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
# Config shortcut |
|
648
|
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
# NOTE: Coupling to OI2::URL->create_from_action with the |
|
650
|
|
|
|
|
|
|
# 'url_primary' key. |
|
651
|
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
sub action_table { |
|
653
|
0
|
|
|
0
|
|
|
my ( $self, $table ) = @_; |
|
654
|
0
|
|
0
|
|
|
|
$log_act ||= get_logger( LOG_ACTION ); |
|
655
|
0
|
0
|
|
|
|
|
if ( $table ) { |
|
656
|
0
|
0
|
|
|
|
|
$log_act->is_info && |
|
657
|
|
|
|
|
|
|
$log_act->info( "Assigning new action table" ); |
|
658
|
0
|
|
|
|
|
|
$self->server_config->{action} = $table; |
|
659
|
0
|
|
|
|
|
|
my %url_to_name = (); |
|
660
|
0
|
|
|
|
|
|
while ( my ( $name, $info ) = each %{ $table } ) { |
|
|
0
|
|
|
|
|
|
|
|
661
|
0
|
0
|
|
|
|
|
next if ( $info->{redir} ); |
|
662
|
0
|
0
|
|
|
|
|
$log_act->is_debug && |
|
663
|
|
|
|
|
|
|
$log_act->debug( "Finding URL(s) for action '$name'" ); |
|
664
|
0
|
|
|
|
|
|
my $action = eval { OpenInteract2::Action->new( $info ) }; |
|
|
0
|
|
|
|
|
|
|
|
665
|
0
|
0
|
|
|
|
|
if ( $@ ) { |
|
666
|
0
|
|
|
|
|
|
$log_act->error( |
|
667
|
|
|
|
|
|
|
"Failed to create action '$name' when assigned a new ", |
|
668
|
|
|
|
|
|
|
"set of action configurations. Will remove action data ", |
|
669
|
|
|
|
|
|
|
"from action table. Error: $@" ); |
|
670
|
0
|
|
|
|
|
|
delete $self->server_config->{action}->{ $name }; |
|
671
|
|
|
|
|
|
|
} |
|
672
|
|
|
|
|
|
|
else { |
|
673
|
0
|
|
|
|
|
|
my $respond_urls = $action->get_dispatch_urls; |
|
674
|
0
|
|
|
|
|
|
$url_to_name{ $_ } = $name for ( @{ $respond_urls } ); |
|
|
0
|
|
|
|
|
|
|
|
675
|
0
|
|
|
|
|
|
$info->{url_primary} = $respond_urls->[0]; |
|
676
|
|
|
|
|
|
|
} |
|
677
|
|
|
|
|
|
|
} |
|
678
|
0
|
|
|
|
|
|
$self->server_config->{action_url} = \%url_to_name; |
|
679
|
|
|
|
|
|
|
} |
|
680
|
0
|
|
|
|
|
|
return $self->server_config->{action}; |
|
681
|
|
|
|
|
|
|
} |
|
682
|
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
# Config shortcut |
|
685
|
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
sub spops_config { |
|
687
|
0
|
|
|
0
|
|
|
my ( $self, $table ) = @_; |
|
688
|
0
|
|
0
|
|
|
|
$log_spops ||= get_logger( LOG_SPOPS ); |
|
689
|
0
|
0
|
|
|
|
|
if ( $table ) { |
|
690
|
0
|
0
|
|
|
|
|
$log_spops->is_info && |
|
691
|
|
|
|
|
|
|
$log_spops->info( "Assigning new SPOPS configuration" ); |
|
692
|
0
|
|
|
|
|
|
$self->server_config->{SPOPS} = $table; |
|
693
|
|
|
|
|
|
|
} |
|
694
|
0
|
|
|
|
|
|
return $self->server_config->{SPOPS}; |
|
695
|
|
|
|
|
|
|
} |
|
696
|
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
# Config shortcut |
|
698
|
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
sub assign_datasource_config { |
|
700
|
0
|
|
|
0
|
|
|
my ( $self, $name, $config ) = @_; |
|
701
|
0
|
0
|
0
|
|
|
|
unless ( $name and $config ) { |
|
702
|
0
|
|
|
|
|
|
return; |
|
703
|
|
|
|
|
|
|
} |
|
704
|
0
|
|
|
|
|
|
$self->server_config->{datasource}{ $name } = $config; |
|
705
|
0
|
|
|
|
|
|
return $config; |
|
706
|
|
|
|
|
|
|
} |
|
707
|
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
sub lookup_datasource_config { |
|
709
|
0
|
|
|
0
|
|
|
my ( $self, $name ) = @_; |
|
710
|
0
|
0
|
|
|
|
|
if ( $name ) { |
|
711
|
0
|
|
|
|
|
|
return $self->server_config->{datasource}{ $name }; |
|
712
|
|
|
|
|
|
|
} |
|
713
|
0
|
|
|
|
|
|
return $self->server_config->{datasource}; |
|
714
|
|
|
|
|
|
|
} |
|
715
|
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
sub lookup_datasource_type_config { |
|
717
|
0
|
|
|
0
|
|
|
my ( $self, $type ) = @_; |
|
718
|
0
|
0
|
|
|
|
|
if ( $type ) { |
|
719
|
0
|
|
|
|
|
|
return $self->server_config->{datasource_type}{ $type }; |
|
720
|
|
|
|
|
|
|
} |
|
721
|
0
|
|
|
|
|
|
return $self->server_config->{datasource_type}; |
|
722
|
|
|
|
|
|
|
} |
|
723
|
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
sub lookup_system_datasource_name { |
|
725
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
726
|
0
|
|
|
|
|
|
return $self->server_config->{datasource_config}{system}; |
|
727
|
|
|
|
|
|
|
} |
|
728
|
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
sub lookup_default_datasource_name { |
|
730
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
731
|
0
|
|
|
|
|
|
return $self->server_config->{datasource_config}{spops}; |
|
732
|
|
|
|
|
|
|
} |
|
733
|
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
sub lookup_default_ldap_datasource_name { |
|
735
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
736
|
0
|
|
|
|
|
|
return $self->server_config->{datasource_config}{ldap}; |
|
737
|
|
|
|
|
|
|
} |
|
738
|
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
sub lookup_default_object_id { |
|
740
|
0
|
|
|
0
|
|
|
my ( $self, $name ) = @_; |
|
741
|
0
|
0
|
|
|
|
|
if ( $name ) { |
|
742
|
0
|
|
|
|
|
|
return $self->server_config->{default_objects}{ $name }; |
|
743
|
|
|
|
|
|
|
} |
|
744
|
0
|
|
|
|
|
|
return $self->server_config->{default_objects}; |
|
745
|
|
|
|
|
|
|
} |
|
746
|
|
|
|
|
|
|
|
|
747
|
|
|
|
|
|
|
sub lookup_id_config { |
|
748
|
0
|
|
|
0
|
|
|
my ( $self, $definition ) = @_; |
|
749
|
0
|
0
|
|
|
|
|
if ( $definition ) { |
|
750
|
0
|
|
|
|
|
|
return $self->{server_config}{id}{ $definition }; |
|
751
|
|
|
|
|
|
|
} |
|
752
|
0
|
|
|
|
|
|
return $self->{server_config}{id}; |
|
753
|
|
|
|
|
|
|
} |
|
754
|
|
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
######################################## |
|
757
|
|
|
|
|
|
|
# GLOBAL RESOURCES |
|
758
|
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
# Get the named datasource -- just pass along the request to the |
|
760
|
|
|
|
|
|
|
# DatasourceManager |
|
761
|
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
sub datasource { |
|
763
|
0
|
|
|
0
|
|
|
my ( $self, $name ) = @_; |
|
764
|
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
# TODO: Why choose the 'system' default here? |
|
766
|
0
|
|
0
|
|
|
|
$name ||= $self->server_config->{datasource_config}{system}; |
|
767
|
0
|
|
|
|
|
|
return OpenInteract2::DatasourceManager->datasource( $name ); |
|
768
|
|
|
|
|
|
|
} |
|
769
|
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
sub content_generator { |
|
771
|
0
|
|
|
0
|
|
|
my ( $self, $name ) = @_; |
|
772
|
0
|
|
|
|
|
|
return OpenInteract2::ContentGenerator->instance( $name ); |
|
773
|
|
|
|
|
|
|
} |
|
774
|
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
sub assign_default_language_handle { |
|
777
|
0
|
|
|
0
|
|
|
my ( $self, $lh ) = @_; |
|
778
|
0
|
|
|
|
|
|
$DEFAULT_LANGUAGE_HANDLE = $lh |
|
779
|
|
|
|
|
|
|
} |
|
780
|
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
sub language_handle { |
|
782
|
0
|
|
|
0
|
|
|
my ( $self, $lang ) = @_; |
|
783
|
0
|
0
|
0
|
|
|
|
if ( $self->request and my $h = $self->request->language_handle ) { |
|
|
|
0
|
|
|
|
|
|
|
784
|
0
|
|
|
|
|
|
return $h; |
|
785
|
|
|
|
|
|
|
} |
|
786
|
|
|
|
|
|
|
elsif ( $lang ) { |
|
787
|
0
|
|
|
|
|
|
return OpenInteract2::I18N->get_handle( $lang ); |
|
788
|
|
|
|
|
|
|
} |
|
789
|
|
|
|
|
|
|
else { |
|
790
|
0
|
|
|
|
|
|
return $DEFAULT_LANGUAGE_HANDLE; |
|
791
|
|
|
|
|
|
|
} |
|
792
|
|
|
|
|
|
|
} |
|
793
|
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
sub cleanup_request { |
|
795
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
796
|
0
|
|
|
|
|
|
$self->set( $_, undef ) for ( @REQUEST_FIELDS ); |
|
797
|
|
|
|
|
|
|
|
|
798
|
|
|
|
|
|
|
# TODO: These two methods Needed? |
|
799
|
0
|
|
|
|
|
|
$self->clear_global_attributes; |
|
800
|
0
|
|
|
|
|
|
$self->clear_exceptions; |
|
801
|
|
|
|
|
|
|
} |
|
802
|
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
|
|
804
|
|
|
|
|
|
|
# Shortcut -- use to check security on classes that are not derived |
|
805
|
|
|
|
|
|
|
# from SPOPS::Secure, or from other resources |
|
806
|
|
|
|
|
|
|
|
|
807
|
|
|
|
|
|
|
sub check_security { |
|
808
|
0
|
|
|
0
|
|
|
my ( $self, $params ) = @_; |
|
809
|
0
|
|
|
|
|
|
my $log_sec = get_logger( LOG_SECURITY ); |
|
810
|
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
# TODO: make static at startup... |
|
812
|
0
|
|
|
|
|
|
my $security_class = $self->lookup_object( 'security' ); |
|
813
|
|
|
|
|
|
|
|
|
814
|
0
|
|
|
|
|
|
my %security_info = ( security_object_class => $security_class, |
|
815
|
|
|
|
|
|
|
class => $params->{class}, |
|
816
|
|
|
|
|
|
|
object_id => $params->{object_id}, |
|
817
|
|
|
|
|
|
|
user => $params->{user}, |
|
818
|
|
|
|
|
|
|
group => $params->{group} ); |
|
819
|
0
|
|
|
|
|
|
my $request = $self->request; |
|
820
|
0
|
0
|
0
|
|
|
|
if ( $request and $request->auth_is_logged_in ) { |
|
821
|
0
|
0
|
|
|
|
|
$log_sec->is_debug && |
|
822
|
|
|
|
|
|
|
$log_sec->debug( "Assigning user/group from login" ); |
|
823
|
0
|
|
0
|
|
|
|
$security_info{user} ||= $request->auth_user; |
|
824
|
0
|
|
0
|
|
|
|
$security_info{group} ||= $request->auth_group; |
|
825
|
|
|
|
|
|
|
} |
|
826
|
|
|
|
|
|
|
$log_sec->is_debug && |
|
827
|
0
|
0
|
|
|
|
|
$log_sec->debug( "Checking security for '$params->{class}' ", |
|
828
|
|
|
|
|
|
|
"'$params->{object_id}' with '$security_class'" ); |
|
829
|
0
|
|
|
|
|
|
return SPOPS::Secure->check_security( \%security_info ); |
|
830
|
|
|
|
|
|
|
} |
|
831
|
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
|
|
833
|
|
|
|
|
|
|
######################################## |
|
834
|
|
|
|
|
|
|
# EXCEPTIONS |
|
835
|
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
# Exception shortcuts |
|
837
|
|
|
|
|
|
|
# TODO: remove? |
|
838
|
|
|
|
|
|
|
|
|
839
|
0
|
|
|
0
|
|
|
sub throw { shift; goto &OpenInteract2::Exception::throw( @_ ) } |
|
|
0
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
# outside world doesn't need to know... |
|
843
|
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
sub dump { |
|
845
|
0
|
|
|
0
|
|
|
shift; |
|
846
|
0
|
|
|
|
|
|
my $output = ''; |
|
847
|
0
|
|
|
|
|
|
$output .= Dumper( $_ ) for ( @_ ); |
|
848
|
0
|
|
|
|
|
|
return $output; |
|
849
|
|
|
|
|
|
|
} |
|
850
|
|
|
|
|
|
|
|
|
851
|
|
|
|
|
|
|
1; |
|
852
|
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
__END__ |