Revision 99601196
Von Moritz Bunkus vor fast 11 Jahren hinzugefügt
SL/Dispatcher.pm | ||
---|---|---|
}
|
||
}
|
||
|
||
sub pre_request_initialization {
|
||
my ($self, %params) = @_;
|
||
|
||
$self->unrequire_bin_mozilla;
|
||
|
||
$::locale = Locale->new($::lx_office_conf{system}->{language});
|
||
$::form = Form->new;
|
||
$::instance_conf = SL::InstanceConfiguration->new;
|
||
$::request = SL::Request->new(
|
||
cgi => CGI->new({}),
|
||
layout => SL::Layout::None->new,
|
||
);
|
||
|
||
my $session_result = $::auth->restore_session;
|
||
$::auth->create_or_refresh_session;
|
||
|
||
if ($params{client}) {
|
||
$::auth->set_client($params{client}) || die("cannot find client " . $params{client});
|
||
|
||
if ($params{login}) {
|
||
die "cannot find user " . $params{login} unless %::myconfig = $::auth->read_user(login => $params{login});
|
||
die "cannot find locale for user " . $params{login} unless $::locale = Locale->new($::myconfig{countrycode});
|
||
|
||
$::form->{login} = $params{login}; # normaly implicit at login
|
||
|
||
$::instance_conf->init;
|
||
}
|
||
}
|
||
|
||
return $session_result;
|
||
}
|
||
|
||
sub render_error_ajax {
|
||
my ($error) = @_;
|
||
|
||
... | ... | |
|
||
my ($script, $path, $suffix, $script_name, $action, $routing_type);
|
||
|
||
$self->unrequire_bin_mozilla;
|
||
|
||
$::locale = Locale->new($::lx_office_conf{system}->{language});
|
||
$::form = Form->new;
|
||
$::instance_conf = SL::InstanceConfiguration->new;
|
||
$::request = SL::Request->new(
|
||
cgi => CGI->new({}),
|
||
layout => SL::Layout::None->new,
|
||
);
|
||
|
||
my $session_result = $::auth->restore_session;
|
||
$::auth->create_or_refresh_session;
|
||
my $session_result = $self->pre_request_initialization;
|
||
|
||
$::form->read_cgi_input;
|
||
|
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";