Skip to content

Commit

Permalink
[BUGFIX] Dont assign random flux parent to translations
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pixelbrackets authored and NamelessCoder committed Jan 4, 2017
1 parent 37228d1 commit f356851
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 7 additions & 1 deletion Classes/Service/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -309,7 +310,12 @@ protected function initializeRecordByNewAndOldAndLanguageUids(
) {
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.
Expand Down
16 changes: 12 additions & 4 deletions Tests/Unit/Service/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,10 @@ public function testupdateRecordInDataMapWithVersionedRecord()
* @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)
{
if (GeneralUtility::compat_version('8.4.0')) {
$this->markTestSkipped(
Expand All @@ -269,7 +270,12 @@ public function testInitializeRecordByNewAndOldAndLanguageUids($newUid, $oldUid,
$recordService->expects($this->any())->method('get')->willReturn(null);
$mock->injectWorkspacesAwareRecordService($recordService);
$dataHandler = $this->getMockBuilder('TYPO3\\CMS\\Core\\DataHandling\\DataHandler')->setMethods(array('resorting'))->getMock();
$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('updateRecordInDataMap');
Expand All @@ -296,8 +302,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)
);
}

Expand Down

0 comments on commit f356851

Please sign in to comment.