Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Prevented "Undefined index" notice when updating #484

Merged
merged 2 commits into from

4 participants

@jaspernbrouwer

While executing updates on an entity scheduled for update without a change-set, an "Undefined index" notice is raised.

This issue will occur when you manually call $em()->getUnitOfWork()->scheduleForUpdate() on an entity that hasn't changed. The entity will be included in UnitOfWork::$entityUpdates, but because there are no changes, its oid will not be included in UnitOfWork::$entityChangeSets.

I know I'm misusing scheduleForUpdate() a bit in this case, but the notice can easily be prevented with a !empty().

@jaspernbrouwer jaspernbrouwer Prevented "Undefined index" notice when updating
While executing updates on an entity scheduled for update without
a change-set, an "Undefined index" notice is raised.
0cfc37d
@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2086

@stof

can you add a testcase to prevent regressions ?

@jaspernbrouwer

I've added a test to UnitOfWorkTests.

Before the fix it outputs:

$ ./run-all.sh tests/Doctrine/Tests/ORM/UnitOfWorkTest.php 
RUNNING TESTS WITH CONFIG mysql.phpunit.xml
PHPUnit 3.7.8 by Sebastian Bergmann.

Configuration read from /Users/jappie/Development/doctrine-tests/mysql.phpunit.xml

......E

Time: 1 second, Memory: 10.50Mb

There was 1 error:

1) Doctrine\Tests\ORM\UnitOfWorkTest::testNoUndefinedIndexNoticeOnScheduleForUpdateWithoutChanges
Undefined index: 00000000381897d5000000005eec8ef2

/Users/jappie/Development/doctrine-tests/lib/Doctrine/ORM/UnitOfWork.php:985
/Users/jappie/Development/doctrine-tests/lib/Doctrine/ORM/UnitOfWork.php:319
/Users/jappie/Development/doctrine-tests/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php:228

FAILURES!
Tests: 7, Assertions: 35, Errors: 1.

After the fix it outputs:

$ ./run-all.sh tests/Doctrine/Tests/ORM/UnitOfWorkTest.php 
RUNNING TESTS WITH CONFIG mysql.phpunit.xml
PHPUnit 3.7.8 by Sebastian Bergmann.

Configuration read from /Users/jappie/Development/doctrine-tests/mysql.phpunit.xml

.......

Time: 1 second, Memory: 10.50Mb

OK (7 tests, 35 assertions)

I hope this will suffice.

@guilhermeblanco guilhermeblanco merged commit cd7ef6e into doctrine:master

1 check passed

Details default The Travis build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 17, 2012
  1. @jaspernbrouwer

    Prevented "Undefined index" notice when updating

    jaspernbrouwer authored
    While executing updates on an entity scheduled for update without
    a change-set, an "Undefined index" notice is raised.
Commits on Oct 19, 2012
  1. @jaspernbrouwer
This page is out of date. Refresh to see the latest.
View
2  lib/Doctrine/ORM/UnitOfWork.php
@@ -982,7 +982,7 @@ private function executeUpdates($class)
);
}
- if ($this->entityChangeSets[$oid]) {
+ if (!empty($this->entityChangeSets[$oid])) {
$persister->update($entity);
}
View
25 tests/Doctrine/Tests/ORM/UnitOfWorkTest.php
@@ -204,6 +204,29 @@ public function testGetEntityStateWithAssignedIdentity()
$this->assertEquals(UnitOfWork::STATE_DETACHED, $this->_unitOfWork->getEntityState($ph2));
$this->assertFalse($persister->isExistsCalled());
}
+
+ /**
+ * DDC-2086 [GH-484] Prevented "Undefined index" notice when updating.
+ */
+ public function testNoUndefinedIndexNoticeOnScheduleForUpdateWithoutChanges()
+ {
+ // Setup fake persister and id generator
+ $userPersister = new EntityPersisterMock($this->_emMock, $this->_emMock->getClassMetadata("Doctrine\Tests\Models\Forum\ForumUser"));
+ $userPersister->setMockIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_IDENTITY);
+ $this->_unitOfWork->setEntityPersister('Doctrine\Tests\Models\Forum\ForumUser', $userPersister);
+
+ // Create a test user
+ $user = new ForumUser();
+ $user->name = 'Jasper';
+ $this->_unitOfWork->persist($user);
+ $this->_unitOfWork->commit();
+
+ // Schedule user for update without changes
+ $this->_unitOfWork->scheduleForUpdate($user);
+
+ // This commit should not raise an E_NOTICE
+ $this->_unitOfWork->commit();
+ }
}
/**
@@ -309,4 +332,4 @@ class VersionedAssignedIdentifierEntity
* @Version @Column(type="integer")
*/
public $version;
-}
+}
Something went wrong with that request. Please try again.