fs::add_file (public)
fs::add_file -name name -parent_id parent_id -package_id package_id \ [ -item_id item_id ] [ -creation_user creation_user ] \ [ -creation_ip creation_ip ] [ -title title ] \ [ -description description ] [ -tmp_filename tmp_filename ] \ [ -mime_type mime_type ] [ -no_callback ] [ -no_notification ]
Defined in packages/file-storage/tcl/file-storage-procs.tcl
Create a new file storage item or add a new revision if an item with the same name and parent folder already exists
- Switches:
- -name (required)
- -parent_id (required)
- -package_id (required)
- -item_id (optional)
- -creation_user (optional)
- -creation_ip (optional)
- -title (optional)
- -description (optional)
- -tmp_filename (optional)
- -mime_type (optional)
- -no_callback (optional, boolean)
- -no_notification (optional, boolean)
- Returns:
- revision_id
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- fs_publish_file, fs_add_delete_copy, fs_add_file_to_folder
Source code: if {[parameter::get -parameter "StoreFilesInDatabaseP" -package_id $package_id]} { set indbp "t" set storage_type "lob" } else { set indbp "f" set storage_type "file" } # This check also happens in content repository, but as something # similar was already here and mimetype coming from this was used # afterwards, we kept this behavior. set mime_type [cr_check_mime_type -filename $name -mime_type $mime_type -file $tmp_filename] # we have to do this here because we create the object before # calling cr_import_content if {[content::type::content_type_p -mime_type $mime_type -content_type "image"]} { set content_type image } else { set content_type file_storage_object } if {$item_id eq ""} { set item_id [db_nextval acs_object_id_seq] } db_transaction { if {![db_string item_exists {}]} { set item_id [content::item::new -item_id $item_id -parent_id $parent_id -creation_user "$creation_user" -creation_ip "$creation_ip" -package_id "$package_id" -name $name -storage_type "$storage_type" -content_type "file_storage_object" -mime_type "text/plain" ] if {$creation_user ne ""} { permission::grant -party_id $creation_user -object_id $item_id -privilege admin } # Deal with notifications. Usually, send out the notification # But suppress it if the parameter is given if {$no_notification_p} { set do_notify_here_p "f" } else { set do_notify_here_p "t" } } else { # th: fixed to set old item_id if item already exists and no new item needed to be created db_1row get_old_item "" set do_notify_here_p "f" } if {$no_callback_p} { set revision_id [fs::add_version -name $name -tmp_filename $tmp_filename -package_id $package_id -item_id $item_id -creation_user $creation_user -creation_ip $creation_ip -title $title -description $description -suppress_notify_p $do_notify_here_p -storage_type $storage_type -mime_type $mime_type -no_callback ] } else { set revision_id [fs::add_version -name $name -tmp_filename $tmp_filename -package_id $package_id -item_id $item_id -creation_user $creation_user -creation_ip $creation_ip -title $title -description $description -suppress_notify_p $do_notify_here_p -storage_type $storage_type -mime_type $mime_type ] } if {[string is true $do_notify_here_p]} { fs::do_notifications -folder_id $parent_id -filename $title -item_id $revision_id -action "new_file" -package_id $package_id if {!$no_callback_p} { callback fs::file_new -package_id [ad_conn package_id] -file_id $item_id } } } return $revision_idGeneric XQL file: <fullquery name="fs::add_file.item_exists"> <querytext> select count(*) from cr_items where name=:name and parent_id=:parent_id </querytext> </fullquery> <fullquery name="fs::add_file.get_old_item"> <querytext> select item_id from cr_items where name=:name and parent_id=:parent_id </querytext> </fullquery>packages/file-storage/tcl/file-storage-procs.xql
PostgreSQL XQL file: <fullquery name="fs::add_file.create_item"> <querytext> select file_storage__new_file ( :name, :parent_id, :creation_user, :creation_ip, :indbp, :item_id, :package_id ) </querytext> </fullquery>packages/file-storage/tcl/file-storage-procs-postgresql.xql
Oracle XQL file: <fullquery name="fs::add_file.create_item"> <querytext> begin :1 := file_storage.new_file ( folder_id => :parent_id, title => :name, creation_user => :creation_user, creation_ip => :creation_ip, item_id => :item_id, indb_p => :indbp ); end; </querytext> </fullquery>packages/file-storage/tcl/file-storage-procs-oracle.xql