From c7edb24800396748f2bf1e40ff05f90a18d31b02 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 20 Jul 2010 10:27:17 +0200 Subject: [PATCH] Nur ein globales Locale-Objekt anlegen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Außerdem alle lokalen Locale-Objekte entfernt. Ist so noch nicht funktionabel. Conflicts: SL/Template/Plugin/T8.pm scripts/console scripts/rose_auto_create_model.pl scripts/sync_with_sugarcrm.pl --- SL/Dispatcher.pm | 6 +- SL/Template/Plugin/LxERP.pm | 3 +- SL/Template/Plugin/T8.pm | 6 +- SL/User.pm | 5 +- bin/mozilla/login.pl | 21 ++-- bin/mozilla/menuXML.pl | 13 +-- bin/mozilla/menujs.pl | 7 +- bin/mozilla/menunew.pl | 5 +- bin/mozilla/menuv3.pl | 5 +- bin/mozilla/menuv4.pl | 5 +- scripts/console | 196 ++++++++++++++++++++++++++++++++++++ scripts/dbupgrade2_tool.pl | 2 +- 12 files changed, 221 insertions(+), 53 deletions(-) create mode 100755 scripts/console diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index 0e1995410..6dc741f57 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -34,7 +34,7 @@ sub show_error { my $template = shift; my $error_type = shift || ''; - $::locale = Locale->new($::language, 'all'); + $::locale = Locale->new($::language); $::form->{error} = $::locale->text('The session is invalid or has expired.') if ($error_type eq 'session'); $::form->{error} = $::locale->text('Incorrect password!.') if ($error_type eq 'password'); $::myconfig{countrycode} = $::language; @@ -128,7 +128,7 @@ sub handle_request { require_main_code($script, $suffix); $::cgi = CGI->new(''); - $::locale = Locale->new($::language, $script); + $::locale = Locale->new($::language); $::form = Form->new; $::form->{script} = $script . $suffix; @@ -150,7 +150,7 @@ sub handle_request { show_error('login/password_error', 'password') unless $::myconfig{login}; - $::locale = Locale->new($::myconfig{countrycode}, $script); + $::locale = Locale->new($::myconfig{countrycode}); show_error('login/password_error', 'password') if SL::Auth::OK != $::auth->authenticate($::form->{login}, $::form->{password}, 0); diff --git a/SL/Template/Plugin/LxERP.pm b/SL/Template/Plugin/LxERP.pm index b36fcebee..40bf195f2 100644 --- a/SL/Template/Plugin/LxERP.pm +++ b/SL/Template/Plugin/LxERP.pm @@ -110,8 +110,7 @@ sub abs { sub t8 { my ($self, $text, @args) = @_; - $self->{locale} ||= Locale->new($::myconfig{countrycode}, 'all'); - return $self->{locale}->text($text, @args) || $text; + return $::locale->text($text, @args) || $text; } 1; diff --git a/SL/Template/Plugin/T8.pm b/SL/Template/Plugin/T8.pm index e736e0cd2..2208ff42f 100644 --- a/SL/Template/Plugin/T8.pm +++ b/SL/Template/Plugin/T8.pm @@ -3,13 +3,9 @@ package SL::Template::Plugin::T8; use Template::Plugin::Filter; use base qw( Template::Plugin::Filter ); -my $locale = undef; - sub init { my $self = shift; - $locale ||= Locale->new($main::myconfig{countrycode}, 'all'); - # first arg can specify filter name $self->install_filter($self->{ _ARGS }->[0] || 'T8'); @@ -18,7 +14,7 @@ sub init { sub filter { my ($self, $text, $args) = @_; - return $locale->text($text, @{ $args || [] }) || $text; + return $::locale->text($text, @{ $args || [] }) || $text; } return 'SL::Template::Plugin::T8'; diff --git a/SL/User.pm b/SL/User.pm index 88ea5b3f5..46fe85581 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -450,10 +450,7 @@ sub process_perl_script { map({ $dbup_myconfig{$_} = $form->{$_}; } qw(dbname dbuser dbpasswd dbhost dbport dbconnect)); - my $nls_file = $filename; - $nls_file =~ s|.*/||; - $nls_file =~ s|.pl$||; - my $dbup_locale = Locale->new($main::language, $nls_file); + my $dbup_locale = $::locale; my $result = eval($contents); diff --git a/bin/mozilla/login.pl b/bin/mozilla/login.pl index 622db697d..b04adc21e 100644 --- a/bin/mozilla/login.pl +++ b/bin/mozilla/login.pl @@ -39,7 +39,6 @@ use strict; our $cgi; our $form; -our $locale; our $auth; sub run { @@ -48,14 +47,13 @@ sub run { $cgi = $::cgi; $form = $::form; - $locale = $::locale; $auth = $::auth; $form->{stylesheet} = "lx-office-erp.css"; $form->{favicon} = "favicon.ico"; if (SL::Auth::SESSION_EXPIRED == $session_result) { - $form->{error_message} = $locale->text('The session is invalid or has expired.'); + $form->{error_message} = $::locale->text('The session is invalid or has expired.'); login_screen(); ::end_of_request(); } @@ -67,14 +65,14 @@ sub run { our %myconfig = $auth->read_user($form->{login}) if ($form->{login}); if (!$myconfig{login} || (SL::Auth::OK != $auth->authenticate($form->{login}, $form->{password}, 0))) { - $form->{error_message} = $locale->text('Incorrect Password!'); + $form->{error_message} = $::locale->text('Incorrect Password!'); login_screen(); } else { $auth->set_session_value('login', $form->{login}, 'password', $form->{password}); $auth->create_or_refresh_session(); $form->{titlebar} .= " - $myconfig{name} - $myconfig{dbname}"; - call_sub($locale->findsub($action)); + call_sub($::locale->findsub($action)); } } else { login_screen(); @@ -103,7 +101,7 @@ sub login { $main::lxdebug->enter_sub(); unless ($form->{login}) { - login_screen($locale->text('You did not enter a name!')); + login_screen($::locale->text('You did not enter a name!')); ::end_of_request(); } @@ -113,7 +111,7 @@ sub login { my $result; if (($result = $user->login($form)) <= -1) { ::end_of_request() if $result == -2; - login_screen($locale->text('Incorrect username or password!')); + login_screen($::locale->text('Incorrect username or password!')); ::end_of_request(); } @@ -151,7 +149,7 @@ sub logout { # remove the callback to display the message $form->{callback} = "login.pl?action="; - $form->redirect($locale->text('You are logged out!')); + $form->redirect($::locale->text('You are logged out!')); $main::lxdebug->leave_sub(); } @@ -160,12 +158,10 @@ sub company_logo { $main::lxdebug->enter_sub(); my %myconfig = %main::myconfig; - $locale = new Locale $myconfig{countrycode}, "login" if ($main::language ne $myconfig{countrycode}); - $form->{todo_list} = create_todo_list('login_screen' => 1) if (!$form->{no_todo_list}); $form->{stylesheet} = $myconfig{stylesheet}; - $form->{title} = $locale->text('About'); + $form->{title} = $::locale->text('About'); # create the logo screen $form->header() unless $form->{noheader}; @@ -177,8 +173,7 @@ sub company_logo { sub show_error { my $template = shift; - my %myconfig = %main::myconfig; - $locale = Locale->new($main::language, 'all'); + my %myconfig = %main::myconfig; $myconfig{countrycode} = $main::language; $form->{stylesheet} = 'css/lx-office-erp.css'; diff --git a/bin/mozilla/menuXML.pl b/bin/mozilla/menuXML.pl index 5744c841f..b79d605fd 100644 --- a/bin/mozilla/menuXML.pl +++ b/bin/mozilla/menuXML.pl @@ -45,8 +45,6 @@ use URI; use strict; -my $locale; - 1; # end of main @@ -55,7 +53,6 @@ sub display { my $form = $main::form; my %myconfig = %main::myconfig; - $locale = Locale->new($myconfig{countrycode}, "menu"); my $charset = $main::dbcharset || 'ISO-8859-1'; my $callback = $form->unescape($form->{callback}); $callback = URI->new($callback)->rel($callback) if $callback; @@ -66,10 +63,10 @@ sub display { . qq| {iconv_iso8859}->convert('ß') . qq|"> -{iconv_iso8859}->convert('ä') . qq|"> -{iconv_iso8859}->convert('ö') . qq|"> -{iconv_iso8859}->convert('ü') . qq|"> +{iconv_iso8859}->convert('ß') . qq|"> +{iconv_iso8859}->convert('ä') . qq|"> +{iconv_iso8859}->convert('ö') . qq|"> +{iconv_iso8859}->convert('ü') . qq|"> ]> @@ -129,7 +126,7 @@ sub print_menu { next if (($item eq "") || ($item =~ /--/)); my $menu_item = $menu->{"${parent}${item}"}; - my $menu_title = $locale->text($item); + my $menu_title = $::locale->text($item); my $menu_text = $menu_title; my $target = "main_window"; diff --git a/bin/mozilla/menujs.pl b/bin/mozilla/menujs.pl index ef7b2b817..af60595c8 100644 --- a/bin/mozilla/menujs.pl +++ b/bin/mozilla/menujs.pl @@ -41,8 +41,6 @@ use CGI::Carp qw(fatalsToBrowser); use strict; -my $locale; - 1; # end of main @@ -82,7 +80,7 @@ sub clock_line { my $login = "[Nutzer " . $form->{login} . " - " - . $locale->text('Logout') + . $::locale->text('Logout') . "] "; my ($Sekunden, $Minuten, $Stunden, $Monatstag, $Monat, $Jahr, $Wochentag, $Jahrestag, $Sommerzeit) @@ -136,7 +134,6 @@ sub acc_menu { my $form = $main::form; my %myconfig = %main::myconfig; - $locale = Locale->new($myconfig{countrycode}, "menu"); my $mainlevel = $form->{level}; $mainlevel =~ s/$mainlevel--//g; my $menu = new Menu "$menufile"; @@ -390,7 +387,7 @@ sub section_menu { my $ml = $item; $label =~ s/$level--//g; $ml =~ s/--.*//; - $label = $locale->text($label); + $label = $::locale->text($label); $label =~ s/ / /g; $menu->{$item}{target} = "main_window" unless $menu->{$item}{target}; diff --git a/bin/mozilla/menunew.pl b/bin/mozilla/menunew.pl index 793cec24e..6b4f97175 100644 --- a/bin/mozilla/menunew.pl +++ b/bin/mozilla/menunew.pl @@ -40,8 +40,6 @@ use SL::Menu; use strict; -my $locale; - 1; # end of main @@ -91,7 +89,6 @@ sub clock_line { sub acc_menu { my $form = $main::form; my %myconfig = %main::myconfig; - $locale = Locale->new($myconfig{countrycode}, "menu"); my $mainlevel = $form->{level}; $mainlevel =~ s/\Q$mainlevel\E--//g; @@ -135,7 +132,7 @@ sub create_menu { next if (($name eq "") || ($name =~ /--/)); my $menu_item = $menu->{"${parent}${name}"}; - my $item = { 'title' => $locale->text($name) }; + my $item = { 'title' => $::locale->text($name) }; push @{ $all_items }, $item; if ($menu_item->{submenu} || !defined($menu_item->{module}) || ($menu_item->{module} eq "menu.pl")) { diff --git a/bin/mozilla/menuv3.pl b/bin/mozilla/menuv3.pl index 683cabfa2..49adcefa1 100644 --- a/bin/mozilla/menuv3.pl +++ b/bin/mozilla/menuv3.pl @@ -38,7 +38,6 @@ use URI; use strict; my $menufile = "menu.ini"; -my $locale; 1; @@ -86,8 +85,6 @@ sub acc_menu { my $form = $main::form; my %myconfig = %main::myconfig; - $locale = Locale->new($myconfig{countrycode}, "menu"); - my $mainlevel = $form->{level}; $mainlevel =~ s/\Q$mainlevel\E--//g; my $menu = new Menu "$menufile"; @@ -118,7 +115,7 @@ sub print_menu { next if (($item eq "") || ($item =~ /--/)); my $menu_item = $menu->{"${parent}${item}"}; - my $menu_title = $locale->text($item); + my $menu_title = $::locale->text($item); my $menu_text = $menu_title; my $target = "main_window"; diff --git a/bin/mozilla/menuv4.pl b/bin/mozilla/menuv4.pl index 3b736bf41..5459f6e8a 100644 --- a/bin/mozilla/menuv4.pl +++ b/bin/mozilla/menuv4.pl @@ -38,7 +38,6 @@ use URI; use strict; my $menufile = "menu.ini"; -my $locale; 1; @@ -88,8 +87,6 @@ sub acc_menu { my $form = $main::form; my %myconfig = %main::myconfig; - $locale = Locale->new($myconfig{countrycode}, "menu"); - my $mainlevel = $form->{level}; $mainlevel =~ s/\Q$mainlevel\E--//g; my $menu = new Menu "$menufile"; @@ -120,7 +117,7 @@ sub print_menu { next if (($item eq "") || ($item =~ /--/)); my $menu_item = $menu->{"${parent}${item}"}; - my $menu_title = $locale->text($item); + my $menu_title = $::locale->text($item); my $menu_text = $menu_title; my $target = "main_window"; diff --git a/scripts/console b/scripts/console new file mode 100755 index 000000000..d7679d0f6 --- /dev/null +++ b/scripts/console @@ -0,0 +1,196 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use 5.008; # too much magic in here to include perl 5.6 + +BEGIN { + unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML). + push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version. +} + +use Config::Std; +use Data::Dumper; +use Devel::REPL 1.002001; +use Term::ReadLine::Perl::Bind; # use sane key binding for rxvt users + +read_config 'config/console.conf' => my %config;# if -f 'config/console.conf'; + +my $login = shift || $config{Console}{login} || 'demo'; +my $history_file = $config{Console}{history_file} || '/tmp/lxoffice_console_history.log'; # fallback if users is not writable +my $autorun = $config{Console}{autorun}; + +# will be configed eventually +my @plugins = qw(History LexEnv Colors MultiLine::PPI FancyPrompt PermanentHistory AutoloadModules); + +my $repl = Devel::REPL->new; +$repl->load_plugin($_) for @plugins; +$repl->load_history($history_file); +$repl->eval('help'); +$repl->print("trying to auto login as '$login'..."); +$repl->print($repl->eval("lxinit '$login'")); +$repl->print($repl->eval($autorun)) if $autorun; +$repl->run; + +package Devel::REPL; + + +# this is a cleaned up version of am.pl +# it lacks redirection, some html setup and most of the authentication process. +# it is assumed that anyone with physical access and execution rights on this script +# won't be hindered by authentication anyway. +sub lxinit { + my $login = shift; + + die 'need login' unless $login; + + package main; + + { no warnings 'once'; + $::userspath = "users"; + $::templates = "templates"; + $::memberfile = "users/members"; + $::sendmail = "| /usr/sbin/sendmail -t"; + } + + use SL::LXDebug; + $::lxdebug = LXDebug->new; + + use CGI qw( -no_xhtml); + use SL::Auth; + use SL::Form; + use SL::Locale; + use Data::Dumper; + + eval { require "config/lx-erp.conf"; }; + eval { require "config/lx-erp-local.conf"; } if -f "config/lx-erp-local.conf"; + + $::cgi = CGI->new qw(); + $::form = Form->new; + $::auth = SL::Auth->new; + + die 'cannot reach auth db' unless $::auth->session_tables_present; + + $::auth->restore_session; + + require "bin/mozilla/common.pl"; + + die "cannot find user $login" unless %::myconfig = $::auth->read_user($login); + die "cannot find locale for user $login" unless $::locale = Locale->new($::myconfig{countrycode}); + + return "logged in as $login"; +} + +# these function provides a load command to slurp in a lx-office module +# since it's seldomly useful, it's not documented in help +sub load { + my $module = shift; + $module =~ s/[^\w]//g; + require "bin/mozilla/$module.pl"; +} + +sub reload { + use Module::Reload; + Module::Reload->check(); + + return "modules reloaded"; +} + +sub quit { + exit; +} + +sub help { + print < help # displays a brief documentation + +=head1 DESCRIPTION + +Users of Ruby on Rails will recognize this as a perl reimplementation of the +rails scripts/console. It's intend is to provide a shell environment to the +lx-office internals. This will mostly not interest you if you just want to do +your ERP stuff with lx-office, but will be invaluable for those who wish to +make changes to lx-office itself. + +=head1 FUNCTIONS + +You can do most things in the console that you could do in an actual perl +script. Certain helper functions will aid you in debugging the state of the +program: + +=head2 pp C + +Named after the rails pretty print gem, this will call Data::Dumper on the +given C. Use it to see what is going on. + +Currently C will set the Data::Dumper depth to 2, so if you need a +different depth, you'll have to change that. A nice feature would be to +configure that, or at least to be able to change it at runtime. + +=head2 lxinit C + +Login into lx-office using a specified login. No password will be required, and +security mechanisms will mostly be inactive. form, locale, myconfig will be +correctly set. + +=head2 reload + +Attempts to reload modules that changed since last reload (or inital startup). +This will mostly work just fine, except for Moose classes that have been made +immutable. Keep in mind that existing objects will continue to have the methods +of the classes they were created with. + +=head1 BUGS + + - Reload on immutable Moose classes is buggy. + - Logging in more than once is not supported by the program, and thus not by + the console. It seems to work, but strange things may happen. + +=head1 SEE ALSO + +Configuration of this script is located in: + + config/console.conf + config/console.conf.default + +See there for interesting options. + +=head1 AUTHOR + + Sven Schöling + +=cut diff --git a/scripts/dbupgrade2_tool.pl b/scripts/dbupgrade2_tool.pl index f1dcf9387..bef04f0dd 100755 --- a/scripts/dbupgrade2_tool.pl +++ b/scripts/dbupgrade2_tool.pl @@ -355,7 +355,7 @@ eval { require "config/lx-erp.conf"; }; eval { require "config/lx-erp-local.conf"; } if (-f "config/lx-erp-local.conf"); $form = Form->new(); -$locale = Locale->new("de", "login"); +$locale = Locale->new("de"); ####### ####### -- 2.20.1