-- sql/objects-drop.sql
--
-- Remove object types and things like that.
--
-- Ian Baker <ibaker@arsdigita.com>
-- $Id: objects-drop.sql,v 1.1 2002/07/09 17:35:10 rmello Exp $
--

-- This needs to go through each type and delete all the objects
-- before removing the type, using the correct procedures and all,
-- instead of these crazy hacks...

delete from acs_permissions where object_id in (
	(select object_id from acs_objects where object_type in (
		'portal', 'portal_template', 'portal_element_config','portal_datasource', 'portal_element'
	))
);

delete from acs_permissions where object_id in (
	(select package_id from apm_packages where package_key = 'portal')
);


create function inline_0 ()
returns integer as '
declare
	a_row RECORD;
begin
	for a_row in
	    select object_id, object_type 
              from acs_objects
             where object_type in (''portal'', ''portal_template'', ''portal_element_config'',''portal_datasource'', ''portal_element'')
	loop
	    execute ''select '' || a_row.object_type || ''__delete('' || a_row.object_id || '')'';
	end loop;
	return 0;
end;
' language 'plpgsql';

select inline_0 ();

drop function inline_0 ();

select acs_object_type__drop_type('portal', 'f');
select acs_object_type__drop_type('portal_template', 'f');
select acs_object_type__drop_type('portal_element_config', 'f');
select acs_object_type__drop_type('portal_datasource', 'f');
select acs_object_type__drop_type('portal_element', 'f');
