Revision 99601196
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/Dispatcher.pm | ||
---|---|---|
81 | 81 |
} |
82 | 82 |
} |
83 | 83 |
|
84 |
sub pre_request_initialization { |
|
85 |
my ($self, %params) = @_; |
|
86 |
|
|
87 |
$self->unrequire_bin_mozilla; |
|
88 |
|
|
89 |
$::locale = Locale->new($::lx_office_conf{system}->{language}); |
|
90 |
$::form = Form->new; |
|
91 |
$::instance_conf = SL::InstanceConfiguration->new; |
|
92 |
$::request = SL::Request->new( |
|
93 |
cgi => CGI->new({}), |
|
94 |
layout => SL::Layout::None->new, |
|
95 |
); |
|
96 |
|
|
97 |
my $session_result = $::auth->restore_session; |
|
98 |
$::auth->create_or_refresh_session; |
|
99 |
|
|
100 |
if ($params{client}) { |
|
101 |
$::auth->set_client($params{client}) || die("cannot find client " . $params{client}); |
|
102 |
|
|
103 |
if ($params{login}) { |
|
104 |
die "cannot find user " . $params{login} unless %::myconfig = $::auth->read_user(login => $params{login}); |
|
105 |
die "cannot find locale for user " . $params{login} unless $::locale = Locale->new($::myconfig{countrycode}); |
|
106 |
|
|
107 |
$::form->{login} = $params{login}; # normaly implicit at login |
|
108 |
|
|
109 |
$::instance_conf->init; |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
return $session_result; |
|
114 |
} |
|
115 |
|
|
84 | 116 |
sub render_error_ajax { |
85 | 117 |
my ($error) = @_; |
86 | 118 |
|
... | ... | |
199 | 231 |
|
200 | 232 |
my ($script, $path, $suffix, $script_name, $action, $routing_type); |
201 | 233 |
|
202 |
$self->unrequire_bin_mozilla; |
|
203 |
|
|
204 |
$::locale = Locale->new($::lx_office_conf{system}->{language}); |
|
205 |
$::form = Form->new; |
|
206 |
$::instance_conf = SL::InstanceConfiguration->new; |
|
207 |
$::request = SL::Request->new( |
|
208 |
cgi => CGI->new({}), |
|
209 |
layout => SL::Layout::None->new, |
|
210 |
); |
|
211 |
|
|
212 |
my $session_result = $::auth->restore_session; |
|
213 |
$::auth->create_or_refresh_session; |
|
234 |
my $session_result = $self->pre_request_initialization; |
|
214 | 235 |
|
215 | 236 |
$::form->read_cgi_input; |
216 | 237 |
|
Auch abrufbar als: Unified diff
Dispatcher: Pro-Request-Initialisierung in eigene Sub verschoben
Weiterhin optionale Initialisierung von Client und User in besagter Sub.
Erleichert die Verwendung die Initialisierung vom Dispatcher in eigenen
Scripten (z.B. der console oder rose_auto_generate_models.pl, auch wenn
die noch nicht umgestellt sind), weil dann nicht in jedem Script der
Initialiserungspfad nachgebaut werden muss.
Beispiel ($client_id_or_name und $login können z.B. vorher aus einer
Konfigurationsdatei gelesen werden):
use SL::Dispatcher;
use SL::DB::Customer;
our $dispatcher = SL::Dispatcher->new('CGI');
$dispatcher->pre_startup;
$dispatcher->pre_request_initialization(
client => $client_id_or_name,
login => $login,
);
print join("\n", map { $_->id . ":" . $_->name } @{ SL::DB::Manager::Customer->get_all(limit => 5) }), "\n";