Closed (fixed)
Project:
Migrate Extras
Version:
7.x-2.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
27 Oct 2011 at 16:43 UTC
Updated:
16 Nov 2011 at 17:10 UTC
This is what I've got so far:
/**
* Provides a ipaddress FieldHandler for the Migrate module.
*/
class MigrateFieldIpaddressFieldHandler extends MigrateFieldHandler {
public function __construct() {
$this->registerTypes(array('field_ipaddress'));
}
public function prepare($entity, array $field_info, array $instance, array $values) {
$migration = Migration::currentMigration();
$arguments = (isset($values['arguments']))? $values['arguments']: array();
$language = $this->getFieldLanguage($entity, $field_info, $arguments);
// Setup the standard Field API array for saving.
$delta = 0;
foreach (array_filter($values) as $value) {
$return[$language][$delta]['start'] = $value['start'];
$return[$language][$delta]['end'] = $value['end'];
$delta++;
}
if (!isset($return)) {
$return = NULL;
}
return $return;
}
}
The error I'm getting is:
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column [error]
'field_subscription_iprange_start' at row 1: INSERT INTO {field_data_field_subscription_iprange}
(entity_type, entity_id, revision_id, bundle, delta, language, field_subscription_iprange_start,
field_subscription_iprange_end) 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, :db_insert_placeholder_6,
:db_insert_placeholder_7); Array
(
[:db_insert_placeholder_0] => user
[:db_insert_placeholder_1] => 2884
[:db_insert_placeholder_2] => 2884
[:db_insert_placeholder_3] => user
[:db_insert_placeholder_4] => 0
[:db_insert_placeholder_5] => und
[:db_insert_placeholder_6] =>
[:db_insert_placeholder_7] =>
)Any tips?
P.s. I'm so appreciative of the hard work you've all put into this module. It's really quite an amazing framework.
Comments
Comment #1
mikeryanSupport for contrib modules goes into the migrate_extras module.
There's nothing here to set the 'start' and 'end' values coming into the handler. In the Migration class, addFieldMapping() directly only takes a single source value for the field, you need to use arguments() to pass additional values. See, for example, MigrateTextFieldHandler and how the summary value is handled.
Comment #2
drewish commentedThe test you're using for valid rows:
foreach (array_filter($values) as $value) {is not sufficient. You'll want to check that 'start' and 'end' are populated with numbers.
Comment #3
mikeryanComment #4
aidanlis commentedThanks drewish, that was it. The data is now being passed to user_save() correctly, but the actual problem is the field_ipaddress presave function is not decoupled from the widget. I suspect when I work out how to do that the migrate part should work :)
Thanks,