Skip to content

Commit e69af07

Browse files
committed
Repository::findAllIterator returns iterable
Adation to IterableResult deprecation.
1 parent 90c5b4b commit e69af07

File tree

4 files changed

+7
-44
lines changed

4 files changed

+7
-44
lines changed

Neos.Flow/Classes/Persistence/Doctrine/Repository.php

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313

1414
use Doctrine\ORM\EntityManagerInterface;
1515
use Doctrine\ORM\EntityRepository;
16-
use Doctrine\ORM\Internal\Hydration\IterableResult;
17-
use Doctrine\ORM\OptimisticLockException;
18-
use Doctrine\ORM\ORMException;
19-
use Doctrine\ORM\TransactionRequiredException;
2016
use Doctrine\ORM\QueryBuilder;
2117
use Doctrine\Persistence\Mapping\ClassMetadata;
2218
use Neos\Flow\Annotations as Flow;
@@ -97,7 +93,6 @@ public function getEntityClassName(): string
9793
* @param object $object The object to add
9894
* @return void
9995
* @throws IllegalObjectTypeException
100-
* @throws ORMException
10196
* @api
10297
*/
10398
public function add($object): void
@@ -115,7 +110,6 @@ public function add($object): void
115110
* @param object $object The object to remove
116111
* @return void
117112
* @throws IllegalObjectTypeException
118-
* @throws ORMException
119113
* @api
120114
*/
121115
public function remove($object): void
@@ -142,51 +136,23 @@ public function findAll(): QueryResultInterface
142136
/**
143137
* Find all objects and return an IterableResult
144138
*
145-
* @return IterableResult
139+
* @return iterable
146140
*/
147-
public function findAllIterator(): IterableResult
141+
public function findAllIterator(): iterable
148142
{
149143
/** @var QueryBuilder $queryBuilder */
150144
$queryBuilder = $this->entityManager->createQueryBuilder();
151145
return $queryBuilder
152146
->select('entity')
153147
->from($this->getEntityClassName(), 'entity')
154-
->getQuery()->iterate();
155-
}
156-
157-
/**
158-
* Iterate over an IterableResult and return a Generator
159-
*
160-
* This method is useful for batch processing a huge result set.
161-
*
162-
* @param IterableResult $iterator
163-
* @param callable|null $callback
164-
* @return \Generator
165-
*
166-
* @deprecated Will be removed with Flow 9. The {@see findAllIterator} will return an \iterable directly
167-
*/
168-
public function iterate(IterableResult $iterator, callable $callback = null): ?\Generator
169-
{
170-
$iteration = 0;
171-
foreach ($iterator as $object) {
172-
$object = current($object);
173-
yield $object;
174-
if ($callback !== null) {
175-
$callback($iteration, $object);
176-
}
177-
178-
$iteration++;
179-
}
148+
->getQuery()->toIterable();
180149
}
181150

182151
/**
183152
* Finds an object matching the given identifier.
184153
*
185154
* @param mixed $identifier The identifier of the object to find
186155
* @return object|null The matching object if found, otherwise NULL
187-
* @throws ORMException
188-
* @throws OptimisticLockException
189-
* @throws TransactionRequiredException
190156
* @api
191157
*/
192158
public function findByIdentifier($identifier)
@@ -239,7 +205,6 @@ public function countAll(): int
239205
*
240206
* @return void
241207
* @throws IllegalObjectTypeException
242-
* @throws ORMException
243208
* @todo maybe use DQL here, would be much more performant
244209
* @api
245210
*/

Neos.Flow/Classes/Persistence/Doctrine/Service.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
use Doctrine\Migrations\Version\Version;
4242
use Doctrine\ORM\EntityManagerInterface;
4343
use Doctrine\ORM\Mapping\MappingException;
44-
use Doctrine\ORM\ORMException;
4544
use Doctrine\ORM\Tools\SchemaTool;
4645
use Doctrine\ORM\Tools\SchemaValidator;
4746
use Doctrine\ORM\Tools\ToolsException;
@@ -166,7 +165,6 @@ public function compileProxies(): void
166165
* mapping information contains errors or not.
167166
*
168167
* @return array
169-
* @throws ORMException
170168
*/
171169
public function getEntityStatus(): array
172170
{
@@ -626,15 +624,16 @@ public function generateMigration(bool $diffAgainstCurrent = true, string $filte
626624
}
627625

628626
/**
629-
* Get name of current database platform
627+
* Get class name of current database platform
630628
*
631629
* @return string
632630
* @throws DBALException
633631
* @deprecated will be removed in Flow 9. Compare the connection class name instead.
634632
*/
635633
public function getDatabasePlatformName(): string
636634
{
637-
return ucfirst($this->entityManager->getConnection()->getDatabasePlatform()->getName());
635+
$platform = $this->entityManager->getConnection()->getDatabasePlatform();
636+
return $platform !== null ? get_class($platform) : '';
638637
}
639638

640639
/**

Neos.Flow/Classes/ResourceManagement/ResourceRepository.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313

1414
use Doctrine\ORM\EntityManagerInterface;
15-
use Doctrine\ORM\Internal\Hydration\IterableResult;
1615
use Doctrine\ORM\QueryBuilder;
1716
use Neos\Flow\Annotations as Flow;
1817
use Neos\Flow\Persistence\PersistenceManagerInterface;

Neos.Flow/Tests/Functional/Persistence/Doctrine/RepositoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function findAllIteratorReturnsSubTypesOfTheManagedType()
248248
$iterator = $this->superEntityRepository->findAllIterator();
249249
$expectedCount = 0;
250250

251-
foreach ($this->superEntityRepository->iterate($iterator) as $entity) {
251+
foreach ($iterator as $entity) {
252252
$expectedCount++;
253253
}
254254

0 commit comments

Comments
 (0)