迁移节点引用

发布于 2024-10-16 01:43:54 字数 257 浏览 6 评论 0原文

我正在开发一个将网站从 asp.net 迁移到 drupal 架构的项目。但网站内容非常具有层次性,并且实体之间有很多引用。

例如:每个内容都属于一个类别,每个类别又属于另一个类别部分。现在甚至可能还有另一个层次。

我计划利用迁移模块来迁移数据库内容并通过节点引用字段链接迁移的节点。

但我陷入了迁移模块的困境,因为我找不到将节点引用字段迁移到任何地方的方法...

任何人都可以帮我解决这个问题...

I am working on a project to migrate a website from asp.net to drupal architecture. But the site content is very hierarchal and has a lot of references between entities.

for example: each content belongs to a category, and each category belongs to another category section. Now there may be another level of hierarchy even.

I am planning to make use of migrate module for migrating the database content and linking the migrated nodes via a node reference field.

But i am getting stuck with migrate module as i can't find a way to migrate the node reference field anywhere...

can anyone help me out with this...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

月亮是我掰弯的 2024-10-23 01:43:54

实际上,在 2012 年,这似乎并不难。是的,您必须跟踪源 ID 与导入 ID,但迁移模块会在一个整洁的小表中为您完成此操作。您可以在源查询中加入该表,并使用 .. 引用节点的 nid 更新节点引用字段。当然,引用的节点应该已经导入。如果不是,您可以稍后运行“更新”,并根据后面的导入输入引用的 nids。实际上:

$query = Database::getConnection(
    'default', 'mysourcedb'
)->select(
    'mysourcetable','source'
)->fields('source', array(
        'id',
        'title',
        'whatever'
        'rel_rec_id'
    )
);

$query->leftJoin('migrate_map_relimport','relmap','relmap.sourceid1=source.rel_rec_id');
$query->addField('relmap','destid1','rel_node_id');

上面的代码假设您有一个“mysourcedb”,其中有一个“mysourcetable”引用“rel_rec_id”,并且还有另一个名为 RelImport 的导入,它导入 rel_rec_id 引用的 rel 表;它应该已经运行(或者将在运行附加更新之前运行)。获得 RelImport 类后,执行迁移状态以确保表存在。

为了能够连接到“migrate_map_relimport”表,请确保映射表写入源数据库,而不是 drupal 数据库。这并不总是必要的,但它是:

$this->map = new MigrateSQLMap(
    $this->machineName,
        array(
            'id' => array(
                'type' => 'int',
                'unsigned' => true,
                'not null' => true,
                'alias' => 'source' 
              )
        ),
        MigrateDestinationNode::getKeySchema(),
        'mysourcedb' // connection to use to write map tables
);

最后,将检索到的 rel_node_id 分配给您的节点引用:

$this->addFieldMapping( 'field_rel_node', 'rel_node_id' );

是的,这是火箭科学.. YMMV

Actually, it doesnt seem to be that hard .. in 2012. Yes, you have to keep track of source IDs versus import IDs, but the migrate module does this for you, in a neat little table. You can join that table in your source query, and update the node reference field with the nid of the .. referenced node. Ofcourse, the referenced nodes should have already been imported. If they werent, you can run an run an 'update' later and referenced nids get entered based on the latter imports too. In practice:

$query = Database::getConnection(
    'default', 'mysourcedb'
)->select(
    'mysourcetable','source'
)->fields('source', array(
        'id',
        'title',
        'whatever'
        'rel_rec_id'
    )
);

$query->leftJoin('migrate_map_relimport','relmap','relmap.sourceid1=source.rel_rec_id');
$query->addField('relmap','destid1','rel_node_id');

The code above assumes you have a 'mysourcedb' with a 'mysourcetable' in it that refers to a 'rel_rec_id', and theres another import called RelImport that imports the rel table that rel_rec_id is refering to; it should have already run (or will run before you run an additional update). Do a migrate-status once you have the RelImport class to make sure the table exists.

To be able to make joins to the 'migrate_map_relimport' table, make sure map tables are written to the source database, not the drupal database. This is not always necessary, but here it is:

$this->map = new MigrateSQLMap(
    $this->machineName,
        array(
            'id' => array(
                'type' => 'int',
                'unsigned' => true,
                'not null' => true,
                'alias' => 'source' 
              )
        ),
        MigrateDestinationNode::getKeySchema(),
        'mysourcedb' // connection to use to write map tables
);

and finally, assign the retrieved rel_node_id to your node reference:

$this->addFieldMapping( 'field_rel_node', 'rel_node_id' );

Yay, it is rocket science .. YMMV

霓裳挽歌倾城醉 2024-10-23 01:43:54

据我所知,您将无法完全在 migrate 模块中完成此操作。您必须直接在 MySQL 中运行一些查询。

本质上,您必须在每个内容类型中创建一个额外的字段来容纳其旧 ID,并为每个旧引用创建一个附加字段(除了实际的节点引用字段之外)。将所有数据加载到内容类型中(将节点引用字段留空)。然后,一旦加载了所有实体,您就可以运行 mysql 查询来根据旧 ID 和旧引用字段填充节点引用字段。完成后,您可以安全地删除这些旧字段。

这不是最优雅的解决方案,但我已经使用过很多次了。

注意事项:

  • 这是针对 Drupal 6 的;据我所知,Drupal 7 的字段实现完全不同。
  • 对于非常大的迁移,您可能希望通过 MySQL 删除旧字段。

As far as I know, you will not be able to do this entirely within the migrate module. You'll have to run a few queries directly in MySQL.

Essentially, you'll have to create an extra field in each content type to house their legacy ID's and an additional field for each legacy reference (in addition to the actual nodereference field). Load all the data into the content types (leave the nodereference field empty). Then once all of the entities are loaded in, you run mysql queries to populate the nodereference fields based on the legacy IDs and legacy reference fields. Once that's done you can safely delete these legacy fields.

Not the most elegant solution, but I've used it many times.

Caveats:

  • This is for Drupal 6; Drupal 7's fields implementation is totally different AFAIK.
  • For very large migrations, you might want to do your legacy field deletions through MySQL.
白色秋天 2024-10-23 01:43:54

您还可以查看内容迁移模块的代码(更多信息请访问 https://drupal.org/node /1144136)。它用于将 D6 内容构建工具包 (CCK) 内容迁移到 D7 字段,并且已与参考模块集成。

它不会立即执行您需要的操作,因为您来自 ASP.net 站点而不是 D6 站点,但它可能会提供一些线索。

You might also take a look at the code for the Content Migrate module (more information at https://drupal.org/node/1144136). It's for migrating D6 Content Construction Kit (CCK) content to D7 Fields and it's been integrated with the References module.

It won't do what you need out of the box, as you're coming from an ASP.net site instead of a D6 site, but it may provide some clues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文