Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 64a301e5

Von Sven Schöling vor mehr als 7 Jahren hinzugefügt

  • ID 64a301e55d72df9005e35647a2f166d978c1d8de
  • Vorgänger aad72b4a
  • Nachfolger 39be0a81

DN: single-dbh und disconnects

Unterschiede anzeigen:

SL/DN.pm
46 46
use SL::DB::Language;
47 47
use SL::TransNumber;
48 48
use SL::Util qw(trim);
49
use SL::DB;
49 50

  
50 51
use strict;
51 52

  
......
55 56
  my ($self, $myconfig, $form) = @_;
56 57

  
57 58
  # connect to database
58
  my $dbh = $form->dbconnect($myconfig);
59
  my $dbh = SL::DB->client->dbh;
59 60

  
60 61
  my $query =
61 62
    qq|SELECT * | .
......
73 74
       FROM defaults|;
74 75
  ($form->{AR_amount_fee}, $form->{AR_amount_interest}, $form->{AR}) = selectrow_query($form, $dbh, $query);
75 76

  
76
  $dbh->disconnect();
77

  
78 77
  $main::lxdebug->leave_sub();
79 78
}
80 79

  
81 80
sub save_config {
81
  my ($self, $myconfig, $form) = @_;
82 82
  $main::lxdebug->enter_sub();
83 83

  
84
  my $rc = SL::DB->client->with_transaction(\&_save_config, $self, $myconfig, $form);
85

  
86
  $::lxdebug->leave_sub;
87
  return $rc;
88
}
89

  
90
sub _save_config {
84 91
  my ($self, $myconfig, $form) = @_;
85 92

  
86
  # connect to database
87
  my $dbh = $form->dbconnect_noauto($myconfig);
93
  my $dbh = SL::DB->client->dbh;
88 94

  
89 95
  my ($query, @values);
90 96

  
......
132 138
  @values = (conv_i($form->{AR_amount_fee}), conv_i($form->{AR_amount_interest}), conv_i($form->{AR}));
133 139
  do_query($form, $dbh, $query, @values);
134 140

  
135
  $dbh->commit();
136
  $dbh->disconnect();
137

  
138
  $main::lxdebug->leave_sub();
141
  return 1;
139 142
}
140 143

  
141 144
sub create_invoice_for_fees {
......
283 286
  $main::lxdebug->leave_sub();
284 287
}
285 288

  
289

  
286 290
sub save_dunning {
291
  my ($self, $myconfig, $form, $rows) = @_;
287 292
  $main::lxdebug->enter_sub();
288 293

  
294
  my $rc = SL::DB->client->with_transaction(\&_save_dunning, $self, $myconfig, $form, $rows);
295
  $::lxdebug->leave_sub;
296

  
297
  return $rc;
298
}
299

  
300

  
301
sub _save_dunning {
289 302
  my ($self, $myconfig, $form, $rows) = @_;
290
  # connect to database
291
  my $dbh = $form->dbconnect_noauto($myconfig);
303

  
304
  my $dbh = SL::DB->client->dbh;
292 305

  
293 306
  my ($query, @values);
294 307

  
......
353 366
    $self->send_email($myconfig, $form, $dunning_id, $dbh);
354 367
  }
355 368

  
356
  $dbh->commit();
357
  $dbh->disconnect();
358

  
359
  $main::lxdebug->leave_sub();
369
  return 1;
360 370
}
361 371

  
362 372
sub send_email {
......
479 489
  my ($self, $myconfig, $form) = @_;
480 490

  
481 491
  # connect to database
482
  my $dbh = $form->dbconnect($myconfig);
492
  my $dbh = SL::DB->client->dbh;
483 493

  
484 494
  my $where;
485 495
  my @values;
......
596 606
  $query = qq|SELECT id, dunning_description FROM dunning_config ORDER BY dunning_level|;
597 607
  $form->{DUNNING_CONFIG} = selectall_hashref_query($form, $dbh, $query);
598 608

  
599
  $dbh->disconnect;
600 609
  $main::lxdebug->leave_sub();
601 610
}
602 611

  
......
607 616
  my ($self, $myconfig, $form) = @_;
608 617

  
609 618
  # connect to database
610
  my $dbh = $form->dbconnect($myconfig);
619
  my $dbh = SL::DB->client->dbh;
611 620

  
612 621
  my $where = qq| WHERE (da.trans_id = a.id)|;
613 622

  
......
709 718
    map { $ref->{$_} = $form->format_amount($myconfig, $ref->{$_}, 2)} qw(amount fee interest);
710 719
  }
711 720

  
712
  $dbh->disconnect;
713 721
  $main::lxdebug->leave_sub();
714 722
}
715 723

  
......
765 773
  my ($self, $myconfig, $form, $dunning_id, $provided_dbh) = @_;
766 774

  
767 775
  # connect to database
768
  my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect_noauto($myconfig);
776
  my $dbh = $provided_dbh || SL::DB->client->dbh;
769 777

  
770 778
  $dunning_id =~ s|[^\d]||g;
771 779

  
......
892 900

  
893 901
  $form->parse_template($myconfig);
894 902

  
895
  $dbh->disconnect() unless $provided_dbh;
896

  
897 903
  $main::lxdebug->leave_sub();
898 904
}
899 905

  
......
902 908

  
903 909
  my ($self, $myconfig, $form, $dunning_id, $provided_dbh) = @_;
904 910

  
905
  my $dbh = $provided_dbh ? $provided_dbh : $form->dbconnect($myconfig);
911
  my $dbh = $provided_dbh || SL::DB->client->dbh;
906 912

  
907 913
  my ($query, @values, $sth);
908 914

  
......
989 995
  push @{ $form->{DUNNING_PDFS_EMAIL} }, { 'filename' => "${spool}/$filename",
990 996
                                           'name'     => "dunning_invoice_${dunning_id}.pdf" };
991 997

  
992
  $dbh->disconnect() unless $provided_dbh;
993

  
994 998
  $main::lxdebug->leave_sub();
995 999
}
996 1000

  

Auch abrufbar als: Unified diff