Index: openacs-4/packages/static-pages/sql/postgresql/static-pages-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/static-pages/sql/postgresql/static-pages-create.sql,v
diff -u -r1.11 -r1.12
--- openacs-4/packages/static-pages/sql/postgresql/static-pages-create.sql	26 Oct 2001 03:31:29 -0000	1.11
+++ openacs-4/packages/static-pages/sql/postgresql/static-pages-create.sql	26 Oct 2001 19:26:14 -0000	1.12
@@ -76,10 +76,10 @@
         select coalesce(max(tree_sortkey),'''') into v_parent_sk 
           from sp_folders 
          where folder_id = new.parent_id;
-
-        new.tree_sortkey := v_parent_sk || ''/'' || tree_next_key(max_key);
 	end if;
+        new.tree_sortkey := v_parent_sk || ''/'' || tree_next_key(max_key);
 
+
         return new;
 
 end;' language 'plpgsql';
@@ -603,7 +603,7 @@
         begin
                 for v_folder_row in 
                         select folder_id from (
-                                select folder_id, tree_level(''folder_id'')  as path_depth from sp_folders
+                                select folder_id, tree_level(tree_sortkey)  as path_depth, tree_sortkey from sp_folders
 		where tree_sortkey like ( select tree_sortkey || ''%''
 		from sp_folders
 		where folder_id = p_folder_id)
@@ -653,7 +653,6 @@
 			   sp_extant_files
 				where session_id = p_session_id )
 	loop
-
 		PERFORM static_page__delete(v_stale_file_row.static_page_id);
 	end loop;
 
@@ -674,7 +673,7 @@
                                         where session_id = p_session_id
                                 )
                         ) dead,
-                        (select folder_id,tree_level(''folder_id'') as depth from sp_folders
+                        (select folder_id,tree_level(tree_sortkey) as depth, tree_sortkey from sp_folders
 		where tree_sortkey like ( select tree_sortkey || ''%''
 		from sp_folders
 		where folder_id = v_root_folder_id)
@@ -683,9 +682,8 @@
                                 and dead.folder_id <> v_root_folder_id
                         order by path.depth desc
                  loop
-                        delete from sp_folders
+		delete from sp_folders
                         where folder_id = v_stale_folder_row.folder_id;
-
                         perform content_folder__delete(v_stale_folder_row.folder_id);
                 end loop;
 
