Home
The Toolkit for Online Communities
17712 Community Members, 2 members online, 2085 visitors today
Log In Register
OpenACS Home : Forums : OpenACS Development : xoWiki and images : One Message

Forum OpenACS Development: Re: Re: xoWiki and images

Collapse
3: Re: Re: xoWiki and images (response to 2)
Posted by Stan Kaufman on
The behavior I noted indeed isn't "random" though it appeared that at first. What's going on is that when there are multiple instances of file-storage in various subsites and the main site, the file-selector.tcl code grabs the first one it finds (because apm_version_id_from_package_key will return all the instances, and then site_node::get_children uses the first one it gets):

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!

Collapse
Posted by Gustaf Neumann on
Stan, the same problem with images and subsites happens with link to files. therefore it is better to put this code into the file-selector. secondly, if someone passes explicit a folder_id or a fs_package_id, the search is not needed and is actually wrong since it can overwrite the specified value. I would put the your added code to file-selector in the section called now "get package_id from package name".

Do you see arguments against this?
-gustaf

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!