Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8b39e389

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID 8b39e3893d7e9061c0e8142aca681c90f137bf30
  • Vorgänger a1d1605e
  • Nachfolger 35636cc2

Funktion "process_perl_script" von User.pm nach DBUpgrade2.pm verschoben

Unterschiede anzeigen:

SL/DBUpgrade2.pm
204 204
  $main::lxdebug->leave_sub();
205 205
}
206 206

  
207
# Process a Perl script which updates the database.
208
# If the script returns 1 then the update was successful.
209
# Return code "2" means "needs more interaction; remove
210
# users/nologin and end current request".
211
# All other return codes are fatal errors.
212
sub process_perl_script {
213
  $main::lxdebug->enter_sub();
214

  
215
  my ($self, $dbh, $filename, $version_or_control, $db_charset) = @_;
216

  
217
  my $form         = $self->{form};
218
  my $fh           = IO::File->new($filename, "r") or $form->error("$filename : $!\n");
219
  my $file_charset = Common::DEFAULT_CHARSET;
220

  
221
  if (ref($version_or_control) eq "HASH") {
222
    $file_charset = $version_or_control->{charset};
223

  
224
  } else {
225
    while (<$fh>) {
226
      last if !/^--/;
227
      next if !/^--\s*\@charset:\s*(.+)/;
228
      $file_charset = $1;
229
      last;
230
    }
231
    $fh->seek(0, SEEK_SET);
232
  }
233

  
234
  my $contents = join "", <$fh>;
235
  $fh->close();
236

  
237
  $db_charset ||= Common::DEFAULT_CHARSET;
238

  
239
  my $iconv = SL::Iconv::get_converter($file_charset, $db_charset);
240

  
241
  $dbh->begin_work();
242

  
243
  # setup dbup_ export vars
244
  my %dbup_myconfig = ();
245
  map({ $dbup_myconfig{$_} = $form->{$_}; } qw(dbname dbuser dbpasswd dbhost dbport dbconnect));
246

  
247
  my $dbup_locale = $::locale;
248

  
249
  my $result = eval($contents);
250

  
251
  if (1 != $result) {
252
    $dbh->rollback();
253
    $dbh->disconnect();
254
  }
255

  
256
  if (!defined($result)) {
257
    print $form->parse_html_template("dbupgrade/error",
258
                                     { "file"  => $filename,
259
                                       "error" => $@ });
260
    ::end_of_request();
261
  } elsif (1 != $result) {
262
    unlink("users/nologin") if (2 == $result);
263
    ::end_of_request();
264
  }
265

  
266
  if (ref($version_or_control) eq "HASH") {
267
    $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
268
             $dbh->quote($version_or_control->{"tag"}) . ", " .
269
             $dbh->quote($form->{"login"}) . ")");
270
  } elsif ($version_or_control) {
271
    $dbh->do("UPDATE defaults SET version = " .
272
             $dbh->quote($version_or_control));
273
  }
274
  $dbh->commit();
275

  
276
  $main::lxdebug->leave_sub();
277
}
278

  
207 279
sub _check_for_loops {
208 280
  my ($form, $file_name, $controls, $tag, @path) = @_;
209 281

  
SL/User.pm
410 410
  $main::lxdebug->leave_sub();
411 411
}
412 412

  
413
# Process a Perl script which updates the database.
414
# If the script returns 1 then the update was successful.
415
# Return code "2" means "needs more interaction; remove
416
# users/nologin and end current request".
417
# All other return codes are fatal errors.
418
sub process_perl_script {
419
  $main::lxdebug->enter_sub();
420

  
421
  my ($self, $form, $dbh, $filename, $version_or_control, $db_charset) = @_;
422

  
423
  my $fh = IO::File->new($filename, "r") or $form->error("$filename : $!\n");
424

  
425
  my $file_charset = Common::DEFAULT_CHARSET;
426

  
427
  if (ref($version_or_control) eq "HASH") {
428
    $file_charset = $version_or_control->{charset};
429

  
430
  } else {
431
    while (<$fh>) {
432
      last if !/^--/;
433
      next if !/^--\s*\@charset:\s*(.+)/;
434
      $file_charset = $1;
435
      last;
436
    }
437
    $fh->seek(0, SEEK_SET);
438
  }
439

  
440
  my $contents = join "", <$fh>;
441
  $fh->close();
442

  
443
  $db_charset ||= Common::DEFAULT_CHARSET;
444

  
445
  my $iconv = SL::Iconv::get_converter($file_charset, $db_charset);
446

  
447
  $dbh->begin_work();
448

  
449
  # setup dbup_ export vars
450
  my %dbup_myconfig = ();
451
  map({ $dbup_myconfig{$_} = $form->{$_}; }
452
      qw(dbname dbuser dbpasswd dbhost dbport dbconnect));
453

  
454
  my $dbup_locale = $::locale;
455

  
456
  my $result = eval($contents);
457

  
458
  if (1 != $result) {
459
    $dbh->rollback();
460
    $dbh->disconnect();
461
  }
462

  
463
  if (!defined($result)) {
464
    print $form->parse_html_template("dbupgrade/error",
465
                                     { "file"  => $filename,
466
                                       "error" => $@ });
467
    ::end_of_request();
468
  } elsif (1 != $result) {
469
    unlink("users/nologin") if (2 == $result);
470
    ::end_of_request();
471
  }
472

  
473
  if (ref($version_or_control) eq "HASH") {
474
    $dbh->do("INSERT INTO schema_info (tag, login) VALUES (" .
475
             $dbh->quote($version_or_control->{"tag"}) . ", " .
476
             $dbh->quote($form->{"login"}) . ")");
477
  } elsif ($version_or_control) {
478
    $dbh->do("UPDATE defaults SET version = " .
479
             $dbh->quote($version_or_control));
480
  }
481
  $dbh->commit();
482

  
483
  $main::lxdebug->leave_sub();
484
}
485

  
486 413
sub dbdelete {
487 414
  $main::lxdebug->enter_sub();
488 415

  
......
714 641
      if ($file_type eq "sql") {
715 642
        $dbupdater->process_query($dbh, "sql/" . $form->{"dbdriver"} . "-upgrade/$upgradescript", $str_maxdb, $db_charset);
716 643
      } else {
717
        $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
718
                                   "-upgrade/$upgradescript", $str_maxdb, $db_charset);
644
        $dbupdater->process_perl_script($dbh, "sql/" . $form->{"dbdriver"} . "-upgrade/$upgradescript", $str_maxdb, $db_charset);
719 645
      }
720 646

  
721 647
      $version = $maxdb;
......
799 725
      if ($file_type eq "sql") {
800 726
        $dbupdater->process_query($dbh, "sql/" . $form->{"dbdriver"} . "-upgrade2/$control->{file}", $control, $db_charset);
801 727
      } else {
802
        $self->process_perl_script($form, $dbh, "sql/" . $form->{"dbdriver"} .
803
                                   "-upgrade2/$control->{file}", $control, $db_charset);
728
        $dbupdater->process_perl_script($dbh, "sql/" . $form->{"dbdriver"} . "-upgrade2/$control->{file}", $control, $db_charset);
804 729
      }
805 730
    }
806 731

  

Auch abrufbar als: Unified diff