【问题标题】:Drupal 7 - Migrate files into custom file typeDrupal 7 - 将文件迁移到自定义文件类型
【发布时间】:2017-02-28 18:23:30
【问题描述】:

我正在尝试将文件迁移到具有大量自定义字段的自定义文件类型。然而,它们似乎被迁移到 document 文件类型而不是我自定义创建的文件类型中。

我使用MigrateDestinationFile 作为我的目的地,如下所示:

$this->destination = new MigrateDestinationFile();

我尝试将type 映射为this answer,建议如下:

$this->addFieldMapping('type')->defaultValue('custom_file_type');

此解决方案不起作用,在检查 MigrateDestinationFile 的可映射字段时,没有指定 type 字段,所以我认为这就是该解决方案不起作用的原因。

如果有人可以向我指出如何迁移到自定义文件类型的示例,我们将不胜感激。也许我使用了错误的destination?还是我错过了一些非常明显的东西。

迁移的其他部分与这个问题无关。

【问题讨论】:

    标签: drupal drupal-7 migration


    【解决方案1】:

    显然我有两个问题。第一个是,当我们创建文件类型时,我们将其命名为 file,由于某种原因,您无法将其设置为迁移目标,因为它在 MigrateDestinationFile 构造函数中已经是默认设置(请参见下面的代码)。

    From file.inc:544
    
    /**
     * Basic initialization
     *
     * @param array $options
     *  Options applied to files.      
     */
    public function __construct($bundle = 'file', $file_class = 'MigrateFileUri', $options = array()) {
      parent::__construct('file', $bundle, $options);
      $this->fileClass = $file_class;
    }
    

    第二个问题是映射到字段 bundle 本身。在使用不同的名称重新创建文件类型后,我只需要像这样设置正确的目的地:

    $this->destination = new MigrateDestinationFile('product_download');
    

    执行此操作后,迁移的文件将以正确的内容类型创建,而不是 document 文件类型。

    【讨论】:

      猜你喜欢
      • 2019-04-15
      • 2016-12-30
      • 2022-06-29
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多