Index: openacs-4/packages/file-storage/tcl/file-storage-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs.tcl,v
diff -u -r1.52 -r1.53
--- openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 8 Aug 2006 21:26:48 -0000 1.52
+++ openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 14 Nov 2006 06:38:25 -0000 1.53
@@ -1364,3 +1364,64 @@
}
+ad_proc -public fs::file_copy {
+ {-file_id:required}
+ {-target_folder_id:required}
+ {-postfix ""}
+ -symlink:boolean
+} {
+ copy file to target folder
+
+ @param file_id Item_id of the file to be copied
+ @param target_folder_id Folder ID of the folder to which the file is copied to
+ @param postfix Postfix will be added with "_" to the new filename (not title). Very useful if you want to avoid unique name constraints on cr_items.
+ @param symlink Defines if, instead of a full item, we should just add a symlink.
+} {
+ db_1row file_data {}
+
+ if {![empty_string_p $postfix]} {
+ set name [lang::util::localize "[file rootname $name]_$postfix[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]"
+
+ # 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 {![empty_string_p $postfix]} {
+ # set postfixed new title
+ db_dml update_title {}
+ }
+
+ content::item::set_live_revision -revision_id $new_file_rev_id
+
+ return $new_file_id
+ }
+}
+
Index: openacs-4/packages/file-storage/tcl/file-storage-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs.xql,v
diff -u -r1.18 -r1.19
--- openacs-4/packages/file-storage/tcl/file-storage-procs.xql 8 Aug 2006 21:26:48 -0000 1.18
+++ openacs-4/packages/file-storage/tcl/file-storage-procs.xql 14 Nov 2006 06:38:25 -0000 1.19
@@ -207,5 +207,25 @@
and parent_id=:parent_id
+
+
+ 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
+
+
+
+
+
+
+
+ update cr_revisions
+ set title = :title
+ where revision_id = :new_file_rev_id
+
+
+
+