Drupal 8.1.1 - 将3400 INSERT(从sql)迁移到自定义内容类型

时间:2016-07-08 00:09:13

标签: php drupal entities migrate

我需要将3400行从phpMyAdmin导出到Drupal 8上的自定义内容类型。

我尝试使用迁移模块,但是,例如Migrate Plus和Migrate Tools与我的Drupal版本(8.1.1)不兼容

我想使用PHP脚本导入记录。

我尝试了很多东西,但在很多情况下我说过"未定义的功能" (通过使用,例如,entity_create)和我已经完成的更多证据。

示例1:

$new_page_values = array();
$new_page_values['type'] = 'my_content_type';
$new_page_values['title'] = "Titulo";
$new_page_values['path'] = "Path";

$new_page = entity_create('node', $new_page_values);
$new_page->save();

示例2

$language = \Drupal::languageManager()->getCurrentLanguage()->getId();
$node = \Drupal\node\Entity\Node::create(array(
          'type' => 'article',
          'title' => 'The title',
          'langcode' => $language,
          'uid' => 1,
          'status' => 1,
          'body' => array('The body text'),
          'field_date' => array("2000-01-30"),
            //'field_fields' => array('Custom values'), // Add your custon field values like this
    ));
$node->save();

示例3:

db_insert('example_entity')
    ->fields(array(
      'type' => $entity->getEntityTypeId(),
      'id' => $entity->id(),
      'created' => REQUEST_TIME,
      'updated' => REQUEST_TIME,
    ))
    ->execute();

我试图从服务器控制台运行.php文件(php updateData.php)

谢谢和问候。

1 个答案:

答案 0 :(得分:0)

Javier,D8中的迁移仍然是WIP。

我的建议:

  • 安装最新的Drupal 8.1,
  • migrate_tools migrate_plus migrate_source_csv migrate_source_json 安装最新模块。最好是最新的beta版本。
  • 将您的phpAdmin输出更改为csv文件。

也许您需要创建自定义实体。 Migrate_tools有两个迁移示例。它还包含一个csv示例。迁移过程应该无缝地导入您的东西。

  

提示: YAML文件对空格等语法非常敏感。而且您不必识别外部/迁移数据库。但请记住,昨天有用的东西今天可能会有所不同。我正在进行过去6个月的迁移工作。

迁移过程与D7完全不同。

已编辑:安装Drush 8.使用Composer轻松实现。从命令行运行迁移脚本需要Drush,清单已过时。

已编辑2: IMO是使用D8迁移的最佳解释和原因。 看看这个网站https://blog.liip.ch/archive/2016/05/04/using-the-new-drupal-8-migration-api-module.html。您希望使用自己的PHP似乎主要是因为您似乎无法使用D8的迁移?