From 36ed00f59cb518bbbd54b092af804c9071f25997 Mon Sep 17 00:00:00 2001 From: Dan Untenzu Date: Thu, 13 Oct 2016 17:05:12 +0200 Subject: [PATCH] [BUGFIX] Dont assign random flux parent to translations While translating records the newly created record currently always gets assigned a flux parent record even if the origin had no parent record. When searching for the nonexisting parent record the database will return a rather random record. So any translated record without a flux parent got this random record assigned. If this random record is deleted by an editor TYPO3 will check for any related records and delete these as well. This may result in the deletion of all previously translated records. Test for the existence of a parent record value in the origin record to prevent the wrong relation. Refs #1176 --- Classes/Service/ContentService.php | 3 ++- Tests/Unit/Service/ContentServiceTest.php | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Classes/Service/ContentService.php b/Classes/Service/ContentService.php index fb57aa49a..8bcdd97fe 100644 --- a/Classes/Service/ContentService.php +++ b/Classes/Service/ContentService.php @@ -13,6 +13,7 @@ use TYPO3\CMS\Core\DataHandling\DataHandler; use TYPO3\CMS\Core\SingletonInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\MathUtility; /** * Flux FlexForm integration Service @@ -290,7 +291,7 @@ public function initializeRecord($id, array &$row, DataHandler $tceMain) { protected function initializeRecordByNewAndOldAndLanguageUids($row, $newUid, $oldUid, $newLanguageUid, $languageFieldName, DataHandler $tceMain) { if (0 < $newUid && 0 < $oldUid && 0 < $newLanguageUid) { $oldRecord = $this->loadRecordFromDatabase($oldUid); - if ($oldRecord[$languageFieldName] !== $newLanguageUid && $oldRecord['pid'] === $row['pid']) { + if ($oldRecord[$languageFieldName] !== $newLanguageUid && $oldRecord['pid'] === $row['pid'] && MathUtility::canBeInterpretedAsInteger($oldRecord['tx_flux_parent']) && $oldRecord['tx_flux_parent'] > 0) { // look for the translated version of the parent record indicated // in this new, translated record. Below, we adjust the parent UID // so it has the UID of the translated parent if one exists. diff --git a/Tests/Unit/Service/ContentServiceTest.php b/Tests/Unit/Service/ContentServiceTest.php index 6ea0fb381..92d02182e 100644 --- a/Tests/Unit/Service/ContentServiceTest.php +++ b/Tests/Unit/Service/ContentServiceTest.php @@ -258,15 +258,21 @@ public function testUpdateMovePlaceholderWithPlaceholder() { * @param integer $newUid * @param integer $oldUid * @param integer $newLanguageUid + * @param integer $fluxParentUid * @param boolean $expectsInitialization */ - public function testInitializeRecordByNewAndOldAndLanguageUids($newUid, $oldUid, $newLanguageUid, $expectsInitialization) { + public function testInitializeRecordByNewAndOldAndLanguageUids($newUid, $oldUid, $newLanguageUid, $fluxParentUid, $expectsInitialization) { $mock = $this->getMock($this->createInstanceClassName(), array('loadRecordFromDatabase', 'updateRecordInDatabase')); $recordService = $this->getMock('FluidTYPO3\\Flux\\Service\\WorkspacesAwareRecordService', array('get')); $recordService->expects($this->any())->method('get')->willReturn(NULL); $mock->injectWorkspacesAwareRecordService($recordService); $dataHandler = $this->getMock('TYPO3\\CMS\\Core\\DataHandling\\DataHandler', array('resorting')); - $row = array('pid' => 1, 'uid' => 1, 'language' => 1); + $row = array( + 'uid' => 2, + 'pid' => 1, + 'tx_flux_parent' => $fluxParentUid, + 'language' => 1 + ); $mock->expects($this->once())->method('loadRecordFromDatabase')->will($this->returnValue($row)); if (TRUE === $expectsInitialization) { $mock->expects($this->once())->method('updateRecordInDatabase'); @@ -284,8 +290,10 @@ public function testInitializeRecordByNewAndOldAndLanguageUids($newUid, $oldUid, */ public function getLanguageInitializationTestValues() { return array( - array(1, 2, 2, TRUE), - array(1, 2, 1, FALSE) + array(3, 2, 1, 0, FALSE), + array(3, 2, 1, 1, FALSE), + array(3, 2, 2, 0, FALSE), + array(3, 2, 2, 1, TRUE), ); }