fs::file_copy (public)

 fs::file_copy -file_id file_id -target_folder_id target_folder_id \
    [ -postfix postfix ] [ -symlink ]

Defined in packages/file-storage/tcl/file-storage-procs.tcl

copy file to target folder

Switches:
-file_id (required)
Item_id of the file to be copied
-target_folder_id (required)
Folder ID of the folder to which the file is copied to
-postfix (optional)
Postfix will be added with "_" to the new filename (not title). Very useful if you want to avoid unique name constraints on cr_items.
-symlink (optional, boolean)
Defines if, instead of a full item, we should just add a symlink.

Partial Call Graph (max 5 caller/called nodes):
%3 test_fs_add_delete_copy fs_add_delete_copy (test file-storage) fs::file_copy fs::file_copy test_fs_add_delete_copy->fs::file_copy ad_conn ad_conn (public) fs::file_copy->ad_conn ad_file ad_file (public) fs::file_copy->ad_file content::item::get_id_by_name content::item::get_id_by_name (public) fs::file_copy->content::item::get_id_by_name content::item::new content::item::new (public) fs::file_copy->content::item::new content::item::set_live_revision content::item::set_live_revision (public) fs::file_copy->content::item::set_live_revision

Testcases:
fs_add_delete_copy
Source code:
    db_1row file_data {}

    if {$postfix ne ""} {
        set name [lang::util::localize "[ad_file rootname $name]_$postfix[ad_file extension $name]"]
    }

    if {$symlink_p} {
        return [content::symlink::new  -name $name  -label $title  -target_id $file_id  -parent_id $target_folder_id]
    } else {
        set user_id [ad_conn user_id]
        set creation_ip [ad_conn peeraddr]
        #set file_path "[cr_fs_path][cr_create_content_file_path $file_id $file_rev_id]"
        set file_path [content::revision::get_cr_file_path -revision_id $file_rev_id]

        # We need to check if the file already exists with the same name in the target folder
        # If yes, just add a new revision.

        set new_file_id [content::item::get_id_by_name -name $name -parent_id $target_folder_id]
        if {$new_file_id eq ""} {
            set new_file_id [content::item::new  -name $name  -parent_id $target_folder_id  -context_id $target_folder_id  -item_subtype "content_item"  -content_type "file_storage_object"  -storage_type "file"]
        }

        # Now create the revision
        set new_file_rev_id [content::revision::copy  -revision_id $file_rev_id  -target_item_id $new_file_id  -creation_user $user_id  -creation_ip $creation_ip]

        #set new_path [cr_create_content_file_path $new_file_id $new_file_rev_id]
        cr_create_content_file $new_file_id $new_file_rev_id $file_path

        if {$postfix ne ""} {
            # set postfixed new title
            db_dml update_title {}
        }

        content::item::set_live_revision -revision_id $new_file_rev_id

        return $new_file_id
    }
Generic XQL file:
<fullquery name="fs::file_copy.file_data">
    <querytext>

	select i.name, i.latest_revision as file_rev_id, r.title
	from cr_items i, cr_revisions r
	where i.item_id = :file_id
	and r.revision_id = i.latest_revision

         </querytext>
</fullquery>

<fullquery name="fs::file_copy.update_title">
    <querytext>

	    update cr_revisions
	    set title = :title
	    where revision_id = :new_file_rev_id

         </querytext>
</fullquery>

<fullquery name="fs::file_copy.file_data">
    <querytext>

	select i.name, i.latest_revision as file_rev_id, r.title
	from cr_items i, cr_revisions r
	where i.item_id = :file_id
	and r.revision_id = i.latest_revision

         </querytext>
</fullquery>

<fullquery name="fs::file_copy.update_title">
    <querytext>

	    update cr_revisions
	    set title = :title
	    where revision_id = :new_file_rev_id

         </querytext>
</fullquery>
packages/file-storage/tcl/file-storage-procs.xql

PostgreSQL XQL file:
packages/file-storage/tcl/file-storage-procs-postgresql.xql

Oracle XQL file:
packages/file-storage/tcl/file-storage-procs-oracle.xql

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