Revision 38a2e789
Von Moritz Bunkus vor fast 14 Jahren hinzugefügt
SL/DBUpgrade2.pm | ||
---|---|---|
1 | 1 |
package SL::DBUpgrade2; |
2 | 2 |
|
3 | 3 |
use IO::File; |
4 |
use List::MoreUtils qw(any); |
|
4 | 5 |
|
5 | 6 |
use SL::Common; |
6 | 7 |
use SL::Iconv; |
... | ... | |
117 | 118 |
|
118 | 119 |
$::lxdebug->leave_sub(); |
119 | 120 |
|
120 |
return \%all_controls;
|
|
121 |
return $self;
|
|
121 | 122 |
} |
122 | 123 |
|
123 | 124 |
sub process_query { |
... | ... | |
290 | 291 |
} |
291 | 292 |
} |
292 | 293 |
|
294 |
sub update_available { |
|
295 |
my ($self, $cur_version) = @_; |
|
296 |
|
|
297 |
local *SQLDIR; |
|
298 |
|
|
299 |
my $dbdriver = $self->{dbdriver}; |
|
300 |
opendir SQLDIR, "sql/${dbdriver}-upgrade" || error("", "sql/${dbdriver}-upgrade: $!"); |
|
301 |
my @upgradescripts = grep /${dbdriver}-upgrade-\Q$cur_version\E.*\.(sql|pl)$/, readdir SQLDIR; |
|
302 |
closedir SQLDIR; |
|
303 |
|
|
304 |
return ($#upgradescripts > -1); |
|
305 |
} |
|
306 |
|
|
307 |
sub update2_available { |
|
308 |
$::lxdebug->enter_sub(); |
|
309 |
|
|
310 |
my ($self, $dbh) = @_; |
|
311 |
|
|
312 |
map { $_->{applied} = 0; } values %{ $self->{all_controls} }; |
|
313 |
|
|
314 |
my $sth = $dbh->prepare(qq|SELECT tag FROM | . $self->{schema} . qq|schema_info|); |
|
315 |
if ($sth->execute) { |
|
316 |
while (my ($tag) = $sth->fetchrow_array) { |
|
317 |
$self->{all_controls}->{$tag}->{applied} = 1 if defined $self->{all_controls}->{$tag}; |
|
318 |
} |
|
319 |
} |
|
320 |
$sth->finish(); |
|
321 |
|
|
322 |
my $needs_update = any { !$_->{applied} } values %{ $self->{all_controls} }; |
|
323 |
|
|
324 |
$::lxdebug->leave_sub(); |
|
325 |
|
|
326 |
return $needs_update; |
|
327 |
} |
|
328 |
|
|
293 | 329 |
sub _check_for_loops { |
294 | 330 |
my ($form, $file_name, $controls, $tag, @path) = @_; |
295 | 331 |
|
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 |
|
bin/mozilla/admin.pl | ||
---|---|---|
719 | 719 |
|
720 | 720 |
map { $form->{$_} = $form->{"${_}_${i}"} } qw(dbname dbdriver dbhost dbport dbuser dbpasswd); |
721 | 721 |
|
722 |
my $controls = parse_dbupdate_controls($form, $form->{dbdriver}); |
|
723 |
|
|
724 | 722 |
print $form->parse_html_template("admin/dbupgrade_header"); |
725 | 723 |
|
726 | 724 |
$form->{dbupdate} = $form->{dbname}; |
727 | 725 |
$form->{$form->{dbname}} = 1; |
728 | 726 |
|
729 | 727 |
User->dbupdate($form); |
730 |
User->dbupdate2($form, $controls);
|
|
728 |
User->dbupdate2($form, SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver})->parse_dbupdate_controls);
|
|
731 | 729 |
|
732 | 730 |
print $form->parse_html_template("admin/dbupgrade_footer"); |
733 | 731 |
} |
Auch abrufbar als: Unified diff
Funktionen update_available, update2_available nach DBUpgrade2.pm verschoben