Forum OpenACS Development: /file.vuh: set correct package_id in ad_conn

For a generic filter (tracking) I need to make sure that ad_conn package_id is correctly pointing to the package of the object for file.vuh (otherwise it would always be the package of the main site, regardless under which folder and therefore package the file was uploaded).

I was wondering how to do this best. Should I write a filter for /file which sits between the filter filling the ns_set for ad_conn and my generic filter, overwriting the package_id with the "correct" one (for my purposes). Probably not...

Alternatively I could modify file.vuh manually to rewrite the tracked information, though it would mean forking file.vuh, not nice either.

Last but not least I could have a sweeper on my tracking data which cleans it up (meaning sets the correct package_id and subsite_id for all the /file accesses).

I'm raising this here because some others might also stumble upon the fact that ad_conn uses the package_id according to site_map, not according to object. Maybe we could add an object_package_id to ad_conn, I don't know how useful that might be though.

Just in case, here is the addition to ad_conn in the default section

                    recursion_count {
                        # sometimes recusion_count will be uninitialized and
                        # something will call ad_conn recursion_count - return 0
                        # in that instance.  This is filters ahead of rp_filter which throw
                        # an ns_returnnotfound or something like that.
                        set ad_conn(recursion_count) 0
                        return 0
                    }
                    object_package_id {
                        # Package_id of the object_viewed
                        set ad_conn(object_package_id) [acs_object::package_id -object_id $ad_conn(object_id)]
                        return $ad_conn(object_package_id)
                    }
                    default {
                        return [ns_conn $var]
                    }

Collapse
Posted by Dave Bauer on
Of course ad_conn package_id refers to the package_id of the URL you are accessing.

I don't see this as a useful addition to do an additional query for information that is already stored in the database. That is, if you are tracking usage of the object in question, you already have the object_id, and you can get the package_id later if you need it for some report.

In addition ad_conn object_id IS the package_id mounted at the current site_node, unless you have mounted some other object there, but in that case ad_conn package_id is wrong since its set to site_node(object_id) anyway.

That is ad_conn object_id is not referring at all to a "viewed" object.

I know that Jeff Davis proposed a "displayed_object_id" property that would be sent to the master template for handling, but it was never added to ad_conn.

Collapse
Posted by Mark Aufflick on
Malte, if you only need this behaviour for a single script (/file.vuh) why don't you just set it there?

You can alter an ad_conn property with ad_conn -set, that way any tcl/adp pairs you include will transparently have the package_id set the way you want.

Collapse
Posted by Malte Sussdorff on
First of all thanks for the insights. I actually went ahead and collected the object_id manually without changing file.vuh.

Learning that the object_id is actually the package_id is disturbing, I thought it really was the displayed_object_id. And obviously then the code I wrote makes absolutely no sense at all. Thanks for clearing that up Dave. In this case I will deduct the object_id from the URL in general. Especially as this is only a side topic for me 😊.