Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql,v
diff -u -r1.64 -r1.65
--- openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql	20 Mar 2005 15:58:45 -0000	1.64
+++ openacs-4/packages/acs-content-repository/sql/postgresql/content-item.sql	26 Mar 2005 12:30:49 -0000	1.65
@@ -92,8 +92,8 @@
   v_parent_id      cr_items.parent_id%TYPE;
   v_parent_type    acs_objects.object_type%TYPE;
   v_item_id        cr_items.item_id%TYPE;
-  v_revision_id    cr_revisions.revision_id%TYPE;
   v_title          cr_revisions.title%TYPE;
+  v_revision_id    cr_revisions.revision_id%TYPE;
   v_rel_id         acs_objects.object_id%TYPE;
   v_rel_tag        cr_child_rels.relation_tag%TYPE;
   v_context_id     acs_objects.context_id%TYPE;
@@ -117,6 +117,13 @@
     v_context_id := new__context_id;
   end if;
 
+  -- use the name of the item if no title is supplied
+  if new__title is null or new__title = '''' then
+    v_title := new__name;
+  else
+    v_title := new__title;
+  end if;
+
   if new__package_id is null then
     v_package_id := acs_object__package_id(content_item__get_root_folder(v_parent_id));
   else
@@ -167,7 +174,7 @@
       new__creation_ip, 
       v_context_id,
       ''t'',
-      new__name,
+      v_title,
       v_package_id
   );
 
@@ -202,19 +209,10 @@
 
   end if;
 
-
-  -- use the name of the item if no title is supplied
-  if new__title is null then
-    v_title := new__name;
-  else
-    v_title := new__title;
-  end if;
-
-
   if new__data is not null then
 
     v_revision_id := content_revision__new(
-	v_title,
+        v_title,
 	new__description,
         now(),
 	new__mime_type,
@@ -231,7 +229,7 @@
   elsif new__text is not null or new__title is not null then
 
     v_revision_id := content_revision__new(
-	v_title,
+        v_title,
 	new__description,
         now(),
 	new__mime_type,
@@ -403,7 +401,7 @@
       new__creation_ip, 
       v_context_id,
       ''t'',
-      new__name,
+      coalesce(new__title,new__name),
       v_package_id
   );
 
@@ -567,6 +565,13 @@
     v_package_id := new__package_id;
   end if;
 
+  -- use the name of the item if no title is supplied
+  if new__title is null or new__title = '''' then
+    v_title := new__name;
+  else
+    v_title := new__title;
+  end if;
+
   if v_parent_id = 0 or 
     content_folder__is_folder(v_parent_id) = ''t'' then
 
@@ -604,7 +609,7 @@
       new__creation_ip, 
       v_context_id,
       ''t'',
-      new__name,
+      v_title,
       v_package_id
   );
 
@@ -646,19 +651,12 @@
 
   end if;
 
-  -- use the name of the item if no title is supplied
-  if new__title is null or new__title = '''' then
-    v_title := new__name;
-  else
-    v_title := new__title;
-  end if;
-
   -- create the revision if data or title is not null
 
   if new__data is not null then
 
     v_revision_id := content_revision__new(
-	v_title,
+        v_title,
 	new__description,
         now(),
 	new__mime_type,
@@ -758,7 +756,7 @@
                                  ''text'',
                                  new__package_id
                );
-                                 
+
 end;' language 'plpgsql';
 
 create or replace function content_item__new(varchar,integer,varchar,text,text) 
@@ -845,6 +843,13 @@
     v_context_id := new__context_id;
   end if;
 
+  -- use the name of the item if no title is supplied
+  if new__title is null or new__title = '''' then
+    v_title := new__name;
+  else
+    v_title := new__title;
+  end if;
+
   if new__package_id is null then
     v_package_id := acs_object__package_id(content_item__get_root_folder(v_parent_id));
   else
@@ -889,7 +894,7 @@
       new__creation_ip, 
       v_context_id,
       new__security_inherit_p,
-      new__name,
+      v_title,
       v_package_id
   );
 
@@ -932,13 +937,6 @@
 
   end if;
 
-  -- use the name of the item if no title is supplied
-  if new__title is null then
-    v_title := new__name;
-  else
-    v_title := new__title;
-  end if;
-
   if new__title is not null or 
      new__text is not null then
 
