Problem/Motivation
I'm having problem with my migration where I'm trying to match existing user profiles (created with profile module) with new data imported from CSV file. profile_id
mapping fails, even though underlying SQL query return the correct profile ID.
The important part of migration mayors_profiles looks like this:
uid:
plugin: migration_lookup
no_stub: true
# previous user migration
migration: mayors_users
# property in the source data
source: lau
dump_uid:
plugin: callback
callable: var_dump
source: '@uid'
profile_id:
plugin: entity_lookup
entity_type: profile
bundle: profile
bundle_key: type
value_key: uid
source: '@uid'
Steps to reproduce
- add and install modules profile, migrate_plus, migrate_source_csv
- create a user, use the mail from
primary_mail
field of the source data - create a profile type
profile
, add some field to it (like field_first_name) - create a profile for the user you've created
- create a module to store migrations and the source data (please remove .txt extension).
- clear the cache
- run
mayors_users
andmayors_profiles
migrations. Please adjust the path to the source data.
By running query like:
SELECT ufd.uid, ufd.name, pf.profile_id from users_field_data ufd
LEFT JOIN profile pf on ufd.uid = pf.uid
you'll see that second profile has been created. The reason is that $results
is empty at https://git.drupalcode.org/project/migrate_plus/blob/HEAD/src/Plugin/mig.... However, when I enabled query logging in MySQL DB, I see that this SQL query has been performed by the entity lookup plugin:
SELECT base_table.revision_id AS revision_id, base_table.profile_id AS profile_id, profile_2.is_default AS is_default
FROM profile base_table
INNER JOIN profile profile ON profile.profile_id = base_table.profile_id
LEFT JOIN profile profile_2 ON profile_2.profile_id = base_table.profile_id
WHERE (profile.uid = '153')
AND (profile.type = 'profile')
AND (profile.status = '1')
ORDER BY profile_2.is_default DESC, base_table.profile_id DESC
LIMIT 1 OFFSET 0
When you replace the profile.uid
in the WHERE
clause by the uid
of the user you've created, you should get a correct result.
Why this issue happens?
Proposed resolution
The entity lookup plugin should return the profile_id of the profile user already has.
Comment | File | Size | Author |
---|---|---|---|
obce_final_extract.csv_.txt | 138 bytes | milos.kroulik | |
mayors_profiles.yml | 766 bytes | milos.kroulik | |
mayors_users.yml | 863 bytes | milos.kroulik |
Comments