The uri column in {file_managed} is defined as unique. In Media 2.x, file_uri_to_object() by default reuses an existing fid, but to not break backwards compatibility, that is not the default in Media 1.x. To avoid a PDO exception, the provider must either implement a validate() method that throws an exception that media_internet then displays as a form_set_error(), forcing the user to enter a unique URL, or else pass TRUE to file_uri_to_object(), allowing the Media browser to simply return the already existing fid.

This patch does the latter.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ksenzee’s picture

The patch above keeps the user from getting an error when they enter a duplicate URL, and fixes the UX in most situations. I'm attaching a patch that also updates the timestamp when re-saving the piece of media, so the newly (re)embedded media shows up at the top of the list in admin/content/media, where the user would expect it to be. (Note that this addition was also effulgentsia's idea - I just agreed with him and wrote the patch.)

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

#1 looks great to me, so RTBC. I worked on part of this patch, so if you want to bump it back to "needs review", I'll understand.

Anonymous’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.