If importing a user and trying to attach to a role, but the role ID does not exist, the import fails. To fix this, I wrote a small patch. Tested with an import of ~250 users with fairly complex user roles migration.

Comments

krisahil’s picture

Status: Active » Needs review
StatusFileSize
new549 bytes
btopro’s picture

looks legit and logic is sound. I'll put it in the queue to be tested.

btopro’s picture

This patch while fixing this issue can cause an additional logic issue. http://php.net/manual/en/function.array-search.php indicates that if it doesn't find anything it returns FALSE. This current function doesn't assert that the position is actually 0 / first element in the array instead of FALSE.

$role_id = array_search($role, $roles);
if ($role_id !== FALSE) {
  $entity->roles[$role_id] = $role;
}

would be a more appropriate solution. Neither has been tested though so please reroll a patch using this approach and if it works for you I'll apply it to dev

krisahil’s picture

@btopro,

See latest patch. I addressed that issue, and fixed same problem when a single value is supplied.
Also fixed a coding style issue for elseif() construction.

Thanks for the advice!

btopro’s picture

Status: Needs review » Patch (to be ported)

Looks much better thank you for following up on the change! Applying now.

  • btopro committed 8880a0f on 7.x-1.x authored by krisahil
    Issue #2339547 by krisahil: Error when target role ID does not exist
    
btopro’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

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