let administrators modify package contents even if they are not marked as such to...
[xtuple] / foundation-database / public / trigger_functions / pkgscript.sql
1 -- NO create trigger statements. the updater will create them.
2
3 SELECT dropIfExists('TRIGGER', 'pkgscriptbeforetrigger');
4 CREATE OR REPLACE FUNCTION _pkgscriptbeforetrigger() RETURNS "trigger" AS $$
5 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
6 -- See www.xtuple.com/CPAL for the full text of the software license.
7 DECLARE
8   _scriptid     INTEGER;
9   _debug        BOOL := false;
10
11 BEGIN
12   IF (TG_OP = 'UPDATE') THEN
13     RETURN NEW;
14
15   ELSIF (TG_OP = 'INSERT') THEN
16     RETURN NEW;
17
18   ELSIF (TG_OP = 'DELETE') THEN
19     RETURN OLD;
20   END IF;
21
22   RETURN NEW;
23 END;
24 $$ LANGUAGE 'plpgsql';
25
26 CREATE OR REPLACE FUNCTION _pkgscriptalterTrigger() RETURNS TRIGGER AS $$
27 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
28 -- See www.xtuple.com/CPAL for the full text of the software license.
29 BEGIN
30   IF (pkgMayBeModified(TG_TABLE_SCHEMA) OR isDba()) THEN
31     IF (TG_OP = 'DELETE') THEN
32       RETURN OLD;
33     ELSE
34       RETURN NEW;
35     END IF;
36   END IF;
37
38   IF (TG_OP = 'INSERT') THEN
39     RAISE EXCEPTION 'You may not create scripts in packages except using the xTuple Updater utility';
40
41   ELSIF (TG_OP = 'UPDATE') THEN
42     RAISE EXCEPTION 'You may not alter scripts in packages except using the xTuple Updater utility';
43
44   ELSIF (TG_OP = 'DELETE') THEN
45     RAISE EXCEPTION 'You may not delete scripts from packages. Try deleting or disabling the package.';
46
47   END IF;
48
49   RETURN NEW;
50 END;
51 $$ LANGUAGE 'plpgsql';
52
53 CREATE OR REPLACE FUNCTION _pkgscriptaftertrigger() RETURNS TRIGGER AS $$
54 -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. 
55 -- See www.xtuple.com/CPAL for the full text of the software license.
56 BEGIN
57   IF (TG_OP = 'DELETE') THEN
58     RETURN OLD;
59   END IF;
60
61   RETURN NEW;
62 END;
63 $$ LANGUAGE 'plpgsql';