From: Moritz Bunkus Date: Tue, 15 Jan 2013 13:46:30 +0000 (+0100) Subject: Nach Löschen in ar/ap/gl via DB-Trigger in acc_trans aufräumen X-Git-Tag: release-3.1.0beta1~695 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=493457086f727b713cca06c25c1c3bedb92185af;p=kivitendo-erp.git Nach Löschen in ar/ap/gl via DB-Trigger in acc_trans aufräumen --- diff --git a/SL/AP.pm b/SL/AP.pm index 95bde38e5..3c8e2404f 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -395,13 +395,10 @@ sub delete_transaction { # connect to database my $dbh = $form->dbconnect_noauto($myconfig); + # acc_trans entries are deleted by database triggers. my $query = qq|DELETE FROM ap WHERE id = ?|; do_query($form, $dbh, $query, $form->{id}); - $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|; - do_query($form, $dbh, $query, $form->{id}); - - # commit and redirect my $rc = $dbh->commit; $dbh->disconnect; diff --git a/SL/AR.pm b/SL/AR.pm index 57739188a..26c0bca1e 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -417,12 +417,10 @@ sub delete_transaction { # connect to database, turn AutoCommit off my $dbh = $form->dbconnect_noauto($myconfig); + # acc_trans entries are deleted by database triggers. my $query = qq|DELETE FROM ar WHERE id = ?|; do_query($form, $dbh, $query, $form->{id}); - $query = qq|DELETE FROM acc_trans WHERE trans_id = ?|; - do_query($form, $dbh, $query, $form->{id}); - # commit my $rc = $dbh->commit; $dbh->disconnect; diff --git a/SL/GL.pm b/SL/GL.pm index c9fcd9c47..7bcb47509 100644 --- a/SL/GL.pm +++ b/SL/GL.pm @@ -51,9 +51,8 @@ sub delete_transaction { # connect to database my $dbh = $form->dbconnect_noauto($myconfig); - my @values = (conv_i($form->{id})); - do_query($form, $dbh, qq|DELETE FROM acc_trans WHERE trans_id = ?|, @values); - do_query($form, $dbh, qq|DELETE FROM gl WHERE id = ?|, @values); + # acc_trans entries are deleted by database triggers. + do_query($form, $dbh, qq|DELETE FROM gl WHERE id = ?|, conv_i($form->{id})); # commit and redirect my $rc = $dbh->commit; diff --git a/sql/Pg-upgrade2/ar_ap_gl_delete_triggers_deletion_from_acc_trans.sql b/sql/Pg-upgrade2/ar_ap_gl_delete_triggers_deletion_from_acc_trans.sql new file mode 100644 index 000000000..e38e58c34 --- /dev/null +++ b/sql/Pg-upgrade2/ar_ap_gl_delete_triggers_deletion_from_acc_trans.sql @@ -0,0 +1,22 @@ +-- @tag: ar_ap_gl_delete_triggers_deletion_from_acc_trans +-- @description: Beim Löschen aus ar, ap, gl per Trigger auch dazugehörige Einträge aus acc_trans löschen +-- @depends: release_3_0_0 +-- @charset: utf-8 +CREATE OR REPLACE FUNCTION clean_up_acc_trans_after_ar_ap_gl_delete() RETURNS trigger AS $$ + BEGIN + DELETE FROM acc_trans WHERE trans_id = OLD.id; + RETURN OLD; + END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER after_delete_ar_trigger +AFTER DELETE ON ar FOR EACH ROW EXECUTE +PROCEDURE clean_up_acc_trans_after_ar_ap_gl_delete(); + +CREATE TRIGGER after_delete_ap_trigger +AFTER DELETE ON ap FOR EACH ROW EXECUTE +PROCEDURE clean_up_acc_trans_after_ar_ap_gl_delete(); + +CREATE TRIGGER after_delete_gl_trigger +AFTER DELETE ON gl FOR EACH ROW EXECUTE +PROCEDURE clean_up_acc_trans_after_ar_ap_gl_delete();