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

Comments

radiobuzzer’s picture

Title: Error reported on image migration: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry » Upgrade to D7 fails: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry
Project: Field converter » Image
Version: 7.x-1.0-alpha1 » 7.x-1.x-dev
Component: Code » image.module

Changed this as an issue of the Image Legacy module

radiobuzzer’s picture

Status: Active » Needs review
StatusFileSize
new2.35 KB

Problem 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 :-)

radiobuzzer’s picture

Project: Image » Field converter
Issue summary: View changes

Appearance of error message

radiobuzzer’s picture

Project: Field converter » Image

bump

radiobuzzer’s picture

Priority: Normal » Major
radiobuzzer’s picture

Project: Image » Field converter
Component: image.module » Code
radiobuzzer’s picture

Component: Code » Migration plans
joachim’s picture

> 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?

radiobuzzer’s picture

Hi, 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?

loopduplicate’s picture

Thank you so much. Your patch seems to work pretty well.

loopduplicate’s picture

Issue summary: View changes

Reference to similar issue, improved

kenorb’s picture

Project: Field converter » Image
Component: Migration plans » documentation
Issue summary: View changes

This patch is against the Image module.

jacob.embree’s picture

Component: documentation » image.module
StatusFileSize
new2.38 KB
new1.63 KB

#2 worked for me. Here is one without the whitespace warnings from git and improved conformance to the Drupal style guide.

avpaderno’s picture

Status: Needs review » Closed (outdated)

I am closing this bug report, since the module has been marked obsolete on 2016.