From af412f0dd1d839d9afb9d55bb3feff0670dca3da Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 12 Jun 2013 16:38:53 +0200 Subject: [PATCH] Das Einspielen von Client-DB-Upgrades gefixt --- SL/User.pm | 57 ++++++++++++++++++++------------------------ bin/mozilla/admin.pl | 5 +--- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/SL/User.pm b/SL/User.pm index 294a1a3b4..e984dbf0f 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -115,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"); @@ -143,7 +142,7 @@ sub login { $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); SL::System::InstallationLock->unlock; @@ -534,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); - - $dbh->disconnect and next if !@upgradescripts; + $self->create_schema_info_table($form, $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); + my @upgradescripts = $dbupdater->unapplied_upgrade_scripts($dbh); - $dbupdater->process_file($dbh, "sql/Pg-upgrade2/$control->{file}", $control, $db_charset); - } + $dbh->disconnect and next if !@upgradescripts; - $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; diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index d1194ee8a..043cbe9d4 100755 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -221,11 +221,8 @@ sub dbupdate { print $form->parse_html_template("admin/dbupgrade_header"); - $form->{dbupdate} = $form->{dbname}; - $form->{$form->{dbname}} = 1; - User->dbupdate($form); - User->dbupdate2($form, SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls); + User->dbupdate2(form => $form, updater => SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls, database => $form->{dbname}); print $form->parse_html_template("admin/dbupgrade_footer"); } -- 2.20.1