Add support for multiple values in file field + hash check for existing media

Created on 7 June 2022, over 2 years ago
Updated 19 February 2024, 9 months ago

Problem/Motivation

1. The current implementation doesn't migrate multiple files in a file field. Only the first file is migrated for a given field.
2. The current implementation doesn't check / re-use existing media entities.

Proposed resolution

1. Loop through the values within a given field, instead of only using the first value.
2. Create hash of existing media entities. While migrating, check for existing files hashes, and if found, re-use the existing media entity.

I also noticed that the alt-text wasn't migrated (#3274362), I added a fix for this as well.

Remaining tasks

Please review my supplied patch. It loops though multiple values, and adds them to the media field. I also borrowed some of the file hash code from https://www.drupal.org/project/image_field_to_media β†’ , and enhanced it a bit, so it builds the hashes for all existing media entities upon install.

The patch isn't perfect, as I didn't have a lot of spare time, and I'm not a back-end dev, but is does work. I know that it would be better to split this into two issues, but the hash functionality is also used for multi value fields, so I kept the code together.

It can probably use some optimization regarding potential timeouts on very large datasets, etc. But I've used it to migrate about 1.500 images today without a glitch.

✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium tijsdeboeck Antwerp πŸ‡§πŸ‡ͺ πŸ‡ͺπŸ‡Ί 🌎

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

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024