xo::db::CrItem instproc save_new (public)
<instance of xo::db::CrItem> save_new [ -package_id package_id ] \ [ -creation_user creation_user ] [ -creation_ip creation_ip ] \ [ -context_id context_id ] [ -live_p on|off ] \ [ -use_given_publish_date on|off ]
Defined in /var/www/openacs.org/packages/xotcl-core/tcl/cr-procs.tcl
Insert a new item to the content repository.
- Switches:
- -package_id (optional)
- -creation_user (optional)
- user_id if the creating user
- -creation_ip (optional)
- -context_id (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 __class [:info class] if {![info exists package_id] && [info exists :package_id]} { set package_id ${:package_id} } if {![info exists context_id]} { set context_id [expr {[info exists :context_id] ? ${:context_id} : ""}] } [self class] get_context package_id creation_user creation_ip set :creation_user $creation_user set __atts [list creation_user] set __vars $__atts # :log "db_slots for $__class: [$__class array get db_slot]" foreach {__slot_name __slot} [$__class array get db_slot] { # :log "--slot = $__slot" if { [$__slot domain] eq "::xo::db::Object" || $__slot in { "::xo::db::CrItem::slot::name" "::xo::db::CrItem::slot::publish_date" } } continue :instvar $__slot_name if {![info exists $__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 { $__class instvar storage_type object_type [self class] lock acs_objects "SHARE ROW EXCLUSIVE" set revision_id [xo::dc nextval acs_object_id_seq] set :revision_id $revision_id if {![info exists :name] || ${:name} eq ""} { # we have an autonamed item, use a unique value for the name set :name [expr {[info exists :__autoname_prefix] ? "${:__autoname_prefix}$revision_id" : $revision_id}] } if {$title eq ""} { set title [expr {[info exists :__title_prefix] ? "${:__title_prefix} (${:name})" : ${:name}}] } 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 :item_id [::acs::dc call content_item new -name ${:name} -parent_id ${:parent_id} -creation_user $creation_user -creation_ip $creation_ip -context_id $context_id -item_subtype "content_item" -content_type $object_type -description $description -mime_type $mime_type -nls_language $nls_language -is_live f -storage_type $storage_type -package_id $package_id -with_child_rels f] if {$storage_type eq "file"} { set text [cr_create_content_file ${:item_id} $revision_id ${:import_file}] } ::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 :update_item_index } } :db_1row [:qn get_dates] { select creation_date, last_modified from acs_objects where object_id = :revision_id } set :object_id ${:item_id} return ${:item_id}XQL Not present: Generic, PostgreSQL, Oracle