Index: openacs-4/contrib/packages/survey/sql/postgresql/survey-search-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/survey/sql/postgresql/Attic/survey-search-create.sql,v
diff -u -N
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ openacs-4/contrib/packages/survey/sql/postgresql/survey-search-create.sql	13 Jan 2005 13:54:39 -0000	1.2
@@ -0,0 +1,160 @@
+-- 
+-- 
+-- 
+-- @author Dave Bauer (dave@thedesignexperience.org)
+-- @creation-date 2004-09-18
+-- @arch-tag: 575ee1d1-4219-4e2b-9101-be32e48c0893
+-- @cvs-id $Id: survey-search-create.sql,v 1.2 2005/01/13 13:54:39 jeffd Exp $
+--
+
+create or replace function survey_search_itrg ()
+returns trigger as '
+declare search_p     varchar;
+begin
+        if (select apm__get_value(new.package_id,''IndexForSearchP'')) = ''1'' then
+                perform search_observer__enqueue (
+                        new.survey_id,
+                        ''INSERT''
+                        );
+        end if;
+return new;
+end;' language 'plpgsql';
+
+-- drop trigger survey_search_itrg on surveys;
+-- drop trigger survey_search_utrg on surveys;
+-- drop trigger survey_search_dtrg on surveys;
+-- drop trigger survey_sec_search_itrg on survey_sections;
+-- drop trigger survey_sec_search_utrg on survey_sections;
+-- drop trigger survey_sec_search_dtrg on survey_sections;
+-- drop trigger survey_q_search_itrg on survey_questions;
+-- drop trigger survey_q_search_utrg on survey_questions;
+-- drop trigger survey_q_search_dtrg on survey_questions;
+
+create trigger survey_search_itrg after insert on surveys
+        for each row execute procedure survey_search_itrg();
+
+create or replace function survey_search_utrg ()
+returns trigger as '
+begin
+        if (select apm__get_value(new.package_id,''IndexForSearchP'')) = ''1'' then
+                perform search_observer__enqueue(
+                        new.survey_id,
+                        ''UPDATE''
+                        );
+        end if;
+        return new;
+end;' language 'plpgsql';
+
+create trigger survey_search_utrg after update on surveys
+        for each row execute procedure survey_search_utrg();
+
+create or replace function survey_search_dtrg()
+returns trigger as '
+begin
+        if (select apm__get_value(old.package_id,''IndexForSearchP'')) = ''1'' then
+                perform search_observer__enqueue(
+                old.survey_id,
+                ''DELETE''
+                );
+        end if;
+        return old;
+end;' language 'plpgsql';
+
+create trigger survey_search_dtrg before delete on surveys
+        for each row execute procedure survey_search_dtrg();
+
+-- survey sections triggers
+
+
+create or replace function survey_sec_search_itrg ()
+returns trigger as '
+begin
+        if (select apm__get_value((select package_id from surveys where survey_id=new.survey_id),''IndexForSearchP'')) = ''1'' then
+                perform search_observer__enqueue (
+                        new.section_id,
+                        ''INSERT''
+                        );
+        end if;
+return new;
+end;' language 'plpgsql';
+
+create trigger survey_sec_search_itrg after insert on survey_sections
+        for each row execute procedure survey_sec_search_itrg();
+
+create or replace function survey_sec_search_utrg ()
+returns trigger as '
+begin
+        if (select apm__get_value((select package_id from surveys where survey_id=new.survey_id),''IndexForSearchP'')) = ''1'' then
+                perform search_observer__enqueue(
+                        new.section_id,
+                        ''UPDATE''
+                        );
+        end if;
+        return new;
+end;' language 'plpgsql';
+
+create trigger survey_sec_search_utrg after update on survey_sections
+        for each row execute procedure survey_sec_search_utrg();
+
+create or replace function survey_sec_search_dtrg()
+returns trigger as '
+begin
+--        if (select apm__get_value((select package_id from surveys where survey_id=old.survey_id),''IndexForSearchP'')) = ''1'' then
+                perform search_observer__enqueue(
+                        old.section_id,
+                        ''DELETE''
+                );
+--        end if;
+        return old;
+end;' language 'plpgsql';
+
+create trigger survey_sec_search_dtrg before delete on survey_sections
+        for each row execute procedure survey_sec_search_dtrg();
+
+-- survey question triggers
+
+
+create or replace function survey_q_search_itrg ()
+returns trigger as '
+begin
+        if (select apm__get_value((select s.package_id from surveys s, survey_sections ss where s.survey_id=ss.survey_id and ss.section_id=new.section_id),''IndexForSearchP'')) = ''1'' then
+                perform search_observer__enqueue (
+                        new.question_id,
+                        ''INSERT''
+                        );
+        end if;
+return new;
+end;' language 'plpgsql';
+
+create trigger survey_q_search_itrg after insert on survey_questions
+        for each row execute procedure survey_q_search_itrg();
+
+create or replace function survey_q_search_utrg ()
+returns trigger as '
+begin
+        if (select apm__get_value((select s.package_id from surveys s, survey_sections ss where s.survey_id=ss.survey_id and ss.section_id=new.section_id),''IndexForSearchP'')) = ''1'' then
+                perform search_observer__enqueue(
+                        new.question_id,
+                        ''UPDATE''
+                        );
+        end if;
+        return new;
+end;' language 'plpgsql';
+
+create trigger survey_q_search_utrg after update on survey_questions
+        for each row execute procedure survey_q_search_utrg();
+
+create or replace function survey_q_search_dtrg()
+returns trigger as '
+begin
+--        if (select apm__get_value((select s.package_id from surveys s, survey_sections ss where s.survey_id=ss.survey_id and ss.section_id=old.section_id),''IndexForSearchP'')) = ''1'' then
+                perform search_observer__enqueue(
+                        old.question_id,
+                        ''DELETE''
+                        );
+--        end if;
+        return old;
+end;' language 'plpgsql';
+
+create trigger survey_q_search_dtrg before delete on survey_questions
+        for each row execute procedure survey_q_search_dtrg();
