Index: openacs-4/packages/acs-kernel/acs-kernel.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/acs-kernel.info,v
diff -u -r1.100 -r1.101
--- openacs-4/packages/acs-kernel/acs-kernel.info 25 Nov 2008 17:08:49 -0000 1.100
+++ openacs-4/packages/acs-kernel/acs-kernel.info 12 Feb 2009 02:27:02 -0000 1.101
@@ -7,15 +7,15 @@
t
t
-
+
OpenACS Core Team
Routines and data models providing the foundation for OpenACS-based Web services.
2008-05-31
OpenACS
The OpenACS kernel contains the core datamodel create and drop scripts for such things as objects, groups, partiies and the supporting PL/SQL and PL/pgSQL procedures.
3
-
+
Index: openacs-4/packages/acs-kernel/sql/oracle/groups-body-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/oracle/groups-body-create.sql,v
diff -u -r1.15 -r1.16
--- openacs-4/packages/acs-kernel/sql/oracle/groups-body-create.sql 4 Jun 2006 00:45:38 -0000 1.15
+++ openacs-4/packages/acs-kernel/sql/oracle/groups-body-create.sql 12 Feb 2009 02:27:02 -0000 1.16
@@ -792,10 +792,22 @@
-- setup the permissible relationship types for this group
insert into group_rels
(group_rel_id, group_id, rel_type)
- select acs_object_id_seq.nextval, v_group_id, g.rel_type
- from group_type_rels g
- where g.group_type = new.object_type;
-
+ select t_acs_object_id_seq.nextval, v_group_id, rels.rel_type
+ from
+ ( select distinct g.rel_type
+ from group_type_rels g,
+ ( select object_type as parent_type
+ from acs_object_types
+ start with new.object_type
+ connect by object_type = prior.supertype
+ ) types
+ where g.group_type = types.parent_type
+ and not exists
+ ( select 1 from group_rels
+ where group_rels.group_id = v_group_id
+ and group_rels.rel_type = g.rel_type)
+ ) rels;
+
return v_group_id;
end new;
Index: openacs-4/packages/acs-kernel/sql/oracle/upgrade/upgrade-5.5.0d4-5.5.0d5.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/oracle/upgrade/upgrade-5.5.0d4-5.5.0d5.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-kernel/sql/oracle/upgrade/upgrade-5.5.0d4-5.5.0d5.sql 12 Feb 2009 02:27:02 -0000 1.1
@@ -0,0 +1,206 @@
+--
+--
+--
+-- @author Dave Bauer (dave@thedesignexperience.org)
+-- @creation-date 2009-02-11
+-- @cvs-id $Id: upgrade-5.5.0d4-5.5.0d5.sql,v 1.1 2009/02/12 02:27:02 daveb Exp $
+--
+
+
+create or replace package body acs_group
+is
+ function new (
+ group_id in groups.group_id%TYPE default null,
+ object_type in acs_objects.object_type%TYPE
+ default 'group',
+ 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,
+ email in parties.email%TYPE default null,
+ url in parties.url%TYPE default null,
+ group_name in groups.group_name%TYPE,
+ join_policy in groups.join_policy%TYPE default null,
+ context_id in acs_objects.context_id%TYPE default null
+ )
+ return groups.group_id%TYPE
+ is
+ v_group_id groups.group_id%TYPE;
+ v_group_type_exists_p integer;
+ v_join_policy groups.join_policy%TYPE;
+ begin
+ v_group_id :=
+ party.new(group_id, object_type, creation_date, creation_user,
+ creation_ip, email, url, context_id);
+
+ v_join_policy := join_policy;
+
+ -- if join policy wasn't specified, select the default based on group type
+ if v_join_policy is null then
+ select count(*) into v_group_type_exists_p
+ from group_types
+ where group_type = object_type;
+
+ if v_group_type_exists_p = 1 then
+ select default_join_policy into v_join_policy
+ from group_types
+ where group_type = object_type;
+ else
+ v_join_policy := 'open';
+ end if;
+ end if;
+
+ insert into groups
+ (group_id, group_name, join_policy)
+ values
+ (v_group_id, group_name, v_join_policy);
+
+ update acs_objects
+ set title = group_name
+ where object_id = v_group_id;
+
+
+ -- setup the permissible relationship types for this group
+ insert into group_rels
+ (group_rel_id, group_id, rel_type)
+ select t_acs_object_id_seq.nextval, v_group_id, rels.rel_type
+ from
+ ( select distinct g.rel_type
+ from group_type_rels g,
+ ( select object_type as parent_type
+ from acs_object_types
+ start with new.object_type
+ connect by object_type = prior.supertype
+ ) types
+ where g.group_type = types.parent_type
+ and not exists
+ ( select 1 from group_rels
+ where group_rels.group_id = v_group_id
+ and group_rels.rel_type = g.rel_type)
+ ) rels;
+
+ return v_group_id;
+ end new;
+
+
+ procedure del (
+ group_id in groups.group_id%TYPE
+ )
+ is
+ begin
+
+ -- Delete all the relations of any type to this group
+ for row in (select r.rel_id, t.package_name
+ from acs_rels r, acs_object_types t
+ where r.rel_type = t.object_type
+ and (r.object_id_one = acs_group.del.group_id
+ or r.object_id_two = acs_group.del.group_id)) loop
+ execute immediate 'begin ' || row.package_name || '.del(' || row.rel_id || '); end;';
+ end loop;
+
+ -- Delete all segments defined for this group
+ for row in (select segment_id
+ from rel_segments
+ where group_id = acs_group.del.group_id) loop
+
+ rel_segment.del(row.segment_id);
+
+ end loop;
+
+ party.del(group_id);
+ end del;
+
+ function name (
+ group_id in groups.group_id%TYPE
+ )
+ return varchar2
+ is
+ group_name varchar2(200);
+ begin
+ select group_name
+ into group_name
+ from groups
+ where group_id = name.group_id;
+
+ return group_name;
+ end name;
+
+ function member_p (
+ party_id in parties.party_id%TYPE,
+ group_id in groups.group_id%TYPE,
+ cascade_membership char
+ )
+ return char
+ is
+ m_result integer;
+ begin
+
+ if cascade_membership = 't' then
+ select count(*)
+ into m_result
+ from group_member_map
+ where group_id = member_p.group_id and
+ member_id = member_p.party_id;
+
+ if m_result > 0 then
+ return 't';
+ end if;
+ else
+ select count(*)
+ into m_result
+ from acs_rels rels, all_object_party_privilege_map perm
+ where perm.object_id = rels.rel_id
+ and perm.privilege = 'read'
+ and rels.rel_type = 'membership_rel'
+ and rels.object_id_one = member_p.group_id
+ and rels.object_id_two = member_p.party_id;
+
+ if m_result > 0 then
+ return 't';
+ end if;
+ end if;
+
+ return 'f';
+ end member_p;
+
+ function check_representation (
+ group_id in groups.group_id%TYPE
+ ) return char
+ is
+ result char(1);
+ begin
+ result := 't';
+ acs_log.notice('acs_group.check_representation',
+ 'Running check_representation on group ' || group_id);
+
+ if acs_object.check_representation(group_id) = 'f' then
+ result := 'f';
+ end if;
+
+ for c in (select c.rel_id
+ from acs_rels r, composition_rels c
+ where r.rel_id = c.rel_id
+ and r.object_id_one = group_id) loop
+ if composition_rel.check_representation(c.rel_id) = 'f' then
+ result := 'f';
+ end if;
+ end loop;
+
+ for m in (select m.rel_id
+ from acs_rels r, membership_rels m
+ where r.rel_id = m.rel_id
+ and r.object_id_one = group_id) loop
+ if membership_rel.check_representation(m.rel_id) = 'f' then
+ result := 'f';
+ end if;
+ end loop;
+
+ acs_log.notice('acs_group.check_representation',
+ 'Done running check_representation on group ' || group_id);
+ return result;
+ end;
+
+end acs_group;
+/
+show errors
Index: openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql,v
diff -u -r1.30 -r1.31
--- openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql 4 Jun 2006 00:45:38 -0000 1.30
+++ openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql 12 Feb 2009 02:27:02 -0000 1.31
@@ -866,10 +866,24 @@
insert into group_rels
(group_rel_id, group_id, rel_type)
- select nextval(''t_acs_object_id_seq''), v_group_id, g.rel_type
- from group_type_rels g
- where g.group_type = new__object_type;
-
+ select nextval(''t_acs_object_id_seq''), v_group_id, rels.rel_type
+ from
+ ( select distinct g.rel_type
+ from group_type_rels g,
+ ( select parent.object_type as parent_type
+ from acs_object_types child, acs_object_types parent
+ where child.object_type <> parent.object_type
+ and child.tree_sortkey between parent.tree_sortkey
+ and tree_right(parent.tree_sortkey)
+ and child.object_type = new__object_type
+ order by parent.tree_sortkey desc) types
+ where g.group_type = types.parent_type
+ and not exists
+ ( select 1 from group_rels
+ where group_rels.group_id = v_group_id
+ and group_rels.rel_type = g.rel_type)
+ ) rels;
+
return v_group_id;
end;' language 'plpgsql';
Index: openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.5.0d4-5.5.0d5.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.5.0d4-5.5.0d5.sql,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.5.0d4-5.5.0d5.sql 12 Feb 2009 02:27:02 -0000 1.1
@@ -0,0 +1,90 @@
+--
+--
+--
+-- @author Dave Bauer (dave@thedesignexperience.org)
+-- @creation-date 2009-02-11
+-- @cvs-id $Id: upgrade-5.5.0d4-5.5.0d5.sql,v 1.1 2009/02/12 02:27:02 daveb Exp $
+--
+
+
+create or replace function acs_group__new (integer,varchar,timestamptz,integer,varchar,varchar,varchar,varchar,varchar,integer)
+returns integer as '
+declare
+ new__group_id alias for $1; -- default null
+ new__object_type alias for $2; -- default ''group''
+ new__creation_date alias for $3; -- default now()
+ new__creation_user alias for $4; -- default null
+ new__creation_ip alias for $5; -- default null
+ new__email alias for $6; -- default null
+ new__url alias for $7; -- default null
+ new__group_name alias for $8;
+ new__join_policy alias for $9; -- default null
+ new__context_id alias for $10; -- default null
+ v_group_id groups.group_id%TYPE;
+ v_group_type_exists_p integer;
+ v_join_policy groups.join_policy%TYPE;
+begin
+ v_group_id :=
+ party__new(new__group_id, new__object_type, new__creation_date,
+ new__creation_user, new__creation_ip, new__email,
+ new__url, new__context_id);
+
+ v_join_policy := new__join_policy;
+
+ -- if join policy was not specified, select the default based on group type
+ if v_join_policy is null or v_join_policy = '''' then
+ select count(*) into v_group_type_exists_p
+ from group_types
+ where group_type = new__object_type;
+
+ if v_group_type_exists_p = 1 then
+ select default_join_policy into v_join_policy
+ from group_types
+ where group_type = new__object_type;
+ else
+ v_join_policy := ''open'';
+ end if;
+ end if;
+
+ update acs_objects
+ set title = new__group_name
+ where object_id = v_group_id;
+
+ insert into groups
+ (group_id, group_name, join_policy)
+ values
+ (v_group_id, new__group_name, v_join_policy);
+
+ -- setup the permissible relationship types for this group
+
+ -- DRB: we have to call nextval() directly because the select may
+ -- return more than one row. The sequence hack will only compute
+ -- one nextval value causing the insert to fail ("may" in PG, which
+ -- is actually broken. It should ALWAYS return exactly one value for
+ -- the view. In PG it may or may not depending on the optimizer''s
+ -- mood. PG group seems uninterested in acknowledging the fact that
+ -- this is a bug)
+
+ insert into group_rels
+ (group_rel_id, group_id, rel_type)
+ select nextval(''t_acs_object_id_seq''), v_group_id, rels.rel_type
+ from
+ ( select distinct g.rel_type
+ from group_type_rels g,
+ ( select parent.object_type as parent_type
+ from acs_object_types child, acs_object_types parent
+ where child.object_type <> parent.object_type
+ and child.tree_sortkey between parent.tree_sortkey
+ and tree_right(parent.tree_sortkey)
+ and child.object_type = new__object_type
+ order by parent.tree_sortkey desc) types
+ where g.group_type = types.parent_type
+ and not exists
+ ( select 1 from group_rels
+ where group_rels.group_id = v_group_id
+ and group_rels.rel_type = g.rel_type)
+ ) rels;
+
+ return v_group_id;
+
+end;' language 'plpgsql';