umbraco/Umbraco-CMS — pull request #453 by rolfis (2014-08-19 16:27:01+00:00)
Title: U4-5370 Handle relationships between Content and Media

Content and Media is pretty much separated in terms of structure. To give editors a better and more powerful tool, Umbraco should have a clue what relationships exists between the two, as they depend upon each other. An editor could for example be tasked to go trough the Media library and clean it up, but there is no (easy) way for the editor of knowing if the nodes are used or not. Deletion of Media could break the site in terms of design.

My proposed solution is based on my package MediaContentUsage that:
1) creates relationships with custom RelationType between Content and Media nodes
2) reads relationships and Content node properties using a custom Property Editor/DataType to be put on Media Types (like "Image")

However, the internal relationships between Content and Media is not an easy question. For example, my solution uses the ContentService.Publish event and then does SQL queries to find referenced Media nodes. This is done by filtering out a range of DataTypes (Media Picker, Richtext Editor or whatever custom) that could contain references to Media nodes. All the PropertyData fields are combined into one and then tokenized and sanitized, as we're looking for integers. The Richtext Editor PropertyData is regex'd for rel="\d+" as the Media Picker for RTE adds this attribute (good thing).

Then we have the events. Publish is really the main event to handle, but that doesn't cover all. If Content is UnPublished or Trashed, this is handled in the Property Editor that looks upon these attributes on the Content node. If the node is deleted, Umbraco deletes the relations.

But if a writer works with a new Content node and does Save or Send to Publish, this isn't covered and the Media relation won't show up. There could be a number of relations depending on the number of editors and versions of Content, but I'm not really sure if this is important to cover. Most important must be the Published Content on site.

We also have issues like overhead/performance and if it's better to use Examine instead of Relations.