Control of the can_edit_macros user permission.
[cocanwiki.git] / schema / contents_jsgo_check_tg.sql
1 -- Check the contents.jsgo field points to a valid URL.
2 -- This is triggered on rows inserted or updated in contents.
3 -- $Id: contents_jsgo_check_tg.sql,v 1.2 2006/07/26 13:41:34 rich Exp $
4
5 create or replace function contents_jsgo_check_tg() returns trigger as '
6
7 declare
8         my_hostid integer;
9         my_count integer;
10
11 begin
12         if new.jsgo is not null then
13                 -- Get the hostid
14                 select into my_hostid p.hostid
15                   from pages p
16                  where p.id = new.pageid;
17                 -- Check that (hostid, url) where url = new.jsgo exists.
18                 select into my_count count(p.*)
19                   from pages p
20                  where p.hostid = my_hostid
21                    and p.url is not null
22                    and p.url = new.jsgo
23                    and p.redirect is null;
24                 if my_count < 1 then
25                         raise exception ''contents.jsgo points to non-existent page (%, %)'',
26                           my_hostid, new.jsgo;
27                 end if;
28         end if;
29
30         -- Everything is OK.  Return the new row unmodified.
31         return new;
32 end;
33
34 ' language plpgsql;