You are here

function location_migrate_import_location in Migrate Extras 6

Implementation of hook_migrate_import().

1 call to location_migrate_import_location()
location_user_migrate_import_location_user in ./location_user.migrate.inc
Implementation of hook_migrate_import().

File

./location.migrate.inc, line 80
Integrates location module with the migrate module

Code

function location_migrate_import_location($tblinfo, $row) {
  $loc = (object) array();
  foreach ($tblinfo->fields as $destfield => $values) {
    if ($values['srcfield'] && $row->{$values}['srcfield']) {
      $loc->{$destfield} = $row->{$values}['srcfield'];
    }
    else {
      $loc->{$destfield} = $values['default_value'];
    }
  }
  timer_start('location_prepare hooks');
  $errors = migrate_destination_invoke_all('prepare_location', $loc, $tblinfo, $row);
  timer_stop('location_prepare hooks');
  $context = $loc->context;
  unset($loc->context);
  $success = TRUE;
  foreach ($errors as $error) {
    if ($error['level'] != MIGRATE_MESSAGE_INFORMATIONAL) {
      $success = FALSE;
      break;
    }
  }

  //change loc to array for location_save().

  //$loc = array(0 => (array)$loc);
  $loc = (array) $loc;
  if ($success) {
    timer_start('location_save');
    $not_empty = location_save($loc, FALSE, $context);

    //$success = location_save_locations($loc, $context);
    timer_stop('location_save');
    if (!$not_empty) {
      $errors[] = migrate_message("Empty Location - location module considers this location 'empty' so it will not be saved. It probably matches the default location form.");
    }

    //change loc back to object
    $loc = (object) $loc;
    $loc->context = $context;
    $loc->not_empty = (bool) $not_empty;

    // Call completion hooks, for any processing which needs to be done after node_save
    timer_start('location_completion hooks');
    $errors = array_merge($errors, migrate_destination_invoke_all('complete_location', $loc, $tblinfo, $row));
    timer_stop('location_completion hooks');
  }
  return $errors;
}