xo::db::CrItem instproc save (public)
<instance of xo::db::CrItem> save \ [ -modifying_user modifying_user ] [ -live_p on|off ] \ [ -use_given_publish_date on|off ]
Defined in /var/www/openacs.org/packages/xotcl-core/tcl/cr-procs.tcl
Updates an item in the content repository. We insert a new revision instead of changing the current revision.
- Switches:
- -modifying_user (optional)
- -live_p (optional, boolean, defaults to
"true"
)- make this revision the live revision
- -use_given_publish_date (optional, boolean, defaults to
"false"
)- Testcases:
- xotcl_core_tutorial_4, test_cr_items
Source code: set __atts [list creation_user] set __vars $__atts if {[ns_conn isconnected]} { lappend __atts creation_ip set peeraddr [ad_conn peeraddr] lappend __vars peeraddr } # # The modifying_user is not maintained by the CR (bug?). # xotcl-core handles this by having the modifying user as # creation_user of the revision. # # Caveat: the creation_user fetched can be different if we fetch # via item_id (the creation_user is the creator of the item) or if # we fetch via revision_id (the creation_user is the creator of # the revision). set creation_user [expr {[info exists modifying_user] ? $modifying_user : [:current_user_id]}] #set old_revision_id ${:revision_id} foreach {__slot_name __slot} [[:info class] array get db_slot] { if { [$__slot domain] eq "::xo::db::Object" || $__slot in { "::xo::db::CrItem::slot::name" "::xo::db::CrItem::slot::publish_date" } } continue #ns_log notice "REMAINING SLOT: [$__slot serialize]" set $__slot_name [set :$__slot_name] lappend __atts [$__slot column_name] lappend __vars $__slot_name } if {$use_given_publish_date} { if {"publish_date" ni $__atts} { set publish_date ${:publish_date} lappend __atts publish_date lappend __vars publish_date } set publish_date_flag [list -publish_date $publish_date] } else { set publish_date_flag "" } ::xo::dc transaction { # # Provide a row-lock to protect against deadlocks during # concurrent updates on the same item in different threads. # ::xo::dc row_lock -for "no key update" -prepare integer item_lock { select item_id from cr_items where item_id = :item_id } [:info class] instvar storage_type set revision_id [xo::dc nextval acs_object_id_seq] if {$storage_type eq "file"} { # # Get the mime_type from the file, eventually creating a new # one if it's unrecognized. # set :mime_type [cr_check_mime_type -mime_type ${:mime_type} -filename ${:name} -file ${:import_file}] set :text [cr_create_content_file $item_id $revision_id ${:import_file}] set text ${:text} set mime_type ${:mime_type} } ::xo::dc [::xo::dc insert-view-operation] revision_add [[:info class] insert_statement $__atts $__vars] :fix_content $revision_id $text if {$live_p} { # # Update the life revision with the publish status and # optionally the "publish_date". # ::acs::dc call content_item set_live_revision -revision_id $revision_id -publish_status ${:publish_status} -is_latest true {*}$publish_date_flag set :revision_id $revision_id :update_item_index } else { # # If we do not make the revision live, use the old # revision_id, and let CrCache save it ...... # } # # Update instance variables "modifying_user" and "last_modified" # from potentially changed DB values. # set :modifying_user $creation_user ::xo::dc 1row -prepare integer get_metadata { select last_modified from acs_objects where object_id = :revision_id } set :last_modified $last_modified # # In case the context_id has in the DB is different as in the # instance variable, push the value from the instance variable # to the DB as well. # if {[info exists :context_id]} { set context_id ${:context_id} ::xo::dc dml update_context { UPDATE acs_objects SET context_id = :context_id WHERE object_id = :item_id AND context_id != :context_id } } } return $item_idXQL Not present: Generic, PostgreSQL, Oracle