# we got a connection, check the version
my ($dbversion) = $dbh->selectrow_array(qq|SELECT version FROM defaults|);
- $self->create_employee_entry($form, $dbh, \%myconfig);
-
$self->create_schema_info_table($form, $dbh);
# Auth DB upgrades available?
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");
$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;
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};
-
- # 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;
-
- $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;
-
- 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;
-}
-
-sub save_member {
- $main::lxdebug->enter_sub();
-
- my ($self) = @_;
-
- # format dbconnect and dboptions string
- dbconnect_vars($self, $self->{dbname});
-
- map { $self->{$_} =~ s/\r//g; } qw(address signature);
-
- $main::auth->save_user($self->{login}, map { $_, $self->{$_} } config_vars());
-
- my $dbh = SL::DBConnect->connect($self->{dbconnect}, $self->{dbuser}, $self->{dbpasswd}, SL::DBConnect->get_options);
- if ($dbh) {
- $self->create_employee_entry($::form, $dbh, $self, 1);
- $dbh->disconnect();
- }
+ &dbconnect_vars($form, $db);
- $main::lxdebug->leave_sub();
-}
+ my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options) or $form->dberror;
-sub create_employee_entry {
- $main::lxdebug->enter_sub();
+ $dbh->do($form->{dboptions}) if ($form->{dboptions});
- my $self = shift;
- my $form = shift;
- my $dbh = shift;
- my $myconfig = shift;
- my $update_existing = shift;
+ $self->create_schema_info_table($form, $dbh);
- if (!does_table_exist($dbh, 'employee')) {
- $main::lxdebug->leave_sub();
- return;
- }
+ my @upgradescripts = $dbupdater->unapplied_upgrade_scripts($dbh);
- # add login to employee table if it does not exist
- # no error check for employee table, ignore if it does not exist
- my ($id) = selectrow_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $self->{login});
- my ($good_db) = selectrow_query($form, $dbh, qq|select * from pg_tables where tablename = ? and schemaname = ?|, 'schema_info', 'public');
- my $can_delete;
- ($can_delete) = selectrow_query($form, $dbh, qq|SELECT tag FROM schema_info WHERE tag = ?|, 'employee_deleted') if $good_db;
+ $dbh->disconnect and next if !@upgradescripts;
- if (!$id) {
- my $query = qq|INSERT INTO employee (login, name, workphone, role) VALUES (?, ?, ?, ?)|;
- do_query($form, $dbh, $query, ($self->{login}, $myconfig->{name}, $myconfig->{tel}, "user"));
+ foreach my $control (@upgradescripts) {
+ # apply upgrade
+ $main::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}");
+ print $form->parse_html_template("dbupgrade/upgrade_message2", $control);
- } elsif ($update_existing && $can_delete) {
- my $query = qq|UPDATE employee SET name = ?, workphone = ?, role = 'user', deleted = 'f' WHERE id = ?|;
- do_query($form, $dbh, $query, $myconfig->{name}, $myconfig->{tel}, $id);
+ $dbupdater->process_file($dbh, "sql/Pg-upgrade2/$control->{file}", $control, $db_charset);
}
- $main::lxdebug->leave_sub();
-}
-
-sub config_vars {
- $main::lxdebug->enter_sub();
-
- my @conf = qw(copies countrycode dateformat default_media default_printer_id email favorites fax hide_cvar_search_options mandatory_departments menustyle name
- numberformat show_form_details signature stylesheet taxincluded_checked tel template_format vclimit);
+ $rc = 0;
+ $dbh->disconnect;
$main::lxdebug->leave_sub();
- return @conf;
+ return $rc;
}
sub data {