Index: openacs-4/packages/acs-content-repository/sql/oracle/content-item.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/oracle/content-item.sql,v
diff -u -r1.10 -r1.11
--- openacs-4/packages/acs-content-repository/sql/oracle/content-item.sql	25 May 2002 14:30:02 -0000	1.10
+++ openacs-4/packages/acs-content-repository/sql/oracle/content-item.sql	17 May 2003 09:42:02 -0000	1.11
@@ -132,11 +132,19 @@
 
     begin
 
+     -- Figure out the relation_tag to use
+     if content_item.new.relation_tag is null then
+       v_rel_tag := content_item.get_content_type(v_parent_id) 
+         || '-' || content_item.new.content_type;
+     else
+       v_rel_tag := content_item.new.relation_tag;
+     end if;
+
      select object_type into v_parent_type from acs_objects
        where object_id = v_parent_id;
 
      if is_subclass(v_parent_type, 'content_item') = 't' and
-	is_valid_child(v_parent_id, content_item.new.content_type) = 'f' then
+	is_valid_child(v_parent_id, content_item.new.content_type, v_rel_tag) = 'f' then
 
        raise_application_error(-20000, 
 	 'This item''s content type ' || content_item.new.content_type ||
@@ -179,23 +187,15 @@
   );
 
   -- if the parent is not a folder, insert into cr_child_rels
+  -- We checked above before creating the object that it is a valid rel
   if v_parent_id ^= 0 and
-    content_folder.is_folder(v_parent_id) = 'f' and 
-    content_item.is_valid_child(v_parent_id, 
-      content_item.new.content_type) = 't' then
+    content_folder.is_folder(v_parent_id) = 'f' then
 
     v_rel_id := acs_object.new(
       object_type	=> 'cr_item_child_rel',
       context_id	=> v_parent_id
     );
 
-    if content_item.new.relation_tag is null then
-      v_rel_tag := content_item.get_content_type(v_parent_id) 
-        || '-' || content_item.new.content_type;
-    else
-      v_rel_tag := content_item.new.relation_tag;
-    end if;
-
     insert into cr_child_rels (
       rel_id, parent_id, child_id, relation_tag, order_n
     ) values (
@@ -396,10 +396,10 @@
         return 'f';
 end is_publishable;
 
-
 function is_valid_child (
   item_id		in cr_items.item_id%TYPE,
-  content_type		in acs_object_types.object_type%TYPE
+  content_type		in acs_object_types.object_type%TYPE,
+  relation_tag          in cr_child_rels.relation_tag%TYPE default null
 ) return char
 is
   v_is_valid_child      char(1);
@@ -412,13 +412,16 @@
   -- first check if content_type is a registered child_type
   begin
     select
-      max_n into v_max_children
+      sum(max_n) into v_max_children
     from
       cr_type_children
     where
       parent_type = content_item.get_content_type( is_valid_child.item_id )
     and
-      child_type = is_valid_child.content_type;
+      child_type = is_valid_child.content_type
+    and 
+      (is_valid_child.relation_tag is null 
+       or is_valid_child.relation_tag = relation_tag);
 
     exception
       when NO_DATA_FOUND then
@@ -438,7 +441,10 @@
   where
     parent_id = is_valid_child.item_id
   and
-    content_item.get_content_type( child_id ) = is_valid_child.content_type;
+    content_item.get_content_type( child_id ) = is_valid_child.content_type
+  and 
+    (is_valid_child.relation_tag is null 
+     or is_valid_child.relation_tag = relation_tag);
 
   if v_n_children < v_max_children then
     v_is_valid_child := 't';
@@ -1287,6 +1293,14 @@
         creation_user    => copy2.creation_user,
         creation_ip      => copy2.creation_ip
     );
+  -- call content_extlink.copy if the item is a extlink
+  elsif content_extlink.is_extlink(copy2.item_id) = 't' then
+    content_extlink.copy(
+        extlink_id       => copy2.item_id,
+        target_folder_id => copy2.target_folder_id,
+        creation_user    => copy2.creation_user,
+        creation_ip      => copy2.creation_ip
+    );
   -- make sure the target folder is really a folder
   elsif content_folder.is_folder(copy2.target_folder_id) = 't' then
 
