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 -r1.10 -r1.11 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-extlink.sql 11 Dec 2003 21:39:46 -0000 1.10 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-extlink.sql 23 Jan 2004 05:45:45 -0000 1.11 @@ -99,15 +99,44 @@ return v_extlink_p; +end;' language 'plpgsql'; + +create or replace function content_extlink__copy ( + integer, + integer, + integer, + varchar) +returns integer as ' +declare + copy__extlink_id alias for $1; + copy__target_folder_id alias for $2; + copy__creation_user alias for $3; + copy__creation_ip alias for $4; -- default null + v_extlink_id cr_extlinks.extlink_id%TYPE; +begin + v_extlink_id := content_extlink__copy ( + copy__extlink_id, + copy__target_folder_id, + copy__creation_user, + copy__creation_ip, + NULL + ); + return 0; end;' language 'plpgsql' stable; -create or replace function content_extlink__copy (integer,integer,integer,varchar) +create or replace function content_extlink__copy ( + integer, + integer, + integer, + varchar, + varchar) returns integer as ' declare copy__extlink_id alias for $1; copy__target_folder_id alias for $2; copy__creation_user alias for $3; - copy__creation_ip alias for $4; -- default null + copy__creation_ip alias for $4; -- default null + copy__name alias for $5; v_current_folder_id cr_folders.folder_id%TYPE; v_name cr_items.name%TYPE; v_url cr_extlinks.url%TYPE; @@ -127,24 +156,27 @@ item_id = copy__extlink_id; -- can''t copy to the same folder - if copy__target_folder_id != v_current_folder_id then - select - i.name, e.url, e.description, e.label - into - v_name, v_url, v_description, v_label - from - cr_extlinks e, cr_items i - where - e.extlink_id = i.item_id - and - e.extlink_id = copy__extlink_id; + select + i.name, e.url, e.description, e.label + into + v_name, v_url, v_description, v_label + from + cr_extlinks e, cr_items i + where + e.extlink_id = i.item_id + and + e.extlink_id = copy__extlink_id; + + -- copy to a different folder, or same folder if name + -- is different + if copy__target_folder_id != v_current_folder_id or ( v_name <> copy_name and copy_name is not null ) then if content_folder__is_registered(copy__target_folder_id, ''content_extlink'',''f'') = ''t'' then v_extlink_id := content_extlink__new( - v_name, + coalesce (copy__name, v_name), v_url, v_label, v_description, @@ -160,7 +192,8 @@ end if; return 0; -end;' language 'plpgsql'; +end;' language 'plpgsql' stable; + Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql,v diff -u -r1.24 -r1.25 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql 11 Dec 2003 21:39:47 -0000 1.24 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql 23 Jan 2004 05:45:45 -0000 1.25 @@ -199,25 +199,47 @@ end;' language 'plpgsql'; -- procedure delete -create or replace function content_folder__delete (integer) + +create or replace function content_folder__delete (integer, boolean) returns integer as ' declare delete__folder_id alias for $1; + p_cascade_p alias for $2; v_count integer; + v_child_row record; v_parent_id integer; v_path varchar; + v_folder_sortkey varbit; begin - -- check if the folder contains any items + if p_cascade_p = ''f'' then + select count(*) into v_count from cr_items + where parent_id = delete__folder_id; + -- check if the folder contains any items + if v_count > 0 then + v_path := content_item__get_path(delete__folder_id, null); + raise EXCEPTION ''-20000: Folder ID % (%) cannot be deleted because it is not empty.'', delete__folder_id, v_path; + end if; + else + -- delete children + select into v_folder_sortkey tree_sortkey + from cr_items where item_id=delete__folder_id; - select count(*) into v_count from cr_items - where parent_id = delete__folder_id; + for v_child_row in select + item_id, tree_sortkey, name + from cr_items + where tree_sortkey between v_folder_sortkey and tree_right(v_folder_sortkey) + and tree_sortkey != v_folder_sortkey + order by tree_sortkey desc + loop + if content_folder__is_folder(v_child_row.item_id) then + perform content_folder__delete(v_child_row.item_id); + else + perform content_item__delete(v_child_row.item_id); + end if; + end loop; + end if; - if v_count > 0 then - v_path := content_item__get_path(delete__folder_id, null); - raise EXCEPTION ''-20000: Folder ID % (%) cannot be deleted because it is not empty.'', delete__folder_id, v_path; - end if; - PERFORM content_folder__unregister_content_type( delete__folder_id, ''content_revision'', @@ -229,7 +251,7 @@ select parent_id into v_parent_id from cr_items where item_id = delete__folder_id; - + raise notice ''deleteing folder %'',delete__folder_id; PERFORM content_item__delete(delete__folder_id); -- check if any folders are left in the parent @@ -242,6 +264,21 @@ end;' language 'plpgsql'; +create or replace function content_folder__delete (integer) +returns integer as ' +declare + delete__folder_id alias for $1; + v_count integer; + v_parent_id integer; + v_path varchar; +begin + return content_folder__delete( + delete__folder_id, + ''f'' + ); +end;' language 'plpgsql'; + + -- procedure rename create or replace function content_folder__rename (integer,varchar,varchar,varchar) returns integer as ' @@ -367,7 +404,33 @@ v_new_folder_id cr_folders.folder_id%TYPE; v_folder_contents_val record; begin + v_new_folder_id := content_folder__copy ( + copy__folder_id, + copy__target_folder_id, + copy__creation_user, + copy_creation_ip, + NULL + ); + return v_new_folder_id; +end;' language 'plpgsql'; +create function content_folder__copy (integer,integer,integer,varchar,varchar) +returns integer as ' +declare + copy__folder_id alias for $1; + copy__target_folder_id alias for $2; + copy__creation_user alias for $3; + copy__creation_ip alias for $4; -- default null + copy__name alias for $5; -- default null + v_valid_folders_p integer + v_current_folder_id cr_folders.folder_id%TYPE; + v_name cr_items.name%TYPE; + v_label cr_folders.label%TYPE; + v_description cr_folders.description%TYPE; + v_new_folder_id cr_folders.folder_id%TYPE; + v_folder_contents_val record; +begin + select count(*) into @@ -391,29 +454,28 @@ if copy__folder_id = content_item__get_root_folder(null) or copy__folder_id = content_template__get_root_folder() or copy__target_folder_id = copy__folder_id - or v_current_folder_id = copy__target_folder_id then - v_valid_folders_p := 0; end if; + -- get the source folder info + select + name, label, description + into + v_name, v_label, v_description + from + cr_items i, cr_folders f + where + f.folder_id = i.item_id + and + f.folder_id = copy__folder_id; + if v_valid_folders_p = 2 then - if content_folder__is_sub_folder(copy__folder_id, copy__target_folder_id) != ''t'' then - -- get the source folder info - select - name, label, description - into - v_name, v_label, v_description - from - cr_items i, cr_folders f - where - f.folder_id = i.item_id - and - f.folder_id = copy__folder_id; + if content_folder__is_sub_folder(copy__folder_id, copy__target_folder_id) != ''t'' or v_current_folder_id != copy__target_folder_id or (v_name != copy__name and copy__name is not null) then -- create the new folder v_new_folder_id := content_folder__new( - v_name, + coalesce (copy__name, v_name), v_label, v_description, copy__target_folder_id, 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 -r1.12 -r1.13 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-symlink.sql 11 Dec 2003 21:39:47 -0000 1.12 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-symlink.sql 23 Jan 2004 05:45:45 -0000 1.13 @@ -3,7 +3,6 @@ -- Copyright (C) 1999-2000 ArsDigita Corporation -- Author: Karl Goldstein (karlg@arsdigita.com) - -- $Id$ -- This is free software distributed under the terms of the GNU Public @@ -144,14 +143,19 @@ -- procedure copy -create or replace function content_symlink__copy (integer,integer,integer,varchar) -returns integer as ' +create or replace function content_symlink__copy ( + integer, + integer, + integer, + varchar, + 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; -- default null - v_current_folder_id cr_folders.folder_id%TYPE; + copy__name alias for $5; -- default null +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; @@ -169,28 +173,29 @@ where item_id = copy__symlink_id; - -- can''t copy to the same folder - if copy__target_folder_id != v_current_folder_id then + -- can''t copy to the same folder unless name is different - 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; + 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; - + -- copy to a different folder, or same folder if name + -- is different + if copy__target_folder_id != v_current_folder_id or ( v_name <> copy_name and copy_name is not null ) then if content_folder__is_registered(copy__target_folder_id, ''content_symlink'',''f'') = ''t'' then if content_folder__is_registered(copy__target_folder_id, content_item__get_content_type(content_symlink__resolve(copy__symlink_id)),''f'') = ''t'' then - v_symlink_id := content_symlink__new( - v_name, + v_symlink_id := content_symlink__new( + coalesce (copy__name,v_name), v_label, v_target_id, copy__target_folder_id, @@ -206,9 +211,35 @@ end if; end if; - return 0; + return v_symlink_id; end;' language 'plpgsql'; +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; -- default null + 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 + v_symlink_id := content_symlink__copy ( + copy__symlink_id, + copy__target_folder_id, + copy__creation_user, + copy__creation_ip, + NULL + ); + return v_symlink_id; +end;' language 'plpgsql'; -- function resolve create or replace function content_symlink__resolve (integer)