Index: openacs-4/packages/acs-kernel/sql/oracle/upgrade/upgrade-5.0d-5.0d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/oracle/upgrade/upgrade-5.0d-5.0d2.sql,v diff -u -r1.1 -r1.2 --- openacs-4/packages/acs-kernel/sql/oracle/upgrade/upgrade-5.0d-5.0d2.sql 15 Aug 2003 14:35:50 -0000 1.1 +++ openacs-4/packages/acs-kernel/sql/oracle/upgrade/upgrade-5.0d-5.0d2.sql 25 Aug 2003 21:40:15 -0000 1.2 @@ -9,3 +9,70 @@ -- Adds column timezone to table user_preferences alter table user_preferences add timezone varchar2(100); + +create or replace trigger acs_objects_context_id_up_tr +after update on acs_objects +for each row +declare + security_context_root acs_objects.object_id%TYPE; +begin + if :new.object_id = :old.object_id and + :new.context_id = :old.context_id and + :new.security_inherit_p = :old.security_inherit_p then + return; + end if; + + -- Hate the hardwiring but magic objects aren't defined yet (PG doesn't + -- mind because function bodies aren't compiled until first called) + + security_context_root := -4; + + -- Remove my old ancestors from my descendants. + for pair in ( select object_id from acs_object_contexts where + ancestor_id = :old.object_id) loop + delete from acs_object_context_index + where object_id = pair.object_id + and ancestor_id in ( select ancestor_id from acs_object_contexts + where object_id = :old.object_id ); + end loop; + + -- Kill all my old ancestors. + delete from acs_object_context_index + where object_id = :old.object_id; + + insert into acs_object_context_index + (object_id, ancestor_id, n_generations) + values + (:new.object_id, :new.object_id, 0); + + if :new.context_id is not null and :new.security_inherit_p = 't' then + -- Now insert my new ancestors for my descendants. + for pair in (select * + from acs_object_context_index + where ancestor_id = :new.object_id) loop + insert into acs_object_context_index + (object_id, ancestor_id, n_generations) + select + pair.object_id, ancestor_id, + n_generations + pair.n_generations + 1 as n_generations + from acs_object_context_index + where object_id = :new.context_id; + end loop; + else + if :new.object_id != 0 then + -- We need to make sure that :NEW.OBJECT_ID and all of its + -- children have security_context_root as an ancestor. + for pair in (select * + from acs_object_context_index + where ancestor_id = :new.object_id) + loop + insert into acs_object_context_index + (object_id, ancestor_id, n_generations) + values + (pair.object_id, security_context_root, pair.n_generations + 1); + end loop; + end if; + end if; +end; +/ +show errors Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql,v diff -u -r1.41 -r1.42 --- openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql 24 Aug 2003 00:27:45 -0000 1.41 +++ openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql 25 Aug 2003 21:40:16 -0000 1.42 @@ -432,10 +432,10 @@ for outer in select object_id from acs_object_context_index where ancestor_id = old.object_id and object_id <> old.object_id loop for inner in select ancestor_id from acs_object_context_index where - object_id = old.object_id loop + object_id = old.object_id and ancestor_id <> old.object_id loop delete from acs_object_context_index where object_id = outer.object_id - and ancestor_id = inner.object_id; + and ancestor_id = inner.ancestor_id; end loop; end loop; Index: openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.0d-5.0d2.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.0d-5.0d2.sql,v diff -u -r1.2 -r1.3 --- openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.0d-5.0d2.sql 24 Aug 2003 00:27:46 -0000 1.2 +++ openacs-4/packages/acs-kernel/sql/postgresql/upgrade/upgrade-5.0d-5.0d2.sql 25 Aug 2003 21:40:16 -0000 1.3 @@ -33,10 +33,10 @@ for outer in select object_id from acs_object_context_index where ancestor_id = old.object_id and object_id <> old.object_id loop for inner in select ancestor_id from acs_object_context_index where - object_id = old.object_id loop + object_id = old.object_id and ancestor_id <> old.object_id loop delete from acs_object_context_index where object_id = outer.object_id - and ancestor_id = inner.object_id; + and ancestor_id = inner.ancestor_id; end loop; end loop;