hi there

I'm trying migrate objects from an external database
into (rooms) Enities in drupal 7

by using MigrateDestinationEntityAPI

But In the migarte_ui
I don't get access to the fields of that destination entity

admin / content / migrate / UARoomsMig

migrate ui


class UARoomsMig extends Migration {
   public function __construct() {
    parent::__construct();
  ini_set('auto_detect_line_endings', TRUE);
   
    $query = Database::getConnection('default', 'for_migration')
             ->select( '_immo_objekte', 'io')
             ->fields('io', array('obj_id','titel'));
  
   
    $this->source = new MigrateSourceSQL($query, array(), NULL,
  array('map_joinable' => FALSE));
   
     $this->destination = new MigrateDestinationEntityAPI('rooms_unit', 'rooms_unit');

    // Create a map object for tracking the relationships between source rows
    $this->map = new MigrateSQLMap($this->machineName,
         array(
          'obj_id' => array('type' => 'int',
                          'unsigned' => TRUE,
                          'not null' => TRUE,
                         )
       
      ),
      MigrateDestinationEntityAPI::getKeySchema('rooms_unit', 'rooms_unit')
    );
    $this->addFieldMapping('name', 'titel');
     $this->addFieldMapping('type')->defaultValue("apartment");
     $this->addFieldMapping('base_price')->defaultValue(100);
   
  }
}

Thanks in advanced!

CommentFileSizeAuthor
migarte_felder_fehlen.jpg33.82 KB1kubik

Comments

sunset_bill’s picture

+1
I'm running into exactly the same thing trying to migrate a D6 CCK content type into a D7 entity.

    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'vid' => array('type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        )
      ),
      MigrateDestinationEntityAPI::getKeySchema('clusters')
    );

    $query = db_select(SOURCE_DB . '.content_type_clusters', 'c')
             ->fields('c', array(
                             'vid',
                             'nid',
                             'field_clusters_term_value',
                             'field_clusters_gotta_know_nid',
                             'field_cluster_topics_featured_value',
                             'field_clusters_main_topic_value',
                             'field_cluster_sponsor_code_value',
                             'field_clusters_skin_fid',
                             'field_clusters_skin_list',
                             'field_clusters_skin_data',
                             'field_clusters_event_value',
                             'field_clusters_custom_event_logo_fid',
                             'field_clusters_custom_event_logo_list',
                             'field_clusters_custom_event_logo_data',
                             'field_cluster_enable_sponsor_ad_value'
                      )
             );


    $this->source = new MigrateSourceSQL($query);
    $this->destination = new MigrateDestinationEntityAPI('clusters', 'clusters');
$ drush ms Clusters
                                                                          
 Group: default  Total  Imported  Unimported  Status  Last imported       
 Clusters        78     0         78          Idle    2014-02-21 07:59:41
$
$ drush mfd Clusters

Clusters Destination Fields

$
sunset_bill’s picture

Found my answer. It's because of this code in the fields() method of entity_api.inc in the migrate_extras module:

    foreach ($properties['properties'] as $name => $property_info) {
      if (isset($property_info['setter callback'])) {
        $fields[$name] = $property_info['description'];
      }
    }

If a field in your target entity doesn't have a setter callback specified, that field doesn't get picked up and therefore won't show in your destination fields.

The fix is to implement hook_entity_property_info_alter() in your entity's .module file. So, for my problem above, it looks like

function clusters_entity_property_info_alter(&$info) {
  $properties = &$info['clusters']['properties'];
  $properties['nid'] = array(
    'label' => t('Node id'),
    'type' => 'integer',
    'description' => 'Node ID of this cluster',
    'schema field' => 'nid',
    'getter callback' => 'entity_property_verbatim_get',   // standard getter function
    'setter callback' => 'entity_property_verbatim_set',   // and standard setter function
  );
  // repeat for each field in your target entity
}

When I did that, my destination fields showed up and my migration worked.

sunset_bill’s picture

Status: Active » Closed (works as designed)