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.48 -r1.49 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql 1 Oct 2007 00:10:34 -0000 1.48 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql 23 Oct 2008 13:04:03 -0000 1.49 @@ -546,6 +546,11 @@ v_folder_contents_val record; begin + if copy__folder_id = content_item__get_root_folder(null) + or copy__folder_id = content_template__get_root_folder() then + raise EXCEPTION ''-20000: content_folder.copy - Not allowed to copy root folder''; + end if; + select count(*) into @@ -557,37 +562,40 @@ or folder_id = copy__folder_id; - select - parent_id - into - v_current_folder_id - from - cr_items - where - item_id = copy__folder_id; + if v_valid_folders_p != 2 then + raise EXCEPTION ''-20000: content_folder.copy - Invalid folder(s)''; + end if; - 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 then - v_valid_folders_p := 0; + if copy__target_folder_id = copy__folder_id then + raise EXCEPTION ''-20000: content_folder.copy - Cannot copy folder to itself''; end if; + + if content_folder__is_sub_folder(copy__folder_id, copy__target_folder_id) = ''t'' then + raise EXCEPTION ''-20000: content_folder.copy - Destination folder is subfolder''; + 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 content_folder__is_registered(copy__target_folder_id,''content_folder'',''f'') != ''t'' then + raise EXCEPTION ''-20000: content_folder.copy - Destination folder does not allow subfolders''; + end if; - if v_valid_folders_p = 2 then + -- get the source folder info + select + name, label, description, parent_id + into + v_name, v_label, v_description, v_current_folder_id + 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 + -- would be better to check if the copy__name alredy exists in the destination folder. + if v_current_folder_id = copy__target_folder_id and v_name = copy__name then + raise EXCEPTION ''-20000: content_folder.copy - Destination folder is parent folder and folder alredy exists''; + end if; + -- create the new folder v_new_folder_id := content_folder__new( coalesce (copy__name, v_name), @@ -635,8 +643,6 @@ ); end loop; - end if; - end if; return 0; end;' language 'plpgsql';