Index: openacs-4/packages/file-storage/sql/postgresql/file-storage-package-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/sql/postgresql/file-storage-package-create.sql,v diff -u -r1.8.2.4 -r1.8.2.5 --- openacs-4/packages/file-storage/sql/postgresql/file-storage-package-create.sql 23 Jun 2003 18:47:03 -0000 1.8.2.4 +++ openacs-4/packages/file-storage/sql/postgresql/file-storage-package-create.sql 9 Nov 2003 03:36:56 -0000 1.8.2.5 @@ -63,7 +63,7 @@ end;' language 'plpgsql' with (iscachable); -create function file_storage__new_root_folder ( +create or replace function file_storage__new_root_folder ( -- -- Creates a new root folder -- @@ -73,13 +73,15 @@ -- integer, -- apm_packages.package_id%TYPE varchar, -- cr_folders.label%TYPE - varchar -- cr_folders.description%TYPE + varchar, -- cr_folders.description%TYPE + varchar -- cr_items.name%TYPE ) returns integer as ' -- fs_root_folders.folder_id%TYPE declare new_root_folder__package_id alias for $1; new_root_folder__folder_name alias for $2; new_root_folder__description alias for $3; + new_root_folder__url alias for $4; v_folder_id fs_root_folders.folder_id%TYPE; v_package_name apm_packages.instance_name%TYPE; v_package_key apm_packages.package_key%TYPE; @@ -107,7 +109,7 @@ end if; v_folder_id := content_folder__new ( - v_package_key || ''_'' || new_root_folder__package_id, -- name + coalesce (new_root_folder__url, v_package_key || ''_'' || new_root_folder__package_id), -- name v_folder_name, -- label v_description, -- description null -- parent_id (default) @@ -452,9 +454,9 @@ select label into v_title from cr_symlinks where symlink_id = get_title__item_id; else - select name into v_title - from cr_items - where item_id = get_title__item_id; + select title into v_title + from cr_revisions + where revision_id=(select live_revision from cr_items where item_id = get_title__item_id); end if; end if; @@ -558,7 +560,7 @@ perform acs_object__update_last_modified(v_folder_id,new_version__creation_user,new_version__creation_ip); - return v_revision_id; + return v_revision_id; end;' language 'plpgsql'; Index: openacs-4/packages/file-storage/tcl/file-storage-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-init.tcl,v diff -u -r1.4 -r1.4.2.1 --- openacs-4/packages/file-storage/tcl/file-storage-init.tcl 22 May 2002 16:49:33 -0000 1.4 +++ openacs-4/packages/file-storage/tcl/file-storage-init.tcl 9 Nov 2003 03:36:56 -0000 1.4.2.1 @@ -20,12 +20,13 @@ # "post_instantiation". The parameter passed is always # package_id. The name of the proc is thus: -ad_proc file_storage_post_instantiation { - package_id -} { - Post package instantiation procedure to insert a package_id, - folder_id pair in fs_root_folders -} { +#ad_proc file_storage_post_instantiation { +# package_id +#} { +# Post package instantiation procedure to insert a package_id, +# folder_id pair in fs_root_folders +#} { # We should probably just define this function here, and remove from the fs namespace - return [fs::new_root_folder -package_id $package_id] -} +# return [fs::new_root_folder -package_id $package_id] +#} + Index: openacs-4/packages/file-storage/tcl/file-storage-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs-oracle.xql,v diff -u -r1.19.2.3 -r1.19.2.4 --- openacs-4/packages/file-storage/tcl/file-storage-procs-oracle.xql 28 Mar 2003 01:16:21 -0000 1.19.2.3 +++ openacs-4/packages/file-storage/tcl/file-storage-procs-oracle.xql 9 Nov 2003 03:36:56 -0000 1.19.2.4 @@ -149,4 +149,10 @@ + + + select content_item.get_id ( :name, :folder_id, 'f' ) + + + Index: openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql,v diff -u -r1.29.2.4 -r1.29.2.5 --- openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql 5 May 2003 10:09:12 -0000 1.29.2.4 +++ openacs-4/packages/file-storage/tcl/file-storage-procs-postgresql.xql 9 Nov 2003 03:36:56 -0000 1.29.2.5 @@ -6,9 +6,10 @@ select file_storage__new_root_folder( - :package_id, + :package_id, :pretty_name, - :description + :description, + :name ); @@ -136,4 +137,10 @@ + + + select content_item__get_id ( :name, :folder_id, 'f' ) + + + 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.25.2.5 -r1.25.2.6 --- openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 28 Mar 2003 01:16:21 -0000 1.25.2.5 +++ openacs-4/packages/file-storage/tcl/file-storage-procs.tcl 9 Nov 2003 03:36:56 -0000 1.25.2.6 @@ -181,374 +181,421 @@ return $context_bar } -namespace eval fs { +namespace eval fs {} - ad_proc -public new_root_folder { - {-package_id ""} - {-pretty_name ""} - {-description ""} - } { - Create a root folder for a package instance. +ad_proc -public fs::after_mount { + -package_id + -node_id +} { + Create root folder for package instance + via tcl callback. - @param package_id Package instance associated with this root folder + This sets the cr_items.name to the url of the site + node. +} { + array set sn [site_node::get -node_id $node_id] + regsub -all {/} $sn(name) {} name + fs::new_root_folder \ + -package_id $package_id \ + -pretty_name $sn(instance_name) \ + -name $name +} +ad_proc -public fs::new_root_folder { + {-package_id ""} + {-pretty_name ""} + {-name ""} + {-description ""} +} { + Create a root folder for a package instance. - @return folder_id of the new root folder - } { - if {[empty_string_p $package_id]} { - set package_id [ad_conn package_id] - } + @param package_id Package instance associated with this root folder - return [db_exec_plsql new_root_folder {}] + @return folder_id of the new root folder +} { + if {[empty_string_p $package_id]} { + set package_id [ad_conn package_id] } - ad_proc -public get_root_folder { - {-package_id ""} - } { - Get the root folder of a package instance. + return [db_exec_plsql new_root_folder {}] +} - @param package_id Package instance of the root folder to retrieve +ad_proc -public fs::get_root_folder { + {-package_id ""} +} { + Get the root folder of a package instance. - @return folder_id of the root folder retrieved - } { - if {[empty_string_p $package_id]} { - set package_id [ad_conn package_id] - } + @param package_id Package instance of the root folder to retrieve - return [db_exec_plsql get_root_folder {}] + @return folder_id of the root folder retrieved +} { + if {[empty_string_p $package_id]} { + set package_id [ad_conn package_id] } - ad_proc -public new_folder { - {-name:required} - {-pretty_name:required} - {-parent_id:required} - {-creation_user ""} - {-creation_ip ""} - } { - Create a new folder. + return [db_exec_plsql get_root_folder {}] +} - @param name Internal name of the folder, must be unique under a given - parent_id - @param pretty_name What we show to users of the system - @param parent_id Where we create this folder - @param creation_user Who created this folder - @param creation_ip What is the ip address of the creation_user +ad_proc -public fs::new_folder { + {-name:required} + {-pretty_name:required} + {-parent_id:required} + {-creation_user ""} + {-creation_ip ""} +} { + Create a new folder. - @return folder_id of the newly created folder - } { - if {[empty_string_p $creation_user]} { - set creation_user [ad_conn user_id] - } + @param name Internal name of the folder, must be unique under a given + parent_id + @param pretty_name What we show to users of the system + @param parent_id Where we create this folder + @param creation_user Who created this folder + @param creation_ip What is the ip address of the creation_user - if {[empty_string_p $creation_ip]} { - set creation_ip [ns_conn peeraddr] - } - - return [db_exec_plsql new_folder {}] + @return folder_id of the newly created folder +} { + if {[empty_string_p $creation_user]} { + set creation_user [ad_conn user_id] } - ad_proc -public rename_folder { - {-folder_id:required} - {-name:required} - } { - rename the given folder - } { - db_exec_plsql rename_folder {} + if {[empty_string_p $creation_ip]} { + set creation_ip [ns_conn peeraddr] } - ad_proc -public object_p { - {-object_id:required} - } { - is this a file storage object - } { - return [db_string select_object_p {}] - } + return [db_exec_plsql new_folder {}] +} - ad_proc -public get_object_name { - {-object_id:required} - } { - Select the name of this object. - } { - return [db_string select_object_name {} -default $object_id] - } +ad_proc -public fs::rename_folder { + {-folder_id:required} + {-name:required} +} { + rename the given folder +} { + db_exec_plsql rename_folder {} +} - ad_proc -public get_file_system_safe_object_name { - {-object_id:required} - } { - get the name of a file storage object and make it safe for writing to - the file system - } { - return [remove_special_file_system_characters -string [get_object_name -object_id $object_id]] - } +ad_proc -public fs::object_p { + {-object_id:required} +} { + is this a file storage object +} { + return [db_string select_object_p {}] +} - ad_proc -public remove_special_file_system_characters { - {-string:required} - } { - remove unsafe file system characters. useful if you want to use $string - as the name of an object to write to disk. - } { - regsub -all {[<>:\"|/@#%&+\\]} $string {_} string - return $string - } +ad_proc -public fs::get_object_name { + {-object_id:required} +} { + Select the name of this object. +} { + return [db_string select_object_name {} -default $object_id] +} - ad_proc -public folder_p { - {-object_id:required} - } { - Is this object a folder? +ad_proc -public fs::get_file_system_safe_object_name { + {-object_id:required} +} { + get the name of a file storage object and make it safe for writing to + the file system +} { + return [remove_special_file_system_characters -string [get_object_name -object_id $object_id]] +} - @return true if object_id is a folder - } { - return [db_string select_folder_p {} -default 0] - } +ad_proc -public fs::remove_special_file_system_characters { + {-string:required} +} { + remove unsafe file system characters. useful if you want to use $string + as the name of an object to write to disk. +} { + regsub -all {[<>:\"|/@\#%&+\\]} $string {_} string + return [string trim $string] +} - ad_proc -public get_folder { - {-name:required} - {-parent_id:required} - } { - Retrieve the folder_id of a folder given it's name and parent folder. +ad_proc -public fs::folder_p { + {-object_id:required} +} { + Is this object a folder? - @param name Internal name of the folder, must be unique under a given - parent_id - @param parent_id The parent folder to look under + @return true if object_id is a folder +} { + return [db_string select_folder_p {} -default 0] +} - @return folder_id of the folder, or null if no folder was found by that - name - } { - return [db_string select_folder {} -default ""] - } +ad_proc -public fs::get_folder { + {-name:required} + {-parent_id:required} +} { + Retrieve the folder_id of a folder given it's name and parent folder. - ad_proc -public get_folder_objects { - -folder_id:required - -user_id:required - } { - Return a list the object_ids contained by a file storage folder. + @param name Internal name of the folder, must be unique under a given + parent_id + @param parent_id The parent folder to look under - @param folder_id The folder for which to retrieve contents - @param user_id The viewer of the contents (to make sure they have - permission) + @return folder_id of the folder, or null if no folder was found by that + name +} { + return [db_string select_folder {} -default ""] +} - } { - return [db_list select_folder_contents {}] - } +ad_proc -public fs::get_folder_objects { + -folder_id:required + -user_id:required +} { + Return a list the object_ids contained by a file storage folder. - ad_proc -public get_folder_contents { - {-folder_id ""} - {-user_id ""} - {-n_past_days "99999"} - } { - WARNING: This proc is not scalable because it does too many permission checks. + @param folder_id The folder for which to retrieve contents + @param user_id The viewer of the contents (to make sure they have + permission) - DRB: Not so true now that permissions are fast. However it is now only used - to clone files in dotLRN and for the somewhat brain-damaged syllabus package. - At minimum the permission checks returned by the code can be removed. Most of - the other fields as well. Oh well ... +} { + return [db_list select_folder_contents {}] +} - REMOVE WHEN SYLLABUS IS REWRITTEN TO FIND ITS FILE INTELLIGENTLY +ad_proc -public fs::get_folder_contents { + {-folder_id ""} + {-user_id ""} + {-n_past_days "99999"} +} { + WARNING: This proc is not scalable because it does too many permission checks. - Retrieve the contents of the specified folder in the form of a list - of ns_sets, one for each row returned. The keys for each row are as - follows: + DRB: Not so true now that permissions are fast. However it is now only used + to clone files in dotLRN and for the somewhat brain-damaged syllabus package. + At minimum the permission checks returned by the code can be removed. Most of + the other fields as well. Oh well ... - object_id, name, live_revision, type, - last_modified, new_p, content_size, file_upload_name - write_p, delete_p, admin_p, + REMOVE WHEN SYLLABUS IS REWRITTEN TO FIND ITS FILE INTELLIGENTLY - @param folder_id The folder for which to retrieve contents - @param user_id The viewer of the contents (to make sure they have - permission) - @param n_past_days Mark files that are newer than the past N days as new - } { - if {[empty_string_p $folder_id]} { - set folder_id [get_root_folder -package_id [ad_conn package_id]] - } + Retrieve the contents of the specified folder in the form of a list + of ns_sets, one for each row returned. The keys for each row are as + follows: - if {[empty_string_p $user_id]} { - set user_id [acs_magic_object the_public] - } + object_id, name, live_revision, type, + last_modified, new_p, content_size, file_upload_name + write_p, delete_p, admin_p, - return [db_list_of_ns_sets select_folder_contents {}] + @param folder_id The folder for which to retrieve contents + @param user_id The viewer of the contents (to make sure they have + permission) + @param n_past_days Mark files that are newer than the past N days as new +} { + if {[empty_string_p $folder_id]} { + set folder_id [get_root_folder -package_id [ad_conn package_id]] } - ad_proc -public get_folder_contents_count { - {-folder_id ""} - {-user_id ""} - } { - Retrieve the count of contents of the specified folder. + if {[empty_string_p $user_id]} { + set user_id [acs_magic_object the_public] + } - @param folder_id The folder for which to retrieve contents - @param user_id The viewer of the contents (to make sure they have - permission) - } { - if {[empty_string_p $folder_id]} { - set folder_id [get_root_folder -package_id [ad_conn package_id]] - } + set list_of_ns_sets [db_list_of_ns_sets select_folder_contents {}] - if {[empty_string_p $user_id]} { - set user_id [acs_magic_object the_public] - } + foreach set $list_of_ns_sets { + # in plain Tcl: + # set last_modified_ansi [lc_time_system_to_conn $last_modified_ansi] + ns_set put $set last_modified_ansi [lc_time_system_to_conn [ns_set get $set last_modifed_ansi]] - return [db_string select_folder_contents_count {}] + # in plain Tcl: + # set last_modified [lc_time_fmt $last_modified_ansi "%x %X"] + ns_set put $set last_modified [lc_time_fmt [ns_set get $set last_modified_ansi] "%x %X"] + + # set content_size_pretty [lc_numeric $content_size] + ns_set put $set content_size_pretty [lc_numeric [ns_set get $set content_size]] } - ad_proc -public publish_object_to_file_system { - {-object_id:required} - {-path ""} - {-file_name ""} - {-user_id ""} - } { - publish a file storage object to the file system - } { - if {[empty_string_p $path]} { - set path [ns_tmpnam] - } + return $list_of_ns_sets +} - db_1row select_object_info {} +ad_proc -public fs::get_folder_contents_count { + {-folder_id ""} + {-user_id ""} +} { + Retrieve the count of contents of the specified folder. - if {[string equal folder $type]} { - set result [publish_folder_to_file_system -folder_id $object_id -path $path -folder_name $name -user_id $user_id] - } elseif {[string equal url $type]} { - set result [publish_url -object_id $object_id -path $path -file_name $file_name] - } else { - set result [publish_versioned_object_to_file_system -object_id $object_id -path $path] - } + @param folder_id The folder for which to retrieve contents + @param user_id The viewer of the contents (to make sure they have + permission) +} { + if {[empty_string_p $folder_id]} { + set folder_id [get_root_folder -package_id [ad_conn package_id]] + } - return $result + if {[empty_string_p $user_id]} { + set user_id [acs_magic_object the_public] } - ad_proc -public publish_folder_to_file_system { - {-folder_id:required} - {-path ""} - {-folder_name ""} - {-user_id ""} - } { - publish the contents of a file storage folder to the file system - } { - if {[empty_string_p $path]} { - set path [ns_tmpnam] - } + return [db_string select_folder_contents_count {}] +} - if {[empty_string_p $folder_name]} { - set folder_name [get_object_name -object_id $folder_id] - } - set folder_name [remove_special_file_system_characters -string $folder_name] +ad_proc -public fs::publish_object_to_file_system { + {-object_id:required} + {-path ""} + {-file_name ""} + {-user_id ""} +} { + publish a file storage object to the file system +} { + if {[empty_string_p $path]} { + set path [ns_tmpnam] + } - set dir [file join ${path} ${folder_name}] - file mkdir $dir + db_1row select_object_info {} - foreach object [get_folder_contents -folder_id $folder_id -user_id $user_id] { - publish_object_to_file_system \ - -object_id [ns_set get $object object_id] \ - -path $dir \ - -file_name [remove_special_file_system_characters -string [ns_set get $object name]] \ - -user_id $user_id - } + if {[string equal folder $type]} { + set result [publish_folder_to_file_system -folder_id $object_id -path $path -folder_name $name -user_id $user_id] + } elseif {[string equal url $type]} { + set result [publish_url_to_file_system -object_id $object_id -path $path -file_name $file_name] + } else { + set result [publish_versioned_object_to_file_system -object_id $object_id -path $path] + } - return $dir + return $result +} + +ad_proc -public fs::publish_folder_to_file_system { + {-folder_id:required} + {-path ""} + {-folder_name ""} + {-user_id ""} +} { + publish the contents of a file storage folder to the file system +} { + if {[empty_string_p $path]} { + set path [ns_tmpnam] } - ad_proc -public publish_url_to_file_system { - {-object_id:required} - {-path ""} - {-file_name ""} - } { - publish a url object to the file system - } { - if {[empty_string_p $path]} { - set path [ns_tmpnam] - file mkdir $path - } + if {[empty_string_p $folder_name]} { + set folder_name [get_object_name -object_id $folder_id] + } + set folder_name [remove_special_file_system_characters -string $folder_name] - db_1row select_object_metadata {} + set dir [file join ${path} ${folder_name}] + file mkdir $dir - if {[empty_string_p $file_name]} { - set file_name $label - } - set file_name [remove_special_file_system_characters -string $file_name] + foreach object [get_folder_contents -folder_id $folder_id -user_id $user_id] { + publish_object_to_file_system \ + -object_id [ns_set get $object object_id] \ + -path $dir \ + -file_name [remove_special_file_system_characters -string [ns_set get $object name]] \ + -user_id $user_id + } - set fp [open [file join ${path} ${file_name}] w] - puts $fp url - close $fp + return $dir +} - return [file join ${path} ${file_name}] +ad_proc -public fs::publish_url_to_file_system { + {-object_id:required} + {-path ""} + {-file_name ""} +} { + publish a url object to the file system as a Windows shortcut + (which at least KDE also knows how to handle) +} { + if {[empty_string_p $path]} { + set path [ns_tmpnam] + file mkdir $path } - ad_proc -public publish_versioned_object_to_file_system { - {-object_id:required} - {-path ""} - {-file_name ""} - } { - publish an object to the file system - } { - if {[empty_string_p $path]} { - set path [ns_tmpnam] - file mkdir $path - } + db_1row select_object_metadata {} - db_1row select_object_metadata {} + if {[empty_string_p $file_name]} { + set file_name $label + } + set file_name "${file_name}.url" + set file_name [remove_special_file_system_characters -string $file_name] - if {[empty_string_p $file_name]} { - set file_name $title - } - set file_name [remove_special_file_system_characters -string $file_name] + set fp [open [file join ${path} ${file_name}] w] + puts $fp {[InternetShortcut]} + puts $fp URL=$url + close $fp - switch $storage_type { - lob { + return [file join ${path} ${file_name}] +} - # FIXME: db_blob_get_file is failing when i use bind variables +ad_proc -public fs::publish_versioned_object_to_file_system { + {-object_id:required} + {-path ""} + {-file_name ""} +} { + publish an object to the file system +} { + if {[empty_string_p $path]} { + set path [ns_tmpnam] + file mkdir $path + } - # DRB: you're out of luck - the driver doesn't support them and while it should - # be fixed it will be a long time before we'll want to require an updated - # driver. I'm substituting the Tcl variable value directly in the query due to - # this. It's safe because we've pulled the value ourselves from the database, - # don't need to worry about SQL smuggling etc. + db_1row select_object_metadata {} - db_blob_get_file select_object_content {} -file [file join ${path} ${file_name}] - } - text { - set content [db_string select_object_content {}] + if {[empty_string_p $file_name]} { + set file_name $title + } + set file_name [remove_special_file_system_characters -string $file_name] - set fp [open [file join ${path} ${file_name}] w] - puts $fp $content - close $fp - } - file { - set cr_path [cr_fs_path $storage_area_key] - set cr_file_name [db_string select_file_name {}] + switch $storage_type { + lob { - file copy -- "${cr_path}${cr_file_name}" [file join ${path} ${file_name}] - } - } + # FIXME: db_blob_get_file is failing when i use bind variables - return [file join ${path} ${file_name}] + # DRB: you're out of luck - the driver doesn't support them and while it should + # be fixed it will be a long time before we'll want to require an updated + # driver. I'm substituting the Tcl variable value directly in the query due to + # this. It's safe because we've pulled the value ourselves from the database, + # don't need to worry about SQL smuggling etc. + + db_blob_get_file select_object_content {} -file [file join ${path} ${file_name}] + } + text { + set content [db_string select_object_content {}] + + set fp [open [file join ${path} ${file_name}] w] + puts $fp $content + close $fp + } + file { + set cr_path [cr_fs_path $storage_area_key] + set cr_file_name [db_string select_file_name {}] + + file copy -- "${cr_path}${cr_file_name}" [file join ${path} ${file_name}] + } } - ad_proc -public get_archive_command { - {-in_file ""} - {-out_file ""} - } { - return the archive command after replacing {in_file} and {out_file} with - their respective values. - } { - set cmd [parameter::get -parameter ArchiveCommand -default "cat `find {in_file} -type f` > {out_file}"] + return [file join ${path} ${file_name}] +} - regsub -all {(\W)} $in_file {\\\1} in_file - regsub -all {\\/} $in_file {/} in_file - regsub -all {\\\.} $in_file {.} in_file +ad_proc -public fs::get_archive_command { + {-in_file ""} + {-out_file ""} +} { + return the archive command after replacing {in_file} and {out_file} with + their respective values. +} { + set cmd [parameter::get -parameter ArchiveCommand -default "cat `find {in_file} -type f` > {out_file}"] - regsub -all {(\W)} $out_file {\\\1} out_file - regsub -all {\\/} $out_file {/} out_file - regsub -all {\\\.} $out_file {.} out_file + regsub -all {(\W)} $in_file {\\\1} in_file + regsub -all {\\/} $in_file {/} in_file + regsub -all {\\\.} $in_file {.} in_file - regsub -all {{in_file}} $cmd $in_file cmd - regsub -all {{out_file}} $cmd $out_file cmd + regsub -all {(\W)} $out_file {\\\1} out_file + regsub -all {\\/} $out_file {/} out_file + regsub -all {\\\.} $out_file {.} out_file - return $cmd - } + regsub -all {{in_file}} $cmd $in_file cmd + regsub -all {{out_file}} $cmd $out_file cmd - ad_proc -public get_archive_extension {} { - return the archive extension that should be added to the output file of - an archive command - } { - return [parameter::get -parameter ArchiveExtension -default "txt"] - } + return $cmd +} +ad_proc -public fs::get_archive_extension {} { + return the archive extension that should be added to the output file of + an archive command +} { + return [parameter::get -parameter ArchiveExtension -default "txt"] } + +ad_proc -public fs::get_item_id { + -name + {-folder_id ""} +} { + Get the item_id of a file +} { + if {[empty_string_p $folder_id]} { + set package_id [ad_conn package_id] + set folder_id [fs_get_root_folder -package_id $package_id] + } + return [db_exec_plsql get_item_id ""] +} Index: openacs-4/packages/file-storage/www/file-add-2-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/Attic/file-add-2-oracle.xql,v diff -u -r1.3 -r1.3.4.1 --- openacs-4/packages/file-storage/www/file-add-2-oracle.xql 22 Sep 2001 05:41:51 -0000 1.3 +++ openacs-4/packages/file-storage/www/file-add-2-oracle.xql 9 Nov 2003 03:36:56 -0000 1.3.4.1 @@ -8,7 +8,7 @@ begin :1 := file_storage.new_file ( - title => :title, + title => :filename, folder_id => :folder_id, creation_user => :user_id, creation_ip => :creation_ip, @@ -25,7 +25,7 @@ begin :1 := file_storage.new_file ( - title => :title, + title => :filename, folder_id => :folder_id, creation_user => :user_id, creation_ip => :creation_ip, @@ -43,7 +43,7 @@ begin :1 := file_storage.new_version ( - filename => :filename, + filename => :title, description => :description, mime_type => :mime_type, item_id => :file_id, Index: openacs-4/packages/file-storage/www/file-add-2-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/Attic/file-add-2-postgresql.xql,v diff -u -r1.5 -r1.5.2.1 --- openacs-4/packages/file-storage/www/file-add-2-postgresql.xql 17 Sep 2002 21:03:27 -0000 1.5 +++ openacs-4/packages/file-storage/www/file-add-2-postgresql.xql 9 Nov 2003 03:36:56 -0000 1.5.2.1 @@ -6,7 +6,7 @@ select file_storage__new_file ( - :title, -- title + :filename, -- filename :folder_id, -- parent_id :user_id, -- creation_user :creation_ip, -- creation_ip @@ -18,7 +18,7 @@ select file_storage__new_file ( - :title, -- title + :filename, -- filename :folder_id, -- parent_id :user_id, -- creation_user :creation_ip, -- creation_ip @@ -32,7 +32,7 @@ select file_storage__new_version ( - :filename, -- filename + :title, -- title :description, -- description :mime_type, -- mime_type :file_id, -- item_id Index: openacs-4/packages/file-storage/www/file-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/file-add.adp,v diff -u -r1.6 -r1.6.2.1 --- openacs-4/packages/file-storage/www/file-add.adp 6 Sep 2002 21:50:38 -0000 1.6 +++ openacs-4/packages/file-storage/www/file-add.adp 9 Nov 2003 03:36:56 -0000 1.6.2.1 @@ -2,48 +2,4 @@ Upload New File @context@ -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Version filename :
 Use the "Browse..." button to locate your file, - then click "Open".
  
Title: @title@
Description:
-
-
+ Index: openacs-4/packages/file-storage/www/file-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/file-add.tcl,v diff -u -r1.3 -r1.3.2.1 --- openacs-4/packages/file-storage/www/file-add.tcl 5 Sep 2002 09:29:00 -0000 1.3 +++ openacs-4/packages/file-storage/www/file-add.tcl 9 Nov 2003 03:36:56 -0000 1.3.2.1 @@ -5,7 +5,10 @@ @creation-date 6 Nov 2000 @cvs-id $Id$ } { + item_id:integer,optional folder_id:integer,notnull + upload_file:trim,optional + upload_file.tmpfile:tmpfile,optional {title ""} {lock_title_p 0} } -validate { @@ -19,8 +22,24 @@ context:onevalue title:onevalue lock_title_p:onevalue +} -validate { + valid_folder -requires {folder_id:integer} { + if ![fs_folder_p $folder_id] { + ad_complain "The specified parent folder is not valid." + } + } + + max_size -requires {upload_file} { + set n_bytes [file size ${upload_file.tmpfile}] + set max_bytes [ad_parameter "MaximumFileSize"] + if { $n_bytes > $max_bytes } { + ad_complain "Your file is larger than the maximum file size allowed on this system ([util_commify_number $max_bytes] bytes)" + } + } } +set user_id [ad_conn user_id] + # check for write permission on the folder ad_require_permission $folder_id write @@ -29,11 +48,58 @@ set context [fs_context_bar_list -final "Add File" $folder_id] -# Should probably generate the item_id and version_id now for -# double-click protection - # if title isn't passed in ignore lock_title_p if {[empty_string_p $title]} { set lock_title_p 0 } +ad_form -html { enctype multipart/form-data } -export { folder_id } -form { + item_id:key + {upload_file:file {label "Upload File"} {html "size 30"}} + {title:text,optional {label "Title"} {html "size 30"}} + {description:text(textarea),optional {label "Description"} {html "rows 5 cols 35"}} +} -new_data { + + if {[ad_parameter "StoreFilesInDatabaseP" -package_id [ad_conn package_id]]} { + set indbp "t" + set storage_type "lob" + } else { + set indpb "f" + set storage_type "file" + } + set creation_ip [ad_conn peeraddr] + set name [template::util::file::get_property filename $upload_file] + set tmp_filename [template::util::file::get_property tmp_filename $upload_file] + set tmp_size [file size $tmp_filename] + set mime_type [cr_filename_to_mime_type -create $name] + + set existing_item_id [fs::get_item_id -name $name -folder_id $folder_id] + if {![empty_string_p $existing_item_id]} { + # file with the same name already exists + # in this folder, create a new revision + set item_id $existing_item_id + } else { + db_exec_plsql create_item "" + } + + set revision_id [cr_import_content \ + -item_id $item_id \ + -storage_type $storage_type \ + -creation_user $user_id \ + -creation_ip $creation_ip \ + -other_type "file_storage_object" \ + -title $title \ + -description $description \ + $folder_id \ + $tmp_filename \ + $tmp_size \ + $mime_type \ + $name] + + db_dml set_live_revision "" + db_exec_plsql update_last_modified "" + permission::grant -party_id $user_id -object_id $item_id -privilege admin + ad_returnredirect "." +} + +ad_return_template \ No newline at end of file Index: openacs-4/packages/file-storage/www/file-edit-2-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/Attic/file-edit-2-postgresql.xql,v diff -u -r1.2 -r1.2.4.1 --- openacs-4/packages/file-storage/www/file-edit-2-postgresql.xql 22 Sep 2001 05:47:50 -0000 1.2 +++ openacs-4/packages/file-storage/www/file-edit-2-postgresql.xql 9 Nov 2003 03:36:56 -0000 1.2.4.1 @@ -8,7 +8,7 @@ select file_storage__rename_file ( :file_id, -- file_id - :title -- title + :filename -- title );
Index: openacs-4/packages/file-storage/www/file-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/Attic/file-oracle.xql,v diff -u -r1.6.2.1 -r1.6.2.2 --- openacs-4/packages/file-storage/www/file-oracle.xql 17 Feb 2003 20:33:19 -0000 1.6.2.1 +++ openacs-4/packages/file-storage/www/file-oracle.xql 9 Nov 2003 03:36:56 -0000 1.6.2.2 @@ -3,6 +3,14 @@ oracle8.1.6 + + + + select content_item.get_parent_folder(:file_id) + from dual + + + Index: openacs-4/packages/file-storage/www/file-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/file-storage/www/Attic/file-postgresql.xql,v diff -u -r1.6.2.1 -r1.6.2.2 --- openacs-4/packages/file-storage/www/file-postgresql.xql 17 Feb 2003 20:33:19 -0000 1.6.2.1 +++ openacs-4/packages/file-storage/www/file-postgresql.xql 9 Nov 2003 03:36:56 -0000 1.6.2.2 @@ -3,12 +3,22 @@ postgresql7.1 + + + + + select content_item__get_parent_folder(:file_id) + from dual + + + + select person__name(o.creation_user) as owner, - i.name as title, - r.title as name, + i.name , + r.title , acs_permission__permission_p(:file_id,:user_id,'write') as write_p, acs_permission__permission_p(:file_id,:user_id,'delete') as delete_p, acs_permission__permission_p(:file_id,:user_id,'admin') as admin_p