From 4484904429dc40d09c39824c079e141e88bbadf5 Mon Sep 17 00:00:00 2001 From: Okhin Date: Thu, 13 Dec 2018 15:34:10 +0100 Subject: [PATCH] AUTO_INCREMENT returns the ID of the Next attribute, not the Last one --- app/controller/admin.php | 2 +- app/controller/perso.php | 2 +- app/view/backend/contreparties.html | 4 +++- app/view/backend/user.html | 2 ++ src/LQDN/Finder/CounterpartFinder.php | 4 ++-- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controller/admin.php b/app/controller/admin.php index 7b00620..7135557 100644 --- a/app/controller/admin.php +++ b/app/controller/admin.php @@ -440,7 +440,7 @@ class Admin extends Controller if ($user['cumul'] >= $needed) { // Assez de point, on crée // On récupère le dernier ID inséré - $parent = $f3->get('container')['counterpart_finder']->getLastInsertedId() + 1; + $parent = $f3->get('container')['counterpart_finder']->getNextInsertedId(); $f3->get('container')['command_handler']->handle(new CounterpartCreateCommand($adresse['id'], $user['id'], $quoi, 1, 2, date("Y-m-d H:i:s"), 'Imported from a file', $parent)); // On mets à jour le cumul de l'utilisateur $f3->get('container')['command_handler']->handle(new UserUpdateCumulCommand($user['id'], $user['cumul'] - $needed)); diff --git a/app/controller/perso.php b/app/controller/perso.php index fd6b901..ada08ea 100644 --- a/app/controller/perso.php +++ b/app/controller/perso.php @@ -337,7 +337,7 @@ class Perso extends Controller // Ajout d'une demande de contrepartie pour chaque contrepartie if ((int) $user['cumul'] >= $valeur) { - $parent = $f3->get('container')['counterpart_finder']->getLastInsertedId() + 1; + $parent = $f3->get('container')['counterpart_finder']->getNextInsertedId(); switch ($quoi) { case 'hoodie': $f3->get('container')['command_handler']->handle(new CounterpartCreateCommand(\Utils::asl($adresse_id), $f3->get('SESSION.id'), 'hoodie', \Utils::asl($taille_h), 1, date("Y-m-d H:i:s"), \Utils::asl($commentaire), $parent)); diff --git a/app/view/backend/contreparties.html b/app/view/backend/contreparties.html index 8f71fd0..b77647d 100644 --- a/app/view/backend/contreparties.html +++ b/app/view/backend/contreparties.html @@ -43,6 +43,7 @@ + @@ -56,7 +57,8 @@ - + +
IdId du parent Email Date Quoi
{{ @row.id }}{{ @row.email }}{{ @row.parent }}{{ @row.email }} {{ @row.datec }} {{ @row.quoi }} diff --git a/app/view/backend/user.html b/app/view/backend/user.html index c0ca52a..77aeb5f 100644 --- a/app/view/backend/user.html +++ b/app/view/backend/user.html @@ -95,6 +95,7 @@ + @@ -106,6 +107,7 @@ +
IdId du parent Date Quoi Taille/Piplome
{{ @row.id }}{{ @row.parent }} {{ @row.datec }} {{ @row.quoi }} diff --git a/src/LQDN/Finder/CounterpartFinder.php b/src/LQDN/Finder/CounterpartFinder.php index ac0dca0..16c4bbe 100644 --- a/src/LQDN/Finder/CounterpartFinder.php +++ b/src/LQDN/Finder/CounterpartFinder.php @@ -58,11 +58,11 @@ EOQ; } /** - * return the last inserted id + * return the id of the next item to be inserted * * @return int */ - public function getLastInsertedId() + public function getNextInsertedId() { return (int) $this->connection->fetchColumn( "SELECT AUTO_INCREMENT FROM information_schema.tables WHERE table_name = 'contreparties' AND table_schema = DATABASE()" -- GitLab