Index: openacs-4/packages/cms/sql/postgresql/cms-content-methods.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/cms/sql/postgresql/cms-content-methods.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/cms/sql/postgresql/cms-content-methods.sql 19 May 2001 01:20:10 -0000 1.1 +++ openacs-4/packages/cms/sql/postgresql/cms-content-methods.sql 20 May 2001 04:49:34 -0000 1.2 @@ -9,15 +9,15 @@ -/* Data model *? +/* Data model */ /* Means of inserting content into the database. */ create table cm_content_methods ( - content_method varchar2(100) + content_method varchar(100) constraint cm_content_methods_pk primary key, - label varchar2(100) not null, - description varchar2(4000) + label varchar(100) not null, + description text ); -- insert the standard content methods @@ -46,22 +46,20 @@ ); -/* Map a content type to a content method(s) */ +* Map a content type to a content method(s) */ create table cm_content_type_method_map ( - content_type varchar2(100) + content_type varchar(100) constraint cm_type_method_map_type_fk references acs_object_types, - content_method varchar2(100) default 'no_content' + content_method varchar(100) default 'no_content' constraint cm_type_method_map_method_fk references cm_content_methods, - is_default char(1) - constraint cm_method_map_is_default_ck - check (is_default in ('t','f')) + is_default boolean ); -/* A view of all mapped content methods */ -create or replace view cm_type_methods +* A view of all mapped content methods */ +create view cm_type_methods as select map.content_type, t.pretty_name, @@ -81,69 +79,69 @@ /* PACKAGE DEFINITIONS */ -create or replace package content_method as +-- create or replace package content_method as +-- +-- function get_method ( +-- content_type in cm_content_type_method_map.content_type%TYPE +-- ) return cm_content_type_method_map.content_method%TYPE; +-- +-- function is_mapped ( +-- content_type in cm_content_type_method_map.content_type%TYPE, +-- content_method in cm_content_type_method_map.content_method%TYPE +-- ) return char; +-- +-- procedure add_method ( +-- content_type in cm_content_type_method_map.content_type%TYPE, +-- content_method in cm_content_type_method_map.content_method%TYPE, +-- is_default in cm_content_type_method_map.is_default%TYPE +-- default 'f' +-- ); +-- +-- procedure add_all_methods ( +-- content_type in cm_content_type_method_map.content_type%TYPE +-- ); +-- +-- procedure set_default_method ( +-- content_type in cm_content_type_method_map.content_type%TYPE, +-- content_method in cm_content_type_method_map.content_method%TYPE +-- ); +-- +-- procedure unset_default_method ( +-- content_type in cm_content_type_method_map.content_type%TYPE +-- ); +-- +-- procedure remove_method ( +-- content_type in cm_content_type_method_map.content_type%TYPE, +-- content_method in cm_content_type_method_map.content_method%TYPE +-- ); +-- +-- end content_method; - function get_method ( - content_type in cm_content_type_method_map.content_type%TYPE - ) return cm_content_type_method_map.content_method%TYPE; +-- show errors - function is_mapped ( - content_type in cm_content_type_method_map.content_type%TYPE, - content_method in cm_content_type_method_map.content_method%TYPE - ) return char; - procedure add_method ( - content_type in cm_content_type_method_map.content_type%TYPE, - content_method in cm_content_type_method_map.content_method%TYPE, - is_default in cm_content_type_method_map.is_default%TYPE - default 'f' - ); - procedure add_all_methods ( - content_type in cm_content_type_method_map.content_type%TYPE - ); - procedure set_default_method ( - content_type in cm_content_type_method_map.content_type%TYPE, - content_method in cm_content_type_method_map.content_method%TYPE - ); - procedure unset_default_method ( - content_type in cm_content_type_method_map.content_type%TYPE - ); +-- create or replace package body content_method as +-- function get_method +create function content_method__get_method (varchar) +returns varchar as ' +declare + get_method__content_type alias for $1; + v_method cm_content_type_method_map.content_method%TYPE; + v_count integer; +begin - procedure remove_method ( - content_type in cm_content_type_method_map.content_type%TYPE, - content_method in cm_content_type_method_map.content_method%TYPE - ); - -end content_method; -/ -show errors - - - - - -create or replace package body content_method as - - function get_method ( - content_type in cm_content_type_method_map.content_type%TYPE - ) return cm_content_type_method_map.content_method%TYPE - is - v_method cm_content_type_method_map.content_method%TYPE; - v_count integer; - begin - -- first, look for the default select content_method into v_method from cm_content_type_method_map where - content_type = get_method.content_type + content_type = get_method__content_type and - is_default = 't'; + is_default = ''t''; if v_method is null then -- then check to see if there is only one registered content method @@ -152,7 +150,7 @@ from cm_content_type_method_map where - content_type = get_method.content_type; + content_type = get_method__content_type; if v_count = 1 then -- if so, return the only registered method @@ -161,85 +159,91 @@ from cm_content_type_method_map where - content_type = get_method.content_type; + content_type = get_method__content_type; end if; end if; return v_method; - exception - when NO_DATA_FOUND then - return null; - end get_method; - function is_mapped ( - content_type in cm_content_type_method_map.content_type%TYPE, - content_method in cm_content_type_method_map.content_method%TYPE - ) return char - is - v_is_mapped char(1); - begin +-- exception +-- when NO_DATA_FOUND then +-- return null; + +end;' language 'plpgsql'; + + +-- function is_mapped +create function content_method__is_mapped (varchar,varchar) +returns boolean as ' +declare + is_mapped__content_type alias for $1; + is_mapped__content_method alias for $2; +begin - select - 't' into v_is_mapped + return + count(*) > 0 from cm_content_type_method_map where - content_type = is_mapped.content_type + content_type = is_mapped__content_type and - content_method = is_mapped.content_method; + content_method = is_mapped__content_method; + +end;' language 'plpgsql'; - return v_is_mapped; - exception - when NO_DATA_FOUND then - return 'f'; - end is_mapped; - procedure add_method ( - content_type in cm_content_type_method_map.content_type%TYPE, - content_method in cm_content_type_method_map.content_method%TYPE, - is_default in cm_content_type_method_map.is_default%TYPE - default 'f' - ) is - v_method_already_mapped integer; - begin +-- procedure add_method +create function content_method__add_method (varchar,varchar,char) +returns integer as ' +declare + add_method__content_type alias for $1; + add_method__content_method alias for $2; + add_method__is_default alias for $3; -- default ''f'' + v_method_already_mapped integer; +begin -- check if there is any existing mapping select count(1) into v_method_already_mapped from cm_content_type_method_map where - content_type = add_method.content_type + content_type = add_method__content_type and - content_method = add_method.content_method; + content_method = add_method__content_method; if v_method_already_mapped = 1 then -- update the content type method mapping update cm_content_type_method_map - set is_default = add_method.is_default - where content_type = add_method.content_type - and content_method = add_method.content_method; + set is_default = add_method__is_default + where content_type = add_method__content_type + and content_method = add_method__content_method; else -- insert the content type method mapping insert into cm_content_type_method_map ( content_type, content_method, is_default ) values ( - add_method.content_type, add_method.content_method, - add_method.is_default + add_method__content_type, add_method__content_method, + add_method__is_default ); end if; - end add_method; - procedure add_all_methods ( - content_type in cm_content_type_method_map.content_type%TYPE - ) is - begin + return 0; +end;' language 'plpgsql'; + + +-- procedure add_all_methods +create function content_method__add_all_methods (varchar) +returns integer as ' +declare + add_all_methods__content_type alias for $1; +begin -- map all unmapped content methods to the content type insert into cm_content_type_method_map ( content_type, content_method, is_default ) select - add_all_methods.content_type, content_method, 'f' + add_all_methods__content_type, content_method, ''f'' from cm_content_methods m where @@ -250,49 +254,66 @@ where content_method = m.content_method and - content_type = add_all_methods.content_type + content_type = add_all_methods__content_type ); - end add_all_methods; - procedure set_default_method ( - content_type in cm_content_type_method_map.content_type%TYPE, - content_method in cm_content_type_method_map.content_method%TYPE - ) is - begin + return 0; +end;' language 'plpgsql'; + +-- procedure set_default_method +create function content_method__set_default_method (varchar,varchar) +returns integer as ' +declare + set_default_method__content_type alias for $1; + set_default_method__content_method alias for $2; +begin + -- unset old default - unset_default_method ( - content_type => set_default_method.content_type + PERFORM content_method__unset_default_method ( + set_default_method__content_type ); -- set new default update cm_content_type_method_map - set is_default = 't' - where content_type = set_default_method.content_type - and content_method = set_default_method.content_method; - end set_default_method; + set is_default = ''t'' + where content_type = set_default_method__content_type + and content_method = set_default_method__content_method; - procedure unset_default_method ( - content_type in cm_content_type_method_map.content_type%TYPE - ) is - begin + return 0; +end;' language 'plpgsql'; + +-- procedure unset_default_method +create function content_method__unset_default_method (varchar) +returns integer as ' +declare + unset_default_method__content_type alias for $1; +begin + update cm_content_type_method_map - set is_default = 'f' - where content_type = unset_default_method.content_type; - end unset_default_method; + set is_default = ''f'' + where content_type = unset_default_method__content_type; - procedure remove_method ( - content_type in cm_content_type_method_map.content_type%TYPE, - content_method in cm_content_type_method_map.content_method%TYPE - ) is - begin + return 0; +end;' language 'plpgsql'; + +-- procedure remove_method +create function content_method__remove_method (varchar,varchar) +returns integer as ' +declare + remove_method__content_type alias for $1; + remove_method__content_method alias for $2; +begin + -- delete the content type - method mapping delete from cm_content_type_method_map - where content_type = remove_method.content_type - and content_method = remove_method.content_method; - end remove_method; + where content_type = remove_method__content_type + and content_method = remove_method__content_method; -end content_method; -/ -show errors + return 0; +end;' language 'plpgsql'; + + + +-- show errors Index: openacs-4/packages/cms/sql/postgresql/cms-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/cms/sql/postgresql/cms-create.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/cms/sql/postgresql/cms-create.sql 19 May 2001 01:20:10 -0000 1.1 +++ openacs-4/packages/cms/sql/postgresql/cms-create.sql 20 May 2001 04:49:34 -0000 1.2 @@ -12,232 +12,290 @@ -- Ensure that content repository data model is up-to-date -@@cms-update.sql +\i cms-update.sql +create function inline_0 () +returns integer as ' declare attr_id acs_attributes.attribute_id%TYPE; begin - acs_object_type.create_type ( - supertype => 'content_item', - object_type => 'content_module', - pretty_name => 'Content Module', - pretty_plural => 'Content Modules', - table_name => 'cm_modules', - id_column => 'module_id', - name_method => 'content_module.get_label' - ); + select acs_object_type__create_type ( + ''content_module'', + ''Content Module'', + ''Content Modules'', + ''content_item'', + ''cm_modules'', + ''module_id'', + null, + ''f'', + null, + ''content_module__get_label'' + ); - attr_id := acs_attribute.create_attribute ( - object_type => 'content_module', - attribute_name => 'key', - datatype => 'string', - pretty_name => 'Key', - pretty_plural => 'Keys' - ); + attr_id := acs_attribute__create_attribute ( + ''content_module'', + ''key'', + ''string'', + ''Key'', + ''Keys'', + null, + null, + null, + 1, + 1, + null, + ''type_specific'', + ''f'' + ); - attr_id := acs_attribute.create_attribute ( - object_type => 'content_module', - attribute_name => 'name', - datatype => 'string', - pretty_name => 'Name', - pretty_plural => 'Names' - ); + attr_id := acs_attribute__create_attribute ( + ''content_module'', + ''name'', + ''string'', + ''Name'', + ''Names'', + null, + null, + null, + 1, + 1, + null, + ''type_specific'', + ''f'' + ); - attr_id := acs_attribute.create_attribute ( - object_type => 'content_module', - attribute_name => 'sort_key', - datatype => 'number', - pretty_name => 'Sort Key', - pretty_plural => 'Sort Keys' - ); + attr_id := acs_attribute__create_attribute ( + ''content_module'', + ''sort_key'', + ''number'', + ''Sort Key'', + ''Sort Keys'', + null, + null, + null, + 1, + 1, + null, + ''type_specific'', + ''f'' + ); -end; -/ -show errors + return 0; +end;' language 'plpgsql'; +select inline_0 (); +drop function inline_0 (); + + +-- show errors + + create table cm_modules ( module_id integer constraint cm_modules_id_fk references acs_objects on delete cascade constraint cm_modules_pk primary key, - key varchar2(20) + key varchar(20) constraint cm_modules_unq unique, - name varchar2(100) + name varchar(100) constraint cm_modules_name_nil not null, - root_key varchar2(100), + root_key varchar(100), sort_key integer ); comment on column cm_modules.root_key is ' The value of the ID or key at the root of the module hierarchy. '; -create or replace package content_module -as +-- create or replace package content_module +-- as +-- +-- function new ( +-- name in cm_modules.name%TYPE, +-- key in cm_modules.key%TYPE, +-- root_key in cm_modules.root_key%TYPE, +-- sort_key in cm_modules.sort_key%TYPE, +-- parent_id in acs_objects.context_id%TYPE default null, +-- object_id in acs_objects.object_id%TYPE default null, +-- creation_date in acs_objects.creation_date%TYPE +-- default sysdate, +-- creation_user in acs_objects.creation_user%TYPE +-- default null, +-- creation_ip in acs_objects.creation_ip%TYPE default null, +-- object_type in acs_objects.object_type%TYPE default 'content_module' +-- ) return acs_objects.object_id%TYPE; +-- +-- +-- function get_label ( +-- --/** Returns the label for the module. +-- -- This function is the default name method for the module object +-- -- @author Michael Pih +-- -- @param module_id The module id +-- -- @return The module's label +-- --*/ +-- module_id in cm_modules.module_id%TYPE +-- ) return cm_modules.name%TYPE; +-- +-- +-- end content_module; -function new ( - name in cm_modules.name%TYPE, - key in cm_modules.key%TYPE, - root_key in cm_modules.root_key%TYPE, - sort_key in cm_modules.sort_key%TYPE, - parent_id in acs_objects.context_id%TYPE default null, - object_id in acs_objects.object_id%TYPE default null, - creation_date in acs_objects.creation_date%TYPE - default sysdate, - creation_user in acs_objects.creation_user%TYPE - default null, - creation_ip in acs_objects.creation_ip%TYPE default null, - object_type in acs_objects.object_type%TYPE default 'content_module' -) return acs_objects.object_id%TYPE; +-- show errors +-- create or replace package body content_module -function get_label ( - --/** Returns the label for the module. - -- This function is the default name method for the module object - -- @author Michael Pih - -- @param module_id The module id - -- @return The module's label - --*/ - module_id in cm_modules.module_id%TYPE -) return cm_modules.name%TYPE; +create function content_module__new (varchar,varchar,varchar,integer,integer,integer,timestamp,integer,varchar,varchar) +returns integer as ' +declare + p_name alias for $1; + p_key alias for $2; + p_root_key alias for $3; + p_sort_key alias for $4; +begin + return content_module__new(p_name, + p_key, + p_root_key, + p_sort_key, + null, + null, + now(), + null, + null, + ''content_module'' + ); +end;' language 'plpgsql'; -end content_module; -/ -show errors - -create or replace package body content_module -as - -function new ( - name in cm_modules.name%TYPE, - key in cm_modules.key%TYPE, - root_key in cm_modules.root_key%TYPE, - sort_key in cm_modules.sort_key%TYPE, - parent_id in acs_objects.context_id%TYPE default null, - object_id in acs_objects.object_id%TYPE default null, - creation_date in acs_objects.creation_date%TYPE - default sysdate, - creation_user in acs_objects.creation_user%TYPE - default null, - creation_ip in acs_objects.creation_ip%TYPE default null, - object_type in acs_objects.object_type%TYPE default 'content_module' -) return acs_objects.object_id%TYPE -is - module_id integer; +-- function new +create function content_module__new (varchar,varchar,varchar,integer,integer,integer,timestamp,integer,varchar,varchar) +returns integer as ' +declare + p_name alias for $1; + p_key alias for $2; + p_root_key alias for $3; + p_sort_key alias for $4; + p_parent_id alias for $5; -- null + p_object_id alias for $6; -- null + p_creation_date alias for $7; -- now() + p_creation_user alias for $8; -- null + p_creation_ip alias for $9; -- null + p_object_type alias for $10; -- ''content_module'' + v_module_id integer; begin - module_id := content_item.new( - item_id => object_id, - parent_id => parent_id, - name => name, - content_type => object_type, - item_subtype => 'content_module', - creation_user => creation_user, - creation_ip => creation_ip, - creation_date => creation_date + module_id := content_item__new( + p_name, + p_parent_id, + p_object_id, + null, + p_creation_date, + p_creation_user, + null, + p_creation_ip, + ''content_module'', + p_object_type, + null, + null, + ''text/plain'', + null, + null, + ''file'' ); insert into cm_modules (module_id, key, name, root_key, sort_key) values - (module_id, key, name, root_key, sort_key); + (v_module_id, key, p_name, p_root_key, p_sort_key); return module_id; -end; +end;' language 'plpgsql'; -function get_label ( - module_id in cm_modules.module_id%TYPE -) return cm_modules.name%TYPE -is - v_name cm_modules.name%TYPE; + +create function get_label (integer) returns varchar as ' +declare + p_module_id alias for $1; + v_name cm_modules.name%TYPE; begin select - nvl(name,key) into v_name + coalesce(name,key) into v_name from cm_modules where - module_id = get_label.module_id; + module_id = p_module_id; return v_name; - exception - when NO_DATA_FOUND then - return null; -end get_label; +end;' language 'plpgsql'; - - - -end content_module; -/ -show errors - -- Insert the default modules +create function inline_1 () returns integer as ' declare v_id integer; v_module_id integer; begin - v_id := content_module.new('My Tasks', 'workspace', NULL, 1,0); - v_id := content_module.new('Site Map', 'sitemap', - content_item.get_root_folder, 2,0); - v_id := content_module.new('Templates', 'templates', - content_template.get_root_folder, 3,0); - v_id := content_module.new('Content Types', 'types', - 'content_revision', 4,0); - v_id := content_module.new('Search', 'search', null, 5,0); - v_id := content_module.new('Subject Keywords', 'categories', 0, 6,0); - v_id := content_module.new('Users', 'users', null, 7,0); - v_id := content_module.new('Workflows', 'workflow', null, 8,0); + v_id := content_module__new(''My Tasks'', ''workspace'', NULL, 1,0); + v_id := content_module__new(''Site Map'', ''sitemap'', + content_item__get_root_folder(), 2,0); + v_id := content_module__new(''Templates'', ''templates'', + content_template__get_root_folder(), 3,0); + v_id := content_module__new(''Content Types'', ''types'', + ''content_revision'', 4,0); + v_id := content_module__new(''Search'', ''search'', null, 5,0); + v_id := content_module__new(''Subject Keywords'', ''categories'', 0, 6,0); + v_id := content_module__new(''Users'', ''users'', null, 7,0); + v_id := content_module__new(''Workflows'', ''workflow'', null, 8,0); -end; -/ -show errors + return null; -prompt *** Defining utility functions +end;' language 'plpgsql'; +select inline_1 (); + +drop function inline_1 (); + +-- prompt *** Defining utility functions + -- Get the alphabetical ordering of a string, based on the first --- character. Treat all non-alphabetical characters as before 'a' -create or replace function letter_placement ( - word in varchar2 -) return integer -is - letter varchar2(1); +-- character. Treat all non-alphabetical characters as before ''a'' +create function letter_placement (varchar) returns integer as ' +declare + p_word alias for $1; + v_letter varchar(1); begin - letter := substr(lower(word), 1, 1); + v_letter := substr(lower(p_word), 1, 1); - if letter < 'a' or letter > 'z' then - return ascii('a') - 1; + if v_letter < ''a'' or v_letter > ''z'' then + return ascii(''a'') - 1; else - return ascii(letter); + return ascii(v_letter); end if; -end letter_placement; -/ -show errors -prompt *** Compiling metadata forms package... -@@ cms-forms +end;' language 'plpgsql'; -prompt *** Compiling content methods model... -@@ cms-content-methods +-- prompt *** Compiling metadata forms package... +\i cms-forms.sql -prompt *** Compiling workflow model... -@@ cms-publishing-wf +-- prompt *** Compiling content methods model... +\i cms-content-methods.sql -prompt *** Compiling workflow helper package... -@@ cms-workflow +-- prompt *** Compiling workflow model... +\i cms-publishing-wf.sql -prompt *** Compiling permissions model... -@@ cms-permissions +-- prompt *** Compiling workflow helper package... +\i cms-workflow.sql -prompt *** Compiling fixes that need to be done... -@@ cms-fix +-- prompt *** Compiling permissions model... +\i cms-permissions.sql + +-- prompt *** Compiling fixes that need to be done... +\i cms-fix.sql + + Index: openacs-4/packages/cms/sql/postgresql/cms-fix.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/cms/sql/postgresql/cms-fix.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/cms/sql/postgresql/cms-fix.sql 19 May 2001 01:20:10 -0000 1.1 +++ openacs-4/packages/cms/sql/postgresql/cms-fix.sql 20 May 2001 04:49:34 -0000 1.2 @@ -13,103 +13,120 @@ -- content_module inherit from content_item -- this way it is possible to grant permissions on content modules +create function inline_0 () +returns integer as ' declare - cursor c_module_cur is - select - module_id - from - cm_modules; - - v_user_id users.user_id%TYPE; - v_supertype acs_object_types.supertype%TYPE; - v_id cm_modules.module_id%TYPE; - attr_id acs_attributes.attribute_id%TYPE; - v_module_id cm_modules.module_id%TYPE; - - -- this is an upgrade hack - cursor c_sitemap_perms_cur is - select - grantee_id, privilege - from - acs_permissions - where - object_id = content_item.get_root_folder; + v_user_id users.user_id%TYPE; + v_supertype acs_object_types.supertype%TYPE; + v_id cm_modules.module_id%TYPE; + attr_id acs_attributes.attribute_id%TYPE; + v_module_id cm_modules.module_id%TYPE; + v_module_val record; + v_sitemap_perms record; begin select supertype into v_supertype from acs_object_types where - object_type = 'content_module'; + object_type = ''content_module''; - if v_supertype ^= 'content_item' then + if v_supertype != ''content_item'' then -- delete all existing modules (they will be recreated) delete from acs_permissions where object_id in (select module_id from cm_modules); - for v_module_val in c_module_cur loop - acs_object.delete( v_module_val.module_id ); - end loop; - acs_object_type.drop_type ( 'content_module' ); + for v_module_val in select + module_id + from + cm_modules + LOOP + PERFORM acs_object__delete ( v_module_val.module_id ); + end LOOP; - acs_object_type.create_type ( - supertype => 'content_item', - object_type => 'content_module', - pretty_name => 'Content Module', - pretty_plural => 'Content Modules', - table_name => 'cm_modules', - id_column => 'module_id', - name_method => 'content_module.get_label' - ); + attr_id := acs_attribute__create_attribute ( + ''content_module'', + ''key'', + ''string'', + ''Key'', + ''Keys'', + null, + null, + null, + 1, + 1, + null, + ''type_specific'', + ''f'' + ); - attr_id := acs_attribute.create_attribute ( - object_type => 'content_module', - attribute_name => 'key', - datatype => 'string', - pretty_name => 'Key', - pretty_plural => 'Keys' - ); + attr_id := acs_attribute__create_attribute ( + ''content_module'', + ''name'', + ''string'', + ''Name'', + ''Names'', + null, + null, + null, + 1, + 1, + null, + ''type_specific'', + ''f'' + ); - attr_id := acs_attribute.create_attribute ( - object_type => 'content_module', - attribute_name => 'name', - datatype => 'string', - pretty_name => 'Name', - pretty_plural => 'Names' - ); + attr_id := acs_attribute__create_attribute ( + ''content_module'', + ''sort_key'', + ''number'', + ''Sort Key'', + ''Sort Keys'', + null, + null, + null, + 1, + 1, + null, + ''type_specific'', + ''f'' + ); - attr_id := acs_attribute.create_attribute ( - object_type => 'content_module', - attribute_name => 'sort_key', - datatype => 'number', - pretty_name => 'Sort Key', - pretty_plural => 'Sort Keys' - ); - - v_id := content_module.new('My Tasks', 'workspace', NULL, 1,0); - v_id := content_module.new('Site Map', 'sitemap', + v_id := content_module__new('My Tasks', 'workspace', NULL, 1,0); + v_id := content_module__new('Site Map', 'sitemap', content_item.get_root_folder, 2,0); - v_id := content_module.new('Templates', 'templates', + v_id := content_module__new('Templates', 'templates', content_template.get_root_folder, 3,0); - v_id := content_module.new('Content Types', 'types', + v_id := content_module__new('Content Types', 'types', 'content_revision', 4,0); v_module_id := v_id; - v_id := content_module.new('Search', 'search', null, 5,0); - v_id := content_module.new('Subject Keywords', 'categories', 0, 6,0); - v_id := content_module.new('Users', 'users', null, 7,0); - v_id := content_module.new('Workflows', 'workflow', null, 8,0); + v_id := content_module__new('Search', 'search', null, 5,0); + v_id := content_module__new('Subject Keywords', 'categories', 0, 6,0); + v_id := content_module__new('Users', 'users', null, 7,0); + v_id := content_module__new('Workflows', 'workflow', null, 8,0); -- upgrade hack, grant users with sitemap privs permission on types module - for v_sitemap_perms in c_sitemap_perms_cur loop - acs_permission.grant_permission( v_module_id, + for v_sitemap_perms in + select + grantee_id, privilege + from + acs_permissions + where + object_id = content_item__get_root_folder(); + LOOP + PERFORM acs_permission__grant_permission( v_module_id, v_sitemap_perms.grantee_id, v_sitemap_perms.privilege ); end loop; end if; -end; -/ -show errors + return 0; +end;' language 'plpgsql'; + +select inline_0 (); + +drop function inline_0 (); + Index: openacs-4/packages/cms/sql/postgresql/cms-forms.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/cms/sql/postgresql/cms-forms.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/cms/sql/postgresql/cms-forms.sql 19 May 2001 01:20:10 -0000 1.1 +++ openacs-4/packages/cms/sql/postgresql/cms-forms.sql 20 May 2001 04:49:34 -0000 1.2 @@ -1,7 +1,7 @@ -- Metadata for generating data entry forms create table cm_form_widgets ( - widget varchar2(100) + widget varchar(100) constraint cm_form_widgets_pk primary key ); @@ -10,25 +10,23 @@ Canonical list of all widgets defined in the system '; -create sequence cm_form_widget_param_seq start with 500; +create sequence t_cm_form_widget_param_seq; +create view cm_form_widget_param_seq as +select nextval('t_cm_form_widget_param_seq') as nextval; create table cm_form_widget_params ( param_id integer constraint cm_form_widget_params_pk primary key, - widget varchar2(100) + widget varchar(100) constraint cm_widget_params_fk references cm_form_widgets, - param varchar2(100) + param varchar(100) constraint cm_widget_param_nil not null, - is_required char(1) - constraint cm_widget_param_req_chk - check (is_required in ('t', 'f')), - is_html char(1) - constraint cm_widget_param_html_chk - check (is_html in ('t', 'f')), - default_value varchar2(1000) + is_required boolean, + is_html boolean, + default_value varchar(1000) ); comment on table cm_form_widget_params is ' @@ -42,14 +40,12 @@ primary key constraint cm_attr_widget_fk references acs_attributes, - widget varchar2(100) + widget varchar(100) constraint cm_attr_widget_widget_fk references cm_form_widgets constraint cm_attr_widget_nil not null, - is_required char(1) - constraint cm_attribute_widgets_opt_ck - check(is_required in ('t', 'f')) + is_required boolean ); create table cm_attribute_widget_params ( @@ -59,17 +55,17 @@ param_id integer constraint cm_attr_widget_param_fk references cm_form_widget_params, - param_type varchar2(100) default 'onevalue' + param_type varchar(100) default 'onevalue' constraint cm_attr_widget_param_type_nil not null constraint cm_attr_widget_param_type_ck check (param_type in ('onevalue', 'onelist', 'multilist')), - param_source varchar2(100) default 'literal' + param_source varchar(100) default 'literal' constraint cm_attr_widget_param_src_nil not null, constraint cm_attr_widget_param_src_ck check (param_source in ('literal', 'query', 'eval')), - value varchar2(4000), + value text, constraint cm_attr_widget_param_pk primary key(attribute_id, param_id) ); @@ -80,7 +76,7 @@ -- Get all the parameters for a attribute form widget -create or replace view cm_attribute_widget_param_ext as +create view cm_attribute_widget_param_ext as select widget_params.*, at.attribute_name, at.object_type, at.pretty_name, at.datatype, at.sort_order @@ -93,7 +89,7 @@ params.param, params.param_is_required, params.is_html, params.default_value from - cm_attribute_widgets widgets, + cm_attribute_widgets widgets LEFT OUTER JOIN (select awp.attribute_id, awp.param_id, awp.param_type, awp.param_source, awp.value, @@ -117,134 +113,132 @@ not exists (select 1 from cm_attribute_widget_params where param_id = fwp.param_id and attribute_id = aw.attribute_id) - ) params - where - widgets.attribute_id = params.attribute_id (+)) widget_params + ) params using (attribute_id)) widget_params where widget_params.attribute_id = at.attribute_id order by object_type, sort_order; -create or replace package cm_form_widget -is +-- create or replace package cm_form_widget +-- is +-- +-- procedure set_attribute_order ( +-- --/** Update the sort_order column of acs_attributes. +-- -- @author Karl Goldstein +-- -- @param content_type The name of the content type +-- -- @param attribute_name The name of the attribute +-- -- @param sort_order The sort order. +-- --*/ +-- content_type in acs_attributes.object_type%TYPE, +-- attribute_name in acs_attributes.attribute_name%TYPE, +-- sort_order in acs_attributes.sort_order%TYPE +-- ); +-- +-- procedure register_attribute_widget ( +-- --/** Register a form widget to a content type attribute. The form widget +-- -- uses the default values if none are set. If there is already a widget +-- -- registered to the attribute, the new widget replaces the old widget, +-- -- and all parameters are set to their default values. +-- -- @author Karl Goldstein, Stanislav Freidin +-- -- @param content_type The name of the content type +-- -- @param attribute_name The name of the attribute +-- -- @param widget The name of the form widget to use in metadata +-- -- forms +-- -- @param is_required Whether this form widget requires a value, +-- -- defaults to 'f' +-- -- @see /ats/form-procs.tcl/element_create, +-- -- {cm_form_widget.set_attribute_param_value}, +-- -- {cm_form_widget.unregister_attribute_widget} +-- --*/ +-- content_type in acs_attributes.object_type%TYPE, +-- attribute_name in acs_attributes.attribute_name%TYPE, +-- widget in cm_form_widgets.widget%TYPE, +-- is_required in cm_attribute_widgets.is_required%TYPE default 'f' +-- ); +-- +-- procedure unregister_attribute_widget ( +-- --/** Unregister a form widget from a content type attribute. +-- -- The attribute will no longer show up on the dynamic revision +-- -- upload form.

If no widget is registered to the attribute, +-- -- the procedure does nothing. +-- -- @author Karl Goldstein, Stanislav Freidin +-- -- @param content_type The name of the content type +-- -- @param attribute_name The name of the attribute for which to +-- -- unregister the widget +-- -- @see {cm_form_widget.register_attribute_widget} +-- --*/ +-- content_type in acs_attributes.object_type%TYPE, +-- attribute_name in acs_attributes.attribute_name%TYPE +-- ); +-- +-- procedure set_attribute_param_value ( +-- --/** Sets custom values for the param tag of a form widget that is +-- -- registered to a content type attribute. Unless this procedure is +-- -- called, the default form widget param values are used.

+-- -- If the parameter already has a value associated with it, the old +-- -- value is overwritten. +-- -- @author Karl Goldstein, Stanislav Freidin +-- -- @param content_type The name of the content type +-- -- @param attribute_name The name of the attribute +-- -- @param param The name of the form widget parameter. +-- -- Can be an ATS 'element create' flag or an +-- -- HTML form widget tag +-- -- @param param_type The type of value the param tag expects. +-- -- Can be 'onevalue','onelist', or 'multilist', +-- -- defaults to 'onevalue' +-- -- @param param_source How the param value is to be acquired, either +-- -- 'literal', 'eval', or 'query', defaults to +-- -- 'literal' +-- -- @param value The value(s) or means or obtaining the value(s) +-- -- for the param tag +-- -- @see /ats/form-procs.tcl/element_create, +-- -- {cm_form_widget.register_attribute_widget} +-- --*/ +-- content_type in acs_attributes.object_type%TYPE, +-- attribute_name in acs_attributes.attribute_name%TYPE, +-- param in cm_form_widget_params.param%TYPE, +-- value in cm_attribute_widget_params.value%TYPE, +-- param_type in cm_attribute_widget_params.param_type%TYPE +-- default 'onevalue', +-- param_source in cm_attribute_widget_params.param_source%TYPE +-- default 'literal' +-- ); +-- +-- end cm_form_widget; -procedure set_attribute_order ( - --/** Update the sort_order column of acs_attributes. - -- @author Karl Goldstein - -- @param content_type The name of the content type - -- @param attribute_name The name of the attribute - -- @param sort_order The sort order. - --*/ - content_type in acs_attributes.object_type%TYPE, - attribute_name in acs_attributes.attribute_name%TYPE, - sort_order in acs_attributes.sort_order%TYPE -); +-- show errors -procedure register_attribute_widget ( - --/** Register a form widget to a content type attribute. The form widget - -- uses the default values if none are set. If there is already a widget - -- registered to the attribute, the new widget replaces the old widget, - -- and all parameters are set to their default values. - -- @author Karl Goldstein, Stanislav Freidin - -- @param content_type The name of the content type - -- @param attribute_name The name of the attribute - -- @param widget The name of the form widget to use in metadata - -- forms - -- @param is_required Whether this form widget requires a value, - -- defaults to 'f' - -- @see /ats/form-procs.tcl/element_create, - -- {cm_form_widget.set_attribute_param_value}, - -- {cm_form_widget.unregister_attribute_widget} - --*/ - content_type in acs_attributes.object_type%TYPE, - attribute_name in acs_attributes.attribute_name%TYPE, - widget in cm_form_widgets.widget%TYPE, - is_required in cm_attribute_widgets.is_required%TYPE default 'f' -); -procedure unregister_attribute_widget ( - --/** Unregister a form widget from a content type attribute. - -- The attribute will no longer show up on the dynamic revision - -- upload form.

If no widget is registered to the attribute, - -- the procedure does nothing. - -- @author Karl Goldstein, Stanislav Freidin - -- @param content_type The name of the content type - -- @param attribute_name The name of the attribute for which to - -- unregister the widget - -- @see {cm_form_widget.register_attribute_widget} - --*/ - content_type in acs_attributes.object_type%TYPE, - attribute_name in acs_attributes.attribute_name%TYPE -); - -procedure set_attribute_param_value ( - --/** Sets custom values for the param tag of a form widget that is - -- registered to a content type attribute. Unless this procedure is - -- called, the default form widget param values are used.

- -- If the parameter already has a value associated with it, the old - -- value is overwritten. - -- @author Karl Goldstein, Stanislav Freidin - -- @param content_type The name of the content type - -- @param attribute_name The name of the attribute - -- @param param The name of the form widget parameter. - -- Can be an ATS 'element create' flag or an - -- HTML form widget tag - -- @param param_type The type of value the param tag expects. - -- Can be 'onevalue','onelist', or 'multilist', - -- defaults to 'onevalue' - -- @param param_source How the param value is to be acquired, either - -- 'literal', 'eval', or 'query', defaults to - -- 'literal' - -- @param value The value(s) or means or obtaining the value(s) - -- for the param tag - -- @see /ats/form-procs.tcl/element_create, - -- {cm_form_widget.register_attribute_widget} - --*/ - content_type in acs_attributes.object_type%TYPE, - attribute_name in acs_attributes.attribute_name%TYPE, - param in cm_form_widget_params.param%TYPE, - value in cm_attribute_widget_params.value%TYPE, - param_type in cm_attribute_widget_params.param_type%TYPE - default 'onevalue', - param_source in cm_attribute_widget_params.param_source%TYPE - default 'literal' -); - -end cm_form_widget; -/ -show errors - - -create or replace package body cm_form_widget -is - - procedure register_attribute_widget ( - content_type in acs_attributes.object_type%TYPE, - attribute_name in acs_attributes.attribute_name%TYPE, - widget in cm_form_widgets.widget%TYPE, - is_required in cm_attribute_widgets.is_required%TYPE default 'f' - ) - is - v_attr_id acs_attributes.attribute_id%TYPE; - v_prev_widget integer; - begin +-- create or replace package body cm_form_widget +-- procedure register_attribute_widget +create function cm_form_widget__register_attribute_widget (varchar,varchar,varchar,boolean) +returns integer as ' +declare + p_content_type alias for $1; + p_attribute_name alias for $2; + p_widget alias for $3; + p_is_required alias for $4; -- default ''f'' + v_attr_id acs_attributes.attribute_id%TYPE; + v_prev_widget integer; +begin -- Look for the attribute - begin - select attribute_id into v_attr_id from acs_attributes - where attribute_name=register_attribute_widget.attribute_name - and object_type=register_attribute_widget.content_type; + + select attribute_id into v_attr_id + from acs_attributes + where attribute_name = p_attribute_name + and object_type = p_content_type; - exception when no_data_found then - raise_application_error(-20000, 'Attribute ' || content_type || - ':' || attribute_name || - ' does not exist in cm_form_widget.register_attribute_widget' - ); - end; + if NOT FOUND then + raise EXCEPTION ''-20000: Attribute %: % does not exist in cm_form_widget.register_attribute_widget'', content_type, attribute_name; + end if; + -- Determine if a previous value exists - select count(1) into v_prev_widget from dual - where exists (select 1 from cm_attribute_widgets + select count(1) into v_prev_widget + from dual + where exists (select 1 + from cm_attribute_widgets where attribute_id = v_attr_id); if v_prev_widget > 0 then @@ -254,12 +248,13 @@ where attribute_id = v_attr_id and - param_id in (select param_id from cm_form_widgets - where widget = register_attribute_widget.widget); + param_id in (select param_id + from cm_form_widgets + where widget = p_widget); update cm_attribute_widgets set - widget = register_attribute_widget.widget, - is_required = register_attribute_widget.is_required + widget = p_widget, + is_required = p_is_required where attribute_id = v_attr_id; else @@ -271,56 +266,61 @@ (v_attr_id, widget, is_required); end if; - end register_attribute_widget; + return 0; +end;' language 'plpgsql'; - procedure set_attribute_order ( - content_type in acs_attributes.object_type%TYPE, - attribute_name in acs_attributes.attribute_name%TYPE, - sort_order in acs_attributes.sort_order%TYPE - ) is - begin +-- procedure set_attribute_order +create function cm_form_widget__set_attribute_order (varchar,varchar,integer) +returns integer as ' +declare + p_content_type alias for $1; + p_attribute_name alias for $2; + p_sort_order alias for $3; + +begin update acs_attributes set - sort_order = set_attribute_order.sort_order + sort_order = p_sort_order where - object_type = set_attribute_order.content_type + object_type = p_content_type and - attribute_name = set_attribute_order.attribute_name; + attribute_name = p_attribute_name; - end set_attribute_order; + return 0; +end;' language 'plpgsql'; - procedure unregister_attribute_widget ( - content_type in acs_attributes.object_type%TYPE, - attribute_name in acs_attributes.attribute_name%TYPE - ) - is - v_attr_id acs_attributes.attribute_id%TYPE; - v_widget cm_form_widgets.widget%TYPE; - begin + +-- procedure unregister_attribute_widget +create function cm_form_widget__unregister_attribute_widget (varchar,varchar) +returns integer as ' +declare + p_content_type alias for $1; + p_attribute_name alias for $2; + v_attr_id acs_attributes.attribute_id%TYPE; + v_widget cm_form_widgets.widget%TYPE; +begin -- Look for the attribute - begin - select attribute_id into v_attr_id from acs_attributes - where attribute_name = unregister_attribute_widget.attribute_name - and object_type = unregister_attribute_widget.content_type; + + select attribute_id into v_attr_id from acs_attributes + where attribute_name = p_attribute_name + and object_type = p_content_type; - exception when no_data_found then - raise_application_error(-20000, 'Attribute ' || content_type || - ':' || attribute_name || - ' does not exist in cm_form_widget.unregister_attribute_widget' - ); - end; + if NOT FOUND then + raise EXCEPTION ''-20000: Attribute %: % does not exist in cm_form_widget.unregister_attribute_widget'', content_type, attribute_name; + end if; -- Look for the widget; if no widget is registered, just return - begin - select widget into v_widget from cm_attribute_widgets - where attribute_id = v_attr_id; - exception when no_data_found then - return; - end; + + select widget into v_widget from cm_attribute_widgets + where attribute_id = v_attr_id; + + if NOT FOUND then + return null; + end if; -- Delete the param values and the widget assignment delete from cm_attribute_widget_params @@ -331,56 +331,51 @@ delete from cm_attribute_widgets where attribute_id = v_attr_id; - end unregister_attribute_widget; + return 0; +end;' language 'plpgsql'; - procedure set_attribute_param_value ( - content_type in acs_attributes.object_type%TYPE, - attribute_name in acs_attributes.attribute_name%TYPE, - param in cm_form_widget_params.param%TYPE, - value in cm_attribute_widget_params.value%TYPE, - param_type in cm_attribute_widget_params.param_type%TYPE - default 'onevalue', - param_source in cm_attribute_widget_params.param_source%TYPE - default 'literal' - ) - is - v_attr_id acs_attributes.attribute_id%TYPE; - v_widget cm_form_widgets.widget%TYPE; - v_param_id cm_form_widget_params.param_id%TYPE; - v_prev_value integer; - begin +-- procedure set_attribute_param_value +create function cm_form_widget__set_attribute_param_value (varchar,varchar,varchar,varchar,varchar,varchar) +returns integer as ' +declare + p_content_type alias for $1; + p_attribute_name alias for $2; + p_param alias for $3; + p_value alias for $4; + p_param_type alias for $5; -- default ''one_value'' + p_param_source alias for $6; -- default ''literal'' + v_attr_id acs_attributes.attribute_id%TYPE; + v_widget cm_form_widgets.widget%TYPE; + v_param_id cm_form_widget_params.param_id%TYPE; + v_prev_value integer; +begin + -- Get the attribute id and the widget - begin - select + select a.attribute_id, aw.widget into v_attr_id, v_widget - from - acs_attributes a, cm_attribute_widgets aw - where - a.attribute_name = set_attribute_param_value.attribute_name - and - a.object_type=set_attribute_param_value.content_type - and + from + acs_attributes a, cm_attribute_widgets aw + where + a.attribute_name = p_attribute_name + and + a.object_type=p_content_type + and aw.attribute_id = a.attribute_id; - exception when no_data_found then - raise_application_error(-20000, - 'No widget is registered for attribute ' || - content_type || '.' || attribute_name || - ' in cm_form_widget.set_attribute_param_value'); + + if NOT FOUND then + raise EXCEPTION ''-20000: No widget is registered for attribute %''.% in cm_form_widget.set_attribute_param_value'', content_type, attribute_name; end; -- Get the param id - begin - select param_id into v_param_id from cm_form_widget_params - where widget = v_widget - and param = set_attribute_param_value.param; - exception when no_data_found then - raise_application_error(-20000, - 'No parameter named ' || param || - ' exists for the widget ' || v_widget || - ' in cm_form_widget.set_attribute_param_value'); - end; + select param_id into v_param_id from cm_form_widget_params + where widget = v_widget + and param = p_param; + if NOT FOUND then + raise EXCEPTION ''-20000: No parameter named % exists for the widget % in cm_form_widget.set_attribute_param_value'',param, v_widget; + end if; + -- Check if an old value exists -- Determine if a previous value exists select count(1) into v_prev_value from dual @@ -391,9 +386,9 @@ if v_prev_value > 0 then -- Update the value update cm_attribute_widget_params set - param_type = set_attribute_param_value.param_type, - param_source = set_attribute_param_value.param_source, - value = set_attribute_param_value.value + param_type = p_param_type, + param_source = p_param_source, + value = p_value where attribute_id = v_attr_id and @@ -405,11 +400,11 @@ values (v_attr_id, v_param_id, param_type, param_source, value); end if; - end set_attribute_param_value; -end cm_form_widget; -/ -show errors + return 0; +end;' language 'plpgsql'; +-- show errors -@@cms-widgets + +\i cms-widgets.sql