Index: openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.2.0b5-5.2.0b6.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.2.0b5-5.2.0b6.sql,v
diff -u -r1.1.2.2 -r1.1.2.3
--- openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.2.0b5-5.2.0b6.sql	28 Oct 2005 18:03:47 -0000	1.1.2.2
+++ openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.2.0b5-5.2.0b6.sql	26 Nov 2005 21:24:05 -0000	1.1.2.3
@@ -216,3 +216,101 @@
   return v_item_id;
 
 end;' language 'plpgsql';
+
+
+create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar, boolean,integer)
+returns integer as '
+declare
+  new__name                   alias for $1;  
+  new__label                  alias for $2;  
+  new__description            alias for $3;  -- default null
+  new__parent_id              alias for $4;  -- default null
+  new__context_id             alias for $5;  -- default null
+  new__folder_id              alias for $6;  -- default null
+  new__creation_date          alias for $7;  -- default now()
+  new__creation_user          alias for $8;  -- default null
+  new__creation_ip            alias for $9;  -- default null
+  new__security_inherit_p     alias for $10;  -- default true
+  new__package_id             alias for $11; -- default null
+  v_package_id                acs_objects.object_id%TYPE;
+  v_folder_id                 cr_folders.folder_id%TYPE;
+  v_context_id                acs_objects.context_id%TYPE;
+begin
+
+  -- set the context_id
+  if new__context_id is null then
+    v_context_id := new__parent_id;
+  else
+    v_context_id := new__context_id;
+  end if;
+
+  -- parent_id = 0 means that this is a mount point
+  if new__parent_id != 0 and 
+    content_folder__is_folder(new__parent_id) and
+    content_folder__is_registered(new__parent_id,''content_folder'',''f'') = ''f'' then
+
+    raise EXCEPTION ''-20000: This folder does not allow subfolders to be created'';
+    return null;
+
+  else
+
+    v_package_id := new__package_id;
+
+    if new__parent_id is not null and new__parent_id not in (-100,-200) and new__package_id is null then
+        v_package_id := acs_object__package_id(content_item__get_root_folder(new__parent_id));
+    end if;
+
+    v_folder_id := content_item__new(
+	new__folder_id,
+	new__name, 
+        new__parent_id,
+        null,
+        new__creation_date, 
+        new__creation_user, 
+	new__context_id,
+	new__creation_ip, 
+	''f'',
+	''text/plain'',
+	null,
+	''text'',
+	new__security_inherit_p,
+	''CR_FILES'',
+	''content_folder'',
+        ''content_folder'',
+        v_package_id
+    );
+
+    insert into cr_folders (
+      folder_id, label, description, package_id
+    ) values (
+      v_folder_id, new__label, new__description, v_package_id
+    );
+
+    -- set the correct object title
+    update acs_objects
+    set title = new__label
+    where object_id = v_folder_id;
+
+    -- inherit the attributes of the parent folder
+    if new__parent_id is not null then
+    
+      insert into cr_folder_type_map
+        select
+          v_folder_id as folder_id, content_type
+        from
+          cr_folder_type_map
+
+where
+          folder_id = new__parent_id;
+    end if;
+
+    -- update the child flag on the parent
+    update cr_folders set has_child_folders = ''t''
+      where folder_id = new__parent_id;
+
+    return v_folder_id;
+
+  end if;
+
+  return v_folder_id; 
+end;' language 'plpgsql';
