Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d169fd62

Von Niclas Zimmermann vor fast 11 Jahren hinzugefügt

Benutzer-Variablen aus Aufträgen/Lieferscheinen/Rechnungen löschen

Wenn man Aufträge/Lieferscheine/Rechnungen löscht, werden jetzt
zugehörige benutzerdefinierte Variablen gelöscht.

Fixt #2347.

Unterschiede anzeigen:

sql/Pg-upgrade2/custom_variables_delete_via_trigger.pl
1
# @tag: custom_variables_delete_via_trigger
2
# @description: Benutzerdefinierte Variablen werden nun via Trigger gelöscht.
3
# @depends: custom_variable_configs_column_type_text custom_variables custom_variables_indices custom_variables_indices_2 custom_variables_parts_services_assemblies custom_variables_sub_module_not_null custom_variables_valid
4

  
5
package SL::DBUpgrade2::custom_variables_delete_via_trigger;
6

  
7
use utf8;
8
use strict;
9

  
10
use parent qw(SL::DBUpgrade2::Base);
11

  
12
sub run {
13
  my ($self) = @_;
14

  
15
  my @queries = (
16
    #Delete orphaned entries
17
    q|DELETE FROM custom_variables WHERE sub_module = 'orderitems' AND trans_id NOT IN (SELECT id FROM orderitems)|,
18
    q|DELETE FROM custom_variables WHERE sub_module = 'delivery_order_items' AND trans_id NOT IN (SELECT id FROM delivery_order_items)|,
19
    q|DELETE FROM custom_variables WHERE sub_module = 'invoice' AND trans_id NOT IN (SELECT id FROM invoice)|,
20

  
21
    #Create trigger
22
    q|CREATE OR REPLACE FUNCTION orderitems_before_delete_trigger() RETURNS trigger AS $$
23
        BEGIN
24
          DELETE FROM custom_variables WHERE sub_module = 'orderitems' AND trans_id = OLD.id;
25

  
26
          RETURN OLD;
27
        END;
28
      $$ LANGUAGE plpgsql|,
29

  
30
    q|DROP TRIGGER IF EXISTS delete_orderitems_dependencies ON orderitems|,
31

  
32
    q|CREATE TRIGGER delete_orderitems_dependencies
33
      BEFORE DELETE ON orderitems
34
      FOR EACH ROW EXECUTE PROCEDURE orderitems_before_delete_trigger()|,
35

  
36
    q|CREATE OR REPLACE FUNCTION delivery_order_items_before_delete_trigger() RETURNS trigger AS $$
37
        BEGIN
38
          DELETE FROM custom_variables WHERE sub_module = 'delivery_order_items' AND trans_id = OLD.id;
39

  
40
          RETURN OLD;
41
        END;
42
      $$ LANGUAGE plpgsql|,
43

  
44
    q|DROP TRIGGER IF EXISTS delete_delivery_order_items_dependencies ON delivery_order_items|,
45

  
46
    q|CREATE TRIGGER delete_delivery_order_items_dependencies
47
      BEFORE DELETE ON delivery_order_items
48
      FOR EACH ROW EXECUTE PROCEDURE delivery_order_items_before_delete_trigger()|,
49

  
50
    q|CREATE OR REPLACE FUNCTION invoice_before_delete_trigger() RETURNS trigger AS $$
51
        BEGIN
52
          DELETE FROM custom_variables WHERE sub_module = 'invoice' AND trans_id = OLD.id;
53

  
54
          RETURN OLD;
55
        END;
56
      $$ LANGUAGE plpgsql|,
57

  
58
    q|DROP TRIGGER IF EXISTS delete_invoice_dependencies ON invoice|,
59

  
60
    q|CREATE TRIGGER delete_invoice_dependencies
61
      BEFORE DELETE ON invoice
62
      FOR EACH ROW EXECUTE PROCEDURE invoice_before_delete_trigger()|
63
    );
64

  
65
  $self->db_query($_) for @queries;
66

  
67
  return 1;
68
}
69

  
70
1;

Auch abrufbar als: Unified diff