Skip to content

Commit 83d46d7

Browse files
committed
Change EntityPersister return type
Calling UnitOfWork::assignPostInsertId() is now the way to go.
1 parent f3b6c4b commit 83d46d7

File tree

8 files changed

+18
-40
lines changed

8 files changed

+18
-40
lines changed

UPGRADE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK: `Doctrine\ORM\Persister\Entity\EntityPersister::executeInserts()` return type changed to `void`
4+
5+
Implementors should adapt to the new signature, and should call
6+
`UnitOfWork::assignPostInsertId()` for each entry in the previously returned
7+
array.
8+
39
## BC BREAK: `Doctrine\ORM\Proxy\ProxyFactory` no longer extends abstract factory from `doctrine/common`
410

511
It is no longer possible to call methods, constants or properties inherited

lib/Doctrine/ORM/Cache/Persister/Entity/AbstractEntityPersister.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,7 @@ public function getOwningTable(string $fieldName): string
268268
return $this->persister->getOwningTable($fieldName);
269269
}
270270

271-
/**
272-
* {@inheritDoc}
273-
*/
274-
public function executeInserts()
271+
public function executeInserts(): void
275272
{
276273
// The commit order/foreign key relationships may make it necessary that multiple calls to executeInsert()
277274
// are performed, so collect all the new entities.
@@ -281,7 +278,7 @@ public function executeInserts()
281278
$this->queuedCache['insert'] = array_merge($this->queuedCache['insert'] ?? [], $newInserts);
282279
}
283280

284-
return $this->persister->executeInserts();
281+
$this->persister->executeInserts();
285282
}
286283

287284
/**

lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,7 @@ public function getInserts(): array
218218
return $this->queuedInserts;
219219
}
220220

221-
/**
222-
* {@inheritDoc}
223-
*/
224-
public function executeInserts()
221+
public function executeInserts(): void
225222
{
226223
if (! $this->queuedInserts) {
227224
return;

lib/Doctrine/ORM/Persisters/Entity/EntityPersister.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,8 @@ public function addInsert(object $entity): void;
100100
* Executes all queued entity insertions.
101101
*
102102
* If no inserts are queued, invoking this method is a NOOP.
103-
*
104-
* @psalm-return void|list<array{
105-
* generatedId: int,
106-
* entity: object
107-
* }> Returning an array of generated post-insert IDs is deprecated, implementations
108-
* should call UnitOfWork::assignPostInsertId() and return void.
109103
*/
110-
public function executeInserts();
104+
public function executeInserts(): void;
111105

112106
/**
113107
* Updates a managed entity. The entity is updated according to its current changeset

lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ public function getOwningTable(string $fieldName): string
9494
return $tableName;
9595
}
9696

97-
/**
98-
* {@inheritDoc}
99-
*/
100-
public function executeInserts()
97+
public function executeInserts(): void
10198
{
10299
if (! $this->queuedInserts) {
103100
return;

lib/Doctrine/ORM/UnitOfWork.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,20 +1042,7 @@ private function executeInserts(): void
10421042

10431043
unset($this->entityInsertions[$oid]);
10441044

1045-
$postInsertIds = $persister->executeInserts();
1046-
1047-
if (is_array($postInsertIds)) {
1048-
Deprecation::trigger(
1049-
'doctrine/orm',
1050-
'https://github.com/doctrine/orm/pull/10743/',
1051-
'Returning post insert IDs from \Doctrine\ORM\Persisters\Entity\EntityPersister::executeInserts() is deprecated and will not be supported in Doctrine ORM 3.0. Make the persister call Doctrine\ORM\UnitOfWork::assignPostInsertId() instead.',
1052-
);
1053-
1054-
// Persister returned post-insert IDs
1055-
foreach ($postInsertIds as $postInsertId) {
1056-
$this->assignPostInsertId($postInsertId['entity'], $postInsertId['generatedId']);
1057-
}
1058-
}
1045+
$persister->executeInserts();
10591046

10601047
if (! isset($this->entityIdentifiers[$oid])) {
10611048
//entity was not added to identity map because some identifiers are foreign keys to new entities.

tests/Doctrine/Tests/Mocks/EntityPersisterMock.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ public function addInsert(object $entity): void
3838
];
3939
}
4040

41-
/** @psalm-return list<array{generatedId: int, entity: object}> */
42-
public function executeInserts(): array
41+
public function executeInserts(): void
4342
{
44-
return $this->postInsertIds;
43+
foreach ($this->postInsertIds as $item) {
44+
$this->em->getUnitOfWork()->assignPostInsertId($item['entity'], $item['generatedId']);
45+
}
4546
}
4647

4748
public function setMockIdGeneratorType(int $genType): void

tests/Doctrine/Tests/ORM/Cache/Persister/Entity/EntityPersisterTestCase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ public function testInvokeExecuteInserts(): void
173173
$persister = $this->createPersisterDefault();
174174

175175
$this->entityPersister->expects(self::once())
176-
->method('executeInserts')
177-
->willReturn(['id' => 1]);
176+
->method('executeInserts');
178177

179-
self::assertSame(['id' => 1], $persister->executeInserts());
178+
$persister->executeInserts();
180179
}
181180

182181
public function testInvokeUpdate(): void

0 commit comments

Comments
 (0)