Revision 3b9c2119
Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt
SL/OE.pm | ||
---|---|---|
40 | 40 |
use SL::AM; |
41 | 41 |
use SL::Common; |
42 | 42 |
use SL::CVar; |
43 |
use SL::DB::Order; |
|
43 | 44 |
use SL::DB::PeriodicInvoicesConfig; |
45 |
use SL::DB::Status; |
|
44 | 46 |
use SL::DBUtils; |
45 | 47 |
use SL::IC; |
46 | 48 |
|
... | ... | |
660 | 662 |
|
661 | 663 |
my ($self, $myconfig, $form) = @_; |
662 | 664 |
|
663 |
# connect to database |
|
664 |
my $dbh = $form->get_standard_dbh; |
|
665 |
$dbh->begin_work; |
|
666 |
|
|
667 |
# delete spool files |
|
668 |
my $query = qq|SELECT s.spoolfile FROM status s | . |
|
669 |
qq|WHERE s.trans_id = ?|; |
|
670 |
my @values = (conv_i($form->{id})); |
|
671 |
my $sth = $dbh->prepare($query); |
|
672 |
$sth->execute(@values) || $self->dberror($query); |
|
673 |
|
|
674 |
my $spoolfile; |
|
675 |
my @spoolfiles = (); |
|
676 |
|
|
677 |
while (($spoolfile) = $sth->fetchrow_array) { |
|
678 |
push @spoolfiles, $spoolfile; |
|
679 |
} |
|
680 |
$sth->finish; |
|
681 |
|
|
682 |
# delete-values |
|
683 |
@values = (conv_i($form->{id})); |
|
684 |
|
|
685 |
# periodic invoices and their configuration |
|
686 |
do_query($form, $dbh, qq|DELETE FROM periodic_invoices WHERE config_id IN (SELECT id FROM periodic_invoices_configs WHERE oe_id = ?)|, @values); |
|
687 |
do_query($form, $dbh, qq|DELETE FROM periodic_invoices_configs WHERE oe_id = ?|, @values); |
|
688 |
|
|
689 |
# delete status entries |
|
690 |
$query = qq|DELETE FROM status | . |
|
691 |
qq|WHERE trans_id = ?|; |
|
692 |
do_query($form, $dbh, $query, @values); |
|
693 |
|
|
694 |
# delete individual entries |
|
695 |
$query = qq|DELETE FROM orderitems | . |
|
696 |
qq|WHERE trans_id = ?|; |
|
697 |
do_query($form, $dbh, $query, @values); |
|
665 |
my $rc = SL::DB::Order->new->db->with_transaction(sub { |
|
666 |
my @spoolfiles = grep { $_ } map { $_->spoolfile } @{ SL::DB::Manager::Status->get_all(where => [ trans_id => $form->{id} ]) }; |
|
698 | 667 |
|
699 |
$query = qq|DELETE FROM shipto | . |
|
700 |
qq|WHERE trans_id = ? AND module = 'OE'|; |
|
701 |
do_query($form, $dbh, $query, @values); |
|
702 |
|
|
703 |
# delete OE record |
|
704 |
$query = qq|DELETE FROM oe | . |
|
705 |
qq|WHERE id = ?|; |
|
706 |
do_query($form, $dbh, $query, @values); |
|
668 |
SL::DB::Order->new(id => $form->{id})->delete; |
|
707 | 669 |
|
708 |
my $rc = $dbh->commit; |
|
709 |
|
|
710 |
if ($rc) { |
|
711 | 670 |
my $spool = $::lx_office_conf{paths}->{spool}; |
712 |
foreach $spoolfile (@spoolfiles) {
|
|
713 |
unlink "$spool/$spoolfile" if $spoolfile; |
|
714 |
}
|
|
715 |
} |
|
671 |
unlink map { "$spool/$_" } @spoolfiles if $spool;
|
|
672 |
|
|
673 |
1;
|
|
674 |
});
|
|
716 | 675 |
|
717 | 676 |
$main::lxdebug->leave_sub(); |
718 | 677 |
|
Auch abrufbar als: Unified diff
Abhängigkeiten von Lieferscheinen und Aufträgen/Angeboten in der Datenbank löschen
und nicht mehr programmseitig. Das geschieht durch Verwendung von
sinnvollen 'ON DELETE CASCADE/SET NULL'-Foreign-Key-Anweisungen und
Triggern, die aus diejenigen Tabellen löschen, in denen eine
trans_id-Spalte auf mehrere Tabellen verweisen kann (status, ship_to).