MG 1.1 Missing Files After Server Delete

Blackbeard

Well-known member
We had a mishap with some photos and a Server Admin deleting a folder of images with including the backups.

Now we have entries that don't have correlating photos. Is there a way to detect this, and delete them automatically...we predict there are 2-3 gbs of missing data....otherwise we would go through it and do it by hand.
 
Unless you write a PHP script to automate it, there's probably not a great deal you can do.

To automate it, it would require fetching media records, preferably in small batches, and attempting to retrieve the attachment data for each one. You would have to take care that this only targets media with the type "image_upload" and "video_upload" as obviously video embeds don't have attachments.

Once you locate a media item that doesn't have an attachment, I recommend using the XF DataWrtiter system to programmatically delete the entry. This updates various counts and other caches that may be relevant.

If you were doing it manually, I'd recommend doing it via the Admin CP > Applications > Attachment Browser. This can be filtered by content type so that might make things easier to find.

In fact, if you deleted the contents of the data/attachments directory, and then rebuilt the attachment thumbs (Admin CP > Tools > Rebuild Caches > Rebuild Attachment Thumbnails), you will be able to more easily identify the broken images by those that have broken thumbnails in this list.

From there you can "View host content" and then delete the media item in the proper way.
 
Give this a try.

Install it like a normal add-on, and then go to Admin CP > Tools > Rebuild Caches and look for "XenForo Media Gallery: Delete Orphaned Media".

I have tested this, but if you have a way of testing it on a test installation before running it on your live site, please do. But, at the very least, please do a full backup before using it, and be prepared to restore that backup in case anything else goes wrong!
 

Attachments

Top Bottom