首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >field_collection与migration_d2d的迁移

field_collection与migration_d2d的迁移
EN

Drupal用户
提问于 2019-05-24 16:11:45
回答 1查看 36关注 0票数 0

在D7到D7迁移中,当涉及到field_collections时,我知道“您的字段集合迁移应该在宿主实体迁移之后运行。”。

我已经通过migrate_d2d模块完成了宿主实体的迁移。

对于我的field_collection,我编写了一个自定义模块,并添加了migrate_d2d类名(7f4f1882cNodecook_committee_vote)作为依赖项。

这种逻辑有流动吗?

我之所以这样问,是因为我的field_collection迁移没有更新以前迁移的cook_committee_vote节点,而是为它们创建了空存根!

EN

回答 1

Drupal用户

发布于 2019-05-31 15:38:13

答案是:逻辑不是流动的,它是正确的。当您编写自己的自定义迁移模块时,您可以通过代码或使用migrate_ui或d2d_migrate_ui模块通过UI建立对其他迁移的依赖关系。下面是依赖于d2d_migrade_ui生成的类的自定义迁移代码。这段代码适用于我:

代码语言:javascript
复制
$this->description = t('casey will migrate this field cllection even if it kills him!!!!!!'); 
// class of prviously imported node, this class name was generated by d2d_migrate module
// that is why the name is diffrent
$this->dependencies = array('7f4f1882cNodeorg_vote'); 

$query = $this->getConnection()
// start with the field that embeds the field_collection
->select('field_data_field_org_member_votes', 'nodeField')
->fields('nodeField', array('entity_id', 'field_org_member_votes_value', 'delta'))
->groupBy('nodeField.field_org_member_votes_value')
->orderBy('nodeField.entity_id')
->orderBy('nodeField.delta');

// join it to the fields that make up the field_collection, in my case there were 3 fields
$query->leftJoin('field_data_field_org_votes_member', 'member',
'nodeField.field_org_member_votes_value = member.entity_id');
$query->addField('member', 'field_org_votes_member_nid');

$query->leftJoin('field_data_field_org_votes_vote', 'vote',
'nodeField.field_org_member_votes_value = vote.entity_id');
$query->addField('vote', 'field_org_votes_vote_value');

$query->leftJoin('field_data_field_org_votes_majority', 'majority',
'nodeField.field_org_member_votes_value = majority.entity_id');
$query->addField('majority', 'field_org_votes_majority_value');


$this->source = new MigrateSourceSQL($query);

$this->destination = new MigrateDestinationFieldCollection(
    'field_org_member_votes',
    array('host_entity_type' => 'node')
);

$this->map = new MigrateSQLMap($this->machineName,
    array(
        'field_org_member_votes_value' => array( 
            'type' => 'int',
            'not null' => TRUE,
            'description' => 'Unique ID for each commitee vote',
            'alias' => 'nodeField',
    )
  ),
  MigrateDestinationFieldCollection::getKeySchema()
); //map END

$this->addFieldMapping('host_entity_id', 'entity_id') ->sourceMigration('7f4f1882cNodeorg_committee_vote');

$this->addFieldMapping('field_org_votes_member', 'field_org_votes_member') ->sourceMigration('7f4f1882cNodemember');
$this->addFieldMapping('field_org_votes_member:source_type') ->defaultValue('nid');

$this->addFieldMapping('field_org_votes_vote', 'field_org_votes_vote');

$this->addFieldMapping('field_org_votes_majority', 'field_org_votes_majority'); 

}//construct END

 function prepareRow($row) {
   // this is a good wat to test and make sure 
   // A) you have connected to the db 
   // B) you are getting proper values from your query
   // drush_print_r($row);
 }//prepareRow END
 function complete($row) {
   // drush_print_r($row);
 }
 public function prependTextNotes($row) {
     return 'Imported notes: ' . $row;
 }//prependTextNotes   END

 }
票数 0
EN
页面原文内容由Drupal提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://drupal.stackexchange.com/questions/281561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档