Revision 38a2e789
Von Moritz Bunkus vor fast 14 Jahren hinzugefügt
SL/User.pm | ||
---|---|---|
121 | 121 |
|
122 | 122 |
$self->create_schema_info_table($form, $dbh); |
123 | 123 |
|
124 |
$dbh->disconnect; |
|
125 |
|
|
126 | 124 |
$rc = 0; |
127 | 125 |
|
128 |
my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $myconfig{dbdriver}); |
|
129 |
my $controls = $dbupdater->parse_dbupdate_controls; |
|
126 |
my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $myconfig{dbdriver})->parse_dbupdate_controls; |
|
130 | 127 |
|
131 |
map({ $form->{$_} = $myconfig{$_} } |
|
132 |
qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect dateformat)); |
|
133 |
|
|
134 |
if (update_available($myconfig{"dbdriver"}, $dbversion) || |
|
135 |
update2_available($form, $controls)) { |
|
128 |
map({ $form->{$_} = $myconfig{$_} } qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect dateformat)); |
|
129 |
dbconnect_vars($form, $form->{dbname}); |
|
130 |
my $update_available = $dbupdater->update_available($dbversion) || $dbupdater->update2_available($dbh); |
|
131 |
$dbh->disconnect; |
|
136 | 132 |
|
133 |
if ($update_available) { |
|
137 | 134 |
$form->{"stylesheet"} = "lx-office-erp.css"; |
138 | 135 |
$form->{"title"} = $main::locale->text("Dataset upgrade"); |
139 | 136 |
$form->header(); |
... | ... | |
456 | 453 |
|
457 | 454 |
my ($self, $form) = @_; |
458 | 455 |
|
459 |
my %members = $main::auth->read_all_users(); |
|
460 |
my $controls = SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver})->parse_dbupdate_controls;
|
|
456 |
my %members = $main::auth->read_all_users();
|
|
457 |
my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver})->parse_dbupdate_controls;
|
|
461 | 458 |
|
462 | 459 |
my ($query, $sth, %dbs_needing_updates); |
463 | 460 |
|
... | ... | |
479 | 476 |
($version) = $sth->fetchrow_array(); |
480 | 477 |
} |
481 | 478 |
$sth->finish(); |
482 |
$dbh->disconnect(); |
|
483 | 479 |
|
484 |
next unless $version; |
|
480 |
$dbh->disconnect and next unless $version; |
|
481 |
|
|
482 |
my $update_available = $dbupdater->update_available($version) || $dbupdater->update2_available($dbh); |
|
483 |
$dbh->disconnect; |
|
485 | 484 |
|
486 |
if (update_available($form->{dbdriver}, $version) || update2_available($form, $controls)) {
|
|
485 |
if ($update_available) {
|
|
487 | 486 |
my $dbinfo = {}; |
488 | 487 |
map { $dbinfo->{$_} = $member->{$_} } grep /^db/, keys %{ $member }; |
489 | 488 |
$dbs_needing_updates{$member->{dbhost} . "::" . $member->{dbname}} = $dbinfo; |
... | ... | |
537 | 536 |
return $res_a <=> $res_b; |
538 | 537 |
} |
539 | 538 |
|
540 |
sub update_available { |
|
541 |
my ($dbdriver, $cur_version) = @_; |
|
542 |
|
|
543 |
local *SQLDIR; |
|
544 |
|
|
545 |
opendir SQLDIR, "sql/${dbdriver}-upgrade" || error("", "sql/${dbdriver}-upgrade: $!"); |
|
546 |
my @upgradescripts = grep /${dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, readdir SQLDIR; |
|
547 |
closedir SQLDIR; |
|
548 |
|
|
549 |
return ($#upgradescripts > -1); |
|
550 |
} |
|
551 |
|
|
552 | 539 |
sub create_schema_info_table { |
553 | 540 |
$main::lxdebug->enter_sub(); |
554 | 541 |
|
... | ... | |
730 | 717 |
return $rc; |
731 | 718 |
} |
732 | 719 |
|
733 |
sub update2_available { |
|
734 |
$main::lxdebug->enter_sub(); |
|
735 |
|
|
736 |
my ($form, $controls) = @_; |
|
737 |
|
|
738 |
map({ $_->{"applied"} = 0; } values(%{$controls})); |
|
739 |
|
|
740 |
dbconnect_vars($form, $form->{"dbname"}); |
|
741 |
|
|
742 |
my $dbh = |
|
743 |
DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) || |
|
744 |
$form->dberror; |
|
745 |
|
|
746 |
my ($query, $tag, $sth); |
|
747 |
|
|
748 |
$query = qq|SELECT tag FROM schema_info|; |
|
749 |
$sth = $dbh->prepare($query); |
|
750 |
if ($sth->execute()) { |
|
751 |
while (($tag) = $sth->fetchrow_array()) { |
|
752 |
$controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag})); |
|
753 |
} |
|
754 |
} |
|
755 |
$sth->finish(); |
|
756 |
$dbh->disconnect(); |
|
757 |
|
|
758 |
map({ $main::lxdebug->leave_sub() and return 1 if (!$_->{"applied"}) } |
|
759 |
values(%{$controls})); |
|
760 |
|
|
761 |
$main::lxdebug->leave_sub(); |
|
762 |
return 0; |
|
763 |
} |
|
764 |
|
|
765 | 720 |
sub save_member { |
766 | 721 |
$main::lxdebug->enter_sub(); |
767 | 722 |
|
Auch abrufbar als: Unified diff
Funktionen update_available, update2_available nach DBUpgrade2.pm verschoben