Hi Timo,
usually such a check works fine. Using the reference graph to check for usages is in general the right approach.
There are some edge cases where that might be not enough because some (quite rare) ways of „using“ a media element are not reflected in the reference graph:
- If a medium is only used by „computing“ its uid, e.g. something like $CMS_REF(media:"flag_"+set_language)$
(but using the complete uid like in $CMS_REF(media:"flag_en")$ works!) - When there are mechanisms that rely on template logic to „find“ media elements that are not „directly“ referenced otherwise. An example would be some code that just works on a mediastore folder and iterates through its children to output links to them
- Depending on your use case, you might want to perform the check both on the current AND release store to also find media elements that have already been deleted but their deletion has not been released
- The check only uses the newest revision of the stores (current/release). This MIGHT be relevant if a user later restores a page that referenced the media in the past (but not now anymore)
Those cases are quite rare from my experience but I have come across them - so it would be good to check if your project(s) use such mechanisms.
Of course it is also important to tun that code with a user that has the permissions to access all media elements as only those will be checked.
Michael