Once I had insalled Media Gallery, I uploaded 7 images which uploaded successfully.

I removed one of the images from the gallery itself by clicking on the "Remove" link on the little dropdown menu at the right-hand top of the image itself.

I then proceeded to re-upload the image and noticed that the filename had a 0 appended at the back. I thought this was odd since I had removed the same image earlier.

I then proceeded to delete the image via the gallery using the same method as described above.

I proceeded to search for the file in question and found that the file I had previously deleted as well as the re-upload of the same file was still present on the file system. The file was called expo7.jpg. I found both expo7.jpg and expo7_0.jpg on the file system.

I went ahead and physically deleted both files.

I went to re-uploaded the same image and got the following exception as mentioend below.

I then went into mySQL to the table in question and found that both filenames were still being referred to hence why I got the duplicate entry exception as stated below.

This should be eaisly reproducable by following these steps.

1. Upload image1.jpg to a gallery
2. Remove the image1.jpg from the gallery.
3. Search for image1.jpg on the file system - you'll find the file still there.
4. Look at the file_managed table in the mySQL database and you'll find that the file is still being referred to.

Please correct so that the following is done on removal of a file from the gallery

1. Remove the physical file from the file system.
2. Remove the database entry that points to the file in question.

I stribe to maintain a clean and up-to-date website and I would prefer not to have any files lying around that are not in use any more.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'public://Expo7_0.JPG' for key 'uri': INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp, type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => Expo7_0.JPG [:db_insert_placeholder_2] => public://Expo7_0.JPG [:db_insert_placeholder_3] => image/jpeg [:db_insert_placeholder_4] => 103456 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 1351493076 [:db_insert_placeholder_7] => image ) in drupal_write_record() (line 7036 of C:\xampp\htdocs\mysite\includes\common.inc).

Comments

Moloc’s picture

Title: Integrity constraint violation: 1062 Duplicate entry - Media gallery not cleaning up » Removing a media should delete it in the db and file-system
Category: bug » feature
Priority: Major » Normal

You should not remove files, which are referenced in the database. If so, you get that error message.

Media Gallery removes the images from the gallery only. I think, this issue can not be solved by media_gallery.
Reason:
- upload a file using media module
- goto media_gallery -> add media -> select "libraries" tab -> select uploaded images
- remove media from media_gallery
-> media gallery would remove a file from db and file-system, which is not uploaded with media_gallery.

In media 7.x-2.x the files get deleted, when there is no other reference to the file. See also #1781260: Remove file from gallery may delete file . So it is fixed in file_entity/media in the 2.x release.

ivnish’s picture

Status: Active » Closed (outdated)