Skip to content

Commit

Permalink
chore: Update doctrine/orm to 2.16.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed Sep 7, 2023
1 parent 1945f9a commit b57d7e6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 30 deletions.
2 changes: 1 addition & 1 deletion UPGRADE-5.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This changelog references changes done in Shopware 5.7 patch versions.
* Changed the test kernel, so PHPUnit tests do no longer ignore PHP warnings and notices and are failing instead

* Updated `cocur/slugify` to version 4.4.0
* Updated `doctrine/orm` to version 2.15.3
* Updated `doctrine/orm` to version 2.16.2
* Updated `google/cloud-storage` to version 1.33.1
* Updated `guzzlehttp/guzzle` to version 7.8.0
* Updated `guzzlehttp/psr7` to version 2.6.1
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"doctrine/dbal": "2.13.9",
"doctrine/event-manager": "1.2.0",
"doctrine/inflector": "2.0.4",
"doctrine/orm": "2.15.3",
"doctrine/orm": "2.16.2",
"doctrine/persistence": "3.2.0",
"elasticsearch/elasticsearch": "^7",
"fig/link-util": "1.1.2",
Expand Down
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class BasicEntityPersister implements EntityPersister
*
* @var IdentifierFlattener
*/
private $identifierFlattener;
protected $identifierFlattener;

/** @var CachedPersisterContext */
protected $currentPersisterContext;
Expand Down Expand Up @@ -256,17 +256,17 @@ public function getInserts()
public function executeInserts()
{
if (! $this->queuedInserts) {
return [];
return;
}

$postInsertIds = [];
$uow = $this->em->getUnitOfWork();
$idGenerator = $this->class->idGenerator;
$isPostInsertId = $idGenerator->isPostInsertGenerator();

$stmt = $this->conn->prepare($this->getInsertSQL());
$tableName = $this->class->getTableName();

foreach ($this->queuedInserts as $entity) {
foreach ($this->queuedInserts as $key => $entity) {
$insertData = $this->prepareInsertData($entity);

if (isset($insertData[$tableName])) {
Expand All @@ -280,24 +280,27 @@ public function executeInserts()
$stmt->executeStatement();

if ($isPostInsertId) {
$generatedId = $idGenerator->generateId($this->em, $entity);
$id = [$this->class->identifier[0] => $generatedId];
$postInsertIds[] = [
'generatedId' => $generatedId,
'entity' => $entity,
];
$generatedId = $idGenerator->generateId($this->em, $entity);
$id = [$this->class->identifier[0] => $generatedId];

$uow->assignPostInsertId($entity, $generatedId);
} else {
$id = $this->class->getIdentifierValues($entity);
}

if ($this->class->requiresFetchAfterChange) {
$this->assignDefaultVersionAndUpsertableValues($entity, $id);
}
}

$this->queuedInserts = [];

return $postInsertIds;
// Unset this queued insert, so that the prepareUpdateData() method knows right away
// (for the next entity already) that the current entity has been written to the database
// and no extra updates need to be scheduled to refer to it.
//
// In \Doctrine\ORM\UnitOfWork::executeInserts(), the UoW already removed entities
// from its own list (\Doctrine\ORM\UnitOfWork::$entityInsertions) right after they
// were given to our addInsert() method.
unset($this->queuedInserts[$key]);
}
}

/**
Expand Down Expand Up @@ -376,7 +379,7 @@ protected function fetchVersionAndNotUpsertableValues($versionedClass, array $id
* @return int[]|null[]|string[]
* @psalm-return list<int|string|null>
*/
private function extractIdentifierTypes(array $id, ClassMetadata $versionedClass): array
final protected function extractIdentifierTypes(array $id, ClassMetadata $versionedClass): array
{
$types = [];

Expand Down Expand Up @@ -675,10 +678,30 @@ protected function prepareUpdateData($entity, bool $isInsert = false)
if ($newVal !== null) {
$oid = spl_object_id($newVal);

if (isset($this->queuedInserts[$oid]) || $uow->isScheduledForInsert($newVal)) {
// The associated entity $newVal is not yet persisted, so we must
// set $newVal = null, in order to insert a null value and schedule an
// extra update on the UnitOfWork.
// If the associated entity $newVal is not yet persisted and/or does not yet have
// an ID assigned, we must set $newVal = null. This will insert a null value and
// schedule an extra update on the UnitOfWork.
//
// This gives us extra time to a) possibly obtain a database-generated identifier
// value for $newVal, and b) insert $newVal into the database before the foreign
// key reference is being made.
//
// When looking at $this->queuedInserts and $uow->isScheduledForInsert, be aware
// of the implementation details that our own executeInserts() method will remove
// entities from the former as soon as the insert statement has been executed and
// a post-insert ID has been assigned (if necessary), and that the UnitOfWork has
// already removed entities from its own list at the time they were passed to our
// addInsert() method.
//
// Then, there is one extra exception we can make: An entity that references back to itself
// _and_ uses an application-provided ID (the "NONE" generator strategy) also does not
// need the extra update, although it is still in the list of insertions itself.
// This looks like a minor optimization at first, but is the capstone for being able to
// use non-NULLable, self-referencing associations in applications that provide IDs (like UUIDs).
if (
(isset($this->queuedInserts[$oid]) || $uow->isScheduledForInsert($newVal))
&& ! ($newVal === $entity && $this->class->isIdentifierNatural())
) {
$uow->scheduleExtraUpdate($entity, [$field => [null, $newVal]]);

$newVal = null;
Expand Down

0 comments on commit b57d7e6

Please sign in to comment.