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; ...@@ -9,6 +9,7 @@ use LQDN\Command\DonationInvalidateCommand;
use LQDN\Command\DonationResetPdfCommand; use LQDN\Command\DonationResetPdfCommand;
use LQDN\Command\DonationCreateCommand; use LQDN\Command\DonationCreateCommand;
use LQDN\Command\UserUpdateByAdminCommand; use LQDN\Command\UserUpdateByAdminCommand;
use LQDN\Command\UserCreateCommand;
class Admin extends Controller class Admin extends Controller
{ {
...@@ -1212,11 +1213,14 @@ class Admin extends Controller ...@@ -1212,11 +1213,14 @@ class Admin extends Controller
continue; continue;
} }
// Récupération des informations du don // Récupération des informations du don
$identifier = $data[$identifier_idx]; $identifier = isset($data[$identifier_idx]) ? $data[$identifier_idx] : FALSE;
$transaction = $data[$transaction_idx]; $transaction = isset($data[$transaction_idx]) ? $data[$transaction_idx] : FALSE;
$effect = $data[$effect_idx]; $effect = isset($data[$effect_idx]) ? $data[$effect_idx] : FALSE;
$amount = $data[$amount_idx]; $amount = isset($data[$amount_idx]) ? $data[$amount_idx] : FALSE;
$statut = $data[$statut_idx]; $statut = isset($data[$statut_idx]) ? $data[$statut_idx] : FALSE;
if ( $identifier && $transaction && $effect && $amount && $statut == FALSE ) {
continue;
}
if ($statut == 'Refusé') { if ($statut == 'Refusé') {
$db->query("UPDATE dons SET status = 103 WHERE id='".$transaction."'"); $db->query("UPDATE dons SET status = 103 WHERE id='".$transaction."'");
continue; continue;
...@@ -1258,9 +1262,18 @@ class Admin extends Controller ...@@ -1258,9 +1262,18 @@ class Admin extends Controller
$db->query("INSERT INTO identifiers(user_id, identifier) VALUES ('".$user['id']."', '".$identifier."')"); $db->query("INSERT INTO identifiers(user_id, identifier) VALUES ('".$user['id']."', '".$identifier."')");
$email = $user['email']; $email = $user['email'];
} else { } else {
// No user, let's add to the errors // No user, let's try to create the user
$sans_cumul[] = $user_field; $email = '';
continue; $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 { } else {
$email = $result->fetch(\PDO::FETCH_ASSOC); $email = $result->fetch(\PDO::FETCH_ASSOC);
...@@ -1280,7 +1293,7 @@ class Admin extends Controller ...@@ -1280,7 +1293,7 @@ class Admin extends Controller
JOIN users u ON u.id = d.user_id JOIN users u ON u.id = d.user_id
WHERE u.email='".$email."' WHERE u.email='".$email."'
AND d.status=101 AND d.status=101
AND d.id=".$transaction); AND d.id='".$transaction."'");
$result = $stmt->fetch(\PDO::FETCH_ASSOC); $result = $stmt->fetch(\PDO::FETCH_ASSOC);
if (!$result) { if (!$result) {
// don non trouvé en statut 101. On le crée (la banque à raison) // 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