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 = $this->internal_contact->import_csv($id_user, $read_file['content']);
|
||||
|
||||
break;
|
||||
|
||||
case 'application/json':
|
||||
$result = $this->internal_contact->import_json($id_user, $read_file['content']);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
if ('csv' === $read_file['extension'])
|
||||
{
|
||||
$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']);
|
||||
}
|
||||
elseif ('json' === $read_file['extension'])
|
||||
{
|
||||
$result = $this->internal_contact->import_json($id_user, $read_file['content']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$invalid_type = true;
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($invalid_type)
|
||||
break;
|
||||
|
||||
case ($read_file['mime_type'] === 'text/json' || 'json' === $read_file['extension']) :
|
||||
$result = $this->internal_contact->import_json($id_user, $read_file['content']);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception('Le type de fichier n\'est pas valide.');
|
||||
}
|
||||
}
|
||||
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'));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class AddIndexOnSendedUid extends AbstractMigration
|
|||
|
||||
$table = $this->table('call');
|
||||
$table->changeColumn('uid', 'string', ['limit' => 100]);
|
||||
$table->addIndex('uid');
|
||||
$table->addIndex('uid');
|
||||
$table->update();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue