我正在使用 Migrate 2.4 模块将图像从 Wordpress 迁移到 Drupal。这是我的映射:
$this->addFieldMapping('field_image','images');
$this->addFieldMapping('destination_file', 'images');
$this->addFieldMapping('field_image:source_dir')
->defaultValue('/Users/grafa/htdocs/wordpress/wp-content/uploads');
$this->addFieldMapping('field_image:file_class')
->defaultValue('MigrateFileUri');
图像来自查询 wp_postmeta 表的函数,然后将结果返回给 prepareRow() 函数。
function getImages($row) {
$post_id = $row->id;
$results = db_query("
SELECT pm.post_id, pm.meta_key, pm.meta_value FROM streetroots_wp.wp_postmeta AS pm LEFT JOIN streetroots_wp.wp_posts AS p ON pm.post_id=p.id WHERE p.post_parent = $post_id AND pm.meta_key='_wp_attached_file';");
$images = array();
foreach($results as $result) {
$images[] = $result->meta_value;
}
return !empty($images) ? $images : NULL;
}
这基本上从 wp_postmeta 表中返回图像名称和相对路径,例如“2012/05/figure1.jpg”。然后我像这样使用 prepareRow() :
function prepareRow($row) {
$row->images = $this->getImages($row);
}
我猜我使用处理文件字段的新迁移模块的方式有些奇怪。sql 正确输出文件名,但图像似乎没有被复制。这是使用 Migrate 2.4 的 Drupal 7。任何帮助表示赞赏。