首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Drupal 8迁移插件-需要解释

Drupal 8迁移插件-需要解释
EN

Stack Overflow用户
提问于 2017-04-19 00:44:59
回答 1查看 342关注 0票数 0

我想将数据从定制表迁移到book内容类型,但是我不知道如何实现。这是我的config\install\migrate.migration.book_content.yml文件:

代码语言:javascript
复制
id: book_content
label: Book content
migration_group: example
source:
  plugin: book_content
  target: db_migration
destination:
  plugin: entity:node
process:
  type:
    plugin: default_value
    default_value: article
  title: title
  uid:
    plugin: default_value
    default_value: 1
  sticky:
    plugin: default_value
    default_value: 0
  status:
    plugin: default_value
    default_value: 1
  'body/value': content
  'body/summary': excerpt
  'body/format': 
    plugin: default_value
    default_value: full_html
  # Use of the migration process plugin.
  # That will use the id map of the specified migration 
  # to retrieve the corresponding id ('source' parameter) in the destination database.
  field_description:
    plugin: migration
    source: body

src\Plugin\migrate\source\BookContent.php

代码语言:javascript
复制
<?php
/**
 * @file
 * Contains \Drupal\docapi_migrate\Plugin\migrate\source\BookContent.
 */
namespace Drupal\example_migrate\Plugin\migrate\source;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
use Drupal\migrate\Row;
/**
 * Drupal 8 node from database.
 *
 * @MigrateSource(
 *   id = "book_content"
 * )
 */
class BookContent extends SqlBase {
  /**
   * {@inheritdoc}
   */
  public function query() {
    $query = $this->select('docapi_migrate', 'dm')
                  ->fields('dm', array('url', 'depth', 'body', 'meta'));
    return $query;
  }
  /**
   * {@inheritdoc}
   */
  public function fields() {
    $fields = array(
      'url' => $this->t('Content url'),
      'depth' => $this->t('Depth of the content'),
      'body' => $this->t('Full text of the content'),
      'meta' => $this->t('yaml data'),
    );
    return $fields;
  }

然而,当我这样做的时候:

代码语言:javascript
复制
drush migrate-import book_content

我得到了:

代码语言:javascript
复制
The drush command 'migrate-import book_content' could not be found.

我不明白这在BookContent.php中是如何工作的。应该有带有分类引用的tags_field,但是我不知道应该在哪里处理元数据,例如,我得到了一个标签列表。当我有标签时,我应该如何组合它,这样迁移才能正常工作。我通过谷歌搜索信息,但没有真正有意义的信息。我怎么才能理解这个呢?

EN

回答 1

Stack Overflow用户

发布于 2017-04-20 20:05:34

您的命名空间设置为example_migrate。它需要设置为您的模块的名称,因此除非模块名为"example_migrate“,否则它无法找到类。

更改名称空间以匹配YOUR_MODULE_NAME。

代码语言:javascript
复制
namespace Drupal\YOUR_MODULE_NAME\Plugin\migrate\source;

有关名称空间的更多信息可以在谷歌搜索PSR0时找到。

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

https://stackoverflow.com/questions/43477843

复制
相关文章

相似问题

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