Make it easier to migrate entities in update hooks

Created on 4 April 2024, 9 months ago

Problem/Motivation

The way the module currently works isn't completely compatible with modern site deployment flows. It requires you to migrate the fields manually on production environments in order to migrate the data. Ideally, we could migrate the fields locally and automatically migrate the data during deployment in update hooks.

After some trial and error I found out it's pretty easy to write a post update hook to migrate data:

/**
 * Migrate field_global_cover_image to field_media_image.
 */
function example_post_update_8001(array &$sandbox): void
{
    \Drupal::moduleHandler()->loadInclude('image_field_to_media', 'inc', 'image_field_to_media.batch');
    image_field_to_media_populate_media_field('node', ['book', 'event', 'guide', 'news', 'project', 'reading', 'story', 'workshop'], 'field_global_cover_image', 'field_media_image', $sandbox);
    $sandbox['#finished'] = $sandbox['finished'];
}

Proposed resolution

I'd like to propose making this even simpler by removing the need for the first and third lines. I also think we should document this in the project description.

πŸ“Œ Task
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium dieterholvoet Brussels

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024