fix login sql : ajout d'un retry sur le login, suppression des options
Cadoles/hydra-sql/pipeline/head This commit is unstable Details
Cadoles/hydra-sql/pipeline/pr-develop There was a failure building this commit Details

This commit is contained in:
Rudy Masson 2024-10-10 12:01:15 +02:00
parent 8e56433216
commit d6d9e81df6
3 changed files with 28 additions and 12 deletions

View File

@ -0,0 +1,9 @@
<?php
namespace App\SQLLogin\Exception;
use Exception;
class EmptyResultException extends Exception
{
}

View File

@ -24,12 +24,6 @@ class SQLLoginConnect extends AbstractController
public function connect($urlDatabase, $dbUser, $dbPassword): PDO
{
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_TIMEOUT => 5,
PDO::ATTR_PERSISTENT => false,
];
return new PDO($urlDatabase, $dbUser, $dbPassword, $options);
return new PDO($urlDatabase, $dbUser, $dbPassword);
}
}

View File

@ -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
{
$attempt = 0;
while ($attempt < self::MAX_RETRY) {
$query = $this->pdo->prepare($request);
$query->bindParam($this->sqlLoginRequest->getLoginColumnName(), $login, PDO::PARAM_STR);
$query->execute();
$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;
}