-- packages/resource-list/sql/resource-list-drop.sql
-- drop script
--
-- @author jade@bread.com
-- @creation-date 2003-05-15
-- @cvs-id $Id: resource-list-drop.sql,v 1.1 2003/11/30 02:15:48 jader Exp $
--

--------
-- RESOURCES
--------

drop sequence rl_resources_number_seq;
drop sequence rl_resource_category_type_seq;
drop sequence rl_resource_category_seq;

-- unregister content_types from folder
create function inline_0 ()
returns integer as '
declare
    v_folder_id	  cr_folders.folder_id%TYPE;
    v_item_id     cr_items.item_id%TYPE;
    v_item_cursor RECORD;
begin

    -- delete all contents of resources folder
    FOR v_item_cursor IN
        select
        item_id
        from
        cr_items
        where
        content_type = ''rl_resource''
    LOOP
       	PERFORM rl_resource__delete_item(v_item_cursor.item_id);
    END LOOP;

    select content_item__get_id(''resources'', null, ''f'') into v_folder_id from dual;

    -- unregister_content_types
    PERFORM content_folder__unregister_content_type (
        v_folder_id,            -- folder_id
        ''rl_resource'',        -- content_type
        ''t''                   -- include_subtypes
    );

    -- this table must not hold reference to ''rl_resource'' type
    -- delete from cr_folder_type_map where content_type = ''rl_resource'';

    -- delete resources folder
    PERFORM content_folder__delete(v_folder_id);

    return 0;
end;
' language 'plpgsql';

select inline_0();
drop function inline_0();

drop table rl_resource_category_map;
drop table rl_resource_category;
drop table rl_resource_category_type;

-- drop package, which drops all functions created with define_function_args
select drop_package('rl_resource');

drop table rl_resources;
drop table rl_resources_revisions;

select content_type__drop_type('rl_resource', 't', 'f');

drop view rl_resources_revisionsx;
drop view rl_resources_revisionsi;
