Skip to content

Instantly share code, notes, and snippets.

@geraldvillorente
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldvillorente/cb994d91c4afdb4c00b9 to your computer and use it in GitHub Desktop.
Save geraldvillorente/cb994d91c4afdb4c00b9 to your computer and use it in GitHub Desktop.
Find orphaned files in Drupal
SELECT fm.filename
FROM file_managed AS fm
LEFT OUTER JOIN file_usage AS fu
ON ( fm.fid = fu.fid )
LEFT OUTER JOIN node AS n
ON ( fu.id = n.nid )
WHERE (fu.TYPE = 'node' OR fu.TYPE IS NULL)
AND n.nid IS NULL;
@geraldvillorente
Copy link
Author

Count the number of orphaned files.

SELECT COUNT(fm.filename) FROM file_managed AS fm LEFT OUTER JOIN file_usage AS fu ON ( fm.fid = fu.fid ) LEFT OUTER JOIN node AS n ON ( fu.id = n.nid ) WHERE (fu.TYPE = 'node' OR fu.TYPE IS NULL) AND n.nid IS NULL;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment