Forum OpenACS Development: Re: Re: Re: Re: xoWiki and images

Collapse
Posted by Stan Kaufman on
Gustaf, excellent point; I hadn't checked how file linking works. What do you think of this:

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!