content::revision::new (public)

 content::revision::new [ -revision_id revision_id ] -item_id item_id \
    [ -title title ] [ -description description ] [ -content content ] \
    [ -mime_type mime_type ] [ -publish_date publish_date ] \
    [ -nls_language nls_language ] [ -creation_date creation_date ] \
    [ -content_type content_type ] [ -creation_user creation_user ] \
    [ -creation_ip creation_ip ] [ -package_id package_id ] \
    [ -attributes attributes ] [ -is_live is_live ] \
    [ -tmp_filename tmp_filename ] [ -storage_type storage_type ]

Defined in packages/acs-content-repository/tcl/content-revision-procs.tcl

Adds a new revision of a content item. If content_type is not passed in, we determine it from the content item. This is needed to find the attributes for the content type.

Switches:
-revision_id (optional)
-item_id (required)
-title (optional)
-description (optional)
-content (optional)
-mime_type (optional)
-publish_date (optional)
-nls_language (optional)
-creation_date (optional)
-content_type (optional)
-creation_user (optional)
-creation_ip (optional)
-package_id (optional)
Package_id content belongs to
-attributes (optional)
A list of lists 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 [list attribute value] [list attribute value]]
-is_live (optional, defaults to "f")
True is revision should be set live
-tmp_filename (optional)
file containing content to be added to revision. The caller is responsible for cleaning up the temporary file.
-storage_type (optional)
Returns:
Error:
Author:
Dave Bauer <dave@thedesignexperience.org>
Created:
2004-06-04

Partial Call Graph (max 5 caller/called nodes):
%3 test_content_image content_image (test acs-content-repository) content::revision::new content::revision::new test_content_image->content::revision::new test_content_revision content_revision (test acs-content-repository) test_content_revision->content::revision::new acs_object_type::get_table_name acs_object_type::get_table_name (public) content::revision::new->acs_object_type::get_table_name ad_conn ad_conn (public) content::revision::new->ad_conn content::item::get_content_type content::item::get_content_type (public) content::revision::new->content::item::get_content_type content::item::set_live_revision content::item::set_live_revision (public) content::revision::new->content::item::set_live_revision content::revision::update_content content::revision::update_content (private) content::revision::new->content::revision::update_content apm_generate_tarball apm_generate_tarball (public) apm_generate_tarball->content::revision::new content::item::new content::item::new (public) content::item::new->content::revision::new email_image::edit_email_image email_image::edit_email_image (public) email_image::edit_email_image->content::revision::new email_image::new_item email_image::new_item (public) email_image::new_item->content::revision::new fs::add_created_version fs::add_created_version (public, deprecated) fs::add_created_version->content::revision::new

Testcases:
content_image, content_revision
Source code:

    if {![info exists creation_user]} {
        set creation_user [ad_conn user_id]
    }

    if {![info exists creation_ip]} {
        set creation_ip [ad_conn peeraddr]
    }

    if {![info exists content_type] || $content_type eq ""} {
        set content_type [::content::item::get_content_type -item_id $item_id]
    }
    if {$storage_type eq ""} {
        set storage_type [db_string get_storage_type ""]
    }
    if {![info exists package_id]} {
        set package_id [ad_conn package_id]
    }
    set attribute_names ""
    set attribute_values ""

    if { [info exists attributes] && $attributes ne "" } {
        set type_attributes [package_object_attribute_list $content_type]
        set valid_attributes [list]
        # add in extended attributes for this type, ignore
        # content_revision as those are already captured as named
        # parameters to this procedure

        foreach type_attribute $type_attributes {
            if {"cr_revisions" ne [lindex $type_attribute 1]
                && "acs_objects" ne [lindex $type_attribute 1]
            } {
                lappend valid_attributes [lindex $type_attribute 2]
            }
        }
        foreach attribute_pair $attributes {
            lassign $attribute_pair attribute_name attribute_value
            if {$attribute_name in $valid_attributes}  {

            # first add the column name to the list
            append attribute_names  ", ${attribute_name}"
                # create local variable to use for binding
                set $attribute_name $attribute_value
                append attribute_values ", :${attribute_name}"
            }
        }
    }

    set table_name [acs_object_type::get_table_name -object_type $content_type]
    set mime_type [cr_check_mime_type  -filename  $title  -mime_type $mime_type  -file      $tmp_filename]

    set query_text [subst {
        insert into ${table_name}i
        (revision_id, object_type, creation_user, creation_date, creation_ip, title, description, item_id, object_package_id, mime_type $attribute_names)
        values (:revision_id, :content_type, :creation_user, :creation_date, :creation_ip, :title, :description, :item_id, :package_id, :mime_type $attribute_values)
    }]

    db_transaction {
        # An explicit lock was necessary for PostgreSQL between 8.0 and
        # 8.2; left the following statement here for documentary purposes
        #
        # db_dml lock_objects "LOCK TABLE acs_objects IN SHARE ROW EXCLUSIVE MODE"

        if {$revision_id eq ""} {
            set revision_id [db_nextval "acs_object_id_seq"]
        }
        # the postgres "insert into view" is rewritten by the rule into a "select"
        [expr {[db_driverkey ""] eq "postgresql" ? "db_0or1row" : "db_dml"}]  insert_revision $query_text

        ::content::revision::update_content  -item_id $item_id  -revision_id $revision_id  -content $content  -tmp_filename $tmp_filename  -storage_type $storage_type  -mime_type $mime_type
    }
    if {[string is true $is_live]} {
        content::item::set_live_revision -revision_id $revision_id
    }
    return $revision_id
Generic XQL file:
<fullquery name="content::revision::new.get_storage_type">
    <querytext>
      select storage_type from cr_items where item_id=:item_id
    </querytext>
</fullquery>
packages/acs-content-repository/tcl/content-revision-procs.xql

PostgreSQL XQL file:
packages/acs-content-repository/tcl/content-revision-procs-postgresql.xql

Oracle XQL file:
packages/acs-content-repository/tcl/content-revision-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: