Skip to content

Commit

Permalink
Revert "[BUGFIX] Update localized records when publishing default tra…
Browse files Browse the repository at this point in the history
…nslation"

This reverts commit a71f5ed.

Reason for revert: the tests are broken. Patch gets repushed.

Change-Id: I6df8391429d65f7217e93829b820e11fff43ec88
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66584
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
maddy2101 committed Nov 12, 2020
1 parent a71f5ed commit 6d66da9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 108 deletions.
97 changes: 5 additions & 92 deletions typo3/sysext/workspaces/Classes/Hook/DataHandlerHook.php
Expand Up @@ -611,14 +611,13 @@ protected function version_swap($table, $id, $swapWith, bool $swapIntoWS, DataHa
);
return;
}
$workspaceId = (int)$swapVersion['t3ver_wsid'];
if (!$dataHandler->BE_USER->workspacePublishAccess($workspaceId)) {
$dataHandler->newlog('User could not publish records from workspace #' . $workspaceId, SystemLogErrorClassification::USER_ERROR);
if (!$dataHandler->BE_USER->workspacePublishAccess($swapVersion['t3ver_wsid'])) {
$dataHandler->newlog('User could not publish records from workspace #' . $swapVersion['t3ver_wsid'], SystemLogErrorClassification::USER_ERROR);
return;
}
$wsAccess = $dataHandler->BE_USER->checkWorkspace($workspaceId);
if (!($workspaceId <= 0 || !($wsAccess['publish_access'] & 1) || (int)$swapVersion['t3ver_stage'] === -10)) {
$dataHandler->newlog('Records in workspace #' . $workspaceId . ' can only be published when in "Publish" stage.', SystemLogErrorClassification::USER_ERROR);
$wsAccess = $dataHandler->BE_USER->checkWorkspace($swapVersion['t3ver_wsid']);
if (!($swapVersion['t3ver_wsid'] <= 0 || !($wsAccess['publish_access'] & 1) || (int)$swapVersion['t3ver_stage'] === -10)) {
$dataHandler->newlog('Records in workspace #' . $swapVersion['t3ver_wsid'] . ' can only be published when in "Publish" stage.', SystemLogErrorClassification::USER_ERROR);
return;
}
if (!($dataHandler->doesRecordExist($table, $swapWith, Permission::PAGE_SHOW) && $dataHandler->checkRecordUpdateAccess($table, $swapWith))) {
Expand Down Expand Up @@ -775,8 +774,6 @@ protected function version_swap($table, $id, $swapWith, bool $swapIntoWS, DataHa
if (!empty($sqlErrors)) {
$dataHandler->newlog('During Swapping: SQL errors happened: ' . implode('; ', $sqlErrors), SystemLogErrorClassification::SYSTEM_ERROR);
} else {
// Update localized elements to use the live l10n_parent now
$this->updateL10nOverlayRecordsOnPublish($table, $id, $swapWith, $workspaceId, $dataHandler);
// Register swapped ids for later remapping:
$this->remappedIds[$table][$id] = $swapWith;
$this->remappedIds[$table][$swapWith] = $id;
Expand Down Expand Up @@ -871,90 +868,6 @@ protected function version_swap($table, $id, $swapWith, bool $swapIntoWS, DataHa
}
}

/**
* If an editor is doing "partial" publishing, the translated children need to be "linked" to the now pointed
* live record, as if the versioned record (which is deleted) would have never existed.
*
* This is related to the l10n_source and l10n_parent fields.
*
* This needs to happen before the hook calls DataHandler->deleteEl() otherwise the children get deleted as well.
*
* @param string $table the database table of the published record
* @param int $liveId the live version / online version of the record that was just published
* @param int $previouslyUsedVersionId the versioned record ID (wsid>0) which is about to be deleted
* @param int $workspaceId the workspace ID
* @param DataHandler $dataHandler
*/
protected function updateL10nOverlayRecordsOnPublish(string $table, int $liveId, int $previouslyUsedVersionId, int $workspaceId, DataHandler $dataHandler): void
{
if (!BackendUtility::isTableLocalizable($table)) {
return;
}
if (!BackendUtility::isTableWorkspaceEnabled($table)) {
return;
}
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
$queryBuilder = $connection->createQueryBuilder();
$queryBuilder->getRestrictions()->removeAll();

$l10nParentFieldName = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
$constraints = $queryBuilder->expr()->eq(
$l10nParentFieldName,
$queryBuilder->createNamedParameter($previouslyUsedVersionId, \PDO::PARAM_INT)
);
$translationSourceFieldName = $GLOBALS['TCA'][$table]['ctrl']['translationSource'] ?? null;
if ($translationSourceFieldName) {
$constraints = $queryBuilder->expr()->orX(
$constraints,
$queryBuilder->expr()->eq(
$translationSourceFieldName,
$queryBuilder->createNamedParameter($previouslyUsedVersionId, \PDO::PARAM_INT)
)
);
}

$queryBuilder
->select('uid', $l10nParentFieldName)
->from($table)
->where(
$constraints,
$queryBuilder->expr()->eq(
't3ver_wsid',
$queryBuilder->createNamedParameter($workspaceId, \PDO::PARAM_INT)
)
);

if ($translationSourceFieldName) {
$queryBuilder->addSelect($translationSourceFieldName);
}

$statement = $queryBuilder->execute();
while ($record = $statement->fetch()) {
$updateFields = [];
$dataTypes = [\PDO::PARAM_INT];
if ((int)$record[$l10nParentFieldName] === $previouslyUsedVersionId) {
$updateFields[$l10nParentFieldName] = $liveId;
$dataTypes[] = \PDO::PARAM_INT;
}
if ($translationSourceFieldName && (int)$record[$translationSourceFieldName] === $previouslyUsedVersionId) {
$updateFields[$translationSourceFieldName] = $liveId;
$dataTypes[] = \PDO::PARAM_INT;
}

if (empty($updateFields)) {
continue;
}

$connection->update(
$table,
$updateFields,
['uid' => (int)$record['uid']],
$dataTypes
);
$dataHandler->updateRefIndex($table, $record['uid']);
}
}

/**
* Processes fields of a record for the publishing/swapping process.
* Basically this takes care of IRRE (type "inline") child references.
Expand Down
Expand Up @@ -11,14 +11,14 @@
,311,90,512,0,1,0,310,310,0,0,0,0,0,"[Translate to Dansk:] Regular Element #10"
,312,90,768,0,2,0,311,311,0,0,0,0,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #10"
,320,89,512,0,0,0,0,298,2,2,0,298,0,"Regular Element #2"
,323,89,384,0,1,297,297,301,1,4,0,301,0,"[Translate to Dansk:] Regular Element #1"
,323,89,384,0,1,321,297,301,1,4,0,301,0,"[Translate to Dansk:] Regular Element #1"
,324,89,576,0,1,297,0,0,1,3,0,0,301,"[MOVE-TO PLACEHOLDER for #301, WS#1]"
,325,89,448,0,2,297,301,302,1,4,0,302,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1"
,325,89,448,0,2,321,301,302,1,4,0,302,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1"
,326,89,544,0,2,297,0,0,1,3,0,0,302,"[MOVE-TO PLACEHOLDER for #302, WS#1]"
"sys_refindex",,,,,,,,,,,,,,
,"hash","tablename","recuid","field","sorting","deleted","workspace","ref_table","ref_uid",,,,,
,"25426f92d44dd2ccf416108462b446e3","sys_workspace",1,"custom_stages",0,0,0,"sys_workspace_stage",1,,,,,
,"01a3ce8c4e3b2bb1aa439dc29081f996","sys_workspace_stage",1,"responsible_persons",0,0,0,"be_users",3,,,,,
,"1b70a8e25c22645f7a49a79f57f3cf3f","sys_category",31,"parent",0,0,0,"sys_category",28,,,,,
,"cfe2297ddc6d88ee467f4104f50aba25","tt_content",323,"l18n_parent",0,0,1,"tt_content",297,,,,,
,"a254b2d44709add64b50bba7921b1e90","tt_content",325,"l18n_parent",0,0,1,"tt_content",297,,,,,
,"cd92ab3ab5798dc139f98107e7c28cb7","tt_content",323,"l18n_parent",0,0,1,"tt_content",321,,,,,
,"1c8013278ae997181374e3c76322e114","tt_content",325,"l18n_parent",0,0,1,"tt_content",321,,,,,
Expand Up @@ -11,14 +11,14 @@
,311,90,512,0,1,0,310,310,0,0,0,0,0,"[Translate to Dansk:] Regular Element #10"
,312,90,768,0,2,0,311,311,0,0,0,0,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #10"
,320,89,512,0,0,0,0,298,2,2,0,298,0,"Regular Element #2"
,323,89,384,0,1,297,297,301,1,4,0,301,0,"[Translate to Dansk:] Regular Element #1"
,323,89,384,0,1,321,297,301,1,4,0,301,0,"[Translate to Dansk:] Regular Element #1"
,324,89,416,0,1,297,0,0,1,3,0,0,301,"[MOVE-TO PLACEHOLDER for #301, WS#1]"
,325,89,448,0,2,297,301,302,1,4,0,302,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1"
,325,89,448,0,2,321,301,302,1,4,0,302,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1"
,326,89,480,0,2,297,0,0,1,3,0,0,302,"[MOVE-TO PLACEHOLDER for #302, WS#1]"
"sys_refindex",,,,,,,,,,,,,,
,"hash","tablename","recuid","field","sorting","deleted","workspace","ref_table","ref_uid",,,,,
,"25426f92d44dd2ccf416108462b446e3","sys_workspace",1,"custom_stages",0,0,0,"sys_workspace_stage",1,,,,,
,"01a3ce8c4e3b2bb1aa439dc29081f996","sys_workspace_stage",1,"responsible_persons",0,0,0,"be_users",3,,,,,
,"1b70a8e25c22645f7a49a79f57f3cf3f","sys_category",31,"parent",0,0,0,"sys_category",28,,,,,
,"cfe2297ddc6d88ee467f4104f50aba25","tt_content",323,"l18n_parent",0,0,1,"tt_content",297,,,,,
,"a254b2d44709add64b50bba7921b1e90","tt_content",325,"l18n_parent",0,0,1,"tt_content",297,,,,,
,"cd92ab3ab5798dc139f98107e7c28cb7","tt_content",323,"l18n_parent",0,0,1,"tt_content",321,,,,,
,"1c8013278ae997181374e3c76322e114","tt_content",325,"l18n_parent",0,0,1,"tt_content",321,,,,,
Expand Up @@ -19,9 +19,9 @@
,311,90,512,0,1,0,310,310,0,0,0,0,0,"[Translate to Dansk:] Regular Element #10"
,312,90,768,0,2,0,311,311,0,0,0,0,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #10"
,320,89,512,0,0,0,0,298,2,2,0,298,0,"Regular Element #2"
,323,89,384,0,1,297,297,301,1,4,0,301,0,"[Translate to Dansk:] Regular Element #1"
,323,89,384,0,1,321,297,301,1,4,0,301,0,"[Translate to Dansk:] Regular Element #1"
,324,89,576,0,1,297,0,0,1,3,0,0,301,"[MOVE-TO PLACEHOLDER for #301, WS#1]"
,325,89,448,0,2,297,301,302,1,4,0,302,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1"
,325,89,448,0,2,321,301,302,1,4,0,302,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1"
,326,89,544,0,2,297,0,0,1,3,0,0,302,"[MOVE-TO PLACEHOLDER for #302, WS#1]"
,327,91,256,0,0,0,0,299,1,1,0,0,0,"Regular Element #3"
,328,91,256,0,0,0,0,299,1,-1,0,327,0,"Regular Element #3"
Expand All @@ -40,8 +40,8 @@
,"25426f92d44dd2ccf416108462b446e3","sys_workspace",1,"custom_stages",0,0,0,"sys_workspace_stage",1,,,,,
,"01a3ce8c4e3b2bb1aa439dc29081f996","sys_workspace_stage",1,"responsible_persons",0,0,0,"be_users",3,,,,,
,"1b70a8e25c22645f7a49a79f57f3cf3f","sys_category",31,"parent",0,0,0,"sys_category",28,,,,,
,"cfe2297ddc6d88ee467f4104f50aba25","tt_content",323,"l18n_parent",0,0,1,"tt_content",297,,,,,
,"a254b2d44709add64b50bba7921b1e90","tt_content",325,"l18n_parent",0,0,1,"tt_content",297,,,,,
,"cd92ab3ab5798dc139f98107e7c28cb7","tt_content",323,"l18n_parent",0,0,1,"tt_content",321,,,,,
,"1c8013278ae997181374e3c76322e114","tt_content",325,"l18n_parent",0,0,1,"tt_content",321,,,,,
,"893ed65ba064539a74c6c86b2dd3a9ed","tt_content",330,"l18n_parent",0,0,1,"tt_content",327,,,,,
,"b3c908a26827758805d70fd387de5143","tt_content",334,"l18n_parent",0,0,1,"tt_content",331,,,,,
,"01a973226431a87669a5c5ebd9e2b351","tt_content",336,"l18n_parent",0,0,1,"tt_content",331,,,,,
Expand Up @@ -11,14 +11,14 @@
,311,90,512,0,1,0,310,310,0,0,0,0,0,"[Translate to Dansk:] Regular Element #10"
,312,90,768,0,2,0,311,311,0,0,0,0,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #10"
,320,89,512,0,0,0,0,298,2,2,0,298,0,"Regular Element #2"
,325,90,384,0,1,297,297,301,1,4,0,301,0,"[Translate to Dansk:] Regular Element #1"
,325,90,384,0,1,323,297,301,1,4,0,301,0,"[Translate to Dansk:] Regular Element #1"
,326,90,160,0,1,297,0,0,1,3,0,0,301,"[MOVE-TO PLACEHOLDER for #301, WS#1]"
,327,90,448,0,2,297,301,302,1,4,0,302,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1"
,327,90,448,0,2,323,301,302,1,4,0,302,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #1"
,328,90,144,0,2,297,0,0,1,3,0,0,302,"[MOVE-TO PLACEHOLDER for #302, WS#1]"
"sys_refindex",,,,,,,,,,,,,,
,"hash","tablename","recuid","field","sorting","deleted","workspace","ref_table","ref_uid",,,,,
,"25426f92d44dd2ccf416108462b446e3","sys_workspace",1,"custom_stages",0,0,0,"sys_workspace_stage",1,,,,,
,"01a3ce8c4e3b2bb1aa439dc29081f996","sys_workspace_stage",1,"responsible_persons",0,0,0,"be_users",3,,,,,
,"1b70a8e25c22645f7a49a79f57f3cf3f","sys_category",31,"parent",0,0,0,"sys_category",28,,,,,
,"a254b2d44709add64b50bba7921b1e90","tt_content",325,"l18n_parent",0,0,1,"tt_content",297,,,,,
,"e5de620fdfb11e57a69c7d6aca7a7f85","tt_content",327,"l18n_parent",0,0,1,"tt_content",297,,,,,
,"c258bb16afcf92d3ca8dd0af5ccb15db","tt_content",325,"l18n_parent",0,0,1,"tt_content",323,,,,,
,"8c7f3b6705c356900176c779bd77aff3","tt_content",327,"l18n_parent",0,0,1,"tt_content",323,,,,,

0 comments on commit 6d66da9

Please sign in to comment.