[DEV-239] Remove unexpected error in upload csv file (#1151)
* Remove unexpected error in upload csv file * Fix bug when render csv file error list * csv files without eof line work OK * [DEV-239] Prettify code
This commit is contained in:
parent
d5552c0f73
commit
54a5a9803d
|
@ -333,7 +333,7 @@ class AdminPanelAdvancedSettings extends React.Component {
|
||||||
<div>
|
<div>
|
||||||
{i18n('ERRORS_FOUND')}
|
{i18n('ERRORS_FOUND')}
|
||||||
<ul>
|
<ul>
|
||||||
{result.data.map((error) => <li>{error}</li>)}
|
{result.data.map((error, index) => <li key={`csv-file__key-${index}`} >{error}</li>)}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
) : null
|
) : null
|
||||||
|
|
|
@ -42,17 +42,15 @@ class CSVImportController extends Controller {
|
||||||
$file = fopen($fileUploader->getFullFilePath(),'r');
|
$file = fopen($fileUploader->getFullFilePath(),'r');
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
while(!feof($file)) {
|
while(($user = fgetcsv($file)) != false) {
|
||||||
$userList = fgetcsv($file);
|
Controller::setDataRequester(function ($key) use ($user) {
|
||||||
|
|
||||||
Controller::setDataRequester(function ($key) use ($userList) {
|
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'email':
|
case 'email':
|
||||||
return $userList[0];
|
return $user[0];
|
||||||
case 'password':
|
case 'password':
|
||||||
return $userList[1];
|
return $user[1];
|
||||||
case 'name':
|
case 'name':
|
||||||
return $userList[2];
|
return $user[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -64,7 +62,7 @@ class CSVImportController extends Controller {
|
||||||
$signupController->validate();
|
$signupController->validate();
|
||||||
$signupController->handler();
|
$signupController->handler();
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$errors[] = $exception->getMessage() . ' in email ' . $userList[0];
|
$errors[] = $exception->getMessage() . ' in email ' . $user[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue