[BUGFIX] Enable some support for workspace previews
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Sat, 11 Jun 2011 22:42:37 +0000 (00:42 +0200)
committerJochen Rau <jochen.rau@typoplanet.de>
Fri, 3 Feb 2012 17:33:35 +0000 (12:33 -0500)
The Extbase DB Backend does a versioning overlay, however due to the
relevant table almost never being "pages" the relevant uid is saved
to "_ORIG_uid" instead of applying it to the row. This page writes
back "_ORIG_uid" in those cases, which seems to enable previews to a
usable level.

Thanks to Patrick Schriner.

Change-Id: I4de65643057da6d8cc2b0dc608ed69be4fc73ea7
Resolves: #26732
Relates: #7078

typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php
typo3/sysext/extbase/Tests/Unit/Persistence/Storage/Typo3DbBackendTest.php

index fe0cbaa..3b1782e 100644 (file)
@@ -992,6 +992,9 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                                $tableName = $source->getRight()->getSelectorName();
                        }
                        $this->pageSelectObject->versionOL($tableName, $row, TRUE);
+                       if ($this->pageSelectObject->versioningPreview && isset($row['_ORIG_uid'])) {
+                               $row['uid'] = $row['_ORIG_uid'];
+                       }
                        if($tableName == 'pages') {
                                $row = $this->pageSelectObject->getPageOverlay($row, $languageUid);
                        } elseif(isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '') {
index f69442a..9730a13 100644 (file)
@@ -151,5 +151,52 @@ class Tx_Extbase_Tests_Unit_Persistence_Storage_Typo3DbBackendTest extends Tx_Ex
                $this->assertSame($expecedSql, $sql);
        }
 
+       /**
+        * @test
+        */
+       public function doLanguageAndWorkspaceOverlayChangesUidIfInPreview() {
+               $comparisonRow = array(
+                       'uid' => '43',
+                       'pid' => '42',
+                       '_ORIG_pid' => '-1',
+                       '_ORIG_uid' => '43'
+               );
+
+               $row = array(
+                       'uid' => '42',
+                       'pid' => '42',
+               );
+
+               $workspaceVersion = array(
+                       'uid' => '43',
+                       'pid' => '-1',
+               );
+
+               $languageUid = 2;
+               $workspaceUid = 2;
+
+               $sourceMock = new Tx_Extbase_Persistence_QOM_Selector('tx_foo', 'Tx_Foo');
+
+               $pageSelectMock = $this->getMock('t3lib_pageSelect', array('movePlhOL', 'getWorkspaceVersionOfRecord'));
+               $pageSelectMock->versioningPreview = 1;
+
+               $pageSelectMock->expects($this->once())
+                       ->method('getWorkspaceVersionOfRecord')
+                       ->with($workspaceUid, 'tx_foo', '42')
+                       ->will($this->returnValue($workspaceVersion));
+
+               $mockTypo3DbBackend = $this->getAccessibleMock(
+                       'Tx_Extbase_Persistence_Storage_Typo3DbBackend',
+                       array('dummy'),
+                       array(), '', FALSE);
+
+
+               $mockTypo3DbBackend->_set('pageSelectObject', $pageSelectMock);
+
+               $this->assertSame(
+                       array($comparisonRow),
+                       $mockTypo3DbBackend->_call('doLanguageAndWorkspaceOverlay', $sourceMock, array($row), $languageUid, $workspaceUid)
+               );
+       }
 }
 ?>
\ No newline at end of file