Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 46dc5b4b

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 46dc5b4b5eeb2caa302a762e443f67aa4aee26a3
  • Vorgänger b8fc2361
  • Nachfolger e92b979d

dbupgrade2_tool.pl: Unterstützung für die Auth-DB-Upgrade-Scripte via Option --auth-db

Unterschiede anzeigen:

scripts/dbupgrade2_tool.pl
44 44
my ($opt_list, $opt_tree, $opt_rtree, $opt_nodeps, $opt_graphviz, $opt_help);
45 45
my ($opt_user, $opt_apply, $opt_applied, $opt_unapplied, $opt_format, $opt_test_utf8);
46 46
my ($opt_dbhost, $opt_dbport, $opt_dbname, $opt_dbuser, $opt_dbpassword, $opt_create, $opt_type);
47
my ($opt_description, $opt_encoding, @opt_depends);
47
my ($opt_description, $opt_encoding, @opt_depends, $opt_auth_db);
48 48

  
49 49
our (%myconfig, $form, $user, $auth, $locale, $controls, $dbupgrader);
50 50

  
51
sub connect_auth {
52
  return $auth if $auth;
53

  
54
  $auth = SL::Auth->new;
55
  if (!$auth->session_tables_present) {
56
    $form->error("The session and user management tables are not present in the authentication database. Please use the administration web interface to create them.");
57
  }
58

  
59
  return $auth;
60
}
61

  
51 62
sub show_help {
52 63
  my $help_text = <<"END_HELP"
53 64
dbupgrade2_tool.pl [options]
......
94 105
  General Options:
95 106
    --user=name          The name of the user configuration to use for
96 107
                         database connectivity.
108
    --auth-db            Work on the authentication database instead of a
109
                         user database.
97 110
    --dbname=name        Database connection options for the UTF-8
98 111
    --dbhost=host        handling test.
99 112
    --dbport=port
......
310 323

  
311 324
  my @upgradescripts = map { $controls->{$_}->{applied} = 0; $controls->{$_} } @order;
312 325

  
313
  my $dbh = $form->dbconnect_noauto(\%myconfig);
326
  my $dbh            = $opt_auth_db ? connect_auth()->dbconnect : $form->dbconnect_noauto(\%myconfig);
327
  $dbh->{AutoCommit} = 0;
314 328

  
315 329
  $dbh->{PrintWarn}  = 0;
316 330
  $dbh->{PrintError} = 0;
......
348 362
    }
349 363
  }
350 364

  
351
  $dbh->disconnect();
365
  $dbh->disconnect unless $opt_auth_db;
352 366
}
353 367

  
354 368
sub dump_sql_result {
......
381 395
sub dump_applied {
382 396
  my @results;
383 397

  
384
  my $dbh = $form->dbconnect_noauto(\%myconfig);
398
  my $dbh            = $opt_auth_db ? connect_auth()->dbconnect : $form->dbconnect_noauto(\%myconfig);
399
  $dbh->{AutoCommit} = 0;
385 400

  
386 401
  $dbh->{PrintWarn}  = 0;
387 402
  $dbh->{PrintError} = 0;
......
396 411
  }
397 412
  $sth->finish();
398 413

  
399
  $dbh->disconnect();
414
  $dbh->disconnect unless $opt_auth_db;
400 415

  
401 416
  if (!scalar @results) {
402 417
    print "No database upgrades have been applied yet.\n";
......
408 423
sub dump_unapplied {
409 424
  my @results;
410 425

  
411
  my $dbh = $form->dbconnect_noauto(\%myconfig);
426
  my $dbh = $opt_auth_db ? connect_auth()->dbconnect : $form->dbconnect_noauto(\%myconfig);
412 427

  
413 428
  $dbh->{PrintWarn}  = 0;
414 429
  $dbh->{PrintError} = 0;
415 430

  
416 431
  my @unapplied = $dbupgrader->unapplied_upgrade_scripts($dbh);
417 432

  
418
  $dbh->disconnect;
433
  $dbh->disconnect unless $opt_auth_db;
419 434

  
420 435
  if (!scalar @unapplied) {
421 436
    print "All database upgrades have been applied.\n";
......
473 488
           "dbname:s"     => \$opt_dbname,
474 489
           "dbuser:s"     => \$opt_dbuser,
475 490
           "dbpassword:s" => \$opt_dbpassword,
491
           "auth-db"      => \$opt_auth_db,
476 492
           "help"         => \$opt_help,
477 493
  );
478 494

  
479 495
show_help() if ($opt_help);
480 496

  
481
$dbupgrader = SL::DBUpgrade2->new(form => $form, dbdriver => 'Pg');
497
$dbupgrader = SL::DBUpgrade2->new(form => $form, dbdriver => 'Pg', auth => $opt_auth_db);
482 498
$controls   = $dbupgrader->parse_dbupdate_controls->{all_controls};
483 499

  
484 500
dump_list()                                 if ($opt_list);
......
495 511
               depends     => \@opt_depends) if ($opt_create);
496 512

  
497 513
if ($opt_user) {
498
  $auth = SL::Auth->new();
499
  if (!$auth->session_tables_present()) {
500
    $form->error("The session and user management tables are not present in the " .
501
                 "authentication database. Please use the administration web interface " .
502
                 "and to create them.");
503
  }
504

  
505
  %myconfig = $auth->read_user(login => $opt_user);
514
  %myconfig = connect_auth()->read_user(login => $opt_user);
506 515

  
507 516
  if (!$myconfig{login}) {
508 517
    $form->error($form->format_string("The user '#1' does not exist.", $opt_user));
......
515 524
}
516 525

  
517 526
if ($opt_apply) {
518
  $form->error("--apply used but no user name given with --user.") if (!$user);
527
  $form->error("--apply used but no user name given with --user.") if !$user && !$opt_auth_db;
519 528
  apply_upgrade($opt_apply);
520 529
}
521 530

  
522 531
if ($opt_applied) {
523
  $form->error("--applied used but no user name given with --user.") if (!$user);
532
  $form->error("--applied used but no user name given with --user.") if !$user && !$opt_auth_db;
524 533
  dump_applied();
525 534
}
526 535

  
527 536
if ($opt_unapplied) {
528
  $form->error("--unapplied used but no user name given with --user.") if (!$user);
537
  $form->error("--unapplied used but no user name given with --user.") if !$user && !$opt_auth_db;
529 538
  dump_unapplied();
530 539
}
531 540

  

Auch abrufbar als: Unified diff