From 486fe464fc69883e89ce37518473bfb688354d6f Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 30 Nov 2010 10:44:48 +0100 Subject: [PATCH] Admin-DB-Upgrade-Funktion nach DBUpgrade2 verschoben --- SL/DBUpgrade2.pm | 34 ++++++++++++++++++++++++ bin/mozilla/admin.pl | 26 +----------------- templates/webpages/dbupgrade/footer.html | 2 +- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/SL/DBUpgrade2.pm b/SL/DBUpgrade2.pm index 389e7975b..cbb8b9fb9 100644 --- a/SL/DBUpgrade2.pm +++ b/SL/DBUpgrade2.pm @@ -329,6 +329,8 @@ sub update2_available { sub unapplied_upgrade_scripts { my ($self, $dbh) = @_; + $::lxdebug->dump(0, "self", $self); + my @all_scripts = map { $_->{applied} = 0; $_ } $self->sort_dbupdate_controls; my $query = qq|SELECT tag FROM | . $self->{schema} . qq|schema_info|; @@ -342,6 +344,36 @@ sub unapplied_upgrade_scripts { return grep { !$_->{applied} } @all_scripts; } +sub apply_admin_dbupgrade_scripts { + my ($self, $called_from_admin) = @_; + + return if !$self->{auth}; + + my $dbh = $::auth->dbconnect; + my @unapplied_scripts = $self->unapplied_upgrade_scripts($dbh); + + return if !@unapplied_scripts; + + my $db_charset = $main::dbcharset || Common::DEFAULT_CHARSET; + $self->{form}->{login} ||= 'admin'; + + map { $_->{description} = SL::Iconv::convert($_->{charset}, $db_charset, $_->{description}) } values %{ $self->{all_controls} }; + + $self->{form}->{title} = $::locale->text('Dataset upgrade'); + $self->{form}->header; + print $self->{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 $self->{form}->parse_html_template("dbupgrade/upgrade_message2", $control); + + $self->process_file($dbh, "sql/$self->{dbdriver}-upgrade2-auth/$control->{file}", $control, $db_charset); + } + + print $self->{form}->parse_html_template("dbupgrade/footer", { is_admin => $called_from_admin }); + ::end_of_request(); +} + sub _check_for_loops { my ($form, $file_name, $controls, $tag, @path) = @_; @@ -395,6 +427,8 @@ sub _dbupdate2_calculate_depth { sub sort_dbupdate_controls { my $self = shift; + $self->parse_dbupdate_controls unless $self->{all_controls}; + return sort { ($a->{depth} <=> $b->{depth}) || ($a->{priority} <=> $b->{priority}) || ($a->{tag} cmp $b->{tag}) } values %{ $self->{all_controls} }; } diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index 661de8433..11d61e8a4 100755 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -1167,31 +1167,7 @@ sub dispatcher { } 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(); + SL::DBUpgrade2->new(form => $::form, dbdriver => 'Pg', auth => 1)->parse_dbupdate_controls->apply_admin_dbupgrade_scripts(1); } 1; diff --git a/templates/webpages/dbupgrade/footer.html b/templates/webpages/dbupgrade/footer.html index eaf5f30bf..f9dba7052 100644 --- a/templates/webpages/dbupgrade/footer.html +++ b/templates/webpages/dbupgrade/footer.html @@ -1,7 +1,7 @@ [%- USE T8 %] [% USE HTML %]

[% '...done' | $T8 %]

-
+ -- 2.20.1