|
|
@@ -5,8 +5,7 @@ namespace common\logic\User\User\Service; |
|
|
|
use common\helpers\CSV; |
|
|
|
use common\helpers\Password; |
|
|
|
use common\logic\AbstractManager; |
|
|
|
use common\logic\User\User\Model\User; |
|
|
|
use common\logic\User\UserProducer\Model\UserProducer; |
|
|
|
use yii\base\ErrorException; |
|
|
|
|
|
|
|
class UserBulkImporter extends AbstractManager |
|
|
|
{ |
|
|
@@ -28,9 +27,12 @@ class UserBulkImporter extends AbstractManager |
|
|
|
$this->userBuilder = $this->loadService(UserBuilder::class); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @throws ErrorException |
|
|
|
*/ |
|
|
|
public function import(string $fileName): void |
|
|
|
{ |
|
|
|
$usersArray = CSV::csv2array($fileName); |
|
|
|
$usersArray = $this->loadCsv($fileName); |
|
|
|
|
|
|
|
foreach($usersArray as $userData) { |
|
|
|
$this->userBuilder->createUser( |
|
|
@@ -46,4 +48,16 @@ class UserBulkImporter extends AbstractManager |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function loadCsv(string $fileName): array |
|
|
|
{ |
|
|
|
$usersArray = CSV::csv2array($fileName); |
|
|
|
|
|
|
|
if(count($usersArray) && count($usersArray[0]) != 6) { |
|
|
|
throw new ErrorException("Le fichier n'a pas le bon nombre de colonnes. |
|
|
|
Veuillez vous baser sur le fichier d'exemple téléchargeable ci-dessous."); |
|
|
|
} |
|
|
|
|
|
|
|
return $usersArray; |
|
|
|
} |
|
|
|
} |