Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/split_packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
matrix:
mapping: '${{ fromJson(needs.provide_packages_json.outputs.matrix) }}'
tag:
- 6.19.1
- 6.19.4
name: 'Split ${{ matrix.mapping.dir }}'
env:
DIR: 'packages/${{ matrix.mapping.dir }}'
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ext-openssl": "*",
"ext-pdo": "*",
"ext-sodium": "*",
"api-platform/core": "^4.2.15",
"api-platform/core": "^4.2.19",
"async-aws/secrets-manager": "^2.5",
"aws/aws-sdk-php": "^3.288.1",
"bugsnag/bugsnag": "^3.29.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/EasyApiPlatform/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"require": {
"php": "^8.4",
"api-platform/core": "^4.2.15",
"api-platform/core": "^4.2.19",
"doctrine/collections": "^1.7.2 || ^2.1",
"doctrine/dbal": "^3.8",
"doctrine/orm": "^2.20",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@
},
"example": {
"@id": "string",
"type": "string",
"@type": "string",
"hydra:first": "string",
"hydra:last": "string",
"hydra:previous": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@
},
"example": {
"@id": "string",
"type": "string",
"@type": "string",
"hydra:first": "string",
"hydra:last": "string",
"hydra:previous": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace EonX\EasyPagination\Paginator;

use BackedEnum;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Query\QueryBuilder as DbalQueryBuilder;
Expand Down Expand Up @@ -189,6 +191,13 @@ private function getTotalItemsForLargeDataset(OrmQueryBuilder|DbalQueryBuilder $
$paramTypes = $queryBuilder->getParameterTypes();
}

foreach ($params as $key => $param) {
if ($param instanceof BackedEnum) {
$params[$key] = $param->value;
$paramTypes[$key] = \is_int($param->value) ? ParameterType::INTEGER : ParameterType::STRING;
}
}

if (\is_string($sql) === false) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

namespace EonX\EasyPagination\Paginator;

use BackedEnum;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Query\QueryBuilder;

trait DoctrineDbalPaginatorTrait
Expand All @@ -25,11 +27,17 @@ private function createQueryBuilder(): QueryBuilder
*/
private function fetchResults(QueryBuilder $queryBuilder): array
{
return $this->connection->fetchAllAssociative(
$queryBuilder->getSQL(),
$queryBuilder->getParameters(),
$queryBuilder->getParameterTypes()
);
$params = $queryBuilder->getParameters();
$paramTypes = $queryBuilder->getParameterTypes();

foreach ($params as $key => $param) {
if ($param instanceof BackedEnum) {
$params[$key] = $param->value;
$paramTypes[$key] = \is_int($param->value) ? ParameterType::INTEGER : ParameterType::STRING;
}
}

return $this->connection->fetchAllAssociative($queryBuilder->getSQL(), $params, $paramTypes);
}

private function getConnection(): Connection
Expand Down
14 changes: 14 additions & 0 deletions packages/EasyPagination/tests/Stub/Entity/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use EonX\EasyPagination\Tests\Stub\Enum\Status;

#[ORM\Entity]
#[ORM\Table(name: 'items')]
Expand All @@ -15,6 +16,9 @@ class Item
#[ORM\Id]
private int $id;

#[ORM\Column(type: Types::STRING, length: 255, nullable: true, enumType: Status::class)]
private ?Status $status = null;

#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
private ?string $title = null;

Expand All @@ -23,11 +27,21 @@ public function getId(): int
return $this->id;
}

public function getStatus(): ?Status
{
return $this->status;
}

public function getTitle(): ?string
{
return $this->title;
}

public function setStatus(?Status $status): void
{
$this->status = $status;
}

public function setTitle(?string $title): void
{
$this->title = $title;
Expand Down
11 changes: 11 additions & 0 deletions packages/EasyPagination/tests/Stub/Enum/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types=1);

namespace EonX\EasyPagination\Tests\Stub\Enum;

enum Status: string
{
case Active = 'active';

case Inactive = 'inactive';
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\Schema;
use EonX\EasyPagination\Tests\Stub\Enum\Status;
use EonX\EasyPagination\Tests\Unit\AbstractUnitTestCase;
use Symfony\Component\Uid\Uuid;

Expand All @@ -27,9 +28,9 @@ protected static function addChildItemToTable(Connection $connection, string $ti
/**
* @throws \Doctrine\DBAL\Exception
*/
protected static function addItemToTable(Connection $connection, string $title): void
protected static function addItemToTable(Connection $connection, string $title, ?Status $status = null): void
{
$connection->insert('items', ['title' => $title]);
$connection->insert('items', ['title' => $title, 'status' => $status?->value]);
}

/**
Expand Down Expand Up @@ -76,6 +77,10 @@ protected static function createItemsTable(Connection $connection): void
->addColumn('title', 'string', ['length' => 255])
->setNotnull(false);

$table
->addColumn('status', 'string', ['length' => 255])
->setNotnull(false);

$table->setPrimaryKey(['id']);

foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\ORM\Tools\SchemaTool;
use EonX\EasyPagination\Tests\Stub\Entity\ChildItem;
use EonX\EasyPagination\Tests\Stub\Entity\Item;
use EonX\EasyPagination\Tests\Stub\Enum\Status;
use EonX\EasyPagination\Tests\Stub\Type\SqliteStringUuidType;
use EonX\EasyPagination\Tests\Unit\AbstractUnitTestCase;

Expand All @@ -29,10 +30,14 @@ protected static function addChildItemToTable(EntityManagerInterface $manager, s
$manager->flush();
}

protected static function addItemToTable(EntityManagerInterface $manager, string $title): Item
{
protected static function addItemToTable(
EntityManagerInterface $manager,
string $title,
?Status $status = null,
): Item {
$item = new Item();
$item->setTitle($title);
$item->setStatus($status);

$manager->persist($item);
$manager->flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use EonX\EasyPagination\Pagination\Pagination;
use EonX\EasyPagination\Pagination\PaginationInterface;
use EonX\EasyPagination\Paginator\DoctrineDbalLengthAwarePaginator;
use EonX\EasyPagination\Tests\Stub\Enum\Status;
use PHPUnit\Framework\Attributes\DataProvider;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -136,6 +137,27 @@ static function (DoctrineDbalLengthAwarePaginator $paginator): void {
},
];

yield '2 items filter 1 with enum parameter' => [
Pagination::create(1, 15),
'items',
null,
function (Connection $connection, DoctrineDbalLengthAwarePaginator $paginator): void {
self::createItemsTable($connection);
self::addItemToTable($connection, 'my-title', Status::Active);
self::addItemToTable($connection, 'my-title-1', Status::Inactive);

$paginator->setFilterCriteria(static function (QueryBuilder $queryBuilder): void {
$queryBuilder
->where('status = :status')
->setParameter('status', Status::Inactive);
});
},
static function (DoctrineDbalLengthAwarePaginator $paginator): void {
self::assertCount(1, $paginator->getItems());
self::assertEquals(1, $paginator->getTotalItems());
},
];

yield '2 items filter 1 with fromAlias' => [
Pagination::create(1, 15),
'items',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use EonX\EasyPagination\Paginator\DoctrineOrmLengthAwarePaginator;
use EonX\EasyPagination\Tests\Stub\Entity\ChildItem;
use EonX\EasyPagination\Tests\Stub\Entity\Item;
use EonX\EasyPagination\Tests\Stub\Enum\Status;
use PHPUnit\Framework\Attributes\DataProvider;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
Expand Down Expand Up @@ -93,6 +94,28 @@ static function (DoctrineOrmLengthAwarePaginator $paginator): void {
},
];

yield '2 items filter 1 with enum parameter' => [
Pagination::create(1, 15),
Item::class,
'i',
null,
function (EntityManagerInterface $manager, DoctrineOrmLengthAwarePaginator $paginator): void {
self::createItemsTable($manager);
self::addItemToTable($manager, 'my-title', Status::Active);
self::addItemToTable($manager, 'my-title-1', Status::Inactive);

$paginator->setFilterCriteria(static function (QueryBuilder $queryBuilder): void {
$queryBuilder
->where('i.status = :status')
->setParameter('status', Status::Inactive);
});
},
static function (DoctrineOrmLengthAwarePaginator $paginator): void {
self::assertCount(1, $paginator->getItems());
self::assertEquals(1, $paginator->getTotalItems());
},
];

yield '1 item select everything by default' => [
Pagination::create(1, 15),
Item::class,
Expand Down
22 changes: 12 additions & 10 deletions packages/EasyServerless/bundle/SqsHandler/SqsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Bref\Context\Context;
use Bref\Event\Sqs\SqsRecord;
use EonX\EasyErrorHandler\Common\ErrorHandler\ErrorHandlerInterface;
use EonX\EasyErrorHandler\Common\Exception\RetryableException;
use EonX\EasyEventDispatcher\Dispatcher\EventDispatcherInterface;
use EonX\EasyServerless\Messenger\Event\EnvelopeDispatchedEvent;
use EonX\EasyServerless\Messenger\SqsHandler\AbstractSqsHandler;
Expand Down Expand Up @@ -78,14 +79,6 @@ protected function handleSqsRecords(SqsRecord $sqsRecord, Context $context): voi
}

try {
$event = new WorkerMessageReceivedEvent($envelope, $this->transportName);
$this->eventDispatcher?->dispatch($event);
$envelope = $event->getEnvelope();

if ($event->shouldHandle() === false) {
return;
}

$stamps = [
new AmazonSqsReceivedStamp($sqsRecord->getMessageId()),
new ConsumedByWorkerStamp(),
Expand All @@ -103,6 +96,15 @@ protected function handleSqsRecords(SqsRecord $sqsRecord, Context $context): voi

// Replacing the envelope with the containing the new stamps allows the retry strategy to work properly
$envelope = $envelope->with(...$stamps);

$event = new WorkerMessageReceivedEvent($envelope, $this->transportName);
$this->eventDispatcher?->dispatch($event);
$envelope = $event->getEnvelope();

if ($event->shouldHandle() === false) {
return;
}

$envelope = $this->bus->dispatch($envelope);

$this->logger?->info('{class} was handled successfully.', [
Expand All @@ -111,8 +113,6 @@ protected function handleSqsRecords(SqsRecord $sqsRecord, Context $context): voi
'transport' => $this->transportName,
]);
} catch (Throwable $throwable) {
$this->errorHandler?->report($throwable);

$retryStrategy = $this->getRetryStrategyForTransport($this->transportName);
$isThrowableExplicitlyUnrecoverable = $this->isThrowableExplicitlyUnRecoverable($throwable);
$shouldRetry = $isThrowableExplicitlyUnrecoverable === false
Expand All @@ -132,6 +132,8 @@ protected function handleSqsRecords(SqsRecord $sqsRecord, Context $context): voi
));
}

$this->errorHandler?->report(RetryableException::fromThrowable($throwable, $shouldRetry));

// SQS built-in retry mechanism uses the list of failed messages returned by the Lambda function,
// this is why we mark the record as failed only if we want it to be retried by SQS.
// Failure reports should be handled by the application itself (e.g. logging, error tracking, etc.)
Expand Down
Loading
Loading