Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 1 addition & 3 deletions src/Repository/CartRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
33 changes: 18 additions & 15 deletions src/Repository/ConsentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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')
Expand All @@ -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 ?: '';
}

/**
Expand All @@ -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']);
}
Expand All @@ -156,17 +160,16 @@ 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')
->leftJoin('consent', _DB_PREFIX_ . 'psgdpr_consent_lang', 'consent_lang', 'consent.id_gdpr_consent = consent_lang.id_gdpr_consent')
->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;
}
}
8 changes: 3 additions & 5 deletions src/Repository/CustomerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/Repository/LoggerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -56,6 +57,6 @@ public function findAll(): array

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

return $result->fetchAllAssociative();
return $result->fetchAll(FetchMode::ASSOCIATIVE);
}
}
9 changes: 4 additions & 5 deletions src/Repository/OrderInvoiceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}
5 changes: 2 additions & 3 deletions src/Repository/OrderRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 [];
}
Expand Down