[BUGFIX] Getting the identifier for a lazy object fails 59/24859/2
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Tue, 30 Jul 2013 08:52:43 +0000 (10:52 +0200)
committerMarc Bastian Heinrichs <typo3@mbh-software.de>
Thu, 17 Oct 2013 08:42:50 +0000 (10:42 +0200)
Using PersistenceManager::getIdentifierByObject doesn't work for lazy
object since version 6.1, because the function uses the session object
directly. Before the Backend::getIdentifierByObject was used, which
handles lazy objects right.
Solution: use the Backend again.

Resolves: #50548
Releases: 6.2, 6.1
Change-Id: I8381a968f730918b96b6764d3f62bfc5f58509ee
Reviewed-on: https://review.typo3.org/24859
Reviewed-by: Marc Bastian Heinrichs
Tested-by: Marc Bastian Heinrichs
typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php
typo3/sysext/extbase/Classes/Persistence/Generic/PersistenceManager.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/PersistenceManagerTest.php

index 41f907d..acee56e 100644 (file)
@@ -246,11 +246,7 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                                return NULL;
                        }
                }
-               if ($this->session->hasObject($object)) {
-                       return $this->session->getIdentifierByObject($object);
-               } else {
-                       return NULL;
-               }
+               return $this->session->getIdentifierByObject($object);
        }
 
        /**
index ab19fc4..cdcc053 100644 (file)
@@ -153,7 +153,7 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
         * @api
         */
        public function getIdentifierByObject($object) {
-               return $this->persistenceSession->getIdentifierByObject($object);
+               return $this->backend->getIdentifierByObject($object);
        }
 
        /**
@@ -357,4 +357,4 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
 
 }
 
-?>
\ No newline at end of file
+?>
index b55e1e7..8bbb480 100644 (file)
@@ -72,15 +72,17 @@ class PersistenceManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
        /**
         * @test
         */
-       public function getIdentifierByObjectReturnsIdentifierFromSession() {
+       public function getIdentifierByObjectReturnsIdentifierFromBackend() {
                $fakeUuid = 'fakeUuid';
                $object = new \stdClass();
 
-               $mockSession = $this->getMock('TYPO3\CMS\Extbase\Persistence\Generic\Session');
-               $mockSession->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
+               $mockBackend = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\BackendInterface');
+               $mockBackend->expects($this->once())->method('getIdentifierByObject')->with($object)->will($this->returnValue($fakeUuid));
+
+               /** @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $manager */
+               $manager = $this->getAccessibleMock('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager', array('dummy'));
+               $manager->_set('backend', $mockBackend);
 
-               $manager = new \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager();
-               $manager->injectPersistenceSession($mockSession);
 
                $this->assertEquals($manager->getIdentifierByObject($object), $fakeUuid);
        }
@@ -357,4 +359,4 @@ class PersistenceManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
        }
 
 }
-?>
\ No newline at end of file
+?>