diff --git a/config/services.yml b/config/services.yml index 605250bb..374025aa 100644 --- a/config/services.yml +++ b/config/services.yml @@ -15,8 +15,7 @@ services: PrestaShop\Module\Psgdpr\Service\LoggerService: class: 'PrestaShop\Module\Psgdpr\Service\LoggerService' arguments: - - "@PrestaShop\\Module\\Psgdpr\\Repository\\LoggerRepository" - - "@PrestaShop\\Module\\Psgdpr\\Repository\\CustomerRepository" + - '@PrestaShop\Module\Psgdpr\Repository\LoggerRepository' PrestaShop\Module\Psgdpr\Service\ExportService: class: 'PrestaShop\Module\Psgdpr\Service\ExportService' diff --git a/src/Repository/CartRepository.php b/src/Repository/CartRepository.php index ce3475cc..f02014e7 100644 --- a/src/Repository/CartRepository.php +++ b/src/Repository/CartRepository.php @@ -61,9 +61,7 @@ public function findCartsByCustomerId(CustomerId $customerId): array ->setParameter('id_customer', $customerId->getValue() ); - $result = $query->execute(); - - return $result->fetchAssociative(); + return $this->connection->executeQuery($query)->fetch(); } /** diff --git a/src/Repository/ConsentRepository.php b/src/Repository/ConsentRepository.php index 92a2faa3..cd443ed7 100644 --- a/src/Repository/ConsentRepository.php +++ b/src/Repository/ConsentRepository.php @@ -21,15 +21,23 @@ namespace PrestaShop\Module\Psgdpr\Repository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\FetchMode; use Doctrine\Persistence\ManagerRegistry; use PrestaShop\Module\Psgdpr\Entity\PsgdprConsent; use PrestaShop\Module\Psgdpr\Entity\PsgdprConsentLang; class ConsentRepository extends ServiceEntityRepository { + /** + * @var Connection + */ + private $connection; + public function __construct(ManagerRegistry $registry) { parent::__construct($registry, PsgdprConsent::class); + $this->connection = $this->getEntityManager()->getConnection(); } /** @@ -87,16 +95,14 @@ public function findConsentByModuleId(int $moduleId) */ public function findAllRegisteredModules(): array { - $queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder(); + $queryBuilder = $this->connection->createQueryBuilder(); $query = $queryBuilder->select('consent.id_gdpr_consent', 'consent.id_module') ->from(_DB_PREFIX_ . 'psgdpr_consent', 'consent') ->innerJoin('consent', _DB_PREFIX_ . 'module', 'module', 'module.id_module = consent.id_module') ->orderBy('consent.id_gdpr_consent', 'DESC'); - $data = $query->execute(); - - return $data->fetchAllAssociative(); + return $this->connection->executeQuery($query)->fetchAll(FetchMode::ASSOCIATIVE); } /** @@ -109,7 +115,7 @@ public function findAllRegisteredModules(): array */ public function findModuleConsentMessage(int $moduleId, int $langId): string { - $queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder(); + $queryBuilder = $this->connection->createQueryBuilder(); $query = $queryBuilder->select('consent_lang.message') ->from(_DB_PREFIX_ . 'psgdpr_consent', 'consent') @@ -119,10 +125,9 @@ public function findModuleConsentMessage(int $moduleId, int $langId): string ->setParameter('id_module', $moduleId) ->setParameter('id_lang', $langId); - $queryResult = $query->execute(); - $data = $queryResult->fetchOne(); + $data = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN); - return $data ? $data : ''; + return $data ?: ''; } /** @@ -134,15 +139,14 @@ public function findModuleConsentMessage(int $moduleId, int $langId): string */ public function findModuleConsentIsActive(int $moduleId): bool { - $queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder(); + $queryBuilder = $this->connection->createQueryBuilder(); $query = $queryBuilder->select('consent.active') ->from(_DB_PREFIX_ . 'psgdpr_consent', 'consent') ->where('consent.id_module = :id_module') ->setParameter('id_module', $moduleId); - $queryResult = $query->execute(); - $data = $queryResult->fetchAssociative(); + $data = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN); return !empty($data['active']); } @@ -156,7 +160,7 @@ public function findModuleConsentIsActive(int $moduleId): bool */ public function findModuleConsentExist(int $moduleId): bool { - $queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder(); + $queryBuilder = $this->connection->createQueryBuilder(); $query = $queryBuilder->select('id_module') ->from(_DB_PREFIX_ . 'psgdpr_consent', 'consent') @@ -164,9 +168,8 @@ public function findModuleConsentExist(int $moduleId): bool ->where('consent.id_module = :id_module') ->setParameter('id_module', $moduleId); - $queryResult = $query->execute(); - $data = $queryResult->fetchOne(); + $data = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN); - return $data ? true : false; + return (bool) $data; } } diff --git a/src/Repository/CustomerRepository.php b/src/Repository/CustomerRepository.php index dd7b9ca2..67b1cd69 100644 --- a/src/Repository/CustomerRepository.php +++ b/src/Repository/CustomerRepository.php @@ -21,6 +21,7 @@ namespace PrestaShop\Module\Psgdpr\Repository; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\FetchMode; use Doctrine\ORM\Query\Expr; use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId; @@ -60,9 +61,7 @@ public function findCustomerNameByCustomerId(CustomerId $customerId): string ->setParameter('id_customer', $customerId->getValue()) ; - $result = $query->execute(); - - return $result->fetchOne(); + return $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN); } /** @@ -82,8 +81,7 @@ public function findCustomerIdByEmail(string $email) ->setParameter('email', $email) ; - $result = $query->execute(); - $data = $result->fetchOne(); + $data = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN); if ($data) { return (int) $data; diff --git a/src/Repository/LoggerRepository.php b/src/Repository/LoggerRepository.php index 37101b77..9d63d83a 100644 --- a/src/Repository/LoggerRepository.php +++ b/src/Repository/LoggerRepository.php @@ -21,6 +21,7 @@ namespace PrestaShop\Module\Psgdpr\Repository; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\DBAL\FetchMode; use Doctrine\Persistence\ManagerRegistry; use PrestaShop\Module\Psgdpr\Entity\PsgdprLog; @@ -56,6 +57,6 @@ public function findAll(): array $result = $this->getEntityManager()->getConnection()->executeQuery($query); - return $result->fetchAllAssociative(); + return $result->fetchAll(FetchMode::ASSOCIATIVE); } } diff --git a/src/Repository/OrderInvoiceRepository.php b/src/Repository/OrderInvoiceRepository.php index 61602920..d0024265 100644 --- a/src/Repository/OrderInvoiceRepository.php +++ b/src/Repository/OrderInvoiceRepository.php @@ -21,6 +21,7 @@ namespace PrestaShop\Module\Psgdpr\Repository; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\FetchMode; use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId; class OrderInvoiceRepository @@ -57,9 +58,9 @@ public function findIfInvoicesExistByCustomerId(CustomerId $customerId): bool ->where('o.id_customer = :customerId') ->setParameter('customerId', $customerId->getValue()); - $result = $query->execute(); + $result = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN); - if ($result->fetchOne() == 0) { + if ($result == 0) { return false; } @@ -83,8 +84,6 @@ public function findAllInvoicesByCustomerId(CustomerId $customerId): array ->where('o.id_customer = :customerId') ->setParameter('customerId', $customerId->getValue()); - $result = $query->execute(); - - return $result->fetchAllAssociative(); + return $this->connection->executeQuery($query)->fetchAll(FetchMode::ASSOCIATIVE); } } diff --git a/src/Repository/OrderRepository.php b/src/Repository/OrderRepository.php index 93f2ae11..674a5d1e 100644 --- a/src/Repository/OrderRepository.php +++ b/src/Repository/OrderRepository.php @@ -21,6 +21,7 @@ namespace PrestaShop\Module\Psgdpr\Repository; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\FetchMode; use Exception; use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId; @@ -69,9 +70,7 @@ public function findProductsCartsNotOrderedByCustomerId(CustomerId $customerId): ->andWhere('NOT EXISTS (' . $orderedProductQuery . ')') ->setParameter('id_customer', $customerId->getValue()); - $result = $query->execute(); - - return $result->fetchAllAssociative(); + return $this->connection->executeQuery($query)->fetchAll(FetchMode::ASSOCIATIVE); } catch (Exception $e) { return []; }