Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9b0c7269

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID 9b0c72696ee2208dcc756b74a55941b50fcb546f
  • Vorgänger 38a2e789
  • Nachfolger 626ec4b4

DRY

Unterschiede anzeigen:

SL/DBUpgrade2.pm
326 326
  return $needs_update;
327 327
}
328 328

  
329
sub unapplied_upgrade_scripts {
330
  my ($self, $dbh) = @_;
331

  
332
  my @all_scripts = map { $_->{applied} = 0; $_ } $self->sort_dbupdate_controls;
333

  
334
  my $query = qq|SELECT tag FROM schema_info|;
335
  my $sth   = $dbh->prepare($query);
336
  $sth->execute || $self->{form}->dberror($query);
337
  while (my ($tag) = $sth->fetchrow_array()) {
338
    $self->{all_controls}->{$tag}->{applied} = 1 if defined $self->{all_controls}->{$tag};
339
  }
340
  $sth->finish;
341

  
342
  return grep { !$_->{applied} } @all_scripts;
343
}
344

  
329 345
sub _check_for_loops {
330 346
  my ($form, $file_name, $controls, $tag, @path) = @_;
331 347

  
SL/User.pm
647 647

  
648 648
  $form->{sid} = $form->{dbdefault};
649 649

  
650
  my @upgradescripts = ();
651
  my ($query, $sth, $tag);
652
  my $rc = -2;
653

  
654
  @upgradescripts = $dbupdater->sort_dbupdate_controls;
650
  my $rc         = -2;
651
  my $db_charset = $main::dbcharset || Common::DEFAULT_CHARSET;
655 652

  
656
  my $db_charset = $main::dbcharset;
657
  $db_charset ||= Common::DEFAULT_CHARSET;
653
  map { $_->{description} = SL::Iconv::convert($_->{charset}, $db_charset, $_->{description}) } values %{ $dbupdater->{all_controls} };
658 654

  
659 655
  foreach my $db (split / /, $form->{dbupdate}) {
660

  
661 656
    next unless $form->{$db};
662 657

  
663 658
    # strip db from dataset
664 659
    $db =~ s/^db//;
665 660
    &dbconnect_vars($form, $db);
666 661

  
667
    my $dbh =
668
      DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd})
669
      or $form->dberror;
662
    my $dbh = DBI->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}) or $form->dberror;
670 663

  
671 664
    $dbh->do($form->{dboptions}) if ($form->{dboptions});
672 665

  
673
    map({ $_->{"applied"} = 0; } @upgradescripts);
674

  
675 666
    $self->create_schema_info_table($form, $dbh);
676 667

  
677
    $query = qq|SELECT tag FROM schema_info|;
678
    $sth = $dbh->prepare($query);
679
    $sth->execute() || $form->dberror($query);
680
    while (($tag) = $sth->fetchrow_array()) {
681
      $dbupdater->{all_controls}->{$tag}->{"applied"} = 1 if (defined($dbupdater->{all_controls}->{$tag}));
682
    }
683
    $sth->finish();
684

  
685
    my $all_applied = 1;
686
    foreach (@upgradescripts) {
687
      if (!$_->{"applied"}) {
688
        $all_applied = 0;
689
        last;
690
      }
691
    }
668
    my @upgradescripts = $dbupdater->unapplied_upgrade_scripts($dbh);
692 669

  
693
    next if ($all_applied);
670
    $dbh->disconnect and next if !@upgradescripts;
694 671

  
695 672
    foreach my $control (@upgradescripts) {
696
      next if ($control->{"applied"});
697

  
698
      $control->{description} = SL::Iconv::convert($control->{charset}, $db_charset, $control->{description});
699

  
700
      $control->{"file"} =~ /\.(sql|pl)$/;
701
      my $file_type = $1;
702

  
703 673
      # apply upgrade
704 674
      $main::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}");
705 675
      print $form->parse_html_template("dbupgrade/upgrade_message2", $control);

Auch abrufbar als: Unified diff