Commit 444dcde9 authored by okhin's avatar okhin 🚴

Managing bad formatting in csv import and creates missing users on the fly

parent 310521e2
Pipeline #2259 failed with stages
in 5 minutes and 22 seconds
......@@ -9,6 +9,7 @@ use LQDN\Command\DonationInvalidateCommand;
use LQDN\Command\DonationResetPdfCommand;
use LQDN\Command\DonationCreateCommand;
use LQDN\Command\UserUpdateByAdminCommand;
use LQDN\Command\UserCreateCommand;
class Admin extends Controller
{
......@@ -1212,11 +1213,14 @@ class Admin extends Controller
continue;
}
// Récupération des informations du don
$identifier = $data[$identifier_idx];
$transaction = $data[$transaction_idx];
$effect = $data[$effect_idx];
$amount = $data[$amount_idx];
$statut = $data[$statut_idx];
$identifier = isset($data[$identifier_idx]) ? $data[$identifier_idx] : FALSE;
$transaction = isset($data[$transaction_idx]) ? $data[$transaction_idx] : FALSE;
$effect = isset($data[$effect_idx]) ? $data[$effect_idx] : FALSE;
$amount = isset($data[$amount_idx]) ? $data[$amount_idx] : FALSE;
$statut = isset($data[$statut_idx]) ? $data[$statut_idx] : FALSE;
if ( $identifier && $transaction && $effect && $amount && $statut == FALSE ) {
continue;
}
if ($statut == 'Refusé') {
$db->query("UPDATE dons SET status = 103 WHERE id='".$transaction."'");
continue;
......@@ -1258,9 +1262,18 @@ class Admin extends Controller
$db->query("INSERT INTO identifiers(user_id, identifier) VALUES ('".$user['id']."', '".$identifier."')");
$email = $user['email'];
} else {
// No user, let's add to the errors
$sans_cumul[] = $user_field;
continue;
// No user, let's try to create the user
$email = '';
$pseudo = '';
if (strpos($user_field, '@')) {
$email = $user_field;
$pseudo = explode("@", $user_field)[0];
} else {
$email = $user_field . "@example.org";
$pseudo = $user_field;
}
$hash = hash('sha256', date("%Y-%m-%d %H:%i:%d").$email);
$f3->get('container')['command_handler']->handle(new UserCreateCommand($email, $hash, $pseudo, 0, 0));
}
} else {
$email = $result->fetch(\PDO::FETCH_ASSOC);
......@@ -1280,7 +1293,7 @@ class Admin extends Controller
JOIN users u ON u.id = d.user_id
WHERE u.email='".$email."'
AND d.status=101
AND d.id=".$transaction);
AND d.id='".$transaction."'");
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
if (!$result) {
// don non trouvé en statut 101. On le crée (la banque à raison)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment