Creating user in 5.7

Permalink
Hi,

How to i create user when UserInfo->add() and UserInfo->register are deprecated.

I need this to make data migration script to move users from another platform to concrete5

Thanks for reading.

View Replies:
daenu replied on at Permalink Reply
daenu
Hi there
Had the exact same problem today. Here's what I did:

$userInfoObject = \Core::make('user/registration')->createFromPublicRegistration($data);


where $data is exactly what comes from the register form:

This is just an example but this is how this $data array should look like. Remark that the 'akID' entries are User Attributes set to "Show on Registration Form."
array (size=8)
  'ccm_token' => string '1480352511:70823e11dd5283747c5c3e3240a3619b' (length=43)
  'akID' => 
    array (size=6)
      24 => 
        array (size=1)
          'atSelectOptionValue' => string '2' (length=1)
      18 => 
        array (size=1)
          'value' => string 'xxx' (length=3)
      21 => 
        array (size=1)
          'value' => string 'yyy' (length=3)
      23 => 
        array (size=1)


For saving User Attributes I found the following solution (maybe there's a better one, I'm open for feedback!!)

First, get all the attributes required upon Registration:
$aks = UserAttributeKey::getRegistrationList();  // use UserAttributeKey

Then:
foreach($aks as $a) {
    // We need the array keys as they vary depending on the type of attribute
    $keys = array_keys($posts['akID'][$a->getAttributeKeyID()]);
    $value = $posts['akID'][$a->getAttributeKeyID()][$keys[0]];
    // Example for the select attribute
    if($a->atHandle == 'select') {
        $opt = Option::getByID($value);
        $value = $opt->getSelectAttributeOptionValue();
    }
   // And so on for every type of attribute
    $ui->setAttribute($a->akHandle, $data['akID'][$a->getAttributeKeyID()]['value']);
}

See the $data array above.
Don't forget to reindex by doing:
$ui->reindex();
daenu replied on at Permalink Reply
daenu
BTW
I'm developing an Add-On which imports/exports site members.... will be ready soon
ob7dev replied on at Permalink Reply
ob7dev
Can't wait for your add-on! I've heard its going to be a game changer!
daenu replied on at Permalink Reply
daenu
Wow.... Where did u hear that? ;-)