package SL::DBUpgrade2;
+use English qw(-no_match_vars);
use IO::File;
use List::MoreUtils qw(any);
$params{path_suffix} ||= '';
$params{schema} ||= '';
- $params{path} = "sql/" . $params{dbdriver} . "-upgrade2" . $params{path_suffix};
+ $params{path} = "sql/Pg-upgrade2" . $params{path_suffix};
map { $self->{$_} = $params{$_} } keys %params;
# Process a Perl script which updates the database.
# If the script returns 1 then the update was successful.
-# Return code "2" means "needs more interaction; remove
-# users/nologin and end current request".
+# Return code "2" means "needs more interaction; unlock
+# the system and end current request".
# All other return codes are fatal errors.
sub process_perl_script {
$::lxdebug->enter_sub();
my ($self, $dbh, $filename, $version_or_control, $db_charset) = @_;
- my %form_values = map { $_ => $::form->{$_} } qw(dbconnect dbdefault dbdriver dbhost dbmbkiviunstable dbname dboptions dbpasswd dbport dbupdate dbuser login template_object version);
+ my %form_values = map { $_ => $::form->{$_} } qw(dbconnect dbdefault dbhost dbmbkiviunstable dbname dboptions dbpasswd dbport dbupdate dbuser login template_object version);
$dbh->begin_work;
# setup dbup_ export vars & run script
my %dbup_myconfig = map { ($_ => $::form->{$_}) } qw(dbname dbuser dbpasswd dbhost dbport dbconnect);
- my $result = SL::DBUpgrade2::Base::execute_script(
- file_name => $filename,
- tag => $version_or_control->{tag},
- dbh => $dbh,
- myconfig => \%dbup_myconfig,
- );
+ my $result = eval {
+ SL::DBUpgrade2::Base::execute_script(
+ file_name => $filename,
+ tag => $version_or_control->{tag},
+ dbh => $dbh,
+ myconfig => \%dbup_myconfig,
+ );
+ };
- if (1 != ($result // 1)) {
- $dbh->rollback();
- }
+ my $error = $EVAL_ERROR;
+
+ $dbh->rollback if 1 != ($result // -1);
if (!defined($result)) {
- print $::form->parse_html_template("dbupgrade/error", { file => $filename, error => $@ });
+ print $::form->parse_html_template("dbupgrade/error", { file => $filename, error => $error });
::end_of_request();
} elsif (1 != $result) {
- unlink("users/nologin") if (2 == $result);
+ SL::System::InstallationLock->unlock if 2 == $result;
::end_of_request();
}
local *SQLDIR;
- my $dbdriver = $self->{dbdriver};
- opendir SQLDIR, "sql/${dbdriver}-upgrade" || error("", "sql/${dbdriver}-upgrade: $!");
- my @upgradescripts = grep /${dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, readdir SQLDIR;
+ opendir SQLDIR, "sql/Pg-upgrade" || error("", "sql/Pg-upgrade: $!");
+ my @upgradescripts = grep /Pg-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, readdir SQLDIR;
closedir SQLDIR;
return ($#upgradescripts > -1);
$::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);
+ $self->process_file($dbh, "sql/Pg-upgrade2-auth/$control->{file}", $control, $db_charset);
}
print $self->{form}->parse_html_template("dbupgrade/footer", { is_admin => 1 }) if $called_from_admin;
# Apply outstanding updates to the authentication database
my $scripts = SL::DBUpgrade2->new(
form => $::form,
- dbdriver => 'Pg',
auth => 1
);
$scripts->apply_admin_dbupgrade_scripts(1);
# Apply updates to a user database
my $scripts = SL::DBUpgrade2->new(
form => $::form,
- dbdriver => $::form->{dbdriver},
auth => 1
);
- User->dbupdate2($form, $scripts->parse_dbupdate_controls);
+ User->dbupdate2(form => $form,
+ updater => $scripts->parse_dbupdate_controls,
+ database => $dbname);
=head1 OVERVIEW
before the current one is applied.
=item charset
+
=item encoding
The charset this file uses. Defaults to C<ISO-8859-15> if
C<SL::Form> object to use. Required.
-=item dbdriver
-
-Name of the database driver. Currently only C<Pg> for PostgreSQL is
-supported.
-
=item auth
Optional parameter defaulting to 0. If trueish then the scripts read
Perl scripts are executed via L<eval>. If L<eval> returns falsish then
an error is expected. There are two special return values: If the
script returns C<1> then the update was successful. Return code C<2>
-means "needs more interaction from the user; remove users/nologin and
+means "needs more interaction from the user; unlock the system and
end current upgrade process". All other return codes are fatal errors.
Inside the Perl script several local variables exist that can be used: