Forum OpenACS Development: Should content_item__get_id resolve the URL of the root folder id that is passed in?

The pl(pg)sql proc content_item__get_id ( url, root_folder_id, resolve_index_p ) accepts a relavtive URL and the folder_id of a content_folder to start querying from.

If the relative URL passed in is of the root_folder that is specified, no item is found. It seems that it would be convenient to be able to resolve the root folder of a hierarchy in the same way as all the children.

The pertinent query is:

42            select 
43              item_id into child_id
44            from 
45              cr_items
46            where
47              parent_id = get_id__parent_id
48            and
49              name = item_name;
This loops through every part of the url, settign the parent_id to the previous item_id until it gets to the end of the url. A folder is never the parent of itself so this query cannot resolve the case where the URL is of the root folder.

I made this change

42            select 
43              item_id into child_id
44            from 
45              cr_items
46            where
47              (parent_id = get_id__parent_id or item_id = get_id__parent_id)
48            and
49              name = item_name;
It still resolves items exactly the same, but in the case where the url is of the root_folder it will return the folder_id.

Does this make sense, or should I write another version of the procedure that takes an optional argument such as "resolve_self" or something similar?

Dave,

To call the below function might be an alternative, if you are worrying about changing the semantics of existing code that depends on the current behavior.

coalesce (content_item__get_id(item_path, root_folder_id, resolve_index), root_folder_id)
Not sure what happens if resolve_index is 't', though ...

But I am rather convinced the functionality you propose is the desired one in most cases.

/Ola

Hi Dave,

I think what you propose should be correct.  We have to look for code which relies on this wrong behaviour.  Or maybe put it into the the release notes of 5.1 or something.  I also uncovered a bug on the same plsql procedure.  Where as the resolve_index_p does not function if you are on the root already.

I have not yet had time to look for apps that relies on this and fix the oracle one too.

Near the top of the function.  I copied similar code that is on the bottom.

  -- If the request path is the root, then just return the root folder
  if get_id__item_path = ''/'' then
    if get_id__resolve_index = ''t'' then

      -- if the item is a folder and has an index page, then return

      if content_folder__is_folder(v_root_folder_id) = ''t'' and
        content_folder__get_index_page(v_root_folder_id) is not null then

        v_root_folder_id := content_folder__get_index_page(v_root_folder_id);
      end if;

    end if;
    return v_root_folder_id;
  end if;