Forum OpenACS Development: Re: title attribute in both acs_objects and cr_revisions

Collapse
Posted by Stan Kaufman on
Maybe what isn't clear is which proc we're talking about. It's content::attribute_insert_statement, and all it does is return an sql string for inserting into cr_revisioni:

ad_proc -private content::attribute_insert_statement { 
    content_type table_name bind_vars form_name {prefix {}} {new_p 1}
} {

    Prepare the insert statement into the attribute input view for a new
    revision (see the content repository documentation for details about
    the view).

    @param content_type The content type of the item for which a new
                        revision is being prepared.

    @param table_name The storage table of the content type.

    @param bind_vars The name of an ns_set in which to store the
                     attribute values for the revision.  (Typically
                     duplicates the contents of [ns_getform])
    
    @param form_name The name of the ATS form object used to process the
                     submission.

} {
    # get creation_user and creation_ip
    ns_set put $bind_vars creation_user null
    ns_set put $bind_vars creation_ip null


    # initialize the column and value list 
    set columns [list item_id revision_id creation_user creation_ip]
    set values [list :item_id :revision_id null null]
    set default_columns [list] 
    set default_values [list]
    set missing_columns [list]

    # query for attribute names and datatypes
    foreach attribute [get_attributes $content_type attribute_name datatype default_value ancestor] { 

        foreach {attribute_name datatype default_value ancestor} $attribute { break }

        # get the form value
        if { [template::element exists $form_name $prefix$attribute_name] } {

            set value [template::element get_value $form_name $prefix$attribute_name]

            # Convert dates to linear "YYYY MM DD HH24 MI SS" format
            if { [string equal $datatype date] } {
                set value [template::util::date get_property linear_date $value]
                foreach i {1 2} { 
                    if {[string equal [lindex $value $i] "00"]} { 
                        set value [lreplace $value $i $i 01]
                    }
                }
            }
            
            if { ! [string equal $value {} ] && ![expr { [string equal $ancestor "content_revision"] && [string equal $attribute_name "title"] }] } {
                ns_set put $bind_vars $attribute_name $value

                lappend columns $attribute_name
                lappend values [get_sql_value $attribute_name $datatype]
            }
        } elseif { ![string equal $ancestor "acs_object"] 
                   && ( ![string equal $ancestor "cr_revision"] 
                        || [lsearch -exact {revision_id item_id publish_date} $attribute_name] == -1) } { 
            # We preserve attributes not in the form and not "special" like acs_object and some of cr_revision.
            lappend missing_columns $attribute_name
            if {$new_p && ![string equal $default_value {}]} { 
                ns_set put $bind_vars $attribute_name $default_value
                
                lappend default_columns $attribute_name
                lappend default_values [get_sql_value $attribute_name $datatype]
            }
        } 
    }
    
    if {$new_p} { 
        set insert_statement "insert into ${table_name}i ( [join [concat $columns $default_columns] ", "] )\nvalues ( [join [concat $values $default_values] ", "] )"
    } else { 
        set insert_statement "insert into ${table_name}i ( [join [concat $columns $missing_columns] ", "] )\nselect [join [concat $values $missing_columns] ", "]\nfrom ${table_name}i\nwhere revision_id = content_item.get_latest_revision(:item_id)"
    }
    return $insert_statement
}

So it doesn't need to alias anything -- just return the correct args, eh?