When sending a file via UUID Services, e.g. using the deploy module, if there is already a file with the same URI present on the receiving system, but a different UUID, then an exception will be thrown like: "PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed}...". Additionally an error like: "Warning: Header may not contain more than a single header, new line detected in drupal_send_headers()" may also appear, which is due to the services module tacking the exception message onto the HTTP status header.
This is happening because UUID Services is only checking for files with a matching UUID and does not check for URI conflicts before it saves the file.
Comment | File | Size | Author |
---|---|---|---|
#5 | interdiff-1-5.txt | 910 bytes | David_Rothstein |
#5 | uuid-file-entity-1969222-5.patch | 2.65 KB | David_Rothstein |
#1 | uuid-file-entity-1969222-1.patch | 2.28 KB | gilgabar |
Comments
Comment #1
gilgabar CreditAttribution: gilgabar commentedThe attached patch should resolve the issue. It handles the saving of file entities more carefully, checking for a file with a conflicting URI, and renaming the new file when that is the case. It also handles the case which follows from this when you attempt to send the same file a second, third, etc time, so that it will match on the UUID and use the same renamed file rather than creating additional renamed copies for each subsequent request.
Comment #2
kenorb CreditAttribution: kenorb commentedThe current patch didn't solve my issue reported at:
#2063121: Node Export: WD node: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri'
Something related:
#1838482: Cannot import two nodes having one same PDF file attached
Comment #3
jamesmorrish CreditAttribution: jamesmorrish commentedhmmmm me neither..
Comment #5
David_Rothstein CreditAttribution: David_Rothstein commentedThe previous patch has a problem when the file is something like a video (for example, as managed by the Media YouTube module).
It's actually an existing problem with the code but the patch makes it worse:
Trying to get a local directory name from a URI like "youtube://whatever" doesn't make sense and will fail. By writing the failed result back into $entity->uri that winds up empty and is later saved to the database, corrupting the data and prevented the video from being viewed at all with this patch applied.
Here's a new version of the patch which makes the code skip trying to write a local version of the file if the stream wrapper for the file indicates that it's not writable (like youtube://).
Comment #7
dixon_Committed to 7.x-2.x, thanks a lot @gilgabar and @David_Rothstein!
Comment #8
dixon_