Skip to content

Commit 9bf7a15

Browse files
committed
Rebase branch
1 parent ac3efd1 commit 9bf7a15

File tree

2 files changed

+44
-39
lines changed

2 files changed

+44
-39
lines changed

src/batch-doctrine-dbal/src/DoctrineDBALJobExecutionStorage.php

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -153,43 +153,11 @@ public function query(Query $query): iterable
153153
->from($this->table);
154154

155155
/**
156-
* @phpstan-var array<string, array<int, int|string>> $queryParameters
157-
* @phpstan-var array<string, int> $queryTypes
156+
* @phpstan-var array<string, mixed> $queryParameters
157+
* @phpstan-var array<string, string|int> $queryTypes
158158
*/
159159
[$queryParameters, $queryTypes] = $this->addWheres($query, $qb);
160160

161-
if ($query->startTime()) {
162-
$qb->andWhere($qb->expr()->isNotNull('start_time'));
163-
}
164-
$startDateFrom = $query->startTime()?->getFrom();
165-
if ($startDateFrom) {
166-
$qb->andWhere($qb->expr()->gte('start_time', ':startDateFrom'));
167-
$queryParameters['startDateFrom'] = $startDateFrom;
168-
$queryTypes['startDateFrom'] = Types::DATETIME_IMMUTABLE;
169-
}
170-
$startDateTo = $query->startTime()?->getTo();
171-
if ($startDateTo) {
172-
$qb->andWhere($qb->expr()->lte('start_time', ':startDateTo'));
173-
$queryParameters['startDateTo'] = $startDateTo;
174-
$queryTypes['startDateTo'] = Types::DATETIME_IMMUTABLE;
175-
}
176-
177-
if ($query->endTime()) {
178-
$qb->andWhere($qb->expr()->isNotNull('start_time'));
179-
}
180-
$endDateFrom = $query->endTime()?->getFrom();
181-
if ($endDateFrom) {
182-
$qb->andWhere($qb->expr()->gte('end_time', ':endDateFrom'));
183-
$queryParameters['endDateFrom'] = $endDateFrom;
184-
$queryTypes['endDateFrom'] = Types::DATETIME_IMMUTABLE;
185-
}
186-
$endDateTo = $query->endTime()?->getTo();
187-
if ($endDateTo) {
188-
$qb->andWhere($qb->expr()->lte('end_time', ':endDateTo'));
189-
$queryParameters['endDateTo'] = $endDateTo;
190-
$queryTypes['endDateTo'] = Types::DATETIME_IMMUTABLE;
191-
}
192-
193161
switch ($query->sort()) {
194162
case Query::SORT_BY_START_ASC:
195163
$qb->orderBy('start_time', 'asc');
@@ -217,8 +185,14 @@ public function count(Query $query): int
217185
$qb->select('count(*)')
218186
->from($this->table);
219187

188+
/**
189+
* @phpstan-var array<string, mixed> $queryParameters
190+
* @phpstan-var array<string, string|int> $queryTypes
191+
*/
192+
[$queryParameters, $queryTypes] = $this->addWheres($query, $qb);
193+
220194
/** @var int $result */
221-
$result = $this->connection->executeQuery($qb->getSQL(), ...$this->addWheres($query, $qb))->fetchOne();
195+
$result = $this->connection->executeQuery($qb->getSQL(), $queryParameters, $queryTypes)->fetchOne();
222196

223197
return $result;
224198
}
@@ -354,7 +328,7 @@ private function getNormalizer(): JobExecutionRowNormalizer
354328
}
355329

356330
/**
357-
* @return array<int, array<string, array<int|string>|int>>
331+
* @return array{array<string, mixed>, array<string, string|int>}
358332
*/
359333
private function addWheres(Query $query, QueryBuilder $qb): array
360334
{
@@ -382,6 +356,38 @@ private function addWheres(Query $query, QueryBuilder $qb): array
382356
$queryTypes['statuses'] = Connection::PARAM_INT_ARRAY;
383357
}
384358

359+
if ($query->startTime()) {
360+
$qb->andWhere($qb->expr()->isNotNull('start_time'));
361+
}
362+
$startDateFrom = $query->startTime()?->getFrom();
363+
if ($startDateFrom) {
364+
$qb->andWhere($qb->expr()->gte('start_time', ':startDateFrom'));
365+
$queryParameters['startDateFrom'] = $startDateFrom;
366+
$queryTypes['startDateFrom'] = Types::DATETIME_IMMUTABLE;
367+
}
368+
$startDateTo = $query->startTime()?->getTo();
369+
if ($startDateTo) {
370+
$qb->andWhere($qb->expr()->lte('start_time', ':startDateTo'));
371+
$queryParameters['startDateTo'] = $startDateTo;
372+
$queryTypes['startDateTo'] = Types::DATETIME_IMMUTABLE;
373+
}
374+
375+
if ($query->endTime()) {
376+
$qb->andWhere($qb->expr()->isNotNull('start_time'));
377+
}
378+
$endDateFrom = $query->endTime()?->getFrom();
379+
if ($endDateFrom) {
380+
$qb->andWhere($qb->expr()->gte('end_time', ':endDateFrom'));
381+
$queryParameters['endDateFrom'] = $endDateFrom;
382+
$queryTypes['endDateFrom'] = Types::DATETIME_IMMUTABLE;
383+
}
384+
$endDateTo = $query->endTime()?->getTo();
385+
if ($endDateTo) {
386+
$qb->andWhere($qb->expr()->lte('end_time', ':endDateTo'));
387+
$queryParameters['endDateTo'] = $endDateTo;
388+
$queryTypes['endDateTo'] = Types::DATETIME_IMMUTABLE;
389+
}
390+
385391
return [$queryParameters, $queryTypes];
386392
}
387393
}

src/batch/tests/Storage/FilesystemJobExecutionStorageTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,15 @@ public function list(): \Generator
142142
/**
143143
* @dataProvider query
144144
*/
145-
public function testQueryWithProvider(QueryBuilder $query, array $expectedCouples, ?int $expectedCount = null): void
145+
public function testQueryWithProvider(QueryBuilder $query, array $expectedCouples): void
146146
{
147147
$storage = $this->createStorage(
148148
__DIR__ . '/fixtures/filesystem-job-execution',
149149
new JsonJobExecutionSerializer()
150150
);
151151

152152
self::assertExecutions($expectedCouples, $storage->query($query->getQuery()));
153-
$expectedCount ??= count($expectedCouples);
154-
self::assertEquals($expectedCount, $storage->count($query->getQuery()));
153+
self::assertEquals(\count($expectedCouples), $storage->count($query->getQuery()));
155154
}
156155

157156
public function query(): \Generator

0 commit comments

Comments
 (0)