Index: openacs-4/packages/new-portal/sql/postgresql/api-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/new-portal/sql/postgresql/api-create.sql,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/new-portal/sql/postgresql/api-create.sql	11 Jul 2002 20:16:43 -0000	1.7
+++ openacs-4/packages/new-portal/sql/postgresql/api-create.sql	12 Jul 2002 21:26:48 -0000	1.8
@@ -32,22 +32,24 @@
     p_pretty_name                   alias for $2;
     p_portal_id                     alias for $3;
     p_layout_id                     alias for $4;
-    p_object_type                   alias for $6;
-    p_creation_date                 alias for $7;
-    p_create_user                   alias for $8;
-    p_creation_ip                   alias for $9;
-    p_context_id                    alias for $10;
+    p_object_type                   alias for $5;
+    p_creation_date                 alias for $6;
+    p_creation_user                 alias for $7;
+    p_creation_ip                   alias for $8;
+    p_context_id                    alias for $9;
     v_page_id                       portal_pages.page_id%TYPE;
     v_layout_id                     portal_pages.layout_id%TYPE;
     v_sort_key                      portal_pages.sort_key%TYPE;
 begin
 
     v_page_id := acs_object__new(
+        null,
         p_object_type,
         p_creation_date,
         p_creation_user,
         p_creation_ip,
-        p_context_id
+        p_context_id,
+        ''t''
     );
 
     if p_layout_id is null then
@@ -145,6 +147,10 @@
     v_layout_id                     portal_layouts.layout_id%TYPE;
     v_page_id                       portal_pages.page_id%TYPE;
     v_page                          record;
+    v_element                       record;
+    v_param                         record;
+    v_new_element_id                integer;
+    v_new_parameter_id              integer;
 begin
 
     v_portal_id := acs_object__new(
@@ -153,7 +159,8 @@
         p_creation_date,
         p_creation_user,
         p_creation_ip,
-        p_context_id
+        p_context_id,
+        ''t''
     );
 
     if p_template_id is null then
@@ -182,9 +189,11 @@
 
         -- now insert the default page
         v_page_id := portal_page__new(
-            v_portal_id,
+            null,
             p_default_page_name,
+            v_portal_id,
             v_layout_id,
+            ''portal_page'',
             p_creation_date,
             p_creation_user,
             p_creation_ip,
@@ -213,18 +222,24 @@
         loop
 
             v_page_id := portal_page__new(
-                v_portal_id,
-                v_page.pretty_name,
-                v_page.layout_id
+            null,
+            v_page.pretty_name,
+            v_portal_id,
+            v_page.layout_id,
+            ''portal_page'',
+            p_creation_date,
+            p_creation_user,
+            p_creation_ip,
+            p_context_id
             );
 
             -- now get the elements on the templates page and put them on the new page
-            for element in select * 
+            for v_element in select * 
                            from portal_element_map 
-                           where page_id = page.page_id
+                           where page_id = v_page.page_id
             loop
 
-                select nextval(''acs_object_id_seq'')
+                select acs_object_id_seq.nextval
                 into v_new_element_id
                 from dual;
 
@@ -233,15 +248,15 @@
                 (element_id, name, pretty_name, page_id, datasource_id, region, state, sort_key)
                 select v_new_element_id, name, pretty_name, v_page_id, datasource_id, region, state, sort_key
                 from portal_element_map pem
-                where pem.element_id = element.element_id;
+                where pem.element_id = v_element.element_id;
 
                 -- now for the elements params
-                for param in select * 
+                for v_param in select * 
                              from portal_element_parameters 
-                             where element_id = element.element_id
+                             where element_id = v_element.element_id
                 loop
 
-                    select nextval(''acs_object_id_seq'')
+                    select acs_object_id_seq.nextval
                     into v_new_parameter_id
                     from dual;
 
@@ -250,7 +265,7 @@
                     (parameter_id, element_id, config_required_p, configured_p, key, value)
                     select v_new_parameter_id, v_new_element_id, config_required_p, configured_p, key, value
                     from portal_element_parameters
-                    where parameter_id = param.parameter_id;
+                    where parameter_id = v_param.parameter_id;
 
                 end loop;
 
@@ -310,7 +325,8 @@
         p_creation_date,
         p_creation_user,
         p_creation_ip,
-        p_context_id
+        p_context_id,
+        ''t''
     );
 
     insert
@@ -384,7 +400,8 @@
         p_creation_date,
         p_creation_user,
         p_creation_ip,
-        p_context_id
+        p_context_id,
+        ''t''
     );
 
     insert into portal_layouts
@@ -488,7 +505,8 @@
         p_creation_date,
         p_creation_user,
         p_creation_ip,
-        p_context_id
+        p_context_id,
+        ''t''
     );
 
     insert into portal_datasources
@@ -547,7 +565,7 @@
     insert into portal_datasource_def_params
     (parameter_id, datasource_id, config_required_p, configured_p, key, value)
     values
-    (nextval(''acs_object_id_seq''), p_datasource_id, p_config_required_p, p_configured_p, p_key, p_value);
+    (acs_object_id_seq.nextval, p_datasource_id, p_config_required_p, p_configured_p, p_key, p_value);
 
     return 0;
 
