--
-- fs_url__copy/2
--
create or replace function fs_url__copy(
  integer,
  integer
) returns int4 as $$

DECLARE
        p_url_id                alias for $1;
        p_target_folder_id      alias for $2;
        v_new_url_id            integer;
        v_url                   varchar;
        v_name                  varchar;
        v_description           varchar;
        v_creation_user         integer;
        v_creation_ip           varchar;
BEGIN
        select url
        into v_url
        from fs_urls
        where url_id = p_url_id;

        select name
        into v_name
        from fs_simple_objects
        where object_id = p_url_id;

        select description
        into v_description
        from fs_simple_objects
        where object_id = p_url_id;

        select creation_user
        into v_creation_user
        from acs_objects
        where object_id = p_url_id;

        select creation_ip
        into v_creation_ip
        from acs_objects
        where object_id = p_url_id;

        v_new_url_id:= fs_url__new (
            NULL,
            'fs_url',
            v_url,
            p_target_folder_id,
            v_name,
            v_description,
            NULL,
            v_creation_user,
            v_creation_ip,
            p_target_folder_id
        );
           
        return v_new_url_id;
END;
$$ language plpgsql;