Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ private function computeSingleEntityChangeSet($entity): void
$this->computeScheduleInsertsChangeSets();

if ($class->isReadOnly) {
$this->markReadOnly($entity);

return;
}

Expand Down Expand Up @@ -897,11 +899,6 @@ public function computeChangeSets()
foreach ($this->identityMap as $className => $entities) {
$class = $this->em->getClassMetadata($className);

// Skip class if instances are read-only
if ($class->isReadOnly) {
continue;
}

// If change tracking is explicit or happens through notification, then only compute
// changes on entities of that type that are explicitly marked for synchronization.
switch (true) {
Expand All @@ -923,6 +920,13 @@ public function computeChangeSets()
continue;
}

// Skip class if instances are read-only
if ($class->isReadOnly) {
$this->markReadOnly($entity);

continue;
}

// Only MANAGED entities that are NOT SCHEDULED FOR INSERTION OR DELETION are processed here.
$oid = spl_object_id($entity);

Expand Down
25 changes: 24 additions & 1 deletion tests/Tests/ORM/UnitOfWorkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1009,9 +1009,32 @@ public function rollBack(): bool
self::assertSame('Commit failed', $e->getPrevious()->getMessage());
}
}

public function testIsReadOnlyReliability(): void
{
$entity = new ReadOnlyEntity();

$this->_unitOfWork->persist($entity);
$this->_unitOfWork->computeChangeSets();

self::assertTrue($this->_unitOfWork->isReadOnly($entity));
}
}

/** @Entity */

/** @Entity(readOnly=true) */
class ReadOnlyEntity
{
/**
* @var int
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;
}

/** @Entity */
class NotifyChangedEntity implements NotifyPropertyChanged
{
/** @phpstan-var list<PropertyChangedListener> */
Expand Down
Loading