Problem/Motivation
I just finished a core upgrade from drupal 6 to drupal 7. According to the documentation, I tried to use this module in order to upgrade my images as well. After I started the process, I got this error:
An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information follows. Path: /batch?id=3384&op=do StatusText: Service unavailable (with message) ResponseText: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'public://images/eett.jpg' for key 2: INSERT INTO {file_managed} (uid, filename, uri, filemime, filesize, status, timestamp) 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); Array ( [:db_insert_placeholder_0] => 1 [:db_insert_placeholder_1] => eett.jpg [:db_insert_placeholder_2] => public://images/eett.jpg [:db_insert_placeholder_3] => image/jpeg [:db_insert_placeholder_4] => 17768 [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 1261754184 ) in image_legacy_field_convert_object_pre_load() (line 229 of /home/radiofon/public_html/drupal-7.12/sites/all/modules/image/image_legacy.field_convert.inc).
Suspected cause
I am trying to determine the cause of the problem. In the beginning I thought it has to do with file duplicates
#1176186: D6 -> D7 upgrade: Duplicate files cause Integrity constraint violation: 1062 Duplicate entry 'xx' for key 'PRIMARY'
but in fact, the files mentioned in the error, appears only once in the {file} table.
I managed to overcome the problem for this file, by simply renaming the file in the hard disk and the database. A few thousand were processed with no problem, but when another file had the same issue, the upgrade process halts again with the same error.
For some reason, a duplicate is reported when the file is about to be entered in the {file_managed} table. But since this file only occurs once in the original table, I cannot figure out the exact cause of the problem
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | interdiff-1577648-2-11.txt | 1.63 KB | jacob.embree |
| #11 | image.duplicates_file_managed-1577648-11.patch | 2.38 KB | jacob.embree |
| #2 | image.duplicates_f_managed-1577648-2.patch | 2.35 KB | radiobuzzer |
Comments
Comment #1
radiobuzzer commentedChanged this as an issue of the Image Legacy module
Comment #2
radiobuzzer commentedProblem cause
Apparently, it is possible that some image files have already been indexed in the {file_managed} table, before the image convert field process starts. This may be the case, because they have been already migrated as simple files, during the core upgrade.
So, when some files are already indexed in the {file_managed} and the image convert tries to insert them again, there is a duplicate file 'uri' and an integrity error is risen.
In order to reproduce the error, do a full core upgrade of D6 to D7. Then add manually some of the image files, into the {file_managed} table. Finally enable the image_legacy, field convert modules, go to /admin/content/field_convert and upgrade images.
Suggested solution
At the part of the process, when the image file (that needs to be converted) has been determined, first check if it already exists in the {file_managed}. If it doesn't exist, you can proceed with inserting it and getting the new file id. Otherwise, just fetch the existing file id and use it as if a new insertion was done.
PS: This is my first Drupal patch :-)
Comment #2.0
radiobuzzer commentedAppearance of error message
Comment #3
radiobuzzer commentedbump
Comment #4
radiobuzzer commentedComment #5
radiobuzzer commentedComment #6
radiobuzzer commentedComment #7
joachim commented> Apparently, it is possible that some image files have already been indexed in the {file_managed} table, before the image convert field process starts. This may be the case, because they have been already migrated as simple files, during the core upgrade.
Was it all the files or merely some of them?
I'm curious why only some of them would have been migrated. Were any of your image files in multiple use?
Comment #8
radiobuzzer commentedHi, thanks for your response. This was indeed only for some of the files.
So I also assume that some of these were seen by some of the nodes as "files" and by some others as "images". There is no clear explanation for that, but I have been carrying this database since drupal 4.x , so a lot of the different image handling changes occurred since then.
Do you think that my proposed patch would cause a problem?
Comment #9
loopduplicate commentedThank you so much. Your patch seems to work pretty well.
Comment #9.0
loopduplicate commentedReference to similar issue, improved
Comment #10
kenorb commentedThis patch is against the Image module.
Comment #11
jacob.embree commented#2 worked for me. Here is one without the whitespace warnings from git and improved conformance to the Drupal style guide.
Comment #12
avpadernoI am closing this bug report, since the module has been marked obsolete on 2016.