Index: openacs-4/packages/file-storage/sql/postgresql/file-storage-package-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/sql/postgresql/file-storage-package-create.sql,v
diff -u -N -r1.25 -r1.26
--- openacs-4/packages/file-storage/sql/postgresql/file-storage-package-create.sql	9 Jul 2007 07:43:06 -0000	1.25
+++ openacs-4/packages/file-storage/sql/postgresql/file-storage-package-create.sql	30 Mar 2013 22:50:45 -0000	1.26
@@ -6,34 +6,51 @@
 -- @cvs-id $Id$
 --
 
-create or replace function file_storage__get_root_folder (
-       --
-       -- Returns the root folder corresponding to a particular
-       -- package instance.
-       --
-       integer        -- apm_packages.package_id%TYPE
-)
-returns integer as '  -- fs_root_folders.folder_id%TYPE 
-declare
-        get_root_folder__package_id  alias for $1;
+
+
+-- added
+select define_function_args('file_storage__get_root_folder','package_id');
+
+--
+-- procedure file_storage__get_root_folder/1
+--
+    --
+    -- Returns the root folder corresponding to a particular
+    -- package instance.
+    --
+CREATE OR REPLACE FUNCTION file_storage__get_root_folder(
+   get_root_folder__package_id integer
+
+) RETURNS integer AS $$
+-- fs_root_folders.folder_id%TYPE
+DECLARE
         v_folder_id                  fs_root_folders.folder_id%TYPE;
-begin
+BEGIN
         select folder_id into v_folder_id 
         from fs_root_folders
         where package_id = get_root_folder__package_id;
 
         return v_folder_id;
 
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
-create or replace function file_storage__get_package_id (
-    integer                     -- cr_items.item_id%TYPE
-) returns integer as '          -- fs_root_folders.package_id%TYPE
-declare
-    get_package_id__item_id     alias for $1;
+
+
+-- added
+select define_function_args('file_storage__get_package_id','item_id');
+
+--
+-- procedure file_storage__get_package_id/1
+--
+CREATE OR REPLACE FUNCTION file_storage__get_package_id(
+   get_package_id__item_id integer
+) RETURNS integer AS $$
+-- fs_root_folders.package_id%TYPE
+DECLARE
     v_package_id                fs_root_folders.package_id%TYPE;
     v_tree_sortkey              cr_items.tree_sortkey%TYPE;
-begin
+BEGIN
 
     select fs_root_folders.package_id
     into v_package_id
@@ -50,31 +67,35 @@
         return v_package_id;
     end if;
 
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
-create or replace function file_storage__new_root_folder (
-       --
-       -- Creates a new root folder
-       --
-       -- 
-       -- A hackish function to get around the fact that we can not run
-       -- code automatically when a new package instance is created.
-       --
-       integer,         -- apm_packages.package_id%TYPE
-       varchar,         -- cr_folders.label%TYPE
-       varchar,          -- cr_items.name%TYPE
-       varchar
-)
-returns integer as '    --  fs_root_folders.folder_id%TYPE
-declare
-        new_root_folder__package_id         alias for $1;
-        new_root_folder__folder_name        alias for $2;
-	new_root_folder__url	            alias for $3;
-        new_root_folder__description        alias for $4;
-        v_folder_id                         fs_root_folders.folder_id%TYPE;
-begin
 
 
+-- added
+select define_function_args('file_storage__new_root_folder','package_id,folder_name,url,description');
+
+--
+-- procedure file_storage__new_root_folder/4
+--
+    --
+    -- Creates a new root folder
+    --
+    -- 
+    -- A hackish function to get around the fact that we can not run
+    -- code automatically when a new package instance is created.
+    --
+
+CREATE OR REPLACE FUNCTION file_storage__new_root_folder(
+   new_root_folder__package_id integer,
+   new_root_folder__folder_name varchar,
+   new_root_folder__url varchar,
+   new_root_folder__description varchar
+
+) RETURNS integer AS $$
+DECLARE
+        v_folder_id                         fs_root_folders.folder_id%TYPE;
+BEGIN
         v_folder_id := content_folder__new (
             new_root_folder__url, -- name
             new_root_folder__folder_name, -- label
@@ -98,56 +119,59 @@
         -- JS: true since we created a new subtype.
         PERFORM content_folder__register_content_type(
                 v_folder_id,            -- folder_id
-                ''content_revision'',   -- content_types
-                ''t''                   -- include_subtypes 
+                'content_revision',   -- content_types
+                't'                   -- include_subtypes 
                 );
         PERFORM content_folder__register_content_type(
                 v_folder_id,            -- folder_id
-                ''content_folder'',     -- content_types
-                ''t''                   -- include_subtypes 
+                'content_folder',     -- content_types
+                't'                   -- include_subtypes 
                 );
         PERFORM content_folder__register_content_type(
                 v_folder_id,            -- folder_id
-                ''content_symlink'',    -- content_types
-                ''t''                   -- include_subtypes 
+                'content_symlink',    -- content_types
+                't'                   -- include_subtypes 
                 );
         PERFORM content_folder__register_content_type(
                 v_folder_id,            -- folder_id
-                ''content_extlink'',    -- content_types
-                ''t''                   -- include_subtypes 
+                'content_extlink',    -- content_types
+                't'                   -- include_subtypes 
                 );
 
         return v_folder_id;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
     
 
-create or replace function file_storage__new_file(
-       -- 
-       -- Create a file in CR in preparation for actual storage
-       -- Wrapper for content_item__new
-       --
-       -- DRB: I added this version to allow one to predefine item_id, among other things to
-       -- make it easier to use with ad_form
-       varchar,         -- cr_items.name%TYPE,
-       integer,         -- cr_items.parent_id%TYPE,
-       integer,         -- acs_objects.creation_user%TYPE,
-       varchar,         -- acs_objects.creation_ip%TYPE,
-       boolean,         -- store in db? 
-       integer,           -- cr_items.item_id%TYPE,
-       integer        -- apm_packages.package_id%TYPE
-) returns integer as ' -- cr_items.item_id%TYPE
-declare
-        new_file__name                 alias for $1;
-        new_file__folder_id             alias for $2;
-        new_file__user_id               alias for $3;
-        new_file__creation_ip           alias for $4;
-        new_file__indb_p                alias for $5;
-        new_file__item_id               alias for $6;
-        new_file__package_id            alias for $7;
-        v_item_id                       integer;
-begin
 
+
+-- added
+select define_function_args('file_storage__new_file','name,folder_id,user_id,creation_ip,indb_p,item_id,package_id');
+
+--
+-- procedure file_storage__new_file/7
+--
+    -- 
+    -- Create a file in CR in preparation for actual storage
+    -- Wrapper for content_item__new
+    --
+    -- DRB: I added this version to allow one to predefine item_id, among other things to
+    -- make it easier to use with ad_form
+
+CREATE OR REPLACE FUNCTION file_storage__new_file(
+   new_file__name varchar,
+   new_file__folder_id integer,
+   new_file__user_id integer,
+   new_file__creation_ip varchar,
+   new_file__indb_p boolean,
+   new_file__item_id integer,
+   new_file__package_id integer
+
+) RETURNS integer AS $$
+DECLARE
+        v_item_id                       integer;
+BEGIN
         if new_file__indb_p
         then 
             v_item_id := content_item__new (
@@ -159,11 +183,11 @@
                         new_file__user_id,        -- creation_user
                         new_file__folder_id,      -- context_id
                         new_file__creation_ip,    -- creation_ip
-                        ''content_item'',         -- item_subtype (default)
-                        ''file_storage_object'',  -- content_type (needed by site-wide search)
+                        'content_item',         -- item_subtype (default)
+                        'file_storage_object',  -- content_type (needed by site-wide search)
                         null,                       -- title (default)
                         null,                       -- description
-                        ''text/plain'',     -- mime_type (default)
+                        'text/plain',     -- mime_type (default)
                         null,                       -- nls_language (default)
                         null,                       -- data (default)
                         new_file__package_id        -- package_id
@@ -178,14 +202,14 @@
                         new_file__user_id,          -- creation_user
                         new_file__folder_id,        -- context_id
                         new_file__creation_ip,    -- creation_ip
-                        ''content_item'',         -- item_subtype (default)
-                        ''file_storage_object'',  -- content_type (needed by site-wide search)
+                        'content_item',         -- item_subtype (default)
+                        'file_storage_object',  -- content_type (needed by site-wide search)
                         null,                       -- title (default)
                         null,                       -- description
-                        ''text/plain'',     -- mime_type (default)
+                        'text/plain',     -- mime_type (default)
                         null,                       -- nls_language (default)
                         null,                       -- text (default)
-                        ''file'',                   -- storage_type
+                        'file',                   -- storage_type
                         new_file__package_id        -- package_id
                     );
 
@@ -195,25 +219,25 @@
 
         return v_item_id;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
     
 
-create or replace function file_storage__new_file(
-       varchar,         -- cr_items.name%TYPE,
-       integer,         -- cr_items.parent_id%TYPE,
-       integer,         -- acs_objects.creation_user%TYPE,
-       varchar,         -- acs_objects.creation_ip%TYPE,
-       boolean,          -- store in db? 
-       integer        -- apm_packages.package_id%TYPE       
-) returns integer as ' -- cr_items.item_id%TYPE
-declare
-        new_file__name                  alias for $1;
-        new_file__folder_id             alias for $2;
-        new_file__user_id               alias for $3;
-        new_file__creation_ip           alias for $4;
-        new_file__indb_p                alias for $5;
-        new_file__package_id            alias for $6;
-begin
+
+
+--
+-- procedure file_storage__new_file/6
+--
+CREATE OR REPLACE FUNCTION file_storage__new_file(
+   new_file__name varchar,
+   new_file__folder_id integer,
+   new_file__user_id integer,
+   new_file__creation_ip varchar,
+   new_file__indb_p boolean,
+   new_file__package_id integer
+) RETURNS integer AS $$
+DECLARE
+BEGIN
         return file_storage__new_file(
              new_file__name,            -- name
              new_file__folder_id,       -- parent_id
@@ -224,61 +248,83 @@
              new_file__package_id       -- pacakge_id
         );
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
-create or replace function file_storage__delete_file (
-       --
-       -- Delete a file and all its version
-       -- Wrapper to content_item__delete
-       --
-       integer          -- cr_items.item_id%TYPE
-) returns integer as '
-declare
-        delete_file__file_id    alias for $1;
-begin
 
+
+-- added
+select define_function_args('file_storage__delete_file','file_id');
+
+--
+-- procedure file_storage__delete_file/1
+--
+    --
+    -- Delete a file and all its version
+    -- Wrapper to content_item__delete
+    --
+CREATE OR REPLACE FUNCTION file_storage__delete_file(
+   delete_file__file_id integer
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
+
         return content_item__delete(delete_file__file_id);
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
-create or replace function file_storage__rename_file (
-       --
-       -- Rename a file and all
-       -- Wrapper to content_item__edit_name
-       --
-       integer,         -- cr_items.item_id%TYPE,
-       varchar          -- cr_items.name%TYPE
-) returns integer as '
-declare
-        rename_file__file_id    alias for $1;
-        rename_file__name      alias for $2;
 
-begin
 
+-- added
+select define_function_args('file_storage__rename_file','file_id,name');
+
+--
+-- procedure file_storage__rename_file/2
+--
+    --
+    -- Rename a file and all
+    -- Wrapper to content_item__edit_name
+    --
+CREATE OR REPLACE FUNCTION file_storage__rename_file(
+   rename_file__file_id integer,
+   rename_file__name varchar
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
+
         return content_item__edit_name(
                rename_file__file_id,  -- item_id
                rename_file__name     -- name
                );
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function file_storage__copy_file(
-       --
-       -- Copy a file, but only copy the live_revision
-       --
-       integer,         -- cr_items.item_id%TYPE,
-       integer,         -- cr_items.parent_id%TYPE,
-       integer,         -- acs_objects.creation_user%TYPE,
-       varchar          -- acs_objects.creation_ip%TYPE
-) returns integer as '  -- cr_revisions.revision_id%TYPE
-declare
-        copy_file__file_id           alias for $1;
-        copy_file__target_folder_id  alias for $2;
-        copy_file__creation_user     alias for $3;
-        copy_file__creation_ip       alias for $4;
-        v_name                      cr_items.name%TYPE;
+
+
+-- added
+select define_function_args('file_storage__copy_file','file_id,target_folder_id,creation_user,creation_ip');
+
+--
+-- procedure file_storage__copy_file/4
+--
+    --
+    -- Copy a file, but only copy the live_revision
+    --
+CREATE OR REPLACE FUNCTION file_storage__copy_file(
+   copy_file__file_id integer,
+   copy_file__target_folder_id integer,
+   copy_file__creation_user integer,
+   copy_file__creation_ip varchar
+
+) RETURNS integer AS $$
+DECLARE
+        v_name                       cr_items.name%TYPE;
         v_live_revision              cr_items.live_revision%TYPE;
         v_filename                   cr_revisions.title%TYPE;
         v_description                cr_revisions.description%TYPE;
@@ -293,11 +339,11 @@
         v_isurl                      boolean;
         v_content_type               cr_items.content_type%TYPE;
         v_package_id                 apm_packages.package_id%TYPE;
-begin
+BEGIN
 
         v_isurl:= false;
         select content_type into v_content_type from cr_items where item_id = copy_file__file_id;
-        if v_content_type = ''content_extlink''
+        if v_content_type = 'content_extlink'
         then
           v_isurl:= true;
         end if;
@@ -306,7 +352,7 @@
         if v_isurl = false
         then
           select i.name,i.live_revision,r.title,r.description,r.mime_type,r.content_length,
-               (case when i.storage_type = ''lob''
+               (case when i.storage_type = 'lob'
                      then true
                      else false
                 end)
@@ -376,25 +422,33 @@
           return 0;
         end if;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function file_storage__move_file (
-       --
-       -- Move a file (ans all its versions) to a different folder.
-       -- Wrapper for content_item__move
-       -- 
-       integer,         -- cr_folders.folder_id%TYPE,
-       integer,         -- cr_folders.folder_id%TYPE
-       integer,         -- ceration_user
-       varchar          -- creation_ip
-) returns integer as '  -- 0 for success 
-declare
-        move_file__file_id              alias for $1;
-        move_file__target_folder_id     alias for $2;
-        move_file__creation_user        alias for $3;
-        move_file__creation_ip          alias for $4;
-begin
 
+
+-- added
+select define_function_args('file_storage__move_file','file_id,target_folder_id,creation_user,creation_ip');
+
+--
+-- procedure file_storage__move_file/4
+--
+    --
+    -- Move a file (ans all its versions) to a different folder.
+    -- Wrapper for content_item__move
+    -- 
+
+CREATE OR REPLACE FUNCTION file_storage__move_file(
+   move_file__file_id integer,
+   move_file__target_folder_id integer,
+   move_file__creation_user integer,
+   move_file__creation_ip varchar
+
+) RETURNS integer AS $$
+-- 0 for success
+DECLARE
+BEGIN
+
         perform content_item__move(
                move_file__file_id,              -- item_id
                move_file__target_folder_id      -- target_folder_id
@@ -403,29 +457,37 @@
         perform acs_object__update_last_modified(move_file__target_folder_id,move_file__creation_user,move_file__creation_ip);
 
         return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
-create or replace function file_storage__get_title (
-       --
-       integer          -- cr_items.item_id%TYPE
-) returns varchar as ' 
-declare
-  get_title__item_id                 alias for $1;  
+
+
+-- added
+select define_function_args('file_storage__get_title','item_id');
+
+--
+-- procedure file_storage__get_title/1
+--
+CREATE OR REPLACE FUNCTION file_storage__get_title(
+   get_title__item_id integer
+
+) RETURNS varchar AS $$
+DECLARE
   v_title                            cr_revisions.title%TYPE;
   v_content_type                     cr_items.content_type%TYPE;
-begin
+BEGIN
   
   select content_type into v_content_type 
   from cr_items 
   where item_id = get_title__item_id;
 
-  if v_content_type = ''content_folder'' 
+  if v_content_type = 'content_folder' 
   then
       select label into v_title 
       from cr_folders 
       where folder_id = get_title__item_id;
-  else if v_content_type = ''content_symlink'' 
+  else if v_content_type = 'content_symlink' 
        then
          select label into v_title from cr_symlinks 
          where symlink_id = get_title__item_id;
@@ -438,14 +500,14 @@
   end if;
 
   return v_title;
+END;
+$$ LANGUAGE plpgsql;
 
-end;' language 'plpgsql';
 
-create or replace function file_storage__get_parent_id (
-        integer --  item_id in cr_items.item_id%TYPE
-     ) returns integer as ' -- cr_items.item_id%TYPE
+CREATE OR REPLACE FUNCTION file_storage__get_parent_id (
+        get_parent_id__item_id integer 
+) RETURNS integer AS $$
      declare 
-         get_parent_id__item_id alias for $1;
          v_parent_id          cr_items.item_id%TYPE;
      begin
 
@@ -455,63 +517,81 @@
          where item_id = get_parent_id__item_id;
 
        return v_parent_id;
+END;
+$$ LANGUAGE plpgsql;
 
-end;'language 'plpgsql';
 
+-- added
+select define_function_args('file_storage__get_content_type','file_id');
 
-create or replace function file_storage__get_content_type (
-       --
-       -- Wrapper for content_item__get_content_type
-       integer          -- cr_items.item_id%TYPE
-) returns varchar as '  -- cr_items.content_type%TYPE
-declare
-        get_content_type__file_id       alias for $1;
-begin
+--
+-- procedure file_storage__get_content_type/1
+--
+    --
+    -- Wrapper for content_item__get_content_type
+    --
+
+CREATE OR REPLACE FUNCTION file_storage__get_content_type(
+   get_content_type__file_id integer
+) RETURNS varchar AS $$
+DECLARE
+BEGIN
         return content_item__get_content_type(
                           get_content_type__file_id
                           );
 
-end;' language 'plpgsql';  
+END;
+$$ LANGUAGE plpgsql;  
 
 
 
-create or replace function file_storage__get_folder_name (
-       --
-       -- Wrapper for content_folder__get_label
-       integer          -- cr_folders.folder_id%TYPE
-) returns varchar as '  -- cr_folders.label%TYPE 
-declare
-        get_folder_name__folder_id      alias for $1;
-begin
+
+
+-- added
+select define_function_args('file_storage__get_folder_name','folder_id');
+
+--
+-- procedure file_storage__get_folder_name/1
+--
+CREATE OR REPLACE FUNCTION file_storage__get_folder_name(
+   get_folder_name__folder_id integer
+
+) RETURNS varchar AS $$
+DECLARE
+BEGIN
         return content_folder__get_label(
                           get_folder_name__folder_id
                           );
+END;
+$$ LANGUAGE plpgsql;  
 
-end;' language 'plpgsql';  
 
 
-create or replace function file_storage__new_version (
-       --
-       -- Create a new version of a file
-       -- Wrapper for content_revision__new
-       --
-       varchar,         -- cr_revisions.title%TYPE,
-       varchar,         -- cr_revisions.description%TYPE,
-       varchar,         -- cr_revisions.mime_type%TYPE,
-       integer,         -- cr_items.item_id%TYPE,
-       integer,         -- acs_objects.creation_user%TYPE,
-       varchar          -- acs_objects.creation_ip%TYPE
-) returns integer as '  -- cr_revisions.revision_id 
-declare
-        new_version__filename           alias for $1;
-        new_version__description        alias for $2;
-        new_version__mime_type          alias for $3;
-        new_version__item_id            alias for $4;
-        new_version__creation_user      alias for $5;
-        new_version__creation_ip        alias for $6;
+
+-- added
+select define_function_args('file_storage__new_version','filename,description,mime_type,item_id,creation_user,creation_ip');
+
+--
+-- procedure file_storage__new_version/6
+--
+    --
+    -- Create a new version of a file
+    -- Wrapper for content_revision__new
+    --
+
+CREATE OR REPLACE FUNCTION file_storage__new_version(
+   new_version__filename varchar,
+   new_version__description varchar,
+   new_version__mime_type varchar,
+   new_version__item_id integer,
+   new_version__creation_user integer,
+   new_version__creation_ip varchar
+
+) RETURNS integer AS $$
+DECLARE
         v_revision_id                   cr_revisions.revision_id%TYPE;
         v_folder_id                     cr_items.parent_id%TYPE;
-begin
+BEGIN
         -- Create a revision
         v_revision_id := content_revision__new (
                           new_version__filename,        -- title
@@ -540,22 +620,31 @@
 
         return v_revision_id;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
-create or replace function file_storage__delete_version (
-       --
-       -- Delete a version of a file
-       --
-       integer, -- cr_items.item_id%TYPE,
-       integer  -- cr_revisions.revision_id%TYPE
-) returns integer as ' -- cr_items.parent_id%TYPE
-declare
-        delete_version__file_id         alias for $1;
-        delete_version__version_id      alias for $2;
+
+
+-- added
+select define_function_args('file_storage__delete_version','file_id,version_id');
+
+--
+-- procedure file_storage__delete_version/2
+--
+    --
+    -- Delete a version of a file
+    --
+
+CREATE OR REPLACE FUNCTION file_storage__delete_version(
+   delete_version__file_id integer,
+   delete_version__version_id integer
+
+) RETURNS integer AS $$
+DECLARE
         v_parent_id                     cr_items.parent_id%TYPE;
         v_deleted_last_version_p        boolean;
-begin
+BEGIN
 
         if delete_version__version_id = content_item__get_live_revision(delete_version__file_id) 
         then
@@ -580,28 +669,30 @@
         -- we cannot delete the content_item entry if there are no more revisions.
         return v_parent_id;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
-create or replace function file_storage__new_folder(
-       --
-       -- Create a folder
-       --
-       varchar,         -- cr_items.name%TYPE,
-       varchar,         -- cr_folders.label%TYPE,
-       integer,         -- cr_items.parent_id%TYPE,
-       integer,         -- acs_objects.creation_user%TYPE,       
-       varchar          -- acs_objects.creation_ip%TYPE       
-) returns integer as '  -- cr_folders.folder_id%TYPE
-declare
-        new_folder__name              alias for $1;
-        new_folder__folder_name       alias for $2;
-        new_folder__parent_id         alias for $3;
-        new_folder__creation_user     alias for $4;
-        new_folder__creation_ip       alias for $5;
+
+
+-- added
+select define_function_args('file_storage__new_folder','name,folder_name,parent_id,creation_user,creation_ip');
+
+--
+-- procedure file_storage__new_folder/5
+--
+CREATE OR REPLACE FUNCTION file_storage__new_folder(
+   new_folder__name varchar,
+   new_folder__folder_name varchar,
+   new_folder__parent_id integer,
+   new_folder__creation_user integer,
+   new_folder__creation_ip varchar
+
+) RETURNS integer AS $$
+DECLARE
         v_folder_id                   cr_folders.folder_id%TYPE;
         v_package_id                  acs_objects.package_id%TYPE;
-begin
+BEGIN
         v_package_id := file_storage__get_package_id(new_folder__parent_id);
 
         -- Create a new folder
@@ -623,82 +714,105 @@
         -- JS: to true since we created a new subtype.
         PERFORM content_folder__register_content_type(
                         v_folder_id,            -- folder_id
-                        ''content_revision'',   -- content_type
-                        ''t'');                 -- include_subtypes (default)
+                        'content_revision',   -- content_type
+                        't');                 -- include_subtypes (default)
 
         PERFORM content_folder__register_content_type(
                         v_folder_id,            -- folder_id
-                        ''content_folder'',     -- content_type
-                        ''t''                   -- include_subtypes (default)
+                        'content_folder',     -- content_type
+                        't'                   -- include_subtypes (default)
                         );                      
 
         PERFORM content_folder__register_content_type(
                 v_folder_id,            -- folder_id
-                ''content_extlink'',    -- content_types
-                ''t''                   -- include_subtypes 
+                'content_extlink',    -- content_types
+                't'                   -- include_subtypes 
                 );
 
         PERFORM content_folder__register_content_type(
                 v_folder_id,            -- folder_id
-                ''content_symlink'',    -- content_types
-                ''t''                   -- include_subtypes 
+                'content_symlink',    -- content_types
+                't'                   -- include_subtypes 
                 );
 
         -- Give the creator admin privileges on the folder
         PERFORM acs_permission__grant_permission (
                      v_folder_id,                -- object_id
                      new_folder__creation_user,  -- grantee_id
-                     ''admin''                   -- privilege
+                     'admin'                   -- privilege
                      );
 
         return v_folder_id;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
-create or replace function file_storage__delete_folder(
-       --
-       -- Delete a folder
-       --
-       integer          -- cr_folders.folder_id%TYPE
-) returns integer as '  -- 0 for success
-declare
-        delete_folder__folder_id        alias for $1; 
-begin
 
+
+-- added
+
+--
+-- procedure file_storage__delete_folder/1
+--
+    --
+    -- Delete a folder
+    --
+
+CREATE OR REPLACE FUNCTION file_storage__delete_folder(
+   delete_folder__folder_id integer
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
+
         return file_storage__delete_folder(
                     delete_folder__folder_id,  -- folder_id
-                    ''f''
+                    'f'
                     );
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function file_storage__delete_folder(
-       --
-       -- Delete a folder
-       --
-       integer,          -- cr_folders.folder_id%TYPE
-       boolean
-) returns integer as '  -- 0 for success
-declare
-        delete_folder__folder_id        alias for $1; 
-        delete_folder__cascade_p        alias for $2;
-begin
 
+
+-- added
+select define_function_args('file_storage__delete_folder','folder_id,cascade_p');
+
+--
+-- procedure file_storage__delete_folder/2
+--
+    --
+    -- Delete a folder
+    --
+CREATE OR REPLACE FUNCTION file_storage__delete_folder(
+   delete_folder__folder_id integer,
+   delete_folder__cascade_p boolean
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
         return content_folder__delete(
                     delete_folder__folder_id,  -- folder_id
                     delete_folder__cascade_p
                     );
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- JS: BEFORE DELETE TRIGGER to clean up CR entries (except root folder)
-create or replace function fs_package_items_delete_trig () returns opaque as '
-declare
 
+
+--
+-- procedure fs_package_items_delete_trig/0
+--
+CREATE OR REPLACE FUNCTION fs_package_items_delete_trig (
+) RETURNS trigger AS $$
+DECLARE
+
         v_rec   record;
-begin
+BEGIN
 
         for v_rec in
         
@@ -712,35 +826,35 @@
                 order by c1.tree_sortkey desc
         loop
 
-                -- DRB: Why can''t we just use object delete here?
+                -- DRB: Why can't we just use object delete here?
 
 
                 -- We delete the item. On delete cascade should take care
                 -- of deletion of revisions.
-                if v_rec.content_type = ''file_storage_object''
+                if v_rec.content_type = 'file_storage_object'
                 then
-                    raise notice ''Deleting item_id = %'',v_rec.item_id;
+                    raise notice 'Deleting item_id = %',v_rec.item_id;
                     PERFORM content_item__delete(v_rec.item_id);
                 end if;
 
                 -- Instead of doing an if-else, we make sure we are deleting a folder.
-                if v_rec.content_type = ''content_folder''
+                if v_rec.content_type = 'content_folder'
                 then
-                    raise notice ''Deleting folder_id = %'',v_rec.item_id;
+                    raise notice 'Deleting folder_id = %',v_rec.item_id;
                     PERFORM content_folder__delete(v_rec.item_id);
                 end if;
 
                 -- Instead of doing an if-else, we make sure we are deleting a folder.
-                if v_rec.content_type = ''content_symlink''
+                if v_rec.content_type = 'content_symlink'
                 then
-                    raise notice ''Deleting symlink_id = %'',v_rec.item_id;
+                    raise notice 'Deleting symlink_id = %',v_rec.item_id;
                     PERFORM content_symlink__delete(v_rec.item_id);
                 end if;
 
                 -- Instead of doing an if-else, we make sure we are deleting a folder.
-                if v_rec.content_type = ''content_extlink''
+                if v_rec.content_type = 'content_extlink'
                 then
-                    raise notice ''Deleting folder_id = %'',v_rec.item_id;
+                    raise notice 'Deleting folder_id = %',v_rec.item_id;
                     PERFORM content_extlink__delete(v_rec.item_id);
                 end if;
 
@@ -749,20 +863,22 @@
         -- We need to return something for the trigger to be activated
         return old;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 create trigger fs_package_items_delete_trig before delete
 on fs_root_folders for each row 
 execute procedure fs_package_items_delete_trig ();
 
 
 -- JS: AFTER DELETE TRIGGER to clean up last CR entry
-create or replace function fs_root_folder_delete_trig () returns opaque as '
-begin
+CREATE OR REPLACE FUNCTION fs_root_folder_delete_trig () RETURNS trigger AS $$
+BEGIN
         PERFORM content_folder__delete(old.folder_id);
         return null;
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 create trigger fs_root_folder_delete_trig after delete
 on fs_root_folders for each row 
