Title: Bug causing unexpected data loss
Last modified: December 21, 2019

---

# Bug causing unexpected data loss

 *  Resolved [Marco Chiesi](https://wordpress.org/support/users/marcochiesi/)
 * (@marcochiesi)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/bug-causing-unexpected-data-loss/)
 * Hello,
    first of all, thank you very much for this precious and useful plugin.
   I am writing to report a bug that I’ve encountered recently during a media library
   cleanup on a very large site. I have moved lots of images to the Media Cleaner
   Trash and I kept them there for a couple of weeks. During this time new images
   were uploaded to the website. When I finally emptied the trash, the automatic
   procedure also deleted inadvertently some of the new images that were uploaded
   recently. After further investigation, I’ve found that images currently in the
   media library with the very same file name (and in the same original folder) 
   of the ones that were being deleted from the trash were deleted as well. You 
   should be able to reproduce the issue, by moving an image to the trash and then
   upload a new image with the very same name, and finally empty the trash. P.s.
   In my case, there were many (75k+) images, including many with generic file names(
   i.e. IMG_0001.jpg) and moreover I had the option “Organize my uploads into month-
   and year-based folders” disabled; these things increased the probability of matching
   file names.

Viewing 1 replies (of 1 total)

 *  Plugin Author [Jordy Meow](https://wordpress.org/support/users/tigroumeow/)
 * (@tigroumeow)
 * [6 years, 5 months ago](https://wordpress.org/support/topic/bug-causing-unexpected-data-loss/#post-12261613)
 * Hello,
 * I am quite annoyed, I replied to this in details but somehow the reply wasn’t
   posted >< I need to go soon but I really wanted to reply so let me know if it’s
   not enough details.
 * First, thanks for finding this, and it actually makes sense. The issue only appears
   with the Media Library method, not the Filesystem Method.
 * When a Media Entry is trashed, the files are moved by the cleaner to physical
   trash handled by the plugin, and the DB entry is marked as deleted but still 
   in the database (by the WordPress API). When the trash is emptied, files are 
   removed (and that’s fine) but the Cleaner also calls the WordPress API to permanently
   delete the DB entry. WordPress makes sure everything related to that DB entry
   is removed… the old location of the files included! That’s actually normal.
 * One solution would be to modify the DB entry before it’s removed temporarily:
   the location of the files would be updated to the trash folder. If it’s restored,
   then Media Cleaner would restore the previous settings.
 * The second solution would be for Media Cleaner to stop using the trash for the
   Media entries, and to start handling everything by itself. No need to set up 
   this constant in the wp-config neither. The problem is that it’s a big change,
   and it’s hard for me to guess the downsides.
 * I would rather go for solution two. It’s more difficult, but solution 1 is also
   tricky and brings no advantages for my users (and you are the only one who encountered
   that issue). I would prefer to go for solution two since it removes the need 
   of creating the constant so that it works better for you, and easier to uses 
   for the others 🙂
 * Testing will be definitely needed. If you are interested in this, it would be
   great if you could get in touch with me ([http://meowapps.com/contact](http://meowapps.com/contact)).

Viewing 1 replies (of 1 total)

The topic ‘Bug causing unexpected data loss’ is closed to new replies.

 * ![](https://ps.w.org/media-cleaner/assets/icon-256x256.png?rev=2791576)
 * [Media Cleaner: Clean your WordPress!](https://wordpress.org/plugins/media-cleaner/)
 * [Support Threads](https://wordpress.org/support/plugin/media-cleaner/)
 * [Active Topics](https://wordpress.org/support/plugin/media-cleaner/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/media-cleaner/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/media-cleaner/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Jordy Meow](https://wordpress.org/support/users/tigroumeow/)
 * Last activity: [6 years, 5 months ago](https://wordpress.org/support/topic/bug-causing-unexpected-data-loss/#post-12261613)
 * Status: resolved