Index: openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl,v diff -u -r1.7.2.2 -r1.7.2.3 --- openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl 30 Dec 2004 21:01:26 -0000 1.7.2.2 +++ openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl 3 Jan 2005 16:38:02 -0000 1.7.2.3 @@ -36,13 +36,16 @@ @creation-date 2004-05-28 Create a new content item This proc creates versioned content - items where content_type iscontent_revision or subtypes of content - revision. There are procedures for each other base content - item. This procdedure uses package_instantiate object. Under - PostgreSQL the object_type new function must be registered with - define_function_args. If title, description, text, or data are - specified a content revision will also be created. - +items where content_type iscontent_revision or subtypes of content +revision. There are procedures for each other base content +item. This procdedure uses package_instantiate object. Under +PostgreSQL the object_type new function must be registered with +define_function_args. For correct creation of extended content types pass +title and content in the attributes paramter which will cause +content::revision::new to be called and create a proper extended +content type revision. + If title, text, or data are specified a +content revision will also be created. @param name @param item_id - item_id of this content_item. If this is not @@ -59,7 +62,10 @@ @param title - title of content_revision to be created @param description of content_revision to be created @param text - text of content revision to be created - @param attributes - A list of pairs of additional attributes and their values to pass to the constructor. Each pair is a list of two elements: key => value + @param attributes - A list of pairs of additional attributes and + their values to pass to the constructor. Each pair is a list of two + elements: key => value such as + [list attribute value attribute value] @return item_id of the new content item @@ -77,29 +83,44 @@ [list creation_ip $creation_ip ] \ [list item_subtype $item_subtype ] \ [list content_type $content_type ] \ - [list title $title ] \ - [list description $description ] \ [list mime_type $mime_type ] \ [list nls_language $nls_language ] \ - [list text $text ] \ - [list data $data ] \ [list relation_tag $relation_tag ] \ [list is_live $is_live ] \ [list storage_type $storage_type] + # we don't pass title, text, or data to content_item__new + # because the magic revision creation of the pl/sql proc does + # not create a proper subtype of content revision, also it + # can't set attributes of an extended type + # the content type is not the object type of the cr_item so we pass in # the cr_item subtype here and content_type as part of # var_list - ns_log Debug " -DB -------------------------------------------------------------------------------- -DB DAVE debugging /var/lib/aolserver/ctk/packages/acs-content-repository/tcl/content-item-procs.tcl -DB -------------------------------------------------------------------------------- -DB var_list = '${var_list}' -DB --------------------------------------------------------------------------------" + set item_id [package_exec_plsql \ -var_list $var_list \ content_item new] + # if we have attributes we pass in everything + # and create a revision with all subtype attributes that were + # passed in + + if {[exists_and_not_null title] \ + || [exists_and_not_null text] \ + || [exists_and_not_null data] \ + || [llength $attributes]} { + content::revision::new \ + -item_id $item_id \ + -title $title \ + -description $description \ + -content $text \ + -mime_type $mime_type \ + -content_type $content_type \ + -attributes $attributes + } + return $item_id + } ad_proc -public ::content::item::delete { 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.6.2.2 -r1.6.2.3 --- openacs-4/packages/acs-content-repository/tcl/content-type-procs.tcl 29 Dec 2004 20:46:12 -0000 1.6.2.2 +++ openacs-4/packages/acs-content-repository/tcl/content-type-procs.tcl 3 Jan 2005 16:38:02 -0000 1.6.2.3 @@ -20,7 +20,7 @@ -pretty_name:required -pretty_plural:required {-table_name ""} - {-id_column ""} + -id_column:required {-name_method ""} } { @param content_type Index: openacs-4/packages/acs-content-repository/tcl/test/content-item-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/tcl/test/content-item-test-procs.tcl,v diff -u -r1.2.2.2 -r1.2.2.3 --- openacs-4/packages/acs-content-repository/tcl/test/content-item-test-procs.tcl 30 Dec 2004 21:01:26 -0000 1.2.2.2 +++ openacs-4/packages/acs-content-repository/tcl/test/content-item-test-procs.tcl 3 Jan 2005 16:38:02 -0000 1.2.2.3 @@ -10,8 +10,6 @@ } -# FIXME DaveB Write some tests! - aa_register_case content_item { content item test } { @@ -46,14 +44,14 @@ -name "test_item_one" \ -item_id $first_item_id \ -parent_id $first_folder_id \ - -title "Title" + -attributes [list title "Title"] ] aa_true "First item created" [expr $first_item_id == $returned_first_item_id] aa_true "First item exists" [expr $first_item_id == \ [db_string get_item \ "select item_id from - cr_items where item_id=:first_item_id"]] + cr_items where item_id=:first_item_id and name='test_item_one'"]] aa_true "First item's revision exists" \ [expr \ {![string equal "" \ @@ -65,6 +63,49 @@ set is_empty [content::folder::is_empty -folder_id $first_folder_id] aa_true "Folder 1 is not empty" [string is false $is_empty] + + # create a new content type + set new_type_id [content::type::new \ + -content_type "__test_type" \ + -pretty_name "__test_type" \ + -pretty_plural "__test_type" \ + -table_name "__test_type" \ + -id_column "test_id"] + + # todo test that new item is NOT allowed to be created + # unless registered by catching error when creating new + # item + + # register new type to folder + content::folder::register_content_type \ + -folder_id $first_folder_id \ + -content_type "__test_type" + # create an item of that type + set new_type_item_id [db_nextval "acs_object_id_seq"] + set returned_new_type_item_id [content::item::new \ + -name "test_item_${new_type_item_id}" \ + -item_id $new_type_item_id \ + -parent_id $first_folder_id \ + -content_type "__test_type" \ + -attributes [list title "Title"]] + + # check that the item exists + + aa_true "New Type item created" [expr $new_type_item_id == $returned_new_type_item_id] + aa_true "New Type item exists" [expr $new_type_item_id == \ + [db_string get_item \ + "select item_id from + cr_items where item_id=:new_type_item_id and name='test_item_${new_type_item_id}'" -default ""]] + + # check that the extended attributes and the revision + # exist + aa_true "First item's revision exists" \ + [expr \ + {![string equal "" \ + [db_string get_revision "select + latest_revision + from cr_items, __test_typex where latest_revision=test_id and cr_items.item_id=:new_type_item_id" -default ""]]}] + # copy it # move the copy