Problem/Motivation

Installations which have multiple web servers with non shared temporary directories can encounter a PDOException when attempting to replace a files in quick succession. The sequence required is the following:

  • Choose to edit a file
  • Upload a file with any name, called NAME1
  • Choose to edit a file within the temporary file lifetime window, can be same as originally edited file or different file
  • Upload a file called NAME1
  • This is something not controllable by the user, but the uploaded file must be handled by a different server than the original upload. Specifically, the temporary directory can not have a file named NAME1 in it on the server handling the second upload
  • PDOException happens. PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'temporary://test.pdf' 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);

Proposed resolution

Insert a file_delete call after the file_unmanaged_copy call in file_entity_edit_submit

Remaining tasks

  1. Review patch

User interface changes

None

API changes

None

Original report by @tekante

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tekante’s picture

Dave Reid’s picture