Skip to content

Commit

Permalink
Merge pull request #10975 from greg0ire/void-execute-insert
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire authored Oct 9, 2023
2 parents a1d7de6 + 83d46d7 commit 4799c41
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 40 deletions.
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Upgrade to 3.0

## BC BREAK: `Doctrine\ORM\Persister\Entity\EntityPersister::executeInserts()` return type changed to `void`

Implementors should adapt to the new signature, and should call
`UnitOfWork::assignPostInsertId()` for each entry in the previously returned
array.

## BC BREAK: `Doctrine\ORM\Proxy\ProxyFactory` no longer extends abstract factory from `doctrine/common`

It is no longer possible to call methods, constants or properties inherited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,7 @@ public function getOwningTable(string $fieldName): string
return $this->persister->getOwningTable($fieldName);
}

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

return $this->persister->executeInserts();
$this->persister->executeInserts();
}

/**
Expand Down
5 changes: 1 addition & 4 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,7 @@ public function getInserts(): array
return $this->queuedInserts;
}

/**
* {@inheritDoc}
*/
public function executeInserts()
public function executeInserts(): void
{
if (! $this->queuedInserts) {
return;
Expand Down
8 changes: 1 addition & 7 deletions lib/Doctrine/ORM/Persisters/Entity/EntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,8 @@ public function addInsert(object $entity): void;
* Executes all queued entity insertions.
*
* If no inserts are queued, invoking this method is a NOOP.
*
* @psalm-return void|list<array{
* generatedId: int,
* entity: object
* }> Returning an array of generated post-insert IDs is deprecated, implementations
* should call UnitOfWork::assignPostInsertId() and return void.
*/
public function executeInserts();
public function executeInserts(): void;

/**
* Updates a managed entity. The entity is updated according to its current changeset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,7 @@ public function getOwningTable(string $fieldName): string
return $tableName;
}

/**
* {@inheritDoc}
*/
public function executeInserts()
public function executeInserts(): void
{
if (! $this->queuedInserts) {
return;
Expand Down
15 changes: 1 addition & 14 deletions lib/Doctrine/ORM/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,20 +1041,7 @@ private function executeInserts(): void

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

$postInsertIds = $persister->executeInserts();

if (is_array($postInsertIds)) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/10743/',
'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.',
);

// Persister returned post-insert IDs
foreach ($postInsertIds as $postInsertId) {
$this->assignPostInsertId($postInsertId['entity'], $postInsertId['generatedId']);
}
}
$persister->executeInserts();

if (! isset($this->entityIdentifiers[$oid])) {
//entity was not added to identity map because some identifiers are foreign keys to new entities.
Expand Down
7 changes: 4 additions & 3 deletions tests/Doctrine/Tests/Mocks/EntityPersisterMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ public function addInsert(object $entity): void
];
}

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

public function setMockIdGeneratorType(int $genType): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ public function testInvokeExecuteInserts(): void
$persister = $this->createPersisterDefault();

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

self::assertSame(['id' => 1], $persister->executeInserts());
$persister->executeInserts();
}

public function testInvokeUpdate(): void
Expand Down

0 comments on commit 4799c41

Please sign in to comment.