fix login sql : ajout d'un retry sur le login, suppression des options
This commit is contained in:
@ -4,6 +4,7 @@ namespace App\Service;
|
||||
|
||||
use App\SQLLogin\Exception\DatabaseConnectionException;
|
||||
use App\SQLLogin\Exception\DataToFetchConfigurationException;
|
||||
use App\SQLLogin\Exception\EmptyResultException;
|
||||
use App\SQLLogin\Exception\LoginElementsConfigurationException;
|
||||
use App\SQLLogin\Exception\NullDataToFetchException;
|
||||
use App\SQLLogin\SQLLoginConnect;
|
||||
@ -15,6 +16,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class SQLLoginService extends AbstractController
|
||||
{
|
||||
public const MAX_RETRY = 3;
|
||||
private PDO $pdo;
|
||||
|
||||
public function __construct(
|
||||
@ -43,11 +45,22 @@ class SQLLoginService extends AbstractController
|
||||
|
||||
private function executeRequestWithLogin(string $request, string $login): array
|
||||
{
|
||||
$query = $this->pdo->prepare($request);
|
||||
$query->bindParam($this->sqlLoginRequest->getLoginColumnName(), $login, PDO::PARAM_STR);
|
||||
$query->execute();
|
||||
$datas = $query->fetch(PDO::FETCH_ASSOC);
|
||||
$query->closeCursor();
|
||||
$attempt = 0;
|
||||
while ($attempt < self::MAX_RETRY) {
|
||||
$query = $this->pdo->prepare($request);
|
||||
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
|
||||
$datas = $query->fetch(PDO::FETCH_ASSOC);
|
||||
$query->closeCursor();
|
||||
if (false === $datas) {
|
||||
usleep(1000);
|
||||
++$attempt;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (self::MAX_RETRY === $attempt) {
|
||||
throw new EmptyResultException('Résultat vide après 3 tentatives');
|
||||
}
|
||||
|
||||
return $datas;
|
||||
}
|
||||
|
Reference in New Issue
Block a user