Firstly I have to admit that I am not able to tell which module is the culprit of the problem.
The problem:
When I uploaded an image, and clicked the "share" button, the AJAX return:
An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /statuses/ajax
StatusText: n/a
ResponseText:
Error
The website encountered an unexpected error. Please try again later.
ReadyState: undefined
If I disable the AHAH update on statuses, the system simply returns "this image cannot be saved".
The file is uploaded into the sites/default/files directory. No error is caught on the web server's log. And the Drupal log caught an error:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '865-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] => 865 [:db_insert_placeholder_1] => width [:db_insert_placeholder_2] => i:360; [:db_insert_placeholder_3] => 865 [:db_insert_placeholder_4] => height [:db_insert_placeholder_5] => i:479; ) in file_entity_file_insert() (line 70 of /var/www/drupalsite/sites/all/modules/file_entity/file_entity.file.inc).
Versions I am using:
statuses 7.x-1.0-beta2+10-dev (and I've tested the non-dev version, still have same problem)
Statuses Micropublisher(fbsmp) 7.x-1.0-unstable1+7-dev
file_entity 7.x-2.0-beta1+4-dev (and I've tested the non-dev version too, still have same problem)
Obviously some of these code write to the database the second time, so that the primary key is duplicated. Therefore I solved temporarily by adding "try {} catch" on the db_insert() statement of the line 70 of file_entity/file_entity.file.inc :
/**
* Implements hook_file_insert().
*/
function file_entity_file_insert($file) {
// Ensure field data is saved since file_save() does not in Drupal 7.
field_attach_insert('file', $file);
// Save file metadata.
if (!empty($file->metadata)) {
$query = db_insert('file_metadata')->fields(array('fid', 'name', 'value'));
foreach ($file->metadata as $name => $value) {
$query->values(array(
'fid' => $file->fid,
'name' => $name,
'value' => serialize($value),
));
}
try {$query->execute();} catch (Exception $e) { echo $e;} // original: $query->execute();
}
// Clear any related field caches.
file_entity_invalidate_field_caches($file);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | fbsmp-fix_integrity_contraint_error-2372777-4.patch | 563 bytes | cesarmiquel |
Comments
Comment #1
icecreamyou commentedThis is an FBSMP problem. There are a bunch of issues about image uploading in the FBSMP queue. Unfortunately there is not an active FBSMP maintainer right now.
Comment #2
cesarmiquel commentedI figured out what the problem is: when uploading an image this function is called _fbsmp_file_save_upload(). The code for that function is:
The problem with this code is that its invoking hook 'file_insert' and that hook has already been triggered by the previous call to file_save_upload() which calls file_save() which invokes the hook (look here: https://api.drupal.org/api/drupal/includes%21file.inc/function/file_save/7)
The solutions is to remove that block altogether and everything should be good. I can provide a patch if someone can apply it :-)
Comment #3
icecreamyou commentedI will apply it (maybe not immediately - I will need some time) or give you commit access to apply it yourself. Thanks
Comment #4
cesarmiquel commentedGreat! If you want to grant me commit access that would be awesome and I have no problem in doing it. Otherwise here's the patch.
Comment #6
icecreamyou commentedInteresting, this patch is identical to the one in #2425557: Saving photos no longer works. Duplicate calls to hook_file_insert, provided almost at the same time. Committed, and I tagged a new alpha release. Thanks!