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.22.4.2 -r1.22.4.3 --- openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl 2 Oct 2013 08:42:38 -0000 1.22.4.2 +++ openacs-4/packages/acs-content-repository/tcl/content-item-procs.tcl 13 Sep 2014 15:24:28 -0000 1.22.4.3 @@ -106,7 +106,7 @@ # 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 @@ -116,39 +116,39 @@ # # db_dml lock_objects "LOCK TABLE acs_objects IN SHARE ROW EXCLUSIVE MODE" - 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 - - # since we can't rely on content_item__new to create a revision - # we have to pass is_live to content::revision::new and - # set the live revision there - if {([info exists title] && $title ne "") - || ([info exists text] && $text ne "") - || ([info exists data] && $data ne "") - || ([info exists tmp_filename] && $tmp_filename ne "") - || [llength $attributes] - } { - content::revision::new \ - -item_id $item_id \ - -title $title \ - -description $description \ - -content $text \ - -mime_type $mime_type \ - -content_type $content_type \ - -is_live $is_live \ - -package_id $package_id \ - -creation_user $creation_user \ - -creation_ip $creation_ip \ - -creation_date $creation_date \ - -nls_language $nls_language \ - -tmp_filename $tmp_filename \ - -attributes $attributes - } - } + 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 + + # since we can't rely on content_item__new to create a revision + # we have to pass is_live to content::revision::new and + # set the live revision there + if {([info exists title] && $title ne "") + || ([info exists text] && $text ne "") + || ([info exists data] && $data ne "") + || ([info exists tmp_filename] && $tmp_filename ne "") + || [llength $attributes] + } { + content::revision::new \ + -item_id $item_id \ + -title $title \ + -description $description \ + -content $text \ + -mime_type $mime_type \ + -content_type $content_type \ + -is_live $is_live \ + -package_id $package_id \ + -creation_user $creation_user \ + -creation_ip $creation_ip \ + -creation_date $creation_date \ + -nls_language $nls_language \ + -tmp_filename $tmp_filename \ + -attributes $attributes + } + } return $item_id } @@ -204,7 +204,7 @@ [list item_id $item_id] \ [list target_folder_id $target_folder_id] ] if {[info exists name] && $name ne ""} { - lappend var_list [list name $name] + lappend var_list [list name $name] } return [package_exec_plsql \ -var_list $var_list \ @@ -241,7 +241,7 @@ return [db_0or1row get_item_folder "" -column_array local_array] } set table_name [db_string get_table_name "select table_name from acs_object_types where object_type=:content_type"] - set table_name "${table_name}x" + set table_name "${table_name}x" # get attributes of the content_item use the content_typex view return [db_0or1row get_item "" -column_array local_array] } @@ -272,25 +272,25 @@ set update_text "" foreach {attribute_list} $attributes { - set attribute [lindex $attribute_list 0] - set value [lindex $attribute_list 1] - if {$attribute in $valid_attributes} { + set attribute [lindex $attribute_list 0] + set value [lindex $attribute_list 1] + if {$attribute in $valid_attributes} { - # create local variable to use for binding + # create local variable to use for binding - set $attribute $value - if {$update_text ne ""} { - append update_text "," - } - append update_text " ${attribute} = :${attribute} " - } + set $attribute $value + if {$update_text ne ""} { + append update_text "," + } + append update_text " ${attribute} = :${attribute} " } + } if {$update_text ne ""} { - # we have valid attributes, update them + # we have valid attributes, update them - set query_text "update cr_items set ${update_text} where item_id=:item_id" - db_dml item_update $query_text + set query_text "update cr_items set ${update_text} where item_id=:item_id" + db_dml item_update $query_text } } @@ -308,8 +308,8 @@ item exists } { return [package_exec_plsql \ - -var_list [list [list item_id $item_id]] \ - content_item get_content_type] + -var_list [list [list item_id $item_id]] \ + content_item get_content_type] } @@ -375,12 +375,12 @@ revisions, returns an empty string. @param item_id The item_id of the content item - + @return The best revision_id for the item, or an empty string if no revisions exist @see content::revision::item_id - @see content::item::get_live_revision + @see content::item::get_live_revision @see content::item::get_latest_revision } { return [package_exec_plsql -var_list [list \ @@ -393,15 +393,15 @@ } { Retrieves the latest revision for the item. If the item has no live revision, returns an empty string. - + @param item_id The item_id of the content item - + @return The latest revision_id for the item, or an empty string if no revisions exist @see content::revision::item_id @see content::item::get_best_revision - @see content::item::get_live_revision + @see content::item::get_live_revision } { return [package_exec_plsql -var_list [list \ [list item_id $item_id ] \ @@ -414,15 +414,15 @@ } { Retrieves the live revision for the item. If the item has no live revision, returns an empty string. - + @param item_id The item_id of the content item - + @return The live revision_id for the item, or an empty string if no live revision exists @see content::revision::item_id - @see content::item::get_best_revision - @see content::item::get_latest_revision + @see content::item::get_best_revision + @see content::item::get_latest_revision } { return [package_exec_plsql -var_list [list \ [list item_id $item_id ] \ @@ -509,10 +509,10 @@ a template registered directly to the item, returns the id of that template. Otherwise, returns the id of the default template registered to the item's content_type. Returns an empty string on failure. - + @param item_id The item_id @param context The context in which the template will be used (e.g. public) - + @return The template_id of the template which can be used to render the item, or an empty string on failure } { @@ -529,12 +529,12 @@ } { Get the title for the item. If a live revision for the item exists, use the live revision. Otherwise, use the latest revision. - + @param item_id The item_id of the content item @param is_live - + @return The title of the item - + @see content::item::get_best_revision @see content::item::get_title } { @@ -550,8 +550,8 @@ {-root_folder_id ""} } { Retrieves the relative path to the item. The path is relative to the - page root, and has no extension (Example: "/foo/bar/baz"). - + page root, and has no extension (Example: "/foo/bar/baz"). + @param item_id The item_id for the item, for which the path is computed @param root_folder_id Starts path resolution from this folder. Defaults to the root of the sitemap (when null). @@ -592,11 +592,11 @@ (according to min_n and max_n)
+ The datasource will contain a column called "text", representing the + main content (blob) of the revision, but only if the revision has a + textual mime-type. + + @param revision_id The revision whose attributes are to be retrieved + + @param item_id The item_id of the + corresponding item. You can provide this as an optimization. + If you don't provide revision_id, you must provide item_id, + and the item must have a live revision. + + @return 1 on success (and set the array in the calling frame), + 0 on failure + + @see proc content::item::get_content_type + +} { + upvar 1 $array content + + if { $item_id eq "" } { + set item_id [::content::revision::item_id -revision_id $revision_id] + if { $item_id eq "" } { + ns_log notice "item::get_content: no such revision: $revision_id" + return 0 + } + } elseif { $revision_id eq "" } { + set revision_id [::content::item::get_live_revision -item_id $item_id] + } + if { $revision_id eq "" } { + error "You must supply revision_id, or the item must have a live revision." + } + + return [content::item::get_revision_content -revision_id $revision_id -item_id $item_id] +} + +# +# +# +ad_proc -public content::item::get_revision_content { -revision_id:required -item_id } { + + Create a onerow datasource called content in the calling frame + which contains all attributes for the revision (including inherited + ones). + + The datasource will contain a column called "text", representing the + main content (blob) of the revision, but only if the revision has a + textual mime-type. + + @param revision_id The revision whose attributes are to be retrieved + @param item_id The item_id of the corresponding item. + + @return 1 on success (and create a content array in the calling frame), + 0 on failure + + @see content::item::get_content_type + +} { + + if { ![info exists item_id] } { + # Get the item id + set item_id [::content::revision::item_id -revision_id $revision_id] + + if { $item_id eq "" } { + ns_log warning "item::get_revision_content: No such revision: $revision_id" + return 0 + } + } + + # Get the mime type, decide if we want the text + content::item::get -item_id $item_id -array_name item_info + + if { [info exists item_info(mime_type)] + && $item_info(mime_type) ne "" + && [string match "text/*" $item_info(mime_type)] + } { + set text_sql [db_map grc_get_all_content_1] + } else { + set text_sql "" + } + + # Get the content type + set content_type $item_info(content_type) + + # Get the table name + set table_name [db_string grc_get_table_names { + select table_name from acs_object_types + where object_type = :content_type + }] + + upvar content content + + # Get (all) the content (note this is really dependent on file type) + db_0or1row grc_get_all_content [subst { + select x.*, + :item_id as item_id $text_sql, + :content_type as content_type + from cr_revisions r, ${table_name}x x + where r.revision_id = :revision_id + and x.revision_id = r.revision_id + }] -column_array content + + if { ![array exists content] } { + ns_log warning "item::get_revision_content: No data found for item $item_id, revision $revision_id" + return 0 + } + + return 1 +} + +# +# +# +ad_proc -public content::item::publish { + {-item_id:required} + {-revision_id ""} +} { + Publish a content item. Updates the live_revision and publish_date attributes, and + sets publish_status to live. + + @param item_id The id of the content item + @param revision_id The id of the revision to publish. Defaults to the latest revision. + + @author Peter Marklund +} { + if { $revision_id eq "" } { + set revision_id [::content::item::get_latest_revision -item_id $item_id] + } + ::content::item::set_live_revision -revision_id $revision_id -publish_status "live" +} + +# +# +# +ad_proc -public content::item::unpublish { + {-item_id:required} + {-publish_status "production"} +} { + Unpublish a content item. + + @param item_id The id of the content item + @param publish_status The publish_status to put the item in after unpublishing it. + + @author Peter Marklund +} { + ::content::item::set_live_revision -item_id $item_id + ::content::item::update -item_id $item_id -attributes [list [list publish_status $publish_status]] +} + + +# +# Local variables: +# mode: tcl +# tcl-indent-level: 4 +# indent-tabs-mode: nil +# End: