Solving RT ticket #1092988
[civicrm-core.git] / sql / trigger.mysql
CommitLineData
6a488035 1-- +--------------------------------------------------------------------+
6b7eb9df 2-- | Copyright CiviCRM LLC. All rights reserved. |
6a488035 3-- | |
6b7eb9df
TO
4-- | This work is published under the GNU AGPLv3 license with some |
5-- | permitted exceptions and without any warranty. For full license |
6-- | and copyright information, see https://civicrm.org/licensing |
6a488035
TO
7-- +--------------------------------------------------------------------+
8
9DELIMITER |
10
11CREATE TRIGGER civicrm_contact_ad
12BEFORE DELETE ON civicrm_contact
13FOR EACH ROW
14BEGIN
15 -- we delete the corresponding entity_id/entity_table entries
16 -- from all the linked tables (note, log etc)
17 DELETE FROM civicrm_note
c213dee5 18 WHERE entity_id = OLD.id
6a488035
TO
19 AND entity_table = 'civicrm_contact';
20 DELETE FROM civicrm_log
21 WHERE entity_id = OLD.id
22 AND entity_table = 'civicrm_contact';
c213dee5 23 DELETE FROM civicrm_task_status
6a488035
TO
24 WHERE responsible_entity_id = OLD.id
25 AND responsible_entity_table = 'civicrm_contact';
26
27END;
28
29CREATE TRIGGER civicrm_contribution_ad
30BEFORE DELETE ON civicrm_contribution
31FOR EACH ROW
32BEGIN
33 -- we delete the corresponding entity_id/entity_table entries
34 -- from all the linked tables (note, log etc)
35 DELETE FROM civicrm_note WHERE entity_id = OLD.id AND entity_table = 'civicrm_contribution';
36END;
37
38CREATE TRIGGER civicrm_participant_ad
39BEFORE DELETE ON civicrm_participant
40FOR EACH ROW
41BEGIN
42 -- we delete the corresponding entity_id/entity_table entries
43 -- from all the linked tables (note, log etc)
44 DELETE FROM civicrm_note WHERE entity_id = OLD.id AND entity_table = 'civicrm_participant';
45 DELETE FROM civicrm_log WHERE entity_id = OLD.id AND entity_table = 'civicrm_participant';
46END;
47
48|
49
50DELIMITER ;
51