--
-- packages/ticket-tracker/sql/ttracker-drop.sql
--
-- 
-- @author Phong Nguyen (phong@arsdigita.com)
-- @author Tony Tseng (tony@arsidigta.com)
-- 
-- @creation-date 2000-11-15
--
-- @cvs-id $Id: ticket-tracker-drop.sql,v 1.1 2002/07/09 17:35:13 rmello Exp $
--
-- Ported to OpenACS - Vinod Kurup (vkurup@massmed.org)
--

-- drop the workflow process
\i ttracker-workflow-drop.sql

create function inline_0 ()
returns integer as '
declare
	comment_rec			record;
	ticket_rec			record;
	category_rec		record;
begin
    -- iterate through all comments on tickets
	for comment_rec in select gc.comment_id 
	                     from general_comments gc,
	                          ttracker_tickets tt
                         where gc.object_id = tt.ticket_id loop
		perform acs_message__delete(comment_rec.comment_id);
	end loop;

    -- iterate through all tickets
	for ticket_rec in select ticket_id from ttracker_tickets loop
		perform ttracker_ticket__delete(ticket_rec.ticket_id);
	end loop;

    -- iterate through all categories
	for category_rec in select category_id from ttracker_categories loop
		perform ttracker_category__delete(category_rec.category_id);
	end loop;
        
    perform acs_object_type__drop_type (''ttracker_ticket'', ''t'');
    perform acs_object_type__drop_type (''ttracker_category'', ''t'');

	return 0;
end;' language 'plpgsql';

select inline_0();

drop function inline_0();

drop table ttracker_tickets;
drop table ttracker_categories;
drop table ttracker_options;

drop sequence ttracker_option_id_seq;
drop view ttracker_option_id_sequence;

-- drop packages
drop function ttracker_util__notification_sender (integer);
drop function ttracker_util__workflow_url (boolean);
drop function ttracker_util__install (integer);

drop function ttracker_callback__assign_to_submitter (integer,varchar);
drop function ttracker_callback__assign_to_assignee (integer,varchar);
drop function ttracker_callback__clarify_fire (integer,varchar,varchar);
drop function ttracker_callback__resolve_fire (integer,varchar,varchar);
drop function ttracker_callback__notification (integer,varchar,integer,integer,varchar,varchar);
drop function ttracker_callback__notify_admin (integer,varchar);

drop function ttracker_category__new (integer,integer,varchar,timestamp,integer,varchar,integer,varchar,integer,varchar);
drop function ttracker_category__delete (integer);
drop function ttracker_category__name (integer);

drop function ttracker_option__add_option (integer,integer,varchar,varchar,integer);
drop function ttracker_option__update_option (integer,varchar,integer);
drop function ttracker_option__option_name (integer,varchar,integer);
drop function ttracker_option__option_value (integer,varchar,varchar);

drop function ttracker_ticket__new (integer,varchar,integer,varchar,varchar,varchar,integer,integer,integer,timestamp,integer,varchar);
drop function ttracker_ticket__delete (integer);
drop function ttracker_ticket__name (integer);
drop function ttracker_ticket__id_valid_p (integer,integer);
drop function ttracker_ticket__update_mime_subj_desc (integer,varchar,varchar,varchar);

