Revision 18448fca
Von Niclas Zimmermann vor fast 11 Jahren hinzugefügt
sql/Pg-upgrade2/custom_variables_delete_via_trigger_2.pl | ||
---|---|---|
1 |
# @tag: custom_variables_delete_via_trigger_2 |
|
2 |
# @description: Benutzerdefinierte Variablen werden nun via Trigger gelöscht (beim Löschen von Kunden, Lieferanten, Kontaktpersonen, Waren, Dienstleistungen, Erzeugnissen und Projekten). |
|
3 |
# @depends: custom_variables_delete_via_trigger |
|
4 |
|
|
5 |
package SL::DBUpgrade2::custom_variables_delete_via_trigger_2; |
|
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 = '' OR sub_module IS NULL) |
|
18 |
AND trans_id NOT IN (SELECT id FROM customer UNION SELECT id FROM vendor) |
|
19 |
AND (SELECT module FROM custom_variable_configs WHERE id = config_id) = 'CT'|, |
|
20 |
q|DELETE FROM custom_variables WHERE (sub_module = '' OR sub_module IS NULL) |
|
21 |
AND trans_id NOT IN (SELECT id FROM contacts) |
|
22 |
AND (SELECT module FROM custom_variable_configs WHERE id = config_id) = 'Contacts'|, |
|
23 |
q|DELETE FROM custom_variables WHERE (sub_module = '' OR sub_module IS NULL) |
|
24 |
AND trans_id NOT IN (SELECT id FROM parts) |
|
25 |
AND (SELECT module FROM custom_variable_configs WHERE id = config_id) = 'IC'|, |
|
26 |
q|DELETE FROM custom_variables WHERE (sub_module = '' OR sub_module IS NULL) |
|
27 |
AND trans_id NOT IN (SELECT id FROM project) |
|
28 |
AND (SELECT module FROM custom_variable_configs WHERE id = config_id) = 'Projects'|, |
|
29 |
|
|
30 |
#Create trigger |
|
31 |
q|CREATE OR REPLACE FUNCTION delete_cv_custom_variables_trigger() RETURNS trigger AS $$ |
|
32 |
BEGIN |
|
33 |
DELETE FROM custom_variables WHERE (sub_module = '' OR sub_module IS NULL) |
|
34 |
AND trans_id = OLD.id |
|
35 |
AND (SELECT module FROM custom_variable_configs WHERE id = config_id) = 'CT'; |
|
36 |
|
|
37 |
RETURN OLD; |
|
38 |
END; |
|
39 |
$$ LANGUAGE plpgsql|, |
|
40 |
|
|
41 |
q|DROP TRIGGER IF EXISTS delete_cv_custom_variables ON customer|, |
|
42 |
q|DROP TRIGGER IF EXISTS delete_cv_custom_variables ON vendor|, |
|
43 |
|
|
44 |
q|CREATE TRIGGER delete_cv_custom_variables |
|
45 |
BEFORE DELETE ON customer |
|
46 |
FOR EACH ROW EXECUTE PROCEDURE delete_cv_custom_variables_trigger()|, |
|
47 |
q|CREATE TRIGGER delete_cv_custom_variables |
|
48 |
BEFORE DELETE ON vendor |
|
49 |
FOR EACH ROW EXECUTE PROCEDURE delete_cv_custom_variables_trigger()|, |
|
50 |
|
|
51 |
#Create trigger |
|
52 |
q|CREATE OR REPLACE FUNCTION delete_contact_custom_variables_trigger() RETURNS trigger AS $$ |
|
53 |
BEGIN |
|
54 |
DELETE FROM custom_variables WHERE (sub_module = '' OR sub_module IS NULL) |
|
55 |
AND trans_id = OLD.cp_id |
|
56 |
AND (SELECT module FROM custom_variable_configs WHERE id = config_id) = 'Contacts'; |
|
57 |
|
|
58 |
RETURN OLD; |
|
59 |
END; |
|
60 |
$$ LANGUAGE plpgsql|, |
|
61 |
|
|
62 |
q|DROP TRIGGER IF EXISTS delete_contact_custom_variables ON contacts|, |
|
63 |
|
|
64 |
q|CREATE TRIGGER delete_contact_custom_variables |
|
65 |
BEFORE DELETE ON contacts |
|
66 |
FOR EACH ROW EXECUTE PROCEDURE delete_contact_custom_variables_trigger()|, |
|
67 |
|
|
68 |
#Create trigger |
|
69 |
q|CREATE OR REPLACE FUNCTION delete_part_custom_variables_trigger() RETURNS trigger AS $$ |
|
70 |
BEGIN |
|
71 |
DELETE FROM custom_variables WHERE (sub_module = '' OR sub_module IS NULL) |
|
72 |
AND trans_id = OLD.id |
|
73 |
AND (SELECT module FROM custom_variable_configs WHERE id = config_id) = 'IC'; |
|
74 |
|
|
75 |
RETURN OLD; |
|
76 |
END; |
|
77 |
$$ LANGUAGE plpgsql|, |
|
78 |
|
|
79 |
q|DROP TRIGGER IF EXISTS delete_part_custom_variables ON parts|, |
|
80 |
|
|
81 |
q|CREATE TRIGGER delete_part_custom_variables |
|
82 |
BEFORE DELETE ON parts |
|
83 |
FOR EACH ROW EXECUTE PROCEDURE delete_part_custom_variables_trigger()|, |
|
84 |
|
|
85 |
#Create trigger |
|
86 |
q|CREATE OR REPLACE FUNCTION delete_project_custom_variables_trigger() RETURNS trigger AS $$ |
|
87 |
BEGIN |
|
88 |
DELETE FROM custom_variables WHERE (sub_module = '' OR sub_module IS NULL) |
|
89 |
AND trans_id = OLD.id |
|
90 |
AND (SELECT module FROM custom_variable_configs WHERE id = config_id) = 'Projects'; |
|
91 |
|
|
92 |
RETURN OLD; |
|
93 |
END; |
|
94 |
$$ LANGUAGE plpgsql|, |
|
95 |
|
|
96 |
q|DROP TRIGGER IF EXISTS delete_project_custom_variables ON project|, |
|
97 |
|
|
98 |
q|CREATE TRIGGER delete_project_custom_variables |
|
99 |
BEFORE DELETE ON project |
|
100 |
FOR EACH ROW EXECUTE PROCEDURE delete_project_custom_variables_trigger()|, |
|
101 |
|
|
102 |
); |
|
103 |
|
|
104 |
$self->db_query($_) for @queries; |
|
105 |
|
|
106 |
return 1; |
|
107 |
} |
|
108 |
|
|
109 |
1; |
Auch abrufbar als: Unified diff
Noch mehr Trigger für Benutzervariablen
Beim Löschen von Projekten, Ansprechpersonen, Kunden, Lieferanten,
Waren, Erzeugnissen und Dienstleistungen werden jetzt auch die
benutzerdefinierten Variablen gelöscht.