4.2. Handling Deferred Associations With PublishedLink

Associations from a ContentItem (or one of its components) to another top-level ContentItem are not created explicitly at publish time, because the particular live version of the target item may change between the time the source item is first published and the time it is actually made live. Instead, certain metadata describing each association is stored in a PublishedLink object, which will remain in existence until the pending or live source is eventually deleted (unpublished), regardless of how often the target items are published or unpublished.

For each PublishedLink created, the following metadata attributes are stored for each deferred association from object A to (draft) ContentItem B:

When an item is made live, PublishedLink.updateLiveLinks(ContentItem) is called, which performs the following actions:

  1. Generates a list of all PublishedLinks which point to this item from other items which are currently live.

  2. Recreates the association that points to this item for each PublishedLink in the list with specific metadata properties (pendingSource, draftTarget, propertyName, and the live version of draftTarget, which is target). Create the association with the following code:

    if (pendingSource.getObjectType().getProperty(propertyName).\
    isCollection()) {
        DataAssociation da = (DataAssociation) src.get(propertyName);
        da.add(target);
    } else {
        src.set(propertyName,target);
    }       
  3. Generate a list of all PublishedLinks which point from this item to other items which are currently live. Recreate these associations in a similar manner.

  4. For all items which point to this item (as described in the first step) that are published in the file system, refresh the published file by calling QueueManager.queueRepublish(ContentItem)[1].

When a live item is unpublished, associations from the item are automatically deleted by persistence. One-way associations to the item must be manually deleted either in the target item's beforeDelete() method, or in an observer. For the association types defined in the base CMS classes, this is handled automatically by ContentItem.beforeDelete(). For handling updates to published files, PublishedLink.refreshOnUnpublish(ContentItem) is called, which performs the following actions:

  1. Generates a list of all PublishedLinks which point to this item from other items which are currently live.

  2. For all items which point to this item (described in the first step) which are published in the file system, refresh the published file by calling QueueManager.queueRepublish(ContentItem).

Notes

[1]

http://rhea.redhat.com/documentation/api/ccm-cms-6.1.0/com/arsdigita/cms/publishToFile/QueueManager\ .html#queueRepublish(com.arsdigita.cms.ContentItem)