From: Moritz Bunkus Date: Tue, 30 Nov 2010 08:42:28 +0000 (+0100) Subject: DB-Upgrade-Mechanismus für auth-Scripte im Verzeichnis sql/Pg-upgrade2-auth implementiert X-Git-Tag: release-2.6.2beta1~17^2~11^2~3 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=626ec4b4e4f6dbb6d018fa71819098c73fb59c53;p=kivitendo-erp.git DB-Upgrade-Mechanismus für auth-Scripte im Verzeichnis sql/Pg-upgrade2-auth implementiert --- diff --git a/SL/DBUpgrade2.pm b/SL/DBUpgrade2.pm index 929d59210..389e7975b 100644 --- a/SL/DBUpgrade2.pm +++ b/SL/DBUpgrade2.pm @@ -272,7 +272,7 @@ sub process_perl_script { } if (ref($version_or_control) eq "HASH") { - $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" . $dbh->quote($version_or_control->{"tag"}) . ", " . $dbh->quote($form->{"login"}) . ")"); + $dbh->do("INSERT INTO " . $self->{schema} . "schema_info (tag, login) VALUES (" . $dbh->quote($version_or_control->{"tag"}) . ", " . $dbh->quote($form->{"login"}) . ")"); } elsif ($version_or_control) { $dbh->do("UPDATE defaults SET version = " . $dbh->quote($version_or_control)); } @@ -331,7 +331,7 @@ sub unapplied_upgrade_scripts { my @all_scripts = map { $_->{applied} = 0; $_ } $self->sort_dbupdate_controls; - my $query = qq|SELECT tag FROM schema_info|; + my $query = qq|SELECT tag FROM | . $self->{schema} . qq|schema_info|; my $sth = $dbh->prepare($query); $sth->execute || $self->{form}->dberror($query); while (my ($tag) = $sth->fetchrow_array()) { diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index 0e61c3c85..661de8433 100755 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -43,6 +43,7 @@ use Sys::Hostname; use SL::Auth; use SL::Form; +use SL::Iconv; use SL::Mailer; use SL::User; use SL::Common; @@ -84,6 +85,9 @@ sub run { $::auth->set_session_value('rpw', $::form->{rpw}); $::auth->create_or_refresh_session(); } + + _apply_dbupgrade_scripts(); + call_sub($locale->findsub($form->{action})); } } else { @@ -1162,4 +1166,32 @@ sub dispatcher { $form->error($locale->text('No action defined.')); } +sub _apply_dbupgrade_scripts { + my $dbh = $::auth->dbconnect; + my $dbdriver = 'Pg'; + my $dbupdater = SL::DBUpgrade2->new(form => $::form, dbdriver => $dbdriver, auth => 1)->parse_dbupdate_controls; + my @unapplied_scripts = $dbupdater->unapplied_upgrade_scripts($dbh); + + return if !@unapplied_scripts; + + my $db_charset = $main::dbcharset || Common::DEFAULT_CHARSET; + $form->{login} = 'admin'; + + map { $_->{description} = SL::Iconv::convert($_->{charset}, $db_charset, $_->{description}) } values %{ $dbupdater->{all_controls} }; + + $form->{title} = $::locale->text('Dataset upgrade'); + $form->header; + print $form->parse_html_template("dbupgrade/header", { dbname => $::auth->{DB_config}->{db} }); + + foreach my $control (@unapplied_scripts) { + $::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}"); + print $form->parse_html_template("dbupgrade/upgrade_message2", $control); + + $dbupdater->process_file($dbh, "sql/${dbdriver}-upgrade2-auth/$control->{file}", $control, $db_charset); + } + + print $form->parse_html_template("dbupgrade/footer", { is_admin => 1, menufile => 'admin.pl' }); + ::end_of_request(); +} + 1; diff --git a/templates/webpages/dbupgrade/footer.html b/templates/webpages/dbupgrade/footer.html index e4c312ab4..eaf5f30bf 100644 --- a/templates/webpages/dbupgrade/footer.html +++ b/templates/webpages/dbupgrade/footer.html @@ -3,7 +3,7 @@
- +