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

mikeryan’s picture

Project: Migrate » Migrate Extras
Component: Code » Miscellaneous
Category: support » feature

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

drewish’s picture

Project: Migrate Extras » Migrate
Component: Miscellaneous » Code
Category: feature » support

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

mikeryan’s picture

Project: Migrate » Migrate Extras
Component: Code » Miscellaneous
Category: support » feature
aidanlis’s picture

Status: Active » Fixed

Thanks 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,

Status: Fixed » Closed (fixed)

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