Skip to content

Commit da807a1

Browse files
author
Morgan Pichat
committed
Update doctrine queries
1 parent 79a4111 commit da807a1

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

src/Repository/CartRepository.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ public function findCartsByCustomerId(CustomerId $customerId): array
6161
->setParameter('id_customer', $customerId->getValue()
6262
);
6363

64-
$result = $query->execute();
65-
66-
return $result->fetchAssociative();
64+
return $this->connection->executeQuery($query)->fetch();
6765
}
6866

6967
/**

src/Repository/ConsentRepository.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,22 @@
2121
namespace PrestaShop\Module\Psgdpr\Repository;
2222

2323
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
24+
use Doctrine\DBAL\FetchMode;
2425
use Doctrine\Persistence\ManagerRegistry;
2526
use PrestaShop\Module\Psgdpr\Entity\PsgdprConsent;
2627
use PrestaShop\Module\Psgdpr\Entity\PsgdprConsentLang;
2728

2829
class ConsentRepository extends ServiceEntityRepository
2930
{
31+
/**
32+
* @var Connection
33+
*/
34+
private $connection;
35+
3036
public function __construct(ManagerRegistry $registry)
3137
{
3238
parent::__construct($registry, PsgdprConsent::class);
39+
$this->connection = $this->getEntityManager()->getConnection();
3340
}
3441

3542
/**
@@ -87,16 +94,14 @@ public function findConsentByModuleId(int $moduleId)
8794
*/
8895
public function findAllRegisteredModules(): array
8996
{
90-
$queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder();
97+
$queryBuilder = $this->connection->createQueryBuilder();
9198

9299
$query = $queryBuilder->select('consent.id_gdpr_consent', 'consent.id_module')
93100
->from(_DB_PREFIX_ . 'psgdpr_consent', 'consent')
94101
->innerJoin('consent', _DB_PREFIX_ . 'module', 'module', 'module.id_module = consent.id_module')
95102
->orderBy('consent.id_gdpr_consent', 'DESC');
96103

97-
$data = $query->execute();
98-
99-
return $data->fetchAllAssociative();
104+
return $this->connection->executeQuery($query)->fetchAll(FetchMode::ASSOCIATIVE);
100105
}
101106

102107
/**
@@ -109,7 +114,7 @@ public function findAllRegisteredModules(): array
109114
*/
110115
public function findModuleConsentMessage(int $moduleId, int $langId): string
111116
{
112-
$queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder();
117+
$queryBuilder = $this->connection->createQueryBuilder();
113118

114119
$query = $queryBuilder->select('consent_lang.message')
115120
->from(_DB_PREFIX_ . 'psgdpr_consent', 'consent')
@@ -119,10 +124,9 @@ public function findModuleConsentMessage(int $moduleId, int $langId): string
119124
->setParameter('id_module', $moduleId)
120125
->setParameter('id_lang', $langId);
121126

122-
$queryResult = $query->execute();
123-
$data = $queryResult->fetchOne();
127+
$data = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN);
124128

125-
return $data ? $data : '';
129+
return $data ?: '';
126130
}
127131

128132
/**
@@ -134,15 +138,14 @@ public function findModuleConsentMessage(int $moduleId, int $langId): string
134138
*/
135139
public function findModuleConsentIsActive(int $moduleId): bool
136140
{
137-
$queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder();
141+
$queryBuilder = $this->connection->createQueryBuilder();
138142

139143
$query = $queryBuilder->select('consent.active')
140144
->from(_DB_PREFIX_ . 'psgdpr_consent', 'consent')
141145
->where('consent.id_module = :id_module')
142146
->setParameter('id_module', $moduleId);
143147

144-
$queryResult = $query->execute();
145-
$data = $queryResult->fetchAssociative();
148+
$data = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN);
146149

147150
return !empty($data['active']);
148151
}
@@ -156,17 +159,16 @@ public function findModuleConsentIsActive(int $moduleId): bool
156159
*/
157160
public function findModuleConsentExist(int $moduleId): bool
158161
{
159-
$queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder();
162+
$queryBuilder = $this->connection->createQueryBuilder();
160163

161164
$query = $queryBuilder->select('id_module')
162165
->from(_DB_PREFIX_ . 'psgdpr_consent', 'consent')
163166
->leftJoin('consent', _DB_PREFIX_ . 'psgdpr_consent_lang', 'consent_lang', 'consent.id_gdpr_consent = consent_lang.id_gdpr_consent')
164167
->where('consent.id_module = :id_module')
165168
->setParameter('id_module', $moduleId);
166169

167-
$queryResult = $query->execute();
168-
$data = $queryResult->fetchOne();
170+
$data = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN);
169171

170-
return $data ? true : false;
172+
return (bool) $data;
171173
}
172174
}

src/Repository/CustomerRepository.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace PrestaShop\Module\Psgdpr\Repository;
2222

2323
use Doctrine\DBAL\Connection;
24+
use Doctrine\DBAL\FetchMode;
2425
use Doctrine\ORM\Query\Expr;
2526
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId;
2627

@@ -60,9 +61,7 @@ public function findCustomerNameByCustomerId(CustomerId $customerId): string
6061
->setParameter('id_customer', $customerId->getValue())
6162
;
6263

63-
$result = $query->execute();
64-
65-
return $result->fetchOne();
64+
return $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN);
6665
}
6766

6867
/**
@@ -82,8 +81,7 @@ public function findCustomerIdByEmail(string $email)
8281
->setParameter('email', $email)
8382
;
8483

85-
$result = $query->execute();
86-
$data = $result->fetchOne();
84+
$data = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN);
8785

8886
if ($data) {
8987
return (int) $data;

src/Repository/LoggerRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace PrestaShop\Module\Psgdpr\Repository;
2222

2323
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
24+
use Doctrine\DBAL\FetchMode;
2425
use Doctrine\Persistence\ManagerRegistry;
2526
use PrestaShop\Module\Psgdpr\Entity\PsgdprLog;
2627

@@ -56,6 +57,6 @@ public function findAll(): array
5657

5758
$result = $this->getEntityManager()->getConnection()->executeQuery($query);
5859

59-
return $result->fetchAllAssociative();
60+
return $result->fetchAll(FetchMode::ASSOCIATIVE);
6061
}
6162
}

src/Repository/OrderInvoiceRepository.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace PrestaShop\Module\Psgdpr\Repository;
2222

2323
use Doctrine\DBAL\Connection;
24+
use Doctrine\DBAL\FetchMode;
2425
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId;
2526

2627
class OrderInvoiceRepository
@@ -57,9 +58,9 @@ public function findIfInvoicesExistByCustomerId(CustomerId $customerId): bool
5758
->where('o.id_customer = :customerId')
5859
->setParameter('customerId', $customerId->getValue());
5960

60-
$result = $query->execute();
61+
$result = $this->connection->executeQuery($query)->fetch(FetchMode::COLUMN);
6162

62-
if ($result->fetchOne() == 0) {
63+
if ($result == 0) {
6364
return false;
6465
}
6566

@@ -83,8 +84,6 @@ public function findAllInvoicesByCustomerId(CustomerId $customerId): array
8384
->where('o.id_customer = :customerId')
8485
->setParameter('customerId', $customerId->getValue());
8586

86-
$result = $query->execute();
87-
88-
return $result->fetchAllAssociative();
87+
return $this->connection->executeQuery($query)->fetchAll(FetchMode::ASSOCIATIVE);
8988
}
9089
}

src/Repository/OrderRepository.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace PrestaShop\Module\Psgdpr\Repository;
2222

2323
use Doctrine\DBAL\Connection;
24+
use Doctrine\DBAL\FetchMode;
2425
use Exception;
2526
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerId;
2627

@@ -69,9 +70,7 @@ public function findProductsCartsNotOrderedByCustomerId(CustomerId $customerId):
6970
->andWhere('NOT EXISTS (' . $orderedProductQuery . ')')
7071
->setParameter('id_customer', $customerId->getValue());
7172

72-
$result = $query->execute();
73-
74-
return $result->fetchAllAssociative();
73+
return $this->connection->executeQuery($query)->fetchAll(FetchMode::ASSOCIATIVE);
7574
} catch (Exception $e) {
7675
return [];
7776
}

0 commit comments

Comments
 (0)