--
-- cr_revision_latest_tr/0
--
create or replace function cr_revision_latest_tr(
  
) returns trigger as $$

DECLARE
  v_content_type      cr_items.content_type%TYPE;
BEGIN

  select content_type from cr_items into v_content_type where item_id = new.item_id;
  --
  -- Don't set the latest revision via trigger, since other means in
  -- the xotcl-core frame work take care for it. This is not the most
  -- general solution, but improves the situation for busy sites.
  --
  if substring(v_content_type,1,2) != '::' then
     update cr_items set latest_revision = new.revision_id
     where item_id = new.item_id;
  end if;
  
  return new;
END;
$$ language plpgsql;