Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8e0f6e70

Von Sven Schöling vor etwa 8 Jahren hinzugefügt

  • ID 8e0f6e70f1acb084e6757ccd8b59221f78a2ff56
  • Vorgänger cd002768
  • Nachfolger 2df28e2b

OE: single-dbh

Unterschiede anzeigen:

SL/OE.pm
51 51
use SL::IC;
52 52
use SL::TransNumber;
53 53
use SL::Util qw(trim);
54
use SL::DB;
54 55
use Text::ParseWords;
55 56

  
56 57
use strict;
......
419 420
}
420 421

  
421 422
sub save {
423
  my ($self, $myconfig, $form) = @_;
424
  $main::lxdebug->enter_sub();
425

  
426
  my $rc = SL::DB->client->with_transaction(\&_save, $self, $myconfig, $form);
427

  
428
  $::lxdebug->leave_sub;
429

  
430
  return $rc;
431
}
432

  
433
sub _save {
422 434
  $main::lxdebug->enter_sub();
423 435

  
424 436
  my ($self, $myconfig, $form) = @_;
425 437

  
426
  # connect to database, turn off autocommit
427
  my $dbh = $form->get_standard_dbh;
438
  my $dbh = SL::DB->client->dbh;
428 439
  my $restricter = SL::HTML::Restrict->create;
429 440

  
430 441
  my ($query, @values, $sth, $null);
......
793 804

  
794 805
  Common::webdav_folder($form);
795 806

  
796
  my $rc = $dbh->commit;
797

  
798 807
  $self->save_periodic_invoices_config(dbh         => $dbh,
799 808
                                       oe_id       => $form->{id},
800 809
                                       config_yaml => $form->{periodic_invoices_config})
......
802 811

  
803 812
  $main::lxdebug->leave_sub();
804 813

  
805
  return $rc;
814
  return 1;
806 815
}
807 816

  
808 817
sub save_periodic_invoices_config {
......
846 855
  my $myconfig = \%main::myconfig;
847 856
  my $form     = $main::form;
848 857

  
849
  my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
858
  my $dbh      = $params{dbh} || SL::DB->client->dbh;
850 859

  
851
  my $query    = qq|SELECT quotation FROM oe WHERE id = ?|;
852
  my $sth      = prepare_query($form, $dbh, $query);
860
  SL::DB->client->with_transaction(sub {
853 861

  
854
  do_statement($form, $sth, $query, conv_i($params{to_id}));
862
    my $query    = qq|SELECT quotation FROM oe WHERE id = ?|;
863
    my $sth      = prepare_query($form, $dbh, $query);
855 864

  
856
  my ($quotation) = $sth->fetchrow_array();
865
    do_statement($form, $sth, $query, conv_i($params{to_id}));
857 866

  
858
  if ($quotation) {
859
    $main::lxdebug->leave_sub();
860
    return;
861
  }
867
    my ($quotation) = $sth->fetchrow_array();
862 868

  
863
  my @close_ids;
869
    if ($quotation) {
870
      return;
871
    }
864 872

  
865
  foreach my $from_id (@{ $params{from_id} }) {
866
    $from_id = conv_i($from_id);
867
    do_statement($form, $sth, $query, $from_id);
868
    ($quotation) = $sth->fetchrow_array();
869
    push @close_ids, $from_id if ($quotation);
870
  }
873
    my @close_ids;
871 874

  
872
  $sth->finish();
875
    foreach my $from_id (@{ $params{from_id} }) {
876
      $from_id = conv_i($from_id);
877
      do_statement($form, $sth, $query, $from_id);
878
      ($quotation) = $sth->fetchrow_array();
879
      push @close_ids, $from_id if ($quotation);
880
    }
873 881

  
874
  if (scalar @close_ids) {
875
    $query = qq|UPDATE oe SET closed = TRUE WHERE id IN (| . join(', ', ('?') x scalar @close_ids) . qq|)|;
876
    do_query($form, $dbh, $query, @close_ids);
882
    $sth->finish();
877 883

  
878
    $dbh->commit() unless ($params{dbh});
879
  }
884
    if (scalar @close_ids) {
885
      $query = qq|UPDATE oe SET closed = TRUE WHERE id IN (| . join(', ', ('?') x scalar @close_ids) . qq|)|;
886
      do_query($form, $dbh, $query, @close_ids);
887
    }
888

  
889
  });
880 890

  
881 891
  $main::lxdebug->leave_sub();
882 892
}
......
903 913
}
904 914

  
905 915
sub retrieve {
916
  my ($self, $myconfig, $form) = @_;
906 917
  $main::lxdebug->enter_sub();
907 918

  
919
  my $rc = SL::DB->client->with_transaction(\&_retrieve, $self, $myconfig, $form);
920

  
921
  $::lxdebug->leave_sub;
922
  return $rc;
923
}
924

  
925
sub _retrieve {
908 926
  my ($self, $myconfig, $form) = @_;
909 927

  
910 928
  # connect to database
911
  my $dbh = $form->get_standard_dbh;
929
  my $dbh = SL::DB->client->dbh;
912 930

  
913 931
  my ($query, $query_add, @values, @ids, $sth);
914 932

  
......
1206 1224

  
1207 1225
  $self->load_periodic_invoice_config($form);
1208 1226

  
1209
  my $rc = $dbh->commit;
1210

  
1211
  $main::lxdebug->leave_sub();
1212

  
1213
  return $rc;
1227
  return 1;
1214 1228
}
1215 1229

  
1216 1230
sub retrieve_simple {

Auch abrufbar als: Unified diff