Forum OpenACS Development: Re: Re: xoWiki and images
if {![info exists fs_package_id]} { # we have not filestore package_id. This must be the first call. if {[info exists folder_id]} { # get package_id from folder_id foreach {fs_package_id root_folder_id} \ [fs::get_folder_package_and_root $folder_id] break } else { # get package_id from package name set key file-storage set id [apm_version_id_from_package_key $key] set mount_url [site_node::get_children -all -package_key $key -node_id $id] array set site_node [site_node::get -url $mount_url] set fs_package_id $site_node(package_id) } }
Changing this default behavior could be done in file-selector.tcl, or else one could edit insert-image.tcl to find the subsite's file-storage instance and then pass that into file-selector.tcl -- which is what I decided to do. The following tries to set fs_package_id using a file-storage instance in a subsite, or the file-storage instance in the main site if there's none in the subsite. Here's a cvs diff:
Index: xowiki/www/xinha/insert-image.tcl =================================================================== RCS file: /cvsroot/openacs-4/packages/xowiki/www/xinha/insert-image.tcl,v retrieving revision 1.3 diff -u -r1.3 insert-image.tcl --- xowiki/www/xinha/insert-image.tcl 30 Dec 2005 00:09:58 -0000 1.3 +++ xowiki/www/xinha/insert-image.tcl 30 Jun 2006 19:28:36 -0000 @@ -7,7 +7,19 @@ {fs_package_id:integer,optional} {folder_id:integer,optional} } - +# get file-storage instance from this subsite +set subsite_node [subsite::get_element -element node_id] +set mount_url [site_node::get_children -package_key file-storage -node_id $subsite_node] +if { $mount_url eq "" } { + # no file-storage instance at this subsite so look to main site + set subsite_node [subsite::get_element -subsite_id [subsite::main_site_id] -element node_id] + set mount_url [site_node::get_children -package_key file-storage -node_id $subsite_node] +} +if { $mount_url ne "" } { + # file-storage instance IS at main site + array set site_node [site_node::get -url $mount_url] + set fs_package_id $site_node(package_id) +} set selector_type "image" set file_selector_link [export_vars -base file-selector \ {fs_package_id folder_id selector_type}]
If there is no file-storage instance in the main site either, then the default code in file-selector.tcl will use the first one it finds -- or generate a server error if there is no file-storage mounted at all, but presumably this shouldn't happen in a real site.
I can commit this if you approve, Gustaf, or if there's a better way, I'd like to see it.
Thanks for your help with your brilliant package, Gustaf!
Do you see arguments against this?
-gustaf
Index: xowiki/www/xinha/file-selector.tcl =================================================================== RCS file: /cvsroot/openacs-4/packages/xowiki/www/xinha/file-selector.tcl,v retrieving revision 1.3 diff -u -r1.3 file-selector.tcl --- xowiki/www/xinha/file-selector.tcl 30 Dec 2005 00:09:58 -0000 1.3 +++ xowiki/www/xinha/file-selector.tcl 30 Jun 2006 22:45:48 -0000 @@ -20,10 +20,26 @@ } else { # get package_id from package name set key file-storage - set id [apm_version_id_from_package_key $key] - set mount_url [site_node::get_children -all -package_key $key -node_id $id] - array set site_node [site_node::get -url $mount_url] - set fs_package_id $site_node(package_id) + # get file-storage instance from this subsite + set subsite_node [subsite::get_element -element node_id] + set mount_url [site_node::get_children -package_key $key -node_id $subsite_node] + if { $mount_url eq "" } { + # no file-storage instance at this subsite so look to main site + set subsite_node [subsite::get_element -subsite_id [subsite::main_site_id] -element node_id] + set mount_url [site_node::get_children -package_key file-storage -node_id $subsite_node] + } + if { $mount_url ne "" } { + # file-storage instance IS at main site + array set site_node [site_node::get -url $mount_url] + set fs_package_id $site_node(package_id) + } else { + # look for any file-storage instance + # probably not what user wants; could return error instead + set id [apm_version_id_from_package_key $key] + set mount_url [site_node::get_children -all -package_key $key -node_id $id] + array set site_node [site_node::get -url $mount_url] + set fs_package_id $site_node(package_id) + } } }
If that looks OK, let me know and I can commit it. Thanks again!