From: Moritz Bunkus Date: Fri, 23 May 2014 13:53:46 +0000 (+0200) Subject: Dispatcher: Pro-Request-Initialisierung in eigene Sub verschoben X-Git-Tag: release-3.2.0beta~440 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=99601196d8e8438871fd5a814a0cd802c6fd5d68;p=kivitendo-erp.git 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"; --- diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index f9ad09a87..854b863a3 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -81,6 +81,38 @@ sub pre_request_checks { } } +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) = @_; @@ -199,18 +231,7 @@ sub handle_request { 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;