Add verification on phone number on contact import
This commit is contained in:
parent
347084b5c4
commit
9aa3eca812
|
@ -141,8 +141,11 @@ namespace controllers\internals;
|
|||
$nb_insert = 0;
|
||||
|
||||
$head = null;
|
||||
$line_nb = 0;
|
||||
while ($line = fgetcsv($file_handler))
|
||||
{
|
||||
$line_nb ++;
|
||||
|
||||
if (null === $head)
|
||||
{
|
||||
$head = $line;
|
||||
|
@ -185,9 +188,16 @@ namespace controllers\internals;
|
|||
}
|
||||
$data = json_encode($data);
|
||||
|
||||
$contact_name = $line[array_keys($line)[0]];
|
||||
$phone_number = \controllers\internals\Tool::parse_phone($line[array_keys($line)[1]]);
|
||||
if (!$phone_number)
|
||||
{
|
||||
throw new \Exception('Erreur à la ligne ' . $line_nb . ' colonne 1, numéro de téléphone invalide.');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$success = $this->create($id_user, $line[array_keys($line)[1]], $line[array_keys($line)[0]], $data);
|
||||
$success = $this->create($id_user, $line[array_keys($line)[1]], $contact_name, $data);
|
||||
if ($success)
|
||||
{
|
||||
++$nb_insert;
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
|
||||
namespace controllers\publics;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Page des contacts.
|
||||
*/
|
||||
|
@ -345,40 +347,28 @@ namespace controllers\publics;
|
|||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
||||
//Try to import file
|
||||
$invalid_type = false;
|
||||
|
||||
switch ($read_file['mime_type'])
|
||||
try
|
||||
{
|
||||
case 'text/csv':
|
||||
$result = false;
|
||||
switch (true)
|
||||
{
|
||||
case ($read_file['mime_type'] === 'text/csv' || 'csv' === $read_file['extension']) :
|
||||
$result = $this->internal_contact->import_csv($id_user, $read_file['content']);
|
||||
|
||||
break;
|
||||
|
||||
case 'application/json':
|
||||
case ($read_file['mime_type'] === 'text/json' || 'json' === $read_file['extension']) :
|
||||
$result = $this->internal_contact->import_json($id_user, $read_file['content']);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if ('csv' === $read_file['extension'])
|
||||
{
|
||||
$result = $this->internal_contact->import_csv($id_user, $read_file['content']);
|
||||
}
|
||||
elseif ('json' === $read_file['extension'])
|
||||
{
|
||||
$result = $this->internal_contact->import_json($id_user, $read_file['content']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$invalid_type = true;
|
||||
$result = false;
|
||||
throw new Exception('Le type de fichier n\'est pas valide.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($invalid_type)
|
||||
catch (\Exception $e)
|
||||
{
|
||||
\FlashMessage\FlashMessage::push('danger', 'Le type de fichier n\'est pas valide.');
|
||||
\FlashMessage\FlashMessage::push('danger', 'Erreur lors de l\'import: ' . $e->getMessage());
|
||||
|
||||
return $this->redirect(\descartes\Router::url('Contact', 'list'));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue