I have media 2.x and if i upload an image with the media browser i get the message

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '37-width' for key 'PRIMARY': INSERT INTO {file_metadata} (fid, name, value) 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); Array ( [:db_insert_placeholder_0] => 37 [:db_insert_placeholder_1] => width [:db_insert_placeholder_2] => i:1280; [:db_insert_placeholder_3] => 37 [:db_insert_placeholder_4] => height [:db_insert_placeholder_5] => i:800; ) in file_entity_file_insert() (line 70 of /httpdocs/sites/all/modules/file_entity/file_entity.file.inc).

Comments

fox_01 created an issue. See original summary.

yuseferi’s picture

I have the same problem, I have a custom hook_file_insert in my module

function dsfrdev_file_insert($file)
{
    $parts = pathinfo($file->filename);
    if (in_array(mb_strtolower($parts['extension']), array('jpg', 'jpeg', 'gif', 'png', 'tif', 'flv', 'pdf'))) {
        $uri = 'public://' . 'dsfr_' . $file->uid . '_' . $file->timestamp . '.' . $parts['extension'];
        $file = file_move($file, $uri);
    }
}

everything worked correctly but when I install file_entity module when try to upload file I face this problem

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3343-width' for key 'PRIMARY': INSERT INTO {file_metadata}

where is the problem and how I resolve it?

Dave Reid’s picture

Category: Bug report » Support request

@zhilevan: The problem is calling file_move(), which saves managed files, from a hook where a managed file is being saved (and creates unnecessary loops). You should switch to using file_unmanaged_move() which would avoid it.

fox_01’s picture

I think this issue is a problem. i run into that issue after (i assume that this is reason) uploading has aborted because of redirection issues but now that issues are solved and i get this error everytime uploading a file

Found a possible source error #1349288: devel generate has to create paths for filefields

saleempbt5’s picture

I have same problem, has anyone got solution for this?

joseph.olstad’s picture

please provide version and debug information, error messages, what happens before and after error, how to reproduce. What version of database ? mysql, postgresql , mssql ?
version number?

what version of file_entity , what version of core, what version of the 'media' module (if you are using it).

apache error log for the precise moment of the error OR watchdog/dblog (drupal log).

saleempbt5’s picture

I am sorry i forgot to give more details about the error.

Core version : 7.59
Database system MySQL 5.7
fileentity version : Version: 7.x-2.0-beta1
Media : Version: 7.x-2.0-alpha4+38-dev

This is my code

function custommodulename_file_insert($file) {
 $parts = pathinfo($file->filename); 
$new_file_name = substr( $parts['filename'],0,6).'-'.$file->uid .'-'. $file->timestamp . '.' . $parts['extension'];
$file= file_move($file, "public://".$new_file_name, FILE_EXISTS_REPLACE);
}

and this is what i am getting in the dblog after getting an ajax error

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '257473-width' for key 'PRIMARY': INSERT INTO {file_metadata} (fid, name, value) 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); Array ( [:db_insert_placeholder_0] => 257473 [:db_insert_placeholder_1] => width [:db_insert_placeholder_2] => i:889; [:db_insert_placeholder_3] => 257473 [:db_insert_placeholder_4] => height [:db_insert_placeholder_5] => i:278; ) in file_entity_file_insert() (line 70 of /var/www/html/sites/all/modules/file_entity/file_entity.file.inc).

joseph.olstad’s picture

Those are pre-releases of media and file_entity.

Have you tried upgrading media and file_entity?

Try to disable your custom code temporarily, then upgrade to media 7.x-2.23
also upgrade file_entity to 7.x-2.25 at the same time, replace the older versions with the new.

then make sure to visit update.php or do a drush updb

clear caches, check to see if your system is working as expected

then you'll probably want to follow the media recipe for optional configuration and troubleshooting tips

once you've done that, try your custom code again.