Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-extlink.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-extlink.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-extlink.sql 25 Mar 2001 21:18:51 -0000 1.1 @@ -0,0 +1,113 @@ +-- Data model to support content repository of the ArsDigita +-- Community System + +-- Copyright (C) 1999-2000 ArsDigita Corporation +-- Author: Karl Goldstein (karlg@arsdigita.com) + +-- $Id: content-extlink.sql,v 1.1 2001/03/25 21:18:51 danw Exp $ + +-- This is free software distributed under the terms of the GNU Public +-- License. Full text of the license is available from the GNU Project: +-- http://www.fsf.org/copyleft/gpl.html + +-- create or replace package body content_extlink +-- function new +create function content_extlink__new (varchar,varchar,varchar,varchar,integer,integer,timestamp,integer,varchar) +returns integer as ' +declare + new__name alias for $1; + new__url alias for $2; + new__label alias for $3; + new__description alias for $4; + new__parent_id alias for $5; + new__extlink_id alias for $6; + new__creation_date alias for $7; + new__creation_user alias for $8; + new__creation_ip alias for $9; + v_extlink_id cr_extlinks.extlink_id%TYPE; + v_label cr_extlinks.label%TYPE; + v_name cr_items.name%TYPE; +begin + + if new__label is null then + v_label := new__url; + else + v_label := new__label; + end if; + + if new__name is null then + select acs_object_id_seq.nextval into v_extlink_id from dual; + v_name := ''link'' || v_extlink_id; + else + v_name := new__name; + end if; + + v_extlink_id := content_item__new( + name => v_name, + parent_id => content_extlink.new__parent_id, + item_id => content_extlink.new__extlink_id, + null, + creation_date => content_extlink.new__creation_date, + creation_user => content_extlink.new__creation_user, + null, + creation_ip => content_extlink.new__creation_ip, + ''content_item'', + content_type => ''content_extlink'', + null, + null, + ''text/plain'', + null, + null, + null + ); + + insert into cr_extlinks + (extlink_id, url, label, description) + values + (v_extlink_id, new__url, v_label, new__description); + + return v_extlink_id; + +end;' language 'plpgsql'; + + +-- procedure delete +create function content_extlink__delete (integer) +returns integer as ' +declare + delete__extlink_id alias for $1; +begin + + delete from cr_extlinks + where extlink_id = delete__extlink_id; + + PERFORM content_item__delete(delete__extlink_id); + +return 0; +end;' language 'plpgsql'; + + +-- function is_extlink +create function content_extlink__is_extlink (integer) +returns boolean as ' +declare + is_extlink__item_id alias for $1; + v_extlink_p boolean; +begin + + select + count(1) = 1 into v_extlink_p + from + cr_extlinks + where + extlink_id = is_extlink__item_id; + + return v_extlink_p; + +end;' language 'plpgsql'; + + + +-- show errors + + Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-symlink.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-symlink.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-symlink.sql 25 Mar 2001 21:11:23 -0000 1.1 @@ -0,0 +1,272 @@ +-- Data model to support content repository of the ArsDigita +-- Community System + +-- Copyright (C) 1999-2000 ArsDigita Corporation +-- Author: Karl Goldstein (karlg@arsdigita.com) + +-- $Id: content-symlink.sql,v 1.1 2001/03/25 21:11:23 danw Exp $ + +-- This is free software distributed under the terms of the GNU Public +-- License. Full text of the license is available from the GNU Project: +-- http://www.fsf.org/copyleft/gpl.html + +-- create or replace package body content_symlink +-- function new +create function content_symlink__new (varchar,varchar,integer,integer,integer,timestamp,integer,varchar) +returns integer as ' +declare + new__name alias for $1; + new__label alias for $2; + new__target_id alias for $3; + new__parent_id alias for $4; + new__symlink_id alias for $5; + new__creation_date alias for $6; + new__creation_user alias for $7; + new__creation_ip alias for $8; + v_symlink_id cr_symlinks.symlink_id%TYPE; + v_name cr_items.name%TYPE; + v_label cr_symlinks.label%TYPE; +begin + + -- SOME CHECKS -- + + -- 1) check that the target is now a symlink + if content_symlink__is_symlink(new__target_id) = ''t'' then + raise EXCEPTION ''-20000: Cannot create a symlink to a symlink %'', target_id; + end if; + + -- 2) check that the parent is a folder + if content_folder__is_folder(new__parent_id) = ''f'' then + raise EXCEPTION ''-20000: The parent is not a folder''; + end if; + + -- 3) check that parent folder supports symlinks + if content_folder__is_registered(new__parent_id,''content_symlink'') = ''f'' then + raise EXCEPTION ''-20000: This folder does not allow symlinks to be created''; + end if; + + -- 4) check that the content folder supports the target item''s content type + if content_folder__is_registered( + parent_id,content_item__get_content_type(new__target_id)) = ''f'' then + + raise EXCEPTION ''-20000: This folder does not allow symlinks to items of type % to be created'', '', content_item__get_content_type(new__target_id); + end if; + + -- PASSED ALL CHECKS -- + + -- Select default name if the name is null + if name is null then + select + ''symlink_to_'' || name into v_name + from + cr_items + where + item_id = target_id; + + if NOT FOUND then + v_name := null; + end if; + else + v_name := name; + end if; + + -- Select default label if the label is null + if new__label is null then + v_label := ''Symlink to '' || v_name; + else + v_label := new__label; + end if; + + v_symlink_id := content_item__new( + v_name, + new__parent_id + new__symlink_id, + null, + new__creation_date, + new__creation_user, + null, + new__creation_ip, + ''content_item'', + ''content_symlink'', + null, + null, + ''text/plain'', + null, + null, + null + ); + + insert into cr_symlinks + (symlink_id, target_id, label) + values + (v_symlink_id, new__target_id, v_label); + + return v_symlink_id; + +end;' language 'plpgsql'; + + +-- procedure delete +create function content_symlink__delete (integer) +returns integer as ' +declare + delete__symlink_id alias for $1; +begin + + delete from cr_symlinks + where symlink_id = delete__symlink_id; + + PERFORM content_item__delete(delete__symlink_id); + + return 0; +end;' language 'plpgsql'; + + +-- function is_symlink +create function content_symlink__is_symlink (integer) +returns char as ' +declare + is_symlink__item_id alias for $1; + v_symlink_p boolean; +begin + + select + count(*) = 1 into v_symlink_p + from + cr_symlinks + where + symlink_id = is_symlink__item_id; + + return v_symlink_p; + +end;' language 'plpgsql'; + + +-- procedure copy +create function content_symlink__copy (integer,integer,integer,varchar) +returns integer as ' +declare + copy_symlink_id alias for $1; + copy_target_folder_id alias for $2; + copy_creation_user alias for $3; + copy_creation_ip alias for $4; + v_current_folder_id cr_folders.folder_id%TYPE; + v_name cr_items.name%TYPE; + v_target_id cr_items.item_id%TYPE; + v_label cr_symlinks.label%TYPE; + v_symlink_id cr_symlinks.symlink_id%TYPE; +begin + + if content_folder__is_folder(copy__target_folder_id) = ''t'' then + select + parent_id + into + v_current_folder_id + from + cr_items + where + item_id = copy__symlink_id; + + -- can''t copy to the same folder + if copy__target_folder_id ^= v_current_folder_id then + + select + i.name, content_symlink__resolve(i.item_id), s.label + into + v_name, v_target_id, v_label + from + cr_symlinks s, cr_items i + where + s.symlink_id = i.item_id + and + s.symlink_id = copy__symlink_id; + + + if content_folder__is_registered(copy__target_folder_id, + ''content_symlink'') = ''t'' then + if content_folder__is_registered(copy__target_folder_id, + content_item__get_content_type(content_symlink__resolve(copy__symlink_id))) = ''t'' then + + v_symlink_id := content_symlink__new( + v_name, + v_label, + v_target_id, + copy__target_folder_id, + null, + now(), + copy__creation_user, + copy__creation_ip + ); + + + end if; + end if; + end if; + end if; + + return 0; +end;' language 'plpgsql'; + + +-- function resolve +create function content_symlink__resolve (integer) +returns integer as ' +declare + resolve__item_id alias for $1; + v_target_id cr_items.item_id%TYPE; +begin + + select + target_id into v_target_id + from + cr_symlinks + where + symlink_id = resolve__item_id; + + if NOT FOUND then + return resolve__item_id; + else + return v_target_id; + end if; + +end;' language 'plpgsql'; + + +-- function resolve_content_type +create function content_symlink__resolve_content_type (integer) +returns varchar as ' +declare + resolve_content_type__item_id alias for $1; + v_content_type cr_items.content_type%TYPE; +begin + + select + content_item__get_content_type(target_id) into v_content_type + from + cr_symlinks + where + symlink_id = resolve_content_type__item_id; + + if NOT FOUND then + return null; + end if; + + return v_content_type; + +end;' language 'plpgsql'; + + + +-- show errors + +-- Convenience view to simply access to symlink targets + +create view cr_resolved_items as + select + i.parent_id, i.item_id, i.name, + case when s.target_id is NULL then 'f' else 't' end as is_symlink, + coalesce(s.target_id, i.item_id) as resolved_id, s.label + from + cr_items i left outer join cr_symlinks s + where + i.item_id = s.symlink_id;