2017-04-18 38 views
0

我想從自定義表格遷移數據到書籍內容類型,但是我不知道如何實現這一點。 這是我的配置\安裝\ migrate.migration.book_content.yml文件:Drupal 8 migrate插件 - 需要說明

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 \插件\遷移\源\ BookContent.php

<?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; 
    } 

然而,當我這樣做:

drush migrate-import book_content 

我得到:

The drush command 'migrate-import book_content' could not be found. 

我不明白這是如何在BookContent.php工作中的功能。 應該有tags_field是分類引用,但我不知道,我應該在哪裏處理元,所以例如我得到一個標籤列表。 當我有標籤時,我應該如何組合它,以便遷移能夠正常工作。 我正在通過谷歌搜索信息,但沒有任何意義。我如何理解這一點?

回答

0

您的命名空間設置爲example_migrate。它需要設置爲你的模塊的名稱,所以除非模塊被稱爲「example_migrate」,否則它找不到該類。

更改名稱空間以匹配YOUR_MODULE_NAME。

namespace Drupal\YOUR_MODULE_NAME\Plugin\migrate\source; 

當谷歌搜索PSR0時,可以找到關於命名空間的更多信息。