Closed (won't fix)
Project:
Migrate
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
27 Oct 2011 at 12:40 UTC
Updated:
21 Nov 2011 at 22:22 UTC
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
Comment #1
aidanlis commentedOkay 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 ...
Comment #2
mikeryanWell, 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.
Comment #3
aidanlis commentedIt'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.
Comment #4
mikeryanImproved DX on invalid keys is being addressed in core issue #1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID.