From 7e0ad798bc842b710a27b0e1a7a720b117b2566a Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 29 Nov 2010 17:30:44 +0100 Subject: [PATCH] Umstellung DBUpgrade2-Modul auf Objekt-Aufrufsyntax --- SL/DBUpgrade2.pm | 22 ++++++++++++++-------- SL/User.pm | 14 +++++++------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/SL/DBUpgrade2.pm b/SL/DBUpgrade2.pm index ae07d1c08..1a0b0433b 100644 --- a/SL/DBUpgrade2.pm +++ b/SL/DBUpgrade2.pm @@ -2,24 +2,26 @@ package SL::DBUpgrade2; use SL::Common; -require Exporter; -our @ISA = qw(Exporter); - -our @EXPORT = qw(parse_dbupdate_controls sort_dbupdate_controls); - use strict; +sub new { + my ($package, $form, $dbdriver) = @_; + my $self = { form => $form, dbdriver => $dbdriver }; + return bless($self, $package); +} + sub parse_dbupdate_controls { $main::lxdebug->enter_sub(); - my ($form, $dbdriver) = @_; + my ($self) = @_; + my $form = $self->{form}; my $locale = $main::locale; local *IN; my %all_controls; - my $path = "sql/${dbdriver}-upgrade2"; + my $path = "sql/" . $self->{dbdriver} . "-upgrade2"; foreach my $file_name (<$path/*.sql>, <$path/*.pl>) { next unless (open(IN, $file_name)); @@ -92,6 +94,8 @@ sub parse_dbupdate_controls { map({ _dbupdate2_calculate_depth(\%all_controls, $_->{"tag"}) } values(%all_controls)); + $self->{all_controls} = \%all_controls; + $main::lxdebug->leave_sub(); return \%all_controls; @@ -148,9 +152,11 @@ sub _dbupdate2_calculate_depth { } sub sort_dbupdate_controls { + my $self = shift; + return sort({ $a->{"depth"} != $b->{"depth"} ? $a->{"depth"} <=> $b->{"depth"} : $a->{"priority"} != $b->{"priority"} ? $a->{"priority"} <=> $b->{"priority"} - : $a->{"tag"} cmp $b->{"tag"} } values(%{$_[0]})); + : $a->{"tag"} cmp $b->{"tag"} } values(%{ $self->{all_controls} })); } 1; diff --git a/SL/User.pm b/SL/User.pm index b1a904afd..c74c104a0 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -125,8 +125,8 @@ sub login { $rc = 0; - my $controls = - parse_dbupdate_controls($form, $myconfig{"dbdriver"}); + my $dbupdater = SL::DBUpgrade2->new($form, $myconfig{"dbdriver"}); + my $controls = $dbupdater->parse_dbupdate_controls; map({ $form->{$_} = $myconfig{$_} } qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect dateformat)); @@ -163,7 +163,7 @@ sub login { $SIG{QUIT} = 'IGNORE'; $self->dbupdate($form); - $self->dbupdate2($form, $controls); + $self->dbupdate2($form, $dbupdater); close(FH); @@ -622,7 +622,7 @@ sub dbneedsupdate { my ($self, $form) = @_; my %members = $main::auth->read_all_users(); - my $controls = parse_dbupdate_controls($form, $form->{dbdriver}); + my $controls = SL::DBUpgrade2->new($form, $form->{dbdriver})->parse_dbupdate_controls; my ($query, $sth, %dbs_needing_updates); @@ -826,7 +826,7 @@ sub dbupdate { sub dbupdate2 { $main::lxdebug->enter_sub(); - my ($self, $form, $controls) = @_; + my ($self, $form, $dbupdater) = @_; $form->{sid} = $form->{dbdefault}; @@ -834,7 +834,7 @@ sub dbupdate2 { my ($query, $sth, $tag); my $rc = -2; - @upgradescripts = sort_dbupdate_controls($controls); + @upgradescripts = $dbupdater->sort_dbupdate_controls; my $db_charset = $main::dbcharset; $db_charset ||= Common::DEFAULT_CHARSET; @@ -861,7 +861,7 @@ sub dbupdate2 { $sth = $dbh->prepare($query); $sth->execute() || $form->dberror($query); while (($tag) = $sth->fetchrow_array()) { - $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag})); + $dbupdater->{all_controls}->{$tag}->{"applied"} = 1 if (defined($dbupdater->{all_controls}->{$tag})); } $sth->finish(); -- 2.20.1