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|;
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) = @_;
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} };
}
}
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;