site_node::closest_ancestor_package (public)

 site_node::closest_ancestor_package [ -url url ] [ -node_id node_id ] \
    [ -package_key package_key ] [ -include_self ] \
    [ -element element ]

Defined in packages/acs-tcl/tcl/site-nodes-procs.tcl

Starting with the node of the given id, or at given url, climb up the site map and return the id of the first not-null mounted object. If no ancestor object is found the empty string is returned. Will ignore itself and only return true ancestors unless include_self is set.

Switches:
-url (optional)
The url of the node to start from. You must provide either url or node_id. An empty url is taken to mean the main site.
-node_id (optional)
The id of the node to start from. Takes precedence over any provided url.
-package_key (optional)
Restrict search to objects of this package type. You may supply a list of package_keys.
-include_self (boolean) (optional)
Return the package_id at the passed-in node if it is of the desired package_key. Ignored if package_key is empty.
-element (defaults to "object_id") (optional)
Returns:
The id of the first object found and an empty string if no object is found. Throws an error if no node with given url can be found.
Author:
Peter Marklund

Partial Call Graph (max 5 caller/called nodes):
%3 test_site_node_closest_ancestor_package site_node_closest_ancestor_package (test acs-tcl) site_node::closest_ancestor_package site_node::closest_ancestor_package test_site_node_closest_ancestor_package->site_node::closest_ancestor_package ad_conn ad_conn (public) ad_conn->site_node::closest_ancestor_package dir_navbar_list dir_navbar_list (public) dir_navbar_list->site_node::closest_ancestor_package packages/acs-subsite/www/admin/plain-master.tcl packages/acs-subsite/ www/admin/plain-master.tcl packages/acs-subsite/www/admin/plain-master.tcl->site_node::closest_ancestor_package packages/acs-subsite/www/admin/site-map/instance-delete.tcl packages/acs-subsite/ www/admin/site-map/instance-delete.tcl packages/acs-subsite/www/admin/site-map/instance-delete.tcl->site_node::closest_ancestor_package packages/acs-subsite/www/group-master.tcl packages/acs-subsite/ www/group-master.tcl packages/acs-subsite/www/group-master.tcl->site_node::closest_ancestor_package

Testcases:
site_node_closest_ancestor_package
Source code:
    # Make sure we have a URL to work with
    if { $url eq "" } {
        if { $node_id eq "" } {
            set url "/"
        } else {
            set url [site_node::get_url -node_id $node_id]
        }
    }
    #ns_log notice "closest_ancestor_package still [list -url $url urlv [ns_conn urlv]]"

    #
    # GN: Make sure, the URL does not end with multiple slashes. The
    # following regsub is from the standard's point of view not
    # correct, since a URL path /%2f/ is syntactically permissible,
    # but this is not supported in the current site-nodes code. It
    # would be correct, to avoid the parsing of the slashes here and
    # to process instead the result of [ns_conn urlv], which is
    # already parsed (before the percent substitutions). This would
    # probably require the request processor to perform some mangling
    # of urlv in vhost cases to set a a proper [ad_conn urlv] ... and
    # of course to pass the "urlv" instead of the "url" to the
    # slash-parsing functions.
    #
    regsub {(/[/]*)/$} $url / url

    #ns_log notice "closest_ancestor_package simplified [list -url $url]"

    #
    # Should we return the package at the passed-in node/url?
    #
    if { $include_self_p && $package_key ne ""} {
        set node [site_node::get -url $url]
        #ns_log notice "=== [list site_node::get -url $url] => '$node'"

        if {[dict get $node package_key] in $package_key} {
            return [dict get $node $element]
        }
    }

    set elm_value {}
    while { $elm_value eq "" && $url ne "/"} {
        # move up a level
        set url [string trimright $url /]
        set url [string range $url 0 [string last / $url]]

        set node [site_node::get -url $url]

        # are we looking for a specific package_key?
        if { $package_key eq ""
             || [dict get $node package_key] in $package_key
         } {
            set elm_value [dict get $node $element]
        }
    }

    return $elm_value
Generic XQL file:
packages/acs-tcl/tcl/site-nodes-procs.xql

PostgreSQL XQL file:
packages/acs-tcl/tcl/site-nodes-procs-postgresql.xql

Oracle XQL file:
packages/acs-tcl/tcl/site-nodes-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: