@@ -373,11 +373,19 @@ public function deleteUser(User $user)
373
373
* )
374
374
*
375
375
* @param array $users
376
- * @param string $authentication an authentication source
377
- * @param bool $mail do the users need to be mailed
378
- * @param \Closure $logger an anonymous function allowing to log actions
376
+ * @param bool $sendMail
377
+ * @param \Closure $logger an anonymous function allowing to log actions
378
+ * @param array $additionalRoles
379
+ * @param bool $enableEmailNotifaction
380
+ * @param array $options
379
381
*
380
382
* @return array
383
+ *
384
+ * @throws AddRoleException
385
+ * @throws \Claroline\CoreBundle\Persistence\NoFlushSuiteStartedException
386
+ *
387
+ * @internal param string $authentication an authentication source
388
+ * @internal param bool $mail do the users need to be mailed
381
389
*/
382
390
public function importUsers (
383
391
array $ users ,
@@ -392,8 +400,16 @@ public function importUsers(
392
400
$ options ['ignore-update ' ] = false ;
393
401
}
394
402
395
- $ returnValues = [];
403
+ if (!isset ($ options ['single-validate ' ])) {
404
+ $ options ['single-validate ' ] = false ;
405
+ }
406
+
407
+ // Return values
408
+ $ created = [];
409
+ $ updated = [];
396
410
$ skipped = [];
411
+ // Skipped users table
412
+ $ skippedUsers = [];
397
413
//keep these roles before the clear() will mess everything up. It's not what we want.
398
414
$ tmpRoles = $ additionalRoles ;
399
415
$ additionalRoles = [];
@@ -424,6 +440,7 @@ public function importUsers(
424
440
foreach ($ users as $ user ) {
425
441
$ firstName = $ user [0 ];
426
442
$ lastName = $ user [1 ];
443
+ $ fullName = $ firstName .' ' .$ lastName ;
427
444
$ username = $ user [2 ];
428
445
$ pwd = $ user [3 ];
429
446
$ email = trim ($ user [4 ]);
@@ -484,7 +501,6 @@ public function importUsers(
484
501
$ organizations = [];
485
502
}
486
503
487
- $ group = $ groupName ? $ this ->groupManager ->getGroupByName ($ groupName ) : null ;
488
504
if ($ groupName ) {
489
505
$ group = $ this ->groupManager ->getGroupByNameAndScheduledForInsert ($ groupName );
490
506
@@ -497,20 +513,13 @@ public function importUsers(
497
513
$ group = null ;
498
514
}
499
515
500
- $ userEntity = $ this ->userRepo ->findOneByMail ($ email );
501
-
502
- if (!$ userEntity ) {
503
- $ userEntity = $ this ->userRepo ->findOneByUsername ($ username );
504
- if (!$ userEntity && $ code !== null ) {
505
- //the code isn't required afaik
506
- $ userEntity = $ this ->userRepo ->findOneByAdministrativeCode ($ code );
507
- }
508
- }
516
+ $ userEntity = $ this ->getUserByUsernameOrMailOrCode ($ username , $ email , $ code );
509
517
510
518
if ($ userEntity && $ options ['ignore-update ' ]) {
511
519
if ($ logger ) {
512
520
$ logger (" Skipping {$ userEntity ->getUsername ()}... " );
513
521
}
522
+ $ skipped [] = $ fullName ;
514
523
continue ;
515
524
}
516
525
@@ -539,7 +548,8 @@ public function importUsers(
539
548
if ($ options ['single-validate ' ]) {
540
549
$ errors = $ this ->validator ->validate ($ userEntity );
541
550
if (count ($ errors ) > 0 ) {
542
- $ skipped [$ i ] = $ userEntity ;
551
+ $ skippedUsers [$ i ] = $ userEntity ;
552
+ $ skipped [] = $ fullName ;
543
553
if ($ isNew ) {
544
554
--$ countCreated ;
545
555
} else {
@@ -572,7 +582,11 @@ public function importUsers(
572
582
}
573
583
574
584
$ this ->objectManager ->persist ($ userEntity );
575
- $ returnValues [] = $ firstName .' ' .$ lastName ;
585
+ if ($ isNew ) {
586
+ $ created [] = $ fullName ;
587
+ } else {
588
+ $ updated [] = $ fullName ;
589
+ }
576
590
577
591
if ($ group ) {
578
592
$ this ->groupManager ->addUsersToGroup ($ group , [$ userEntity ]);
@@ -616,11 +630,15 @@ public function importUsers(
616
630
$ logger ($ countUpdated .' users updated. ' );
617
631
}
618
632
619
- foreach ($ skipped as $ key => $ user ) {
633
+ foreach ($ skippedUsers as $ key => $ user ) {
620
634
$ logger ('The user ' .$ user .' was skipped at line ' .$ key .' because it failed the validation pass. ' );
621
635
}
622
636
623
- return $ returnValues ;
637
+ return [
638
+ 'created ' => $ created ,
639
+ 'updated ' => $ updated ,
640
+ 'skipped ' => $ skipped ,
641
+ ];
624
642
}
625
643
626
644
/**
@@ -1282,6 +1300,10 @@ public function getUserByUsernameOrMail($username, $mail, $executeQuery = true)
1282
1300
1283
1301
public function getUserByUsernameOrMailOrCode ($ username , $ mail , $ code )
1284
1302
{
1303
+ if (empty ($ code ) || !$ this ->platformConfigHandler ->getParameter ('is_user_admin_code_unique ' )) {
1304
+ return $ this ->getUserByUsernameOrMail ($ username , $ mail , true );
1305
+ }
1306
+
1285
1307
return $ this ->userRepo ->findUserByUsernameOrMailOrCode ($ username , $ mail , $ code );
1286
1308
}
1287
1309
0 commit comments