Create user
Thu Jan 18 2024 14:15:27 GMT+0000 (Coordinated Universal Time)
Saved by
@saida
<?php
# vendor/bin/drush php-script web/modules/custom/henka_utils/scripts/create_user.php
use Drupal\user\Entity\User;
$path = dirname(__FILE__) . '/users.csv';
$i = 0;
$handle = fopen($path, "r");
if ($handle !== FALSE) {
while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
$i++;
if ($i == 1) {
continue;
}
$user = User::create([
'mail' => $row[0],
'field_name' => $row[1],
'field_surname' => $row[2],
]);
$user->activate();
$user->addRole('teacher');
$user->save();
}
fclose($handle);
}
content_copyCOPY
Comments