Step 1 Migration does not find any images

Created on 27 May 2020, over 4 years ago
Updated 9 February 2024, 10 months ago

I generated a step1 migration trying to migrate field_image for the article content type (see below), the article content type has nodes which have valid images loaded in the image field field_image. I have also run the drush migrate:file-media-fields node article image image which successfully created the entity reference field_image_media in the article content type.

When I enable the migration it reports "0" in the Total column of the /admin/structure/migrate/manage/migrate_drupal_7/migrations listing. I traced the code in MediaEntityGenerator, the query executed on line 179 yields 0 results, and the code block starting at line 181 is skipped. Any idea why the query is returning 0 rows when there are hundreds of article nodes that have a valid image file reference in field_image?

My migration is very simple, just the article content type field_image as shipped in D8 core:

# File to Media Migration configuration for image migration

id: migrate_article_images_step1
label: Migrate Article Media
migration_group: migrate_drupal_7
source:
  plugin: media_entity_generator
  entity_type: node
  bundle: article
  langcode: en
  field_names:
    - field_image

destination:
  plugin: entity:media

process:
  bundle:
    plugin: default_value
    default_value: image

  # Using the alt tag if available, else the file name.
  name:
    plugin: media_name
    source: file_name

  # This process plugin will skip the whole row if a existing media is found.
  existing_media_file:
    plugin: check_media_duplicate
    source: target_id

  # This process plugin will skip the whole row if a duplicate image is found.
  unique_file_id:
    plugin: check_duplicate
    source: target_id

  # Map the field image
  field_media_image/target_id: target_id
  field_media_image/alt: alt
  field_media_image/title: title

  langcode: langcode
  uid: uid


dependencies:
  module:
    - migrate_article
  enforced:
    module:
      - migrate_article

πŸ› Bug report
Status

Closed: won't fix

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States captaindav

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.

  • πŸ‡ΊπŸ‡¦Ukraine HitchShock Ukraine

    It looks like the issue is outdated. In the description uses the source plugin for D9 but atm we have a separate source plugin for D7.
    Please check examples in migrate_file_to_media_example module.

  • πŸ‡ΊπŸ‡ΈUnited States alison

    Just in case it's at all helpful to anyone who stumbles upon this thread... Here's what I did:

    1. I started with the instructions on the project page: https://www.drupal.org/project/migrate_file_to_media β†’
    2. BUT, in the generated β€œstep1” migration, I modified the source plugin to media_entity_generator_d7
    3. Then, after importing the migration configs...
    4. I ran
      drush migrate:duplicate-file-detection cwd_migrate_cvm_mf2m_canine_image_step1
    5. Then
      drush mim cwd_migrate_cvm_mf2m_canine_image_step1
    6. Then
      drush mim cwd_migrate_cvm_mf2m_canine_image_step2

    I didn't do the "everything in one go" option (i.e. I didn't add the media_file_copy process that's in the D7 to D7 example YML), because we need all files migrated over for this migration, not just files referenced in file fields (therefore, we're just using upgrade_d7_file from Drupal core to do the file entity migration).

    -------
    Anyway, hope this helps!

  • πŸ‡ΊπŸ‡ΈUnited States jsutta United States

    Posting this in case it helps anyone else. I had to change the source_langcode and langcode values in the source key from und to en.

Production build 0.71.5 2024