Index: openacs-4/packages/acs-content-repository/acs-content-repository.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/acs-content-repository.info,v diff -u -r1.61 -r1.62 --- openacs-4/packages/acs-content-repository/acs-content-repository.info 26 Jul 2006 20:52:47 -0000 1.61 +++ openacs-4/packages/acs-content-repository/acs-content-repository.info 24 Sep 2006 11:37:04 -0000 1.62 @@ -7,7 +7,7 @@ t t - + OpenACS The canonical repository for OpenACS content. @@ -21,8 +21,8 @@ other CMS backing functionality. Utilized by Bug Tracker, File Storage, and other packages. - - + + Index: openacs-4/packages/acs-content-repository/sql/oracle/content-type.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/oracle/content-type.sql,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-content-repository/sql/oracle/content-type.sql 8 Jun 2005 20:58:59 -0000 1.7 +++ openacs-4/packages/acs-content-repository/sql/oracle/content-type.sql 24 Sep 2006 11:37:04 -0000 1.8 @@ -200,7 +200,134 @@ end drop_type; +procedure drop_type ( + content_type in acs_object_types.object_type%TYPE, + drop_children_p in char default 'f', + drop_table_p in char default 'f', + drop_objects_p in char default 'f' +) is + + cursor attribute_cur is + select + attribute_name + from + acs_attributes + where + object_type = drop_type.content_type; + + cursor child_type_cur is + select + object_type + from + acs_object_types + where + supertype = drop_type.content_type; + + cursor revision_cur is + select revision_id + from cr_revisions, acs_objects + where revision_id = object_id + and object_type = drop_type.content_type; + + cursor item_cur is + select item_id + from cr_items + where content_type = drop_type.content_type; + + table_exists integer; + v_table_name varchar2(50); + is_subclassed_p char; + + +begin + + + -- first we'll rid ourselves of any dependent child types, if any , along with their + -- own dependent grandchild types + select + decode(count(*),0,'f','t') into is_subclassed_p + from + acs_object_types + where supertype = drop_type.content_type; + + -- this is weak and will probably break; + -- to remove grand child types, the process will probably + -- require some sort of querying for drop_type + -- methods within the children's packages to make + -- certain there are no additional unanticipated + -- restraints preventing a clean drop + + if drop_children_p = 't' and is_subclassed_p = 't' then + + for child_rec in child_type_cur loop + drop_type( + content_type => child_rec.object_type, + drop_children_p => 't', + drop_table_p => drop_table_p, + drop_objects_p => drop_objects_p ); + end loop; + + end if; + + -- now drop all the attributes related to this type + for attr_row in attribute_cur loop + drop_attribute( + content_type => drop_type.content_type, + attribute_name => attr_row.attribute_name + ); + end loop; + + -- we'll remove the associated table if it exists + select + decode(count(*),0,0,1) into table_exists + from + user_tables u, acs_object_types objet + where + objet.object_type = drop_type.content_type and + u.table_name = upper(objet.table_name); + + if table_exists = 1 and drop_table_p = 't' then + select + table_name into v_table_name + from + acs_object_types + where + object_type = drop_type.content_type; + + -- drop the input/output views for the type + -- being dropped. + -- FIXME: does the trigger get dropped when the + -- view is dropped? This did not exist in the 4.2 release, + -- and it needs to be tested. + + + execute immediate 'drop view ' || v_table_name || 'x'; + execute immediate 'drop view ' || v_table_name || 'i'; + + execute immediate 'drop table ' || v_table_name; + + end if; + + if drop_objects_p = 't' then + for revision_row in revision_cur loop + content_revision.delete( + revision_id => revision_row.revision_id + ); + end loop; + for item_row in item_cur loop + content_item.delete( + item_id => item_row.item_id + ); + end loop; + end if; + + acs_object_type.drop_type( + object_type => drop_type.content_type + ); + +end drop_type; + function create_attribute ( content_type in acs_attributes.object_type%TYPE, attribute_name in acs_attributes.attribute_name%TYPE, Index: openacs-4/packages/acs-content-repository/sql/oracle/upgrade/upgrade-5.3.0d2-5.3.0d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/oracle/upgrade/upgrade-5.3.0d2-5.3.0d3.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-content-repository/sql/oracle/upgrade/upgrade-5.3.0d2-5.3.0d3.sql 24 Sep 2006 11:37:04 -0000 1.1 @@ -0,0 +1,127 @@ +procedure drop_type ( + content_type in acs_object_types.object_type%TYPE, + drop_children_p in char default 'f', + drop_table_p in char default 'f', + drop_objects_p in char default 'f' +) is + + + cursor attribute_cur is + select + attribute_name + from + acs_attributes + where + object_type = drop_type.content_type; + + cursor child_type_cur is + select + object_type + from + acs_object_types + where + supertype = drop_type.content_type; + + cursor revision_cur is + select revision_id + from cr_revisions, acs_objects + where revision_id = object_id + and object_type = drop_type.content_type; + + cursor item_cur is + select item_id + from cr_items + where content_type = drop_type.content_type; + + table_exists integer; + v_table_name varchar2(50); + is_subclassed_p char; + + +begin + + + -- first we'll rid ourselves of any dependent child types, if any , along with their + -- own dependent grandchild types + select + decode(count(*),0,'f','t') into is_subclassed_p + from + acs_object_types + where supertype = drop_type.content_type; + + -- this is weak and will probably break; + -- to remove grand child types, the process will probably + -- require some sort of querying for drop_type + -- methods within the children's packages to make + -- certain there are no additional unanticipated + -- restraints preventing a clean drop + + if drop_children_p = 't' and is_subclassed_p = 't' then + + for child_rec in child_type_cur loop + drop_type( + content_type => child_rec.object_type, + drop_children_p => 't', + drop_table_p => drop_table_p, + drop_objects_p => drop_objects_p ); + end loop; + + end if; + + -- now drop all the attributes related to this type + for attr_row in attribute_cur loop + drop_attribute( + content_type => drop_type.content_type, + attribute_name => attr_row.attribute_name + ); + end loop; + + -- we'll remove the associated table if it exists + select + decode(count(*),0,0,1) into table_exists + from + user_tables u, acs_object_types objet + where + objet.object_type = drop_type.content_type and + u.table_name = upper(objet.table_name); + + if table_exists = 1 and drop_table_p = 't' then + select + table_name into v_table_name + from + acs_object_types + where + object_type = drop_type.content_type; + + -- drop the input/output views for the type + -- being dropped. + -- FIXME: does the trigger get dropped when the + -- view is dropped? This did not exist in the 4.2 release, + -- and it needs to be tested. + + + execute immediate 'drop view ' || v_table_name || 'x'; + execute immediate 'drop view ' || v_table_name || 'i'; + + execute immediate 'drop table ' || v_table_name; + + end if; + + if drop_objects_p = 't' then + for revision_row in revision_cur loop + content_revision.delete( + revision_id => revision_row.revision_id + ); + end loop; + for item_row in item_cur loop + content_item.delete( + item_id => item_row.item_id + ); + end loop; + end if; + + acs_object_type.drop_type( + object_type => drop_type.content_type + ); + +end drop_type; Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-type.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-type.sql,v diff -u -r1.46 -r1.47 --- openacs-4/packages/acs-content-repository/sql/postgresql/content-type.sql 26 Jul 2006 20:52:47 -0000 1.46 +++ openacs-4/packages/acs-content-repository/sql/postgresql/content-type.sql 24 Sep 2006 11:37:05 -0000 1.47 @@ -101,6 +101,126 @@ return 0; end;' language 'plpgsql'; +select define_function_args('content_type__drop_type','content_type,drop_children_p;f,drop_table_p;f,drop_objects_p;f'); + +create or replace function content_type__drop_type (varchar,boolean,boolean,boolean) +returns integer as ' +declare + drop_type__content_type alias for $1; + drop_type__drop_children_p alias for $2; -- default ''f'' + drop_type__drop_table_p alias for $3; -- default ''f'' + drop_type__drop_objects_p alias for $4; -- default ''f'' + table_exists_p boolean; + v_table_name varchar; + is_subclassed_p boolean; + child_rec record; + attr_row record; + revision_row record; + item_row record; +begin + + -- first we''ll rid ourselves of any dependent child types, if any , + -- along with their own dependent grandchild types + + select + count(*) > 0 into is_subclassed_p + from + acs_object_types + where supertype = drop_type__content_type; + + -- this is weak and will probably break; + -- to remove grand child types, the process will probably + -- require some sort of querying for drop_type + -- methods within the children''s packages to make + -- certain there are no additional unanticipated + -- restraints preventing a clean drop + + if drop_type__drop_children_p and is_subclassed_p then + + for child_rec in select + object_type + from + acs_object_types + where + supertype = drop_type__content_type + LOOP + PERFORM content_type__drop_type(child_rec.object_type, ''t'', drop_type__drop_table_p, drop_type__drop_objects_p); + end LOOP; + + end if; + + -- now drop all the attributes related to this type + for attr_row in select + attribute_name + from + acs_attributes + where + object_type = drop_type__content_type + LOOP + PERFORM content_type__drop_attribute(drop_type__content_type, + attr_row.attribute_name, + ''f'' + ); + end LOOP; + + -- we''ll remove the associated table if it exists + select + table_exists(lower(table_name)) into table_exists_p + from + acs_object_types + where + object_type = drop_type__content_type; + + if table_exists_p and drop_type__drop_table_p then + select + table_name into v_table_name + from + acs_object_types + where + object_type = drop_type__content_type; + + -- drop the rule and input/output views for the type + -- being dropped. + -- FIXME: this did not exist in the oracle code and it needs to be + -- tested. Thanks to Vinod Kurup for pointing this out. + -- The rule dropping might be redundant as the rule might be dropped + -- when the view is dropped. + + -- different syntax for dropping a rule in 7.2 and 7.3 so check which + -- version is being used (olah). + + execute ''drop table '' || v_table_name || '' cascade''; + + end if; + + -- If we are dealing with a revision, delete the revision with revision__delete + -- This way the integrity constraint with live revision is dealt with correctly + if drop_type__drop_objects_p then + for revision_row in + select revision_id + from cr_revisions, acs_objects + where revision_id = object_id + and object_type = drop_type__content_type + loop + PERFORM content_revision__delete(revision_row.revision_id); + end loop; + + for item_row in + select item_id + from cr_items + where content_type = drop_type__content_type + loop + PERFORM content_item__delete(item_row.item_id); + end loop; + + end if; + + PERFORM acs_object_type__drop_type(drop_type__content_type, drop_type__drop_objects_p); + + return 0; +end;' language 'plpgsql'; + + select define_function_args('content_type__drop_type','content_type,drop_children_p;f,drop_table_p;f'); create or replace function content_type__drop_type (varchar,boolean,boolean) Index: openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.3.0d2-5.3.0d3.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.3.0d2-5.3.0d3.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/acs-content-repository/sql/postgresql/upgrade/upgrade-5.3.0d2-5.3.0d3.sql 24 Sep 2006 11:37:05 -0000 1.1 @@ -0,0 +1,118 @@ +select define_function_args('content_type__drop_type','content_type,drop_children_p;f,drop_table_p;f,drop_objects_p;f'); + +create or replace function content_type__drop_type (varchar,boolean,boolean,boolean) +returns integer as ' +declare + drop_type__content_type alias for $1; + drop_type__drop_children_p alias for $2; -- default ''f'' + drop_type__drop_table_p alias for $3; -- default ''f'' + drop_type__drop_objects_p alias for $4; -- default ''f'' + table_exists_p boolean; + v_table_name varchar; + is_subclassed_p boolean; + child_rec record; + attr_row record; + revision_row record; + item_row record; +begin + + -- first we''ll rid ourselves of any dependent child types, if any , + -- along with their own dependent grandchild types + + select + count(*) > 0 into is_subclassed_p + from + acs_object_types + where supertype = drop_type__content_type; + + -- this is weak and will probably break; + -- to remove grand child types, the process will probably + -- require some sort of querying for drop_type + -- methods within the children''s packages to make + -- certain there are no additional unanticipated + -- restraints preventing a clean drop + + if drop_type__drop_children_p and is_subclassed_p then + + for child_rec in select + object_type + from + acs_object_types + where + supertype = drop_type__content_type + LOOP + PERFORM content_type__drop_type(child_rec.object_type, ''t'', drop_type__drop_table_p, drop_type__drop_objects_p); + end LOOP; + + end if; + + -- now drop all the attributes related to this type + for attr_row in select + attribute_name + from + acs_attributes + where + object_type = drop_type__content_type + LOOP + PERFORM content_type__drop_attribute(drop_type__content_type, + attr_row.attribute_name, + ''f'' + ); + end LOOP; + + -- we''ll remove the associated table if it exists + select + table_exists(lower(table_name)) into table_exists_p + from + acs_object_types + where + object_type = drop_type__content_type; + + if table_exists_p and drop_type__drop_table_p then + select + table_name into v_table_name + from + acs_object_types + where + object_type = drop_type__content_type; + + -- drop the rule and input/output views for the type + -- being dropped. + -- FIXME: this did not exist in the oracle code and it needs to be + -- tested. Thanks to Vinod Kurup for pointing this out. + -- The rule dropping might be redundant as the rule might be dropped + -- when the view is dropped. + + -- different syntax for dropping a rule in 7.2 and 7.3 so check which + -- version is being used (olah). + + execute ''drop table '' || v_table_name || '' cascade''; + + end if; + + -- If we are dealing with a revision, delete the revision with revision__delete + -- This way the integrity constraint with live revision is dealt with correctly + if drop_type__drop_objects_p then + for revision_row in + select revision_id + from cr_revisions, acs_objects + where revision_id = object_id + and object_type = drop_type__content_type + loop + PERFORM content_revision__delete(revision_row.revision_id); + end loop; + + for item_row in + select item_id + from cr_items + where content_type = drop_type__content_type + loop + PERFORM content_item__delete(item_row.item_id); + end loop; + + end if; + + PERFORM acs_object_type__drop_type(drop_type__content_type, drop_type__drop_objects_p); + + return 0; +end;' language 'plpgsql'; Index: openacs-4/packages/acs-content-repository/tcl/content-type-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/content-type-procs.tcl,v diff -u -r1.7 -r1.8 --- openacs-4/packages/acs-content-repository/tcl/content-type-procs.tcl 21 Jan 2005 14:25:07 -0000 1.7 +++ openacs-4/packages/acs-content-repository/tcl/content-type-procs.tcl 24 Sep 2006 11:37:05 -0000 1.8 @@ -47,16 +47,27 @@ -content_type:required {-drop_children_p ""} {-drop_table_p ""} + {-drop_objects_p "f"} } { @param content_type @param drop_children_p @param drop_table_p + @param drop_objets_p Drop the objects of this content type along with all entries in cr_items and cr_revisions. Will not be done by default. } { - return [package_exec_plsql -var_list [list \ - [list content_type $content_type ] \ - [list drop_children_p $drop_children_p ] \ - [list drop_table_p $drop_table_p ] \ - ] content_type drop_type] + if {$drop_objects_p eq "f"} { + return [package_exec_plsql -var_list [list \ + [list content_type $content_type ] \ + [list drop_children_p $drop_children_p ] \ + [list drop_table_p $drop_table_p ] \ + ] content_type drop_type] + } else { + return [package_exec_plsql -var_list [list \ + [list content_type $content_type ] \ + [list drop_children_p $drop_children_p ] \ + [list drop_table_p $drop_table_p ] \ + [list drop_objects_p $drop_objects_p ] \ + ] content_type drop_type] + } } ad_proc -public content::type::attribute::new {