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 FluidTYPO3#1176
  • Loading branch information
pixelbrackets committed Oct 13, 2016
1 parent bbf8154 commit 3d27701
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 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 @@ -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.
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 @@ -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');
Expand All @@ -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),
);
}

Expand Down

0 comments on commit 3d27701

Please sign in to comment.