Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7e0ad798

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID 7e0ad798bc842b710a27b0e1a7a720b117b2566a
  • Vorgänger a97d97a0
  • Nachfolger a1d1605e

Umstellung DBUpgrade2-Modul auf Objekt-Aufrufsyntax

Unterschiede anzeigen:

SL/DBUpgrade2.pm
2 2

  
3 3
use SL::Common;
4 4

  
5
require Exporter;
6
our @ISA = qw(Exporter);
7

  
8
our @EXPORT = qw(parse_dbupdate_controls sort_dbupdate_controls);
9

  
10 5
use strict;
11 6

  
7
sub new {
8
  my ($package, $form, $dbdriver) = @_;
9
  my $self                        = { form => $form, dbdriver => $dbdriver };
10
  return bless($self, $package);
11
}
12

  
12 13
sub parse_dbupdate_controls {
13 14
  $main::lxdebug->enter_sub();
14 15

  
15
  my ($form, $dbdriver) = @_;
16
  my ($self) = @_;
16 17

  
18
  my $form   = $self->{form};
17 19
  my $locale = $main::locale;
18 20

  
19 21
  local *IN;
20 22
  my %all_controls;
21 23

  
22
  my $path = "sql/${dbdriver}-upgrade2";
24
  my $path = "sql/" . $self->{dbdriver} . "-upgrade2";
23 25

  
24 26
  foreach my $file_name (<$path/*.sql>, <$path/*.pl>) {
25 27
    next unless (open(IN, $file_name));
......
92 94
  map({ _dbupdate2_calculate_depth(\%all_controls, $_->{"tag"}) }
93 95
      values(%all_controls));
94 96

  
97
  $self->{all_controls} = \%all_controls;
98

  
95 99
  $main::lxdebug->leave_sub();
96 100

  
97 101
  return \%all_controls;
......
148 152
}
149 153

  
150 154
sub sort_dbupdate_controls {
155
  my $self = shift;
156

  
151 157
  return sort({   $a->{"depth"}    !=  $b->{"depth"}    ? $a->{"depth"}    <=> $b->{"depth"}
152 158
                : $a->{"priority"} !=  $b->{"priority"} ? $a->{"priority"} <=> $b->{"priority"}
153
                :                                         $a->{"tag"}      cmp $b->{"tag"}      } values(%{$_[0]}));
159
                :                                         $a->{"tag"}      cmp $b->{"tag"}      } values(%{ $self->{all_controls} }));
154 160
}
155 161

  
156 162
1;
SL/User.pm
125 125

  
126 126
    $rc = 0;
127 127

  
128
    my $controls =
129
      parse_dbupdate_controls($form, $myconfig{"dbdriver"});
128
    my $dbupdater = SL::DBUpgrade2->new($form, $myconfig{"dbdriver"});
129
    my $controls  = $dbupdater->parse_dbupdate_controls;
130 130

  
131 131
    map({ $form->{$_} = $myconfig{$_} }
132 132
        qw(dbname dbhost dbport dbdriver dbuser dbpasswd dbconnect dateformat));
......
163 163
      $SIG{QUIT} = 'IGNORE';
164 164

  
165 165
      $self->dbupdate($form);
166
      $self->dbupdate2($form, $controls);
166
      $self->dbupdate2($form, $dbupdater);
167 167

  
168 168
      close(FH);
169 169

  
......
622 622
  my ($self, $form) = @_;
623 623

  
624 624
  my %members  = $main::auth->read_all_users();
625
  my $controls = parse_dbupdate_controls($form, $form->{dbdriver});
625
  my $controls = SL::DBUpgrade2->new($form, $form->{dbdriver})->parse_dbupdate_controls;
626 626

  
627 627
  my ($query, $sth, %dbs_needing_updates);
628 628

  
......
826 826
sub dbupdate2 {
827 827
  $main::lxdebug->enter_sub();
828 828

  
829
  my ($self, $form, $controls) = @_;
829
  my ($self, $form, $dbupdater) = @_;
830 830

  
831 831
  $form->{sid} = $form->{dbdefault};
832 832

  
......
834 834
  my ($query, $sth, $tag);
835 835
  my $rc = -2;
836 836

  
837
  @upgradescripts = sort_dbupdate_controls($controls);
837
  @upgradescripts = $dbupdater->sort_dbupdate_controls;
838 838

  
839 839
  my $db_charset = $main::dbcharset;
840 840
  $db_charset ||= Common::DEFAULT_CHARSET;
......
861 861
    $sth = $dbh->prepare($query);
862 862
    $sth->execute() || $form->dberror($query);
863 863
    while (($tag) = $sth->fetchrow_array()) {
864
      $controls->{$tag}->{"applied"} = 1 if (defined($controls->{$tag}));
864
      $dbupdater->{all_controls}->{$tag}->{"applied"} = 1 if (defined($dbupdater->{all_controls}->{$tag}));
865 865
    }
866 866
    $sth->finish();
867 867

  

Auch abrufbar als: Unified diff