Unable to import images from wxr wordpress export file

Created on 24 February 2020, over 4 years ago
Updated 24 September 2023, about 1 year ago

Hi all, I am trying to import the following wxr xml file.

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
    xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
    xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:wp="http://wordpress.org/export/1.2/" >

    <channel>
        <wp:wxr_version>1.2</wp:wxr_version>

        <!--A post with a little text and of course a gallery of images-->
        <item>
            <title>My first gallery</title>
            <dc:creator><![CDATA[admin]]></dc:creator>
            <description></description>
            <content:encoded><![CDATA[
<p><b>Welcome to my first gallery!</b> Here are the images:</p>
[gallery ids=301,302]
]]></content:encoded>
            <excerpt:encoded><![CDATA[]]></excerpt:encoded>
            <wp:post_id>300</wp:post_id>
            <wp:post_date>2015-03-05 16:20:00</wp:post_date>
            <wp:status>publish</wp:status>
            <wp:post_parent>0</wp:post_parent>
            <wp:post_type>post</wp:post_type>
        </item>

        <!--The images attached to that post-->
        <item>
            <title>Picture of a cat</title>
            <dc:creator><![CDATA[admin]]></dc:creator>
            <description></description>
            <excerpt:encoded><![CDATA[This is a picture of a cat I found]]></excerpt:encoded>
            <wp:post_id>301</wp:post_id>
            <wp:post_date>2015-03-05 16:21:00</wp:post_date>
            <wp:status>inherit</wp:status>
            <wp:post_parent>300</wp:post_parent>
            <wp:post_type>attachment</wp:post_type>
            <wp:attachment_url>https://upload.wikimedia.org/wikipedia/commons/f/fc/Minka.jpg</wp:attachment_url>
        </item>
        <item>
            <title>Picture of a dog</title>
            <dc:creator><![CDATA[admin]]></dc:creator>
            <description></description>
            <excerpt:encoded><![CDATA[]]></excerpt:encoded>
            <wp:post_id>302</wp:post_id>
            <wp:post_date>2015-03-05 16:22:00</wp:post_date>
            <wp:status>inherit</wp:status>
            <wp:post_parent>300</wp:post_parent>
            <wp:post_type>attachment</wp:post_type>
            <wp:attachment_url>https://upload.wikimedia.org/wikipedia/commons/b/b7/Langhaardackel_merlin_2005.jpg</wp:attachment_url>
        </item>
    </channel>
</rss>

The import works fine but the attachment_url cannot be imported to the field_image.
I made some changes to the wordpress_content.yml file (see below) with no result. What I am missing?

id: wordpress_content
label: Import content from WordPress XML
migration_tags:
  - WordPress
source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: xml
  # The item type selector (e.g. '[wp:post_type="post"]') is appended dynamically.
  item_selector: /rss/channel/item
  fields:
    -
      name: title
      label: Content title
      selector: title
    -
      name: post_id
      label: Unique content ID
      selector: wp:post_id
    -
      name: content
      label: Body of the content
      selector: content:encoded
    -
      name: excerpt
      label: Excerpt of the content
      selector: excerpt:encoded
    -
      name: pubDate
      label: Publish date of the content
      selector: pubDate
    -
      name: post_date
      label: Post date of the content
      selector: wp:post_date
    -
      name: status
      label: Published status of the content
      selector: wp:status
    -
      name: creator
      label: Username of the content creator
      selector: dc:creator
    -
      name: post_tag
      label: Tags assigned to the content item
      selector: 'category[@domain="post_tag"]/@nicename'
    -
      name: category
      label: Categories assigned to the content item
      selector: 'category[@domain="category"]/@nicename'
    -
      name: attachment_url
      label: Full URL of the file on the source system
      selector: wp:attachment_url      
  ids:
    post_id:
      type: integer
process:
  # type mapping is dynamically generated.
  # uid mapping is dynamically generated.
  # tag/category field mappings are dynamically generated.
  title: title
  # @todo: Will need process plugin to rewrite links/img refs.
  # @link https://www.drupal.org/node/2742279
  'body/value': content
  'body/summary': excerpt
  field_image: attachment_url
  created:
    plugin: callback
    source: post_date
    callable: strtotime
  changed: '@created'
  status:
    plugin: static_map
    source: status
    default_value: 0
    map:
      publish: 1
destination:
  plugin: entity:node
# Dependencies are dynamically generated.
migration_dependencies: {}

Any idea?
Thanks

πŸ’¬ Support request
Status

Closed: outdated

Version

3.0

Component

Code

Created by

πŸ‡¬πŸ‡·Greece aleada

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States HongPong Philadelphia

    If this recurs with version alpha6 + migrate_plus:6.0+ and latest migrate_tools please re open. Thank you for including the sample wxr xml file!

Production build 0.71.5 2024