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);
}

Comments

icecreamyou’s picture

Project: Statuses (Social Microblog) » Facebook-style Micropublisher
Component: Code (API) » Code - API

This 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.

cesarmiquel’s picture

I figured out what the problem is: when uploading an image this function is called _fbsmp_file_save_upload(). The code for that function is:

<?php
function _fbsmp_file_save_upload($source, $validators = array(), $dest = FALSE) {
  if (!$file = file_save_upload($source, $validators, $dest, FILE_EXISTS_RENAME)) {
    return 0;
  }

  //Let modules add additional properties to the yet barebone file object.
  foreach (module_implements('file_insert') as $module) {
    $function =  $module . '_file_insert';
    $function($file);
  }

  _fbsmp_file_cache($file); //Cache the file in order to minimize load queries
  return $file;
}
?>

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 :-)

icecreamyou’s picture

I will apply it (maybe not immediately - I will need some time) or give you commit access to apply it yourself. Thanks

cesarmiquel’s picture

Great! 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.

  • IceCreamYou committed e833958 on 7.x-1.x
    Issue #2425557, #2372777 by cesarmiquel, mpotter: Fixed saving photos...
icecreamyou’s picture

Status: Active » Fixed

Interesting, 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!

Status: Fixed » Closed (fixed)

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