I have migration that creates files. For file owners I'm trying to find existing user by email and if don't find I create one on fly. Problem is that those users I'm creating must be disabled (I don't want them to login to site). But if I disable them and I try to use them as file owner I get the message:
"This entity (user: 187) cannot be referenced."
I can disable validation for that migration file, but it will disable totally, not only for this user check.
I tried using Account Switcher (from event subscriber, reacting on pre_import and post_import events) to switch to user 1 before migration starts and switch back when ends, but didn't help.
Any idea how to reference disabled users during migration, but with keeping validation turned on?
Update:
Did some research and this checking is done at
\Drupal\user\Plugin\EntityReferenceSelection\UserSelection::buildEntityQuery()
There's a code:
// Adding the permission check is sadly insufficient for users: core
// requires us to also know about the concept of 'blocked' and 'active'.
if (!$this->currentUser->hasPermission('administer users')) {
$query->condition('status', 1);
}
And if I comment out those line, it's not checked if user is disabled or not and validation ends successfully.
Strange thing is that even I use Account Switcher to switch to user 1 and inside my process plugin user really is 1 when this code is executed user is not 1 any more, but the one I created and assigned to file (disabled one), so must be that import is also using Account Switcher?
Any idea how to solve this? Can I force migration to be run as specific (admin) user?