-1

Umbraco version 7.5.14

I have pic.jpg in a Media library (file in Media folder: inetpub\wwwroot...\Media\pic.jpg)

I want to find out if the file is OK to be deleted, if no page uses it. How? (There are bunch of files to be deleted, I suspect they are not used)

Dalibor
  • 1,430
  • 18
  • 42
  • Why don't you search that file in your repo? If it is being used you will come to know. – शेखर Oct 29 '21 at 10:20
  • @शेखर I don't get it. Please help, I googled for "umbraco repo" but didn't find much. (I'm not much of Umbraco expert, I just need to clean up the space a bit) – Dalibor Oct 29 '21 at 10:41

1 Answers1

0

This solution assumes you have access to the CMS database and know how to run SQL. If you do not know how to do these things I would not recommend this approach...

Since your version of Umbraco is a little older I've had to adapt my script - but this should hopefully do the trick.

DECLARE @MediaPath NVARCHAR(255) = '/media/pic.jpg'



 SELECT 
    contentNode.id 'Content Id',
    contentNode.text 'Content Node Name',
    contentNode.path 'Content Node Path',
    mediaNode.id 'Media Id',
    mediaNode.text 'Media Name',
    cpt.Name 'Media Type',
    COALESCE(cpd.dataNtext, cpd.dataNvarchar) 'Media Properties'
FROM cmsPropertyData cpd WITH(NOLOCK)
INNER JOIN cmsPropertyType cpt WITH(NOLOCK) ON cpt.Alias = 'umbracoFile' AND cpd.propertytypeid = cpt.id
INNER JOIN umbracoNode mediaNode WITH(NOLOCK) ON mediaNode.id = cpd.contentNodeId
INNER JOIN cmsContentXml ccx WITH(NOLOCK) ON ccx.xml LIKE CONCAT('%umb://media/', LOWER(REPLACE(mediaNode.uniqueID,'-','')), '%')
INNER JOIN umbracoNode contentNode WITH(NOLOCK) ON ccx.nodeId = contentNode.id
WHERE COALESCE(cpd.dataNtext, cpd.dataNvarchar, '') LIKE CONCAT('%',@MediaPath,'%')

The output of this script will be a data table showing the content nodes where the image is in use. If the results set is empty - the image is not in the content XML.

In other versions of Umbraco (I cannot tell if Older or Newer) there might be a a cmsMedia table you can use - which is far faster

DECLARE @MediaPath NVARCHAR(255) = '/media/pic.jpg'

SELECT 
    contentNode.id 'Content Id',
    contentNode.text 'Content Node Name',
    contentNode.path 'Content Node Path',
    mediaNode.id 'Media Id',
    mediaNode.text 'Media Name',
    cm.mediaPath
FROM cmsMedia cm
INNER JOIN umbraconode mediaNode ON mediaNode.id = cm.nodeId
INNER JOIN cmsContentXml ccx ON ccx.xml LIKE CONCAT('%umb://media/', LOWER(REPLACE(mediaNode.uniqueID,'-','')), '%')
INNER JOIN umbracoNode contentNode ON ccx.nodeId = contentNode.id
WHERE cm.mediaPath = @MediaPath
Joe van de Bilt
  • 225
  • 1
  • 3
  • 12