When doing an import I get 600+ authors imported, and a dozen+ errors, with the error message:
array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! File includes/entity.inc, line 178

I've tried to debug by adding this on line 179:

if (!empty($ids)) { foreach ($ids as $id) { if (!is_string($id) && !is_numeric($id)) { dvm($ids); } } }

.. and nothing is printed.

My migration is:

class VEAuthorMigration extends Migration {
  public function __construct() {
    parent::__construct();
    $this->description = t('Migrate authors.');
    $this->dependencies = array('VEPaper');
    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'id' => array('type' => 'int', 'length' => 11, 'not null' => FALSE, 'description' => 'Author ID'),
      ),
      MigrateDestinationNode::getKeySchema()
    );

    $query = db_select('virtualexplorer.authors', 'authors')
             ->fields('authors', array('id', 'weight', 'paper_id', 'firstname', 'surname', 'email', 'blurb'));

    $this->source = new MigrateSourceSQL($query);
    $this->destination = new MigrateDestinationFieldCollection('field_authors', array('hostEntityType' => 'node'));

    $this->addFieldMapping('hostEntityId', 'paper_id')->sourceMigration('VEPaper');

    $this->addFieldMapping('field_givenname', 'firstname');
    $this->addFieldMapping('field_othername', NULL);
    $this->addFieldMapping('field_surname', 'surname');
    $this->addFieldMapping('field_email', 'email');
    $this->addFieldMapping('field_notes', NULL);

    $this->addUnmigratedDestinations(array('path'));
  }
}

Any ideas on what might be going wrong?

Comments

aidanlis’s picture

Okay I know what's going wrong, the VEPaper migration doesn't import all of the papers, so although the editor/papers tables have key integrity the import does not. Is this something that we can provide a better error message for? I'm happy to write a patch ...

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

Well, let's identify precisely what is happening here. The error comes from entity loading, where the ID passed is for some reason not a string or integer (I'm betting an array). You said you added that line at 179 of entity.inc, which is after the array_flip() causing the error on 178 - try putting it before. And, rather than the dvm($ids), try dvm(debug_backtrace()), to see how you're getting to this point.

aidanlis’s picture

Status: Postponed (maintainer needs more info) » Active

It's being passed NULL, so the ids going to entity_load look like $ids = array(NULL).

There's an issue to #1102570: array_flip() [function.array-flip] issue in DrupalDefaultEntityController / entity.inc throw an exception when this happens, which would make debugging easier.

mikeryan’s picture

Category: bug » support
Status: Active » Closed (won't fix)