Index: openacs-4/packages/xotcl-core/tcl/generic-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-core/tcl/generic-procs.tcl,v diff -u -r1.56 -r1.57 --- openacs-4/packages/xotcl-core/tcl/generic-procs.tcl 17 Apr 2007 08:40:15 -0000 1.56 +++ openacs-4/packages/xotcl-core/tcl/generic-procs.tcl 9 May 2007 18:36:10 -0000 1.57 @@ -162,8 +162,6 @@ register the current object type for folder_id. If folder_id is not specified, use the instvar of the class instead. } { - #set operation [string toupper $operation] - #if {$operation ne "REGISTER" && $operation ne "UNREGISTER"} if {$operation ne "register" && $operation ne "unregister"} { error "[self] operation for folder_type must be 'register' or 'unregister'" } @@ -175,11 +173,34 @@ -folder_id $folder_id \ -content_type $object_type \ -include_subtypes t -# ::xo::db::CONTENT_FOLDER ${operation}_CONTENT_TYPE { -# folder_id {content_type $object_type} {include_subtypes t} -# } } + CrClass instproc create_attributes {} { + if {[my cr_attributes] ne ""} { + my instvar object_type + set o [::xo::OrderedComposite new -contains [my cr_attributes]] + $o destroy_on_cleanup + set parameters [list] + foreach att [$o children] { + $att instvar attribute_name datatype pretty_name sqltype default + if {![attribute::exists_p $object_type $attribute_name]} { + ::xo::db::content_type create_attribute \ + -content_type $object_type \ + -attribute_name $attribute_name \ + -datatype $datatype \ + -pretty_name $pretty_name \ + -column_spec $sqltype + } + if {![info exists default]} { + set default "" + } + lappend parameters [list $attribute_name default] + unset default + } + my parameter $parameters + } + } + CrClass ad_instproc create_object_type {} { Create an oacs object_type and a table for keeping the additional attributes. @@ -194,10 +215,6 @@ } db_transaction { -# ::xo::db::CONTENT_TYPE CREATE_TYPE { -# {content_type $object_type} supertype pretty_name pretty_plural -# table_name id_column name_method -# } ::xo::db::content_type create_type \ -content_type $object_type \ -supertype $supertype \ @@ -207,29 +224,13 @@ -id_column $id_column \ -name_method $name_method - if {[my cr_attributes] ne ""} { - set o [::xo::OrderedComposite new -contains [my cr_attributes]] - $o destroy_on_cleanup - foreach att [$o children] { - $att instvar attribute_name datatype pretty_name sqltype - - ::xo::db::content_type create_attribute \ - -content_type $object_type \ - -attribute_name $attribute_name \ - -datatype $datatype \ - -pretty_name $pretty_name \ - -column_spec $sqltype - -# ::xo::db::CONTENT_TYPE CREATE_ATTRIBUTE { -# {content_type $object_type} attribute_name datatype -# pretty_name {column_spec $sqltype} -# } - } - } + my create_attributes my folder_type register } } + + CrClass ad_instproc drop_object_type {} { Delete the object type and remove the table for the attributes. This method should be called when all instances are deleted. It @@ -356,6 +357,10 @@ if {![my object_type_exists]} { my create_object_type + } else { + db_transaction { + my create_attributes + } } next @@ -588,7 +593,10 @@ return $__result } - Class create Attribute -parameter {attribute_name datatype pretty_name {sqltype "text"}} + Class create Attribute -parameter { + attribute_name datatype pretty_name {sqltype "text"} + default + } Class create CrItem -parameter { package_id