- $main::lxdebug->enter_sub();
-
- my ($self, $form, $controls) = @_;
-
- $form->{sid} = $form->{dbdefault};
-
- my @upgradescripts = ();
- my ($query, $sth, $tag);
- my $rc = -2;
-
- @upgradescripts = sort_dbupdate_controls($controls);
-
- my $db_charset = $main::dbcharset;
- $db_charset ||= Common::DEFAULT_CHARSET;
-
- foreach my $db (split / /, $form->{dbupdate}) {
-
- next unless $form->{$db};
-
- # strip db from dataset
- $db =~ s/^db//;
- &dbconnect_vars($form, $db);
-
- my $dbh =
- DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
- or $form->dberror;
-
- $dbh->do($form->{dboptions}) if ($form->{dboptions});
-
- map({ $_->{"applied"} = 0; } @upgradescripts);
-
- $self->create_schema_info_table($form, $dbh);
-
- $query = qq|SELECT tag FROM schema_info|;
- $sth = $dbh->prepare($query);
- $sth->execute() || $form->dberror($query);
- while (($tag) = $sth->fetchrow_array()) {
- $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
- }
- $sth->finish();
-
- my $all_applied = 1;
- foreach (@upgradescripts) {
- if (!$_->{"applied"}) {
- $all_applied = 0;
- last;
- }
- }
-
- next if ($all_applied);
-
- foreach my $control (@upgradescripts) {
- next if ($control->{"applied"});
-
- $control->{description} = SL::Iconv::convert($control->{charset}, $db_charset, $control->{description});
-
- $control->{"file"} =~ /\.(sql|pl)$/;
- my $file_type = $1;
-
- # apply upgrade
- $main::lxdebug->message(LXDebug::DEBUG2, "Applying Update $control->{file}");
- print $form->parse_html_template("dbupgrade/upgrade_message2", $control);
-
- if ($file_type eq "sql") {
- $self->process_query($form, $dbh, "sql/" . $form->{"dbdriver"} .
- "-upgrade2/$control->{file}", $control, $db_charset);
- } else {
- $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
- "-upgrade2/$control->{file}", $control, $db_charset);
- }
- }
-
- $rc = 0;
- $dbh->disconnect;
-
- }
-
- $main::lxdebug->leave_sub();
-
- return $rc;
-}
-
-sub update2_available {
- $main::lxdebug->enter_sub();
-
- my ($form, $controls) = @_;
-
- map({ $_->{"applied"} = 0; } values(%{$controls}));
-
- dbconnect_vars($form, $form->{"dbname"});
-
- my $dbh =
- DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) ||
- $form->dberror;
-
- my ($query, $tag, $sth);
-
- $query = qq|SELECT tag FROM schema_info|;
- $sth = $dbh->prepare($query);
- if ($sth->execute()) {
- while (($tag) = $sth->fetchrow_array()) {
- $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
- }
- }
- $sth->finish();
- $dbh->disconnect();