Skip to content

Commit a5acb3b

Browse files
#4 Remove DoctrineWriterTask option global_flush due to removing partially flush ability on doctrine/orm 3.* (https://github.com/doctrine/orm/blob/3.0.x/UPGRADE.md#bc-break-removed-ability-to-partially-flushcommit-entity-manager-and-unit-of-work).
1 parent 7c796e0 commit a5acb3b

File tree

4 files changed

+14
-30
lines changed

4 files changed

+14
-30
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ v2.0
33

44
## BC breaks
55

6-
* [#6](https://github.com/cleverage/doctrine-process-bundle/issues/6) Update services according to Symfony best practices. Services should not use autowiring or autoconfiguration. Instead, all services should be defined explicitly.
6+
* [#6](https://github.com/cleverage/doctrine-process-bundle/issues/6) Update services according to Symfony best practices.
7+
Services should not use autowiring or autoconfiguration. Instead, all services should be defined explicitly.
78
Services must be prefixed with the bundle alias instead of using fully qualified class names => `cleverage_doctrine_process`
89
* [#5](https://github.com/cleverage/doctrine-process-bundle/issues/5) Bump "doctrine/doctrine-bundle": "^2.5" according to Symfony versions supported by `cleverage/process-bundle`
910
* [#4](https://github.com/cleverage/doctrine-process-bundle/issues/4) Allow installing "doctrine/orm": ^3.0 using at least require "doctrine/orm": "^2.9 || ^3.0".
1011
Forbid "doctrine/dbal" 4 for now (as on "symfony/orm-pack" - symfony/orm-pack@266bae0#diff-d2ab9925cad7eac58e0ff4cc0d251a937ecf49e4b6bf57f8b95aab76648a9d34R7 ) using "doctrine/dbal": "^2.9 || ^3.0".
1112
Add "doctrine/common": "^3.0" and "doctrine/doctrine-migrations-bundle": "^3.2"
13+
* [#4](https://github.com/cleverage/doctrine-process-bundle/issues/4) Remove DoctrineWriterTask option `global_flush`
14+
due to removing [partially flush ability](https://github.com/doctrine/orm/blob/3.0.x/UPGRADE.md#bc-break-removed-ability-to-partially-flushcommit-entity-manager-and-unit-of-work) on `doctrine/orm` 3.*
1215

1316

1417
### Changes

docs/reference/tasks/doctrine_writer_task.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ Options
2424
| Code | Type | Required | Default | Description |
2525
| ---- | ---- | :------: | ------- | ----------- |
2626
| `entity_manager` | `string` or `null` | | `null` | Use another entity manager than the default |
27-
| `global_flush` | `bool` | | `true` | Flush the whole entity manager after persist |
2827

src/Task/EntityManager/DoctrineReaderTask.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use CleverAge\ProcessBundle\Model\ProcessState;
1818
use Doctrine\ORM\EntityManagerInterface;
1919
use Doctrine\ORM\EntityRepository;
20-
use Doctrine\ORM\Internal\Hydration\IterableResult;
2120
use Doctrine\Persistence\ManagerRegistry;
2221
use Psr\Log\LoggerInterface;
2322

@@ -26,7 +25,7 @@
2625
*/
2726
class DoctrineReaderTask extends AbstractDoctrineQueryTask implements IterableTaskInterface
2827
{
29-
protected ?IterableResult $iterator = null;
28+
protected ?iterable $iterator = null;
3029

3130
public function __construct(
3231
protected LoggerInterface $logger,
@@ -42,32 +41,29 @@ public function __construct(
4241
*/
4342
public function next(ProcessState $state): bool
4443
{
45-
if (!$this->iterator instanceof IterableResult) {
44+
if (!is_iterable($this->iterator)) {
4645
return false;
4746
}
48-
$this->iterator->next();
47+
next($this->iterator);
4948

50-
return $this->iterator->valid();
49+
return false !== current($this->iterator);
5150
}
5251

5352
public function execute(ProcessState $state): void
5453
{
5554
$options = $this->getOptions($state);
56-
if (!$this->iterator instanceof IterableResult) {
55+
if (!is_iterable($this->iterator)) {
5756
/** @var class-string $class */
5857
$class = $options['class_name'];
5958
$entityManager = $this->doctrine->getManagerForClass($class);
6059
if (!$entityManager instanceof EntityManagerInterface) {
6160
throw new \UnexpectedValueException("No manager found for class {$class}");
6261
}
6362
$repository = $entityManager->getRepository($class);
64-
if (!$repository instanceof EntityRepository) {
65-
throw new \UnexpectedValueException("No repository found for class {$class}");
66-
}
6763
$this->initIterator($repository, $options);
6864
}
6965

70-
$result = $this->iterator->current();
66+
$result = current($this->iterator);
7167

7268
// Handle empty results
7369
if (false === $result) {
@@ -95,7 +91,7 @@ protected function initIterator(EntityRepository $repository, array $options): v
9591
);
9692

9793
$this->iterator = $qb->getQuery()
98-
->iterate();
99-
$this->iterator->next(); // Move to first element
94+
->toIterable();
95+
next($this->iterator); // Move to first element
10096
}
10197
}

src/Task/EntityManager/DoctrineWriterTask.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Doctrine\Common\Util\ClassUtils;
1818
use Doctrine\ORM\EntityManager;
1919
use Doctrine\ORM\EntityManagerInterface;
20-
use Symfony\Component\OptionsResolver\OptionsResolver;
2120

2221
/**
2322
* Persists and flush Doctrine entities.
@@ -29,18 +28,9 @@ public function execute(ProcessState $state): void
2928
$state->setOutput($this->writeEntity($state));
3029
}
3130

32-
protected function configureOptions(OptionsResolver $resolver): void
33-
{
34-
parent::configureOptions($resolver);
35-
$resolver->setDefaults([
36-
'global_flush' => true,
37-
]);
38-
$resolver->setAllowedTypes('global_flush', ['boolean']);
39-
}
40-
4131
protected function writeEntity(ProcessState $state): mixed
4232
{
43-
$options = $this->getOptions($state);
33+
$this->getOptions($state);
4434
/** @var object $entity */
4535
$entity = $state->getInput();
4636

@@ -55,11 +45,7 @@ protected function writeEntity(ProcessState $state): mixed
5545
}
5646
$entityManager->persist($entity);
5747

58-
if ($options['global_flush']) {
59-
$entityManager->flush();
60-
} else {
61-
$entityManager->flush($entity);
62-
}
48+
$entityManager->flush();
6349

6450
return $entity;
6551
}

0 commit comments

Comments
 (0)