X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/90bb521a25eeb37c5bbae1ff68c38e6c142b6e6b..57528e5b09f2fea9708d06ec99c3fb0200275534:/SL/User.pm diff --git a/SL/User.pm b/SL/User.pm index ae4c3edef..2159d9243 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -43,6 +43,7 @@ use SL::DBUpgrade2; use SL::DBUtils; use SL::Iconv; use SL::Inifile; +use SL::System::InstallationLock; use strict; @@ -114,20 +115,19 @@ sub login { my $dbupdater = SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls; - $form->{$_} = $::auth->client->{$_} for qw(dbname dbhost dbport dbuser dbpasswd); - $form->{$_} = $myconfig{$_} for qw(dateformat); - - dbconnect_vars($form, $form->{dbname}); - my $update_available = $dbupdater->update_available($dbversion) || $dbupdater->update2_available($dbh); $dbh->disconnect; return 0 if !$update_available; + + $form->{$_} = $::auth->client->{$_} for qw(dbname dbhost dbport dbuser dbpasswd); + $form->{$_} = $myconfig{$_} for qw(datestyle); + $form->{"title"} = $main::locale->text("Dataset upgrade"); $form->header(no_layout => $form->{no_layout}); print $form->parse_html_template("dbupgrade/header"); - $form->{dbupdate} = "db" . $form->{dbname}; + $form->{dbupdate} = "db" . $::auth->client->{dbname}; if ($form->{"show_dbupdate_warning"}) { print $form->parse_html_template("dbupgrade/warning"); @@ -135,26 +135,17 @@ sub login { } # update the tables - my $fh; - if (!$::lx_office_conf{debug}->{keep_installation_unlocked} && !open($fh, ">", $::lx_office_conf{paths}->{userspath} . "/nologin")) { - $form->show_generic_error($main::locale->text('A temporary file could not be created. ' . - 'Please verify that the directory "#1" is writeable by the webserver.', - $::lx_office_conf{paths}->{userspath}), - 'back_button' => 1); - } + SL::System::InstallationLock->lock; # ignore HUP, QUIT in case the webserver times out $SIG{HUP} = 'IGNORE'; $SIG{QUIT} = 'IGNORE'; $self->dbupdate($form); - $self->dbupdate2($form, $dbupdater); + $self->dbupdate2(form => $form, updater => $dbupdater, database => $::auth->client->{dbname}); SL::DBUpgrade2->new(form => $::form, auth => 1)->apply_admin_dbupgrade_scripts(0); - close($fh); - - # remove lock file - unlink($::lx_office_conf{paths}->{userspath} . "/nologin"); + SL::System::InstallationLock->unlock; print $form->parse_html_template("dbupgrade/footer"); @@ -542,43 +533,39 @@ sub dbupdate { sub dbupdate2 { $main::lxdebug->enter_sub(); - my ($self, $form, $dbupdater) = @_; + my ($self, %params) = @_; - my $rc = -2; - my $db_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; + my $form = $params{form}; + my $dbupdater = $params{updater}; + my $db = $params{database}; + my $rc = -2; + my $db_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; map { $_->{description} = SL::Iconv::convert($_->{charset}, $db_charset, $_->{description}) } values %{ $dbupdater->{all_controls} }; - foreach my $db (split / /, $form->{dbupdate}) { - next unless $form->{$db}; + &dbconnect_vars($form, $db); - # strip db from dataset - $db =~ s/^db//; - &dbconnect_vars($form, $db); + my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options) or $form->dberror; - my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options) or $form->dberror; + $dbh->do($form->{dboptions}) if ($form->{dboptions}); - $dbh->do($form->{dboptions}) if ($form->{dboptions}); - - $self->create_schema_info_table($form, $dbh); - - my @upgradescripts = $dbupdater->unapplied_upgrade_scripts($dbh); + $self->create_schema_info_table($form, $dbh); - $dbh->disconnect and next if !@upgradescripts; + my @upgradescripts = $dbupdater->unapplied_upgrade_scripts($dbh); - foreach my $control (@upgradescripts) { - # apply upgrade - $main::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}"); - print $form->parse_html_template("dbupgrade/upgrade_message2", $control); + $dbh->disconnect and next if !@upgradescripts; - $dbupdater->process_file($dbh, "sql/Pg-upgrade2/$control->{file}", $control, $db_charset); - } - - $rc = 0; - $dbh->disconnect; + foreach my $control (@upgradescripts) { + # apply upgrade + $main::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}"); + print $form->parse_html_template("dbupgrade/upgrade_message2", $control); + $dbupdater->process_file($dbh, "sql/Pg-upgrade2/$control->{file}", $control, $db_charset); } + $rc = 0; + $dbh->disconnect; + $main::lxdebug->leave_sub(); return $rc; @@ -627,11 +614,11 @@ sub create_employee_entry { ($can_delete) = selectrow_query($form, $dbh, qq|SELECT tag FROM schema_info WHERE tag = ?|, 'employee_deleted') if $good_db; if (!$id) { - my $query = qq|INSERT INTO employee (login, name, workphone, role) VALUES (?, ?, ?, ?)|; - do_query($form, $dbh, $query, ($self->{login}, $myconfig->{name}, $myconfig->{tel}, "user")); + my $query = qq|INSERT INTO employee (login, name, workphone) VALUES (?, ?, ?)|; + do_query($form, $dbh, $query, ($self->{login}, $myconfig->{name}, $myconfig->{tel})); } elsif ($update_existing && $can_delete) { - my $query = qq|UPDATE employee SET name = ?, workphone = ?, role = 'user', deleted = 'f' WHERE id = ?|; + my $query = qq|UPDATE employee SET name = ?, workphone = ?, deleted = 'f' WHERE id = ?|; do_query($form, $dbh, $query, $myconfig->{name}, $myconfig->{tel}, $id); }