[BUGFIX] Getting the identifier for a lazy object fails 96/22696/6
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:25:07 +0000 (10:25 +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/22696
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Daan Wissing
Tested-by: Daan Wissing
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 cdc4302..74daf12 100644 (file)
@@ -205,11 +205,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 443d59a..107f3eb 100644 (file)
@@ -126,7 +126,7 @@ class PersistenceManager implements \TYPO3\CMS\Extbase\Persistence\PersistenceMa
         * @api
         */
        public function getIdentifierByObject($object) {
-               return $this->persistenceSession->getIdentifierByObject($object);
+               return $this->backend->getIdentifierByObject($object);
        }
 
        /**
index 93e0b9f..c2a2f21 100644 (file)
@@ -78,16 +78,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('persistenceSession', $mockSession);
+               $manager->_set('backend', $mockBackend);
+
 
                $this->assertEquals($manager->getIdentifierByObject($object), $fakeUuid);
        }