Skip to content

Commit 15b4446

Browse files
fix deprecations
1 parent 40f9451 commit 15b4446

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

src/Task/Database/DatabaseReaderTask.php

+7-10
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
use CleverAge\ProcessBundle\Model\IterableTaskInterface;
1919
use CleverAge\ProcessBundle\Model\ProcessState;
2020
use Doctrine\DBAL\Connection;
21-
use Doctrine\DBAL\Driver\PDOStatement;
22-
use Doctrine\DBAL\Driver\ResultStatement;
21+
use Doctrine\DBAL\Result;
2322
use Doctrine\Persistence\ManagerRegistry;
2423
use Psr\Log\LoggerInterface;
2524
use Psr\Log\LogLevel;
@@ -30,7 +29,7 @@
3029
*/
3130
class DatabaseReaderTask extends AbstractConfigurableTask implements IterableTaskInterface, FinalizableTaskInterface
3231
{
33-
protected ?PDOStatement $statement = null;
32+
protected ?Result $statement = null;
3433

3534
protected mixed $nextItem = null;
3635

@@ -51,7 +50,7 @@ public function next(ProcessState $state): bool
5150
return false;
5251
}
5352

54-
$this->nextItem = $this->statement->fetch();
53+
$this->nextItem = $this->statement->fetchAssociative();
5554

5655
return (bool) $this->nextItem;
5756
}
@@ -68,7 +67,7 @@ public function execute(ProcessState $state): void
6867
$result = $this->nextItem;
6968
$this->nextItem = null;
7069
} else {
71-
$result = $this->statement->fetch();
70+
$result = $this->statement->fetchAssociative();
7271
}
7372

7473
// Handle empty results
@@ -88,7 +87,7 @@ public function execute(ProcessState $state): void
8887
$i = 0;
8988
while ($result !== false && $i++ < $options['paginate']) {
9089
$results[] = $result;
91-
$result = $this->statement->fetch();
90+
$result = $this->statement->fetchAssociative();
9291
}
9392
$state->setOutput($results);
9493
} else {
@@ -98,12 +97,10 @@ public function execute(ProcessState $state): void
9897

9998
public function finalize(ProcessState $state): void
10099
{
101-
if ($this->statement) {
102-
$this->statement->closeCursor();
103-
}
100+
$this->statement?->free();
104101
}
105102

106-
protected function initializeStatement(ProcessState $state): ResultStatement
103+
protected function initializeStatement(ProcessState $state): Result
107104
{
108105
$options = $this->getOptions($state);
109106
$connection = $this->getConnection($state);

src/Task/Database/DatabaseUpdaterTask.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
1717
use CleverAge\ProcessBundle\Model\ProcessState;
1818
use Doctrine\DBAL\Connection;
19+
use Doctrine\DBAL\Exception;
1920
use Doctrine\Persistence\ManagerRegistry;
2021
use Psr\Log\LoggerInterface;
2122
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -43,6 +44,7 @@ public function execute(ProcessState $state): void
4344

4445
/**
4546
* @return integer The number of affected rows.
47+
* @throws Exception
4648
*/
4749
protected function initializeStatement(ProcessState $state): int
4850
{
@@ -58,7 +60,7 @@ protected function initializeStatement(ProcessState $state): int
5860
throw new UnexpectedValueException('Expecting an array of params');
5961
}
6062

61-
return $connection->executeUpdate($options['sql'], $params, $options['types']);
63+
return $connection->executeStatement($options['sql'], $params, $options['types']);
6264
}
6365

6466
protected function configureOptions(OptionsResolver $resolver): void

src/Task/EntityManager/AbstractDoctrineQueryTask.php

+5-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Psr\Log\LogLevel;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020
use UnexpectedValueException;
21+
use function is_array;
2122

2223
/**
2324
* Easily extendable task to query entities in their repository
@@ -57,27 +58,23 @@ protected function configureOptions(OptionsResolver $resolver): void
5758
);
5859
}
5960

60-
/**
61-
* @param int $limit
62-
* @param int $offset
63-
*/
6461
protected function getQueryBuilder(
6562
EntityRepository $repository,
6663
array $criteria,
6764
array $orderBy,
68-
$limit = null,
69-
$offset = null
65+
?int $limit = null,
66+
?int $offset = null
7067
): QueryBuilder {
7168
$qb = $repository->createQueryBuilder('e');
7269
foreach ($criteria as $field => $value) {
7370
if (preg_match('/[^a-zA-Z0-9]/', $field)) {
7471
throw new UnexpectedValueException("Forbidden field name '{$field}'");
7572
}
76-
$parameterName = uniqid('param', false);
73+
$parameterName = uniqid('param', true);
7774
if ($value === null) {
7875
$qb->andWhere("e.{$field} IS null");
7976
} else {
80-
if (\is_array($value)) {
77+
if (is_array($value)) {
8178
$qb->andWhere("e.{$field} IN (:{$parameterName})");
8279
} else {
8380
$qb->andWhere("e.{$field} = :{$parameterName}");

0 commit comments

Comments
 (0)