Forum OpenACS Development: content_item__new broken for items with non-cr parents

There is code in the toolkit, for example, the download package, that creates cr_items with parent_id referring to a non-CR object such as a package_id.

This works fine, there is no constraint on parent_id so it is very flexible.

Changes for 5.2 to add package_id to acs_objects also added code in content_item__new to "guess" the package_id if one was not specified. This relies on the parent_id being a content_item, with the root parent of the tree the item is in being a CR root folder. If you put parent_id as a package_id this breaks.

The download package relies on this and has been like this for years. Recently there has been much new code that also relies on parent_ids that are not folders and not even cotnent repository items. Chances are the new code passes package_id explicitly and does not encounter this bug.

How should we fix that? The simplest most straightforward fix is to requite code that needs package_id set to set it correctly or set it NULL.

Another option is to devise a query to find the ultimate parent object without requiring it be a cr_folder. THis is probably possible with a tree query using connect by on oracle and tree_sortkey on PostgreSQL.

This is delaying OpenACS 5.2.1 obviously since I can't upload the new release to openacs.org with this bug.

Collapse
Posted by Dave Bauer on
Besides the parent post looking like hell on the web, I have found an interesting dilemna.

Most items default to rooting at -100.

-100 on openacs.org has package_id of NULL, so the whole exercise is mostly useless.

It would simplify if we just threw out the package_id guesser completely.

Collapse
Posted by Dave Bauer on
Every cr_item eventually has a root parent_id of either -4 (security_context_root) or some other non-cr_item.

So we can just find the item in the hierarchy that has the non-cr_item as the parent, grab the parent_id referring to the non-cr_item, and select package_id from that acs_object.

This query seems to work

select acs_object__package_id(parent_id)
from cr_items
where tree_sortkey=(select tree_ancestor_key(tree_sortkey,2)
 from cr_items where item_id=new__item_id);

I can replace the call to content_item__get_root_folder in content_item__new with this.

If someone with Oracle knowledge would like to write up a connect by version of this, that would be very helpful. Basically we are getting the second item from the root of the hierarchy.
Collapse
Posted by Dave Bauer on
Perhaps something like this on oracle?

 select
      item_id into v_folder_id
    from
	(select item_id, level from
      cr_items
    connect by
      prior parent_id = item_id
    start with
      item_id = get_root_folder.item_id)
	where level = 2;