Inicio de la navegación principal
Methods: | Source: | Variables: |
---|---|---|
[All Methods | Documented Methods | Hide Methods] | [Display Source | Hide Source] | [Show Variables | Hide Variables] |
Class Hierarchy of ::xo::db::CrItem
- ::xotcl::Object
![]()
- Meta-class:
- ::xotcl::Class
- Methods for instances:
- __api_make_doc, __api_make_forward_doc, __nextC, __timediff, abstract, ad_doc, ad_forward, ad_proc, appendC, arrayC, asHTML, autonameC, checkC, classC, cleanupC, configureC, contains, copy, db_1rowC, debug, defaultmethod, destroyC, destroy_on_cleanup, evalC, existsC, extractConfigureArg, filterC, filterguardC, filtersearchC, forwardC, hasclass, incrC, infoC, init, instvarC, invarC, isclassC, ismetaclassC, ismixinC, isobjectC, istypeC, lappendC, log, method, mixinC, mixinguardC, move, msg, noinitC, parametercmdC, procC, procsearchC, qn, requireNamespaceC, self, serialize, setC, substC, traceC, unsetC, uplevelC, upvarC, volatileC, vwaitC
- Methods to be applied on the class (in addition to the methods provided by the meta-class):
- __exitHandler, getExitHandler, setExitHandler, unsetExitHandler
- ::xo::db::Object
![]()
- ::xo::db::CrItem
![]()
- Meta-class:
- ::xo::db::CrClass
- Parameter for instances:
- package_id, parent_id (default "-100"), publish_status (default "ready")
- Methods for instances:
- current_user_id, delete, descriptionC, fix_content, initialize_loaded_object, item_idC, mime_typeC, nameC, nls_languageC, privilege=creator, publish_dateC, rename, revision_idC, revisions, save, save_new, set_live_revision, textC, titleC, update_attribute_from_slot, update_content, update_revision
- Methods to be applied on the class:
- Methods provided by the meta-class
Class Relations
::xo::db::CrClass create ::xo::db::CrItem \ -superclass ::xo::db::Object \ -parameter {package_id {parent_id -100} {publish_status ready}} \ -instmixin ::xo::db::CrCache::Item
::xo::db::CrItem instproc current_user_id {} { if {[my isobject ::xo::cc]} {return [::xo::cc user_id]} if {[ad_conn isconnected]} {return [ad_conn user_id]} return "" }
<instance of ::xo::db::CrItem> delete
Delete the item from the content repositiory with the item_id taken from the instance variable.
::xo::db::CrItem instproc delete {} { # delegate deletion to the class [my info class] delete -item_id [my set item_id] }
::xo::db::CrItem instproc fix_content {{-only_text false} revision_id content} { [my info class] instvar storage_type if {$storage_type eq "file"} { db_dml [my qn fix_content_length] "update cr_revisions set content_length = [file size [my set import_file]] where revision_id = $revision_id" } elseif {$storage_type eq "text"} { db_dml [my qn fix_content] "update cr_revisions set content = empty_blob(), content_length = [string length $content] where revision_id = $revision_id returning content into :1" -blobs [list $content] } if {!$only_text} { foreach {slot_name slot} [[my info class] array get long_text_slots] { my update_attribute_from_slot -revision_id $revision_id $slot [my set $slot_name] } } }
::xo::db::CrItem instproc initialize_loaded_object {} { # empty body, to be refined }
<instance of ::xo::db::CrItem> privilege=creator \ [ -login login ] user_id package_id method
Define an object specific privilege to be used in the policies. Grant access to a content item for the creator (creation_user) of the item, and for the package admin.
- Switches:
- -login (defaults to
"true"
) (optional)- Parameters:
- user_id
package_id
method
::xo::db::CrItem instproc privilege=creator {{-login true} user_id package_id method} { set allowed 0 #my log "--checking privilege [self args]" if {[my exists creation_user]} { if {[my set creation_user] == $user_id} { set allowed 1 } else { # allow the package admin always access set allowed [::xo::cc permission -object_id $package_id -party_id $user_id -privilege admin] } } return $allowed }
<instance of ::xo::db::CrItem> rename -old_name old_name \ -new_name new_name
Rename a content item
- Switches:
- -old_name (required)
- -new_name (required)
::xo::db::CrItem instproc rename {-old_name:required -new_name:required} { db_dml [my qn update_rename] "update cr_items set name = :new_name where item_id = [my item_id]" }
::xo::db::CrItem instproc revisions {} { ::TableWidget t1 -volatile -columns { Field version_number -label "" -html {align right} ImageAnchorField edit -label "" -src /resources/acs-subsite/Zoom16.gif -title "View Item" -alt "view" -width 16 -height 16 -border 0 AnchorField diff -label "" AnchorField author -label [_ file-storage.Author] Field content_size -label [_ file-storage.Size] -html {align right} Field last_modified_ansi -label [_ file-storage.Last_Modified] Field description -label [_ file-storage.Version_Notes] ImageAnchorField live_revision -label [_ xotcl-core.live_revision] -src /resources/acs-subsite/radio.gif -width 16 -height 16 -border 0 -html {align center} ImageField_DeleteIcon version_delete -label "" -html {align center} } set user_id [my current_user_id] set page_id [my set item_id] set live_revision_id [::xo::db::sql::content_item get_live_revision -item_id $page_id] my instvar package_id set base [$package_id url] set sql [::xo::db::sql select -map_function_names true -vars "ci.name, n.revision_id as version_id, person__name(n.creation_user) as author, n.creation_user as author_id, to_char(n.last_modified,'YYYY-MM-DD HH24:MI:SS') as last_modified_ansi, n.description, acs_permission__permission_p(n.revision_id,:user_id,'admin') as admin_p, acs_permission__permission_p(n.revision_id,:user_id,'delete') as delete_p, r.content_length, content_revision__get_number(n.revision_id) as version_number " -from "cr_revisionsi n, cr_items ci, cr_revisions r" -where "ci.item_id = n.item_id and ci.item_id = :page_id and r.revision_id = n.revision_id and exists (select 1 from acs_object_party_privilege_map m where m.object_id = n.revision_id and m.party_id = :user_id and m.privilege = 'read')" -orderby "n.revision_id desc"] db_foreach [my qn revisions_select] $sql { if {$content_length < 1024} { if {$content_length eq ""} {set content_length 0} set content_size_pretty "[lc_numeric $content_length] [_ file-storage.bytes]" } else { set content_size_pretty "[lc_numeric [format %.2f [expr {$content_length/1024.0}]]] [_ file-storage.kb]" } set last_modified_ansi [lc_time_system_to_conn $last_modified_ansi] if {$version_id != $live_revision_id} { set live_revision "Make this Revision Current" set live_revision_icon /resources/acs-subsite/radio.gif } else { set live_revision "Current Live Revision" set live_revision_icon /resources/acs-subsite/radiochecked.gif } set live_revision_link [export_vars -base $base {{m make-live-revision} {revision_id $version_id}}] t1 add -version_number $version_number: -edit.href [export_vars -base $base {{revision_id $version_id}}] -author $author -content_size $content_size_pretty -last_modified_ansi [lc_time_fmt $last_modified_ansi "%x %X"] -description $description -live_revision.src $live_revision_icon -live_revision.title $live_revision -live_revision.href $live_revision_link -version_delete.href [export_vars -base $base {{m delete-revision} {revision_id $version_id}}] -version_delete.title [_ file-storage.Delete_Version] [t1 last_child] set payload(revision_id) $version_id } # providing diff links to the prevision versions. This can't be done in # the first loop, since we have not yet the revision id of entry in the next line. set lines [t1 children] for {set i 0} {$i < [llength $lines]-1} {incr i} { set e [lindex $lines $i] set n [lindex $lines [expr {$i+1}]] set revision_id [$e set payload(revision_id)] set compare_revision_id [$n set payload(revision_id)] $e set diff.href [export_vars -base $base {{m diff} compare_revision_id revision_id}] $e set diff "diff" } set e [lindex $lines end] if {$e ne ""} { $e set diff.href "" $e set diff "" } return [t1 asHTML] }
<instance of ::xo::db::CrItem> save \ [ -modifying_user modifying_user ] [ -live_p on|off ] \ [ -use_given_publish_date on|off ]
Updates an item in the content repository. We insert a new revision instead of changing the current revision.
- Switches:
- -modifying_user (optional)
- -live_p (boolean) (defaults to
"true"
) (optional)- make this revision the live revision
- -use_given_publish_date (boolean) (defaults to
"false"
) (optional)
::xo::db::CrItem instproc save {-modifying_user {-live_p:boolean true} {-use_given_publish_date:boolean false}} { #my instvar creation_user set __atts [list creation_user] set __vars $__atts # 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 is 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 : [my current_user_id]}] #set old_revision_id [my set revision_id] foreach {__slot_name __slot} [[my info class] array get db_slot] { if { $__slot eq "::xo::db::Object::slot::object_title" || $__slot eq "::xo::db::CrItem::slot::name" || $__slot eq "::xo::db::CrItem::slot::publish_date" } continue my instvar $__slot_name lappend __atts [$__slot column_name] lappend __vars $__slot_name } [self class] instvar insert_view_operation db_transaction { [my info class] instvar storage_type set revision_id [db_nextval acs_object_id_seq] if {$storage_type eq "file"} { my instvar import_file set text [cr_create_content_file $item_id $revision_id $import_file] } $insert_view_operation [my qn revision_add] [[my info class] insert_statement $__atts $__vars] my fix_content $revision_id $text if {$live_p} { ::xo::db::sql::content_item set_live_revision -revision_id $revision_id -publish_status [my set publish_status] # # set_live revision updates publish_date to the current date. # In order to keep a given publish date, we have to update the # field manually. # if {$use_given_publish_date} { my update_revision $revision_id publish_date [my publish_date] } my set revision_id $revision_id } else { # if we do not make the revision live, use the old revision_id, # and let CrCache save it ...... TODO: is this still needed? comment out for testing #set revision_id $old_revision_id } } return $item_id }
<instance of ::xo::db::CrItem> save_new \ [ -package_id package_id ] [ -creation_user creation_user ] \ [ -creation_ip creation_ip ] [ -live_p on|off ] \ [ -use_given_publish_date on|off ]
Insert a new item to the content repository
- Switches:
- -package_id (optional)
- -creation_user (optional)
- user_id if the creating user
- -creation_ip (optional)
- -live_p (boolean) (defaults to
"true"
) (optional)- make this revision the live revision
- -use_given_publish_date (boolean) (defaults to
"false"
) (optional)
::xo::db::CrItem instproc save_new {-package_id -creation_user -creation_ip {-live_p:boolean true} {-use_given_publish_date:boolean false}} { set __class [my info class] my instvar parent_id item_id import_file name if {![info exists package_id] && [my exists package_id]} { set package_id [my package_id] } [self class] get_context package_id creation_user creation_ip my set creation_user $creation_user set __atts [list creation_user] set __vars $__atts #my log "db_slots for $__class: [$__class array get db_slot]" foreach {__slot_name __slot} [$__class array get db_slot] { #my log "--slot = $__slot" if { $__slot eq "::xo::db::Object::slot::object_title" || $__slot eq "::xo::db::CrItem::slot::name" || $__slot eq "::xo::db::CrItem::slot::publish_date" } continue my instvar $__slot_name if {![info exists $__slot_name]} {set $__slot_name ""} lappend __atts [$__slot column_name] lappend __vars $__slot_name } [self class] instvar insert_view_operation db_transaction { $__class instvar storage_type object_type [self class] lock acs_objects "SHARE ROW EXCLUSIVE" set revision_id [db_nextval acs_object_id_seq] if {![my exists name] || $name eq ""} { # we have an autonamed item, use a unique value for the name set name [expr {[my exists __autoname_prefix] ? "[my set __autoname_prefix]$revision_id" : $revision_id}] } if {$title eq ""} { set title [expr {[my exists __title_prefix] ? "[my set __title_prefix] ($name)" : $name}] } #my msg --[subst [[self class] set content_item__new_args]] set item_id [eval ::xo::db::sql::content_item new [[self class] set content_item__new_args]] if {$storage_type eq "file"} { set text [cr_create_content_file $item_id $revision_id $import_file] } $insert_view_operation [my qn revision_add] [[my info class] insert_statement $__atts $__vars] my fix_content $revision_id $text if {$live_p} { ::xo::db::sql::content_item set_live_revision -revision_id $revision_id -publish_status [my set publish_status] if {$use_given_publish_date} { my update_revision $revision_id publish_date [my publish_date] } } } my set revision_id $revision_id my db_1row [my qn get_dates] { select creation_date, last_modified from acs_objects where object_id = :revision_id } my set object_id $item_id return $item_id }
<instance of ::xo::db::CrItem> set_live_revision \ -revision_id revision_id [ -publish_status publish_status ]
- Switches:
- -revision_id (required)
- -publish_status (defaults to
"ready"
) (optional)- one of 'live', 'ready' or 'production'
::xo::db::CrItem instproc set_live_revision {-revision_id:required {-publish_status ready}} { ::xo::db::sql::content_item set_live_revision -revision_id $revision_id -publish_status $publish_status ::xo::clusterwide ns_cache flush xotcl_object_cache ::[my item_id] }
::xo::db::CrItem instproc update_attribute_from_slot {-revision_id slot value} { if {![info exists revision_id]} {my instvar revision_id} set domain [$slot domain] set att [$slot column_name] if {[$slot sqltype] eq "long_text"} { db_dml [my qn att-$att] "update [$domain table_name] set $att = empty_clob() where [$domain id_column] = $revision_id returning $att into :1" -clobs [list $value] } else { set sql "update [$domain table_name] set $att = :value where [$domain id_column] = $revision_id" db_dml [my qn update_attribute-$att] $sql } }
::xo::db::CrItem instproc update_content {revision_id content} { # # This method can be used to update the content field (only this) of # an content item without creating a new revision. This works # currently only for storage_type == "text". # [my info class] instvar storage_type if {$storage_type eq "file"} { my log "--update_content not implemented for type file" } else { my fix_content -only_text true $revision_id $content } }
::xo::db::CrItem instproc update_revision {{-quoted false} revision_id attribute value} { # # This method can be use to update arbitrary fields of # an revision. # if {$quoted} {set val $value} {set val :value} db_dml [my qn update_content] "update cr_revisions set $attribute = $val where revision_id = $revision_id" }
Methods: | Source: | Variables: |
---|---|---|
[All Methods | Documented Methods | Hide Methods] | [Display Source | Hide Source] | [Show Variables | Hide Variables] |