cr_import_content (public)
cr_import_content [ -storage_type storage_type ] \ [ -creation_user creation_user ] [ -creation_ip creation_ip ] \ [ -image_only ] [ -image_type image_type ] \ [ -other_type other_type ] [ -title title ] \ [ -description description ] [ -package_id package_id ] \ [ -item_id item_id ] parent_id tmp_filename tmp_size mime_type \ object_name
Defined in packages/acs-content-repository/tcl/revision-procs.tcl
Import an uploaded file into the content repository.
- Switches:
- -storage_type (optional, defaults to
"file"
)- Where to store the content (lob or file), defaults to "file" (later a system-wide parameter)
- -creation_user (optional)
- The creating user (defaults to current user)
- -creation_ip (optional)
- The creating ip (defaults to peeraddr)
- -image_only (optional, boolean)
- Only allow images
- -image_type (optional, defaults to
"image"
)- The type of content item to create if the file contains an image
- -other_type (optional, defaults to
"content_revision"
)- The type of content item to create for a non-image file
- -title (optional)
- The title given to the new revision
- -description (optional)
- The description of the new revision
- -package_id (optional)
- Package ID of the package that created the item
- -item_id (optional)
- If present, make a new revision of this item, otherwise, make a new item
- Parameters:
- parent_id (required)
- The parent of the content item we create
- tmp_filename (required)
- The name of the temporary file holding the uploaded content
- tmp_size (required)
- The size of tmp_file
- mime_type (required)
- The uploaded file's mime type
- object_name (required)
- The name to give the result content item and revision This procedure handles all mime_type details, creating a new item of the appropriate type and stuffing the content into either the filesystem or the database depending on "storage_type". The new revision is set live, and its item_id is returned to the caller. image_type and other_type should be supplied when the client package has extended the image and content_revision types to hold package-specific information. Checking is done to ensure that image_type has been inherited from image, and that other_type has been inherited from content_revision. Is up to the caller to do any checking on size limitations, etc.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- fs_add_delete_copy, fs_add_file_to_folder, oacs_dav_put
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] } # DRB: Eventually we should allow for text storage ... (CLOB for Oracle) if { $storage_type ne "file" && $storage_type ne "lob" } { return -code error "Imported content must be stored in the filesystem or as a large object" } if {$mime_type eq "*/*"} { set mime_type "application/octet-stream" } if {$package_id eq ""} { set package_id [ad_conn package_id] } set old_item_p [info exists item_id] if { !$old_item_p } { set item_id [db_nextval acs_object_id_seq] } # use content_type of existing item if {$old_item_p} { set content_type [db_string get_content_type { select content_type from cr_items where item_id = :item_id }] } else { # all we really need to know is if the mime type is mapped to image, we # actually use the passed in image_type or other_type to create the object if {[db_0or1row image_type_p { select 1 from cr_content_mime_type_map where mime_type = :mime_type and content_type = 'image' }]} { set content_type image } else { set content_type content_revision } } set revision_id [db_nextval acs_object_id_seq] db_transaction { if { ![db_0or1row is_registered { select 1 from cr_content_mime_type_map where mime_type = :mime_type and content_type = 'content_revision' }]} { db_dml mime_type_insert { insert into cr_mime_types (mime_type) select :mime_type from dual where not exists (select 1 from cr_mime_types where mime_type = :mime_type) } db_dml mime_type_register { insert into cr_content_mime_type_map (content_type, mime_type) values ('content_revision', :mime_type) } } switch -- $content_type { image { if { ![db_0or1row image_subclass { with recursive type_hierarchy as ( select object_type, supertype from acs_object_types where object_type = :image_type union all select s.object_type, s.supertype from acs_object_types s, type_hierarchy h where h.object_type <> 'image' and s.object_type = h.supertype ) select 1 from type_hierarchy where object_type = 'image' }]} { error "Image file must be stored in an image object" } set what_nsd_told_us "" if {$mime_type eq "image/jpeg"} { catch { set what_nsd_told_us [ns_jpegsize $tmp_filename] } } elseif {$mime_type eq "image/gif"} { catch { set what_nsd_told_us [ns_gifsize $tmp_filename] } } elseif {$mime_type eq "image/png"} { catch { set what_nsd_told_us [ns_pngsize $tmp_filename] } } else { error "Unknown image type" } # The AOLserver/ jpegsize command has some bugs where the height comes # through as 1 or 2, so trust the valuesresult only on larger values. if { $what_nsd_told_us ne "" && [lindex $what_nsd_told_us 0] > 10 && [lindex $what_nsd_told_us 1] > 10 } { lassign $what_nsd_told_us original_width original_height } else { set original_width "" set original_height "" } if { !$old_item_p } { db_exec_plsql image_new "" } else { db_exec_plsql image_revision_new "" } } default { if { $image_only_p } { error "The file you uploaded was not an image (.gif, .jpg or .jpeg) file" } if { ![db_0or1row content_revision_subclass { with recursive type_hierarchy as ( select object_type, supertype from acs_object_types where object_type = :other_type union all select s.object_type, s.supertype from acs_object_types s, type_hierarchy h where h.object_type <> 'content_revision' and s.object_type = h.supertype ) select 1 from type_hierarchy where object_type = 'content_revision' }]} { error "Content must be stored in a content revision object" } if { !$old_item_p } { db_exec_plsql content_item_new "" } db_exec_plsql content_revision_new "" } } #ns_log notice "TESTING ::content::revision::update_content -storage_type $storage_type" # insert the content into the database ::content::revision::update_content -storage_type $storage_type -item_id $item_id -revision_id $revision_id -content "" -mime_type $mime_type -tmp_filename $tmp_filename } return $revision_idXQL Not present: Generic PostgreSQL XQL file: <fullquery name="cr_import_content.image_new"> <querytext> select image__new( /* name => */ :object_name, /* parent_id => */ :parent_id, /* item_id => */ :item_id, /* revision_id => */ :revision_id, /* mime_type => */ :mime_type, /* creation_user => */ :creation_user, /* creation_ip => */ :creation_ip, /* title => */ :title, /* description => */ :description, /* storage_type => */ :storage_type::cr_item_storage_type_enum, /* content_type => */ :image_type, /* nls_language => */ null, /* publish_date => */ current_timestamp, /* height => */ :original_height, /* width => */ :original_width, /* package_id => */ :package_id ); </querytext> </fullquery> <fullquery name="cr_import_content.image_revision_new"> <querytext> select image__new_revision ( /* item_id => */ :item_id, /* revision_id => */ :revision_id, /* title => */ :title, /* description => */ :description, /* publish_date => */ current_timestamp, /* mime_type => */ :mime_type, /* nls_language => */ null, /* creation_user => */ :creation_user, /* creation_ip => */ :creation_ip, /* height => */ :original_height, /* width => */ :original_width, /* package_id => */ :package_id ); </querytext> </fullquery> <fullquery name="cr_import_content.content_item_new"> <querytext> select content_item__new ( /* name => */ varchar :object_name, /* parent_id => */ :parent_id, /* item_id => */ :item_id, /* new_locale => */ null, /* creation_date => */ current_timestamp, /* creation_user => */ :creation_user, /* context_id => */ :parent_id, /* creation_ip => */ :creation_ip, /* item_subtype => */ 'content_item', /* content_type => */ :other_type, /* title => */ null, /* description => */ null, /* mime_type => */ null, /* nls_language => */ null, /* text => */ null, /* data => */ null, /* relation_tag => */ null, /* is live => */ 'f', /* storage_type => */ :storage_type, /* package_id => */ :package_id, /* w_child_rels => */ 't' ); </querytext> </fullquery> <fullquery name="cr_import_content.content_revision_new"> <querytext> select content_revision__new ( /* title => */ :title, /* description => */ :description, /* publish_date => */ current_timestamp, /* mime_type => */ :mime_type, /* nls_language => */ null, /* data => */ null, /* item_id => */ :item_id, /* revision_id => */ :revision_id, /* creation_date => */ current_timestamp, /* creation_user => */ :creation_user, /* creation_ip => */ :creation_ip, /* content_length => */ null, /* package_id => */ :package_id ); </querytext> </fullquery> <fullquery name="cr_import_content.set_lob_content"> <querytext> update cr_revisions set mime_type = :mime_type, lob = [set __lob_id [db_string get_lob_id {select empty_lob()}]] where revision_id = :revision_id </querytext> </fullquery> <fullquery name="cr_import_content.set_lob_size"> <querytext> update cr_revisions set content_length = lob_length(lob) where revision_id = :revision_id </querytext> </fullquery>packages/acs-content-repository/tcl/revision-procs-postgresql.xql
Oracle XQL file: <fullquery name="cr_import_content.image_new"> <querytext> begin :1 := image.new( name => :object_name, parent_id => :parent_id, item_id => :item_id, revision_id => :revision_id, mime_type => :mime_type, creation_user => :creation_user, creation_ip => :creation_ip, title => :title, content_type => :image_type, storage_type => :storage_type, height => :original_height, width => :original_width, package_id => :package_id ); end; </querytext> </fullquery> <fullquery name="cr_import_content.image_revision_new"> <querytext> begin :1 := image.new_revision ( item_id => :item_id, revision_id => :revision_id, title => :title, description => :description, mime_type => :mime_type, creation_user => :creation_user, creation_ip => :creation_ip, height => :original_height, width => :original_width, package_id => :package_id ); end; </querytext> </fullquery> <fullquery name="cr_import_content.content_item_new"> <querytext> begin :1 := content_item.new( name => :object_name, item_id => :item_id, parent_id => :parent_id, context_id => :parent_id, creation_user => :creation_user, creation_ip => :creation_ip, content_type => :other_type, storage_type => :storage_type, package_id => :package_id ); end; </querytext> </fullquery> <fullquery name="cr_import_content.content_revision_new"> <querytext> begin :1 := content_revision.new ( title => :title, description => :description, mime_type => :mime_type, item_id => :item_id, revision_id => :revision_id, creation_user => :creation_user, creation_ip => :creation_ip, package_id => :package_id, filename => :object_name ); end; </querytext> </fullquery> <fullquery name="cr_import_content.set_lob_content"> <querytext> update cr_revisions set mime_type = :mime_type, content = empty_blob() where revision_id = :revision_id returning content into :1 </querytext> </fullquery> <fullquery name="cr_import_content.set_lob_size"> <querytext> update cr_revisions set content_length = dbms_lob.getlength(content) where revision_id = :revision_id </querytext> </fullquery>packages/acs-content-repository/tcl/revision-procs-oracle.xql