Index: openacs-4/packages/acs-content-repository/sql/oracle/content-folder.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/oracle/content-folder.sql,v
diff -u -r1.19 -r1.20
--- openacs-4/packages/acs-content-repository/sql/oracle/content-folder.sql	4 Jun 2006 00:45:22 -0000	1.19
+++ openacs-4/packages/acs-content-repository/sql/oracle/content-folder.sql	23 Oct 2008 13:04:03 -0000	1.20
@@ -304,6 +304,12 @@
 
 begin
 
+  if folder_id = content_item.get_root_folder or
+    folder_id = content_template.get_root_folder then
+    raise_application_error( -20000, 
+      'content_folder.copy - Cannot copy root folder');
+  end if;
+
   select 
     count(*)
   into 
@@ -315,37 +321,44 @@
   or 
     folder_id = copy.folder_id;
 
+  if v_valid_folders_p ^= 2 then
+    raise_application_error(-20000,
+      'content_folder.copy - Not valid folder(s)');
+  end if;
+
+
+  if target_folder_id = folder_id then
+    raise_application_error(-20000,
+      'content_folder.copy - Cannot copy a folder to itself');
+  end if;
+
+  if is_sub_folder(folder_id, target_folder_id) = 't' then
+    raise_application_error(-20000,
+      'content_folder.copy - Destination folder is subfolder');
+  end if;
+
+
+  if is_registered(target_folder_id,'content_folder') ^= 't' then
+    raise_application_error(-20000,
+      'content_folder.copy - Destination folder does not allow subfolders');
+  end if;
+
+  -- get the source folder info
   select
-    parent_id
+    name, label, description, parent_id
   into
-    v_current_folder_id
-  from
-    cr_items
+    v_name, v_label, v_description, v_current_folder_id
+  from 
+    cr_items i, cr_folders f
   where
-    item_id = copy.folder_id;  
+    f.folder_id = i.item_id
+  and
+    f.folder_id = copy.folder_id;
 
-  if folder_id = content_item.get_root_folder or folder_id = content_template.get_root_folder or target_folder_id = folder_id then
-    v_valid_folders_p := 0;
+  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'';
   end if;
 
-  if v_valid_folders_p = 2 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 is_sub_folder(folder_id, 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
-      if copy.name is not null then
-	v_name := copy.name;
-      end if;
       -- create the new folder
       v_new_folder_id := content_folder.new(
 	  parent_id     => copy.target_folder_id,
@@ -383,14 +396,9 @@
 
       end loop;
 
-    end if;
-  end if;
 end copy;
 
 
-
-
-
 -- returns 1 if the item_id passed in is a folder
 function is_folder (
   item_id	  in cr_items.item_id%TYPE
