Similar to #2633242: Process plugin for importing/creating terms by name

Problem/Motivation

In D7, there is an option to auto create a file record on the content migration. This feature parity doesn't exist (yet) in D8.

Proposed resolution

Build it. Do it.

Remaining tasks

Write code.

User interface changes

n/a

API changes

Probably

Data model changes

n/a

Comments

heddn created an issue. See original summary.

heddn’s picture

heddn’s picture

Title: File fields do not auto create a record » File field migrations do not auto create a record from content migration
heddn’s picture

Title: File field migrations do not auto create a record from content migration » Process plugin for importing/creating files by URL or BLOB or ?
Project: Drupal core » Migrate Plus
Version: 8.0.x-dev » 8.x-1.x-dev
Component: migration system » Code
Status: Postponed » Active

This is no longer blocked. But moving over to the migrate_plus issue queue. This isn't a feature that is needed for migrating from another Drupal instance.

heddn’s picture

heddn’s picture

Status: Active » Needs review
heddn’s picture

heddn’s picture

Title: Process plugin for importing/creating files by URL or BLOB or ? » Process plugin for importing/creating files by URL
Status: Needs review » Needs work

This will need more work. Need to parse out the filename to only the base name when creating the new file.

mikeryan’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Component: Code » Plugins

I need this on 8.1.x for my current project.

mikeryan’s picture

Well, it turned out I didn't need it for that project in April - but I do for this week's project, so I'll be seeing if I can complete this patch within the next day.

mikeryan’s picture

A big piece missing here is actually copying the file into the files directory. Drupal 8.2.x should be introducing a general-purpose file_copy process plugin for this in #2695297: Refactor EntityFile and use process plugins instead - I'm thinking that the best solution here would be to add that plugin to migrate_plus in 8.x-2.x (which will be compatible with core 8.1.x only), and remove in 8.x-3.x (which will be compatible with core 8.2.x and up). Maybe add the urlencode process plugin from that patch as well...

mikeryan’s picture

I think if we do #2765733: entity_lookup should support file/image destination fields, we won't need the file_generate process plugin, just the file_copy plugin.

mikeryan’s picture

Status: Needs work » Needs review
StatusFileSize
new6.74 KB

Yes, a combination of #2765733: entity_lookup should support file/image destination fields and the file_copy plugin does the job without a specialized generation plugin. Here's what the relevant parts of my migration look like to leverage this:

source:
...
  constants:
    picture_directory: public://profile_images/
process:
...
  # From https://www.example.com/profile_images/9629.jpg, generate a
  # destination_basename of 9629.jpg...
  destination_basename:
    plugin: callback
    callable: basename
    source: image_url
  # ...and on to a destination_path of public://profile_images/9629.jpg.
  destination_path:
    plugin: concat
    source:
      - 'constants/picture_directory'
      - '@destination_basename'
  field_picture:
    -
      plugin: skip_on_empty
      method: process
      source: image_url
    -
      plugin: file_copy
      source:
        - image_url
        - '@destination_path'
    -
      plugin: entity_generate

  • mikeryan committed 2a1f208 on 8.x-2.x
    Issue #2635622 by mikeryan: Add file_copy process plugin
    
mikeryan’s picture

Status: Needs review » Fixed

Sigh... Thought I had committed this, so I though it was in beta2...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.