Übersetzungen von Lieferbedingungen löschen, wenn Lieferbed. gelöscht wird.
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Fri, 10 Jan 2014 10:54:42 +0000 (11:54 +0100)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Fri, 10 Jan 2014 10:54:42 +0000 (11:54 +0100)
Via Trigger. Außerdem löscht das Update-Skript alle verweisten Übersetzungen
der Lieferbedingungen.

sql/Pg-upgrade2/delete_translations_on_delivery_term_delete.sql [new file with mode: 0644]

diff --git a/sql/Pg-upgrade2/delete_translations_on_delivery_term_delete.sql b/sql/Pg-upgrade2/delete_translations_on_delivery_term_delete.sql
new file mode 100644 (file)
index 0000000..c4a40a9
--- /dev/null
@@ -0,0 +1,24 @@
+-- @tag: delete_translations_on_delivery_term_delete
+-- @description: Übersetzungen löschen, wenn Lieferbedingung gelöscht wird
+-- @depends: delivery_terms
+-- @encoding: utf-8
+
+CREATE OR REPLACE FUNCTION generic_translations_delete_on_delivery_terms_delete_trigger()
+RETURNS TRIGGER AS $$
+  BEGIN
+    DELETE FROM generic_translations
+      WHERE translation_id = OLD.id AND translation_type LIKE 'SL::DB::DeliveryTerm/description_long';
+    RETURN OLD;
+  END;
+$$ LANGUAGE plpgsql;
+
+DROP TRIGGER IF EXISTS after_delete_delivery_term_trigger ON delivery_terms;
+
+CREATE TRIGGER after_delete_delivery_term_trigger
+  AFTER DELETE ON delivery_terms
+  FOR EACH ROW EXECUTE PROCEDURE generic_translations_delete_on_delivery_terms_delete_trigger();
+
+-- delete orphaned translations
+DELETE FROM generic_translations
+  WHERE translation_type LIKE 'SL::DB::DeliveryTerm/description_long'
+  AND   translation_id NOT IN (SELECT id FROM delivery_terms);