Commit 57d452db authored by Tymoteusz Motylewski's avatar Tymoteusz Motylewski
Browse files

[BUGFIX] Make checks in localize compatible with new Localization Wizard

The checks for language and localization-parent in DataHandler's localize
method are made compatible with the options which the new localization wizard
allows; more specifically allowing translations from other languages than the
default language (but still pointing to a default record).

This makes it also possible to make correct use of the localize command
instead of the copy command now when translating from other languages than
the default language.

Resolves: #78059
Releases: master, 7.6
Change-Id: I01647d759a745abbbf0fa34a16b20f3085ef91ea
Reviewed-on: https://review.typo3.org/50022


Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Tymoteusz Motylewski's avatarTymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski's avatarTymoteusz Motylewski <t.motylewski@gmail.com>
parent e9f52844
......@@ -220,28 +220,9 @@ class LocalizationController
$currentUid = $params['uidList'][$i];
if ($params['action'] === static::ACTION_LOCALIZE) {
if ($srcLanguageId === 0) {
$cmd['tt_content'][$currentUid] = [
'localize' => $destLanguageId
];
} else {
$previousUid = $this->localizationRepository->getPreviousLocalizedRecordUid(
'tt_content',
$currentUid,
$pageId,
$srcLanguageId,
$destLanguageId
);
$cmd['tt_content'][$currentUid] = [
'copy' => [
'action' => 'paste',
'target' => -$previousUid,
'update' => [
'sys_language_uid' => $destLanguageId
]
]
];
}
$cmd['tt_content'][$currentUid] = [
'localize' => $destLanguageId
];
} else {
$previousUid = $this->localizationRepository->getPreviousLocalizedRecordUid(
'tt_content',
......
......@@ -126,19 +126,19 @@ class LocalizationControllerTest extends FunctionalTestCase
'pid' => 1,
'sys_language_uid' => 2,
'l18n_parent' => 1,
'header' => 'Test indhold 1 (copy 1)',
'header' => '[Translate to Deutsch:] Test indhold 1',
],
[
'pid' => 1,
'sys_language_uid' => 2,
'l18n_parent' => 2,
'header' => 'Test indhold 2 (copy 1)',
'header' => '[Translate to Deutsch:] Test indhold 2',
],
[
'pid' => 1,
'sys_language_uid' => 2,
'l18n_parent' => 3,
'header' => 'Test indhold 3 (copy 1)',
'header' => '[Translate to Deutsch:] Test indhold 3',
],
];
$queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tt_content');
......
......@@ -4524,16 +4524,28 @@ class DataHandler
return false;
}
if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0 && $table !== 'pages') {
if ($this->enableLogging) {
$this->newlog('Localization failed; Source record had another language than "Default" or "All" defined!', 1);
// Make sure that records which are translated from another language than the default language have a correct
// localization source set themselves, before translating them to another language.
if ((int)$row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] !== 0
&& $row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] > 0
&& $table !== 'pages') {
$localizationParentRecord = BackendUtility::getRecord(
$table,
$row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']]);
if ((int)$localizationParentRecord[$GLOBALS['TCA'][$table]['ctrl']['languageField']] !== 0) {
if ($this->enableLogging) {
$this->newlog('Localization failed; Source record contained a reference to an original record that is not a default record (which is strange)!', 1);
}
return false;
}
return false;
}
if ($row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] != 0 && $table !== 'pages') {
// Default language records must never have a localization parent as they are the origin of any translation.
if ((int)$row[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] !== 0
&& (int)$row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] === 0
&& $table !== 'pages') {
if ($this->enableLogging) {
$this->newlog('Localization failed; Source record contained a reference to an original default record (which is strange)!', 1);
$this->newlog('Localization failed; Source record contained a reference to an original default record but is a default record itself (which is strange)!', 1);
}
return false;
}
......@@ -4558,7 +4570,12 @@ class DataHandler
$excludeFields = [];
// Set override values:
$overrideValues[$GLOBALS['TCA'][$Ttable]['ctrl']['languageField']] = $langRec['uid'];
$overrideValues[$GLOBALS['TCA'][$Ttable]['ctrl']['transOrigPointerField']] = $uid;
// If the translated record is a default language record, set it's uid as localization parent of the new record.
// If translating from any other language, no override is needed; we just can copy the localization parent of
// the original record (which is pointing to the correspondent default language record) to the new record.
if ($row[$GLOBALS['TCA'][$table]['ctrl']['languageField']] === 0 || $table === 'pages') {
$overrideValues[$GLOBALS['TCA'][$Ttable]['ctrl']['transOrigPointerField']] = $uid;
}
// Copy the type (if defined in both tables) from the original record so that translation has same type as original record
if (isset($GLOBALS['TCA'][$table]['ctrl']['type']) && isset($GLOBALS['TCA'][$Ttable]['ctrl']['type'])) {
$overrideValues[$GLOBALS['TCA'][$Ttable]['ctrl']['type']] = $row[$GLOBALS['TCA'][$table]['ctrl']['type']];
......
......@@ -27,6 +27,7 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
const VALUE_ContentIdThird = 299;
const VALUE_ContentIdThirdLocalized = 300;
const VALUE_LanguageId = 1;
const VALUE_LanguageIdSecond = 2;
const TABLE_Page = 'pages';
const TABLE_Content = 'tt_content';
......@@ -116,6 +117,15 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
$this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdSecond, self::VALUE_LanguageId);
}
/**
* @test
* @see DataSet/Assertion/localizeContentFromNonDefaultLanguage.csv
*/
public function localizeContentFromNonDefaultLanguage()
{
$this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdThirdLocalized, self::VALUE_LanguageIdSecond);
}
/**
* @test
* @see DataSet/Assertion/changeContentRecordSorting.csv
......
......@@ -128,6 +128,21 @@ class ActionTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\A
->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', '[Translate to Dansk:] Regular Element #2'));
}
/**
* @test
* @see DataSet/localizeContentFromNonDefaultLanguage.csv
*/
public function localizeContentFromNonDefaultLanguage()
{
parent::localizeContentFromNonDefaultLanguage();
$this->assertAssertionDataSet('localizeContentFromNonDefaultLanguage');
$responseSections = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageIdSecond)->getResponseSections();
$this->assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #3'));
}
/**
* @test
* @see DataSet/Assertion/changeContentRecordSorting.csv
......
"tt_content",,,,,,,,,,,,,
,"uid","pid","sorting","deleted","sys_language_uid","l18n_parent","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","header"
,297,89,256,0,0,0,0,0,0,0,0,0,"Regular Element #1"
,298,89,512,0,0,0,0,0,0,0,0,0,"Regular Element #2"
,299,89,768,0,0,0,0,0,0,0,0,0,"Regular Element #3"
,300,89,1024,0,1,299,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
,301,89,1280,0,2,299,300,0,0,0,0,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #3"
\ No newline at end of file
......@@ -228,3 +228,6 @@ page {
[globalVar = GP:L = 1]
config.sys_language_uid = 1
[end]
[globalVar = GP:L = 2]
config.sys_language_uid = 2
[end]
\ No newline at end of file
......@@ -29,6 +29,7 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
const VALUE_ContentIdThird = 299;
const VALUE_ContentIdThirdLocalized = 300;
const VALUE_LanguageId = 1;
const VALUE_LanguageIdSecond = 2;
const VALUE_WorkspaceId = 1;
const TABLE_Page = 'pages';
......@@ -144,6 +145,15 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
$this->recordIds['localizedContentId'] = $localizedTableIds[self::TABLE_Content][self::VALUE_ContentIdSecond];
}
/**
* @see DataSet/Assertion/localizeContentRecord.csv
*/
public function localizeContentFromNonDefaultLanguage()
{
$localizedTableIds = $this->actionService->localizeRecord(self::TABLE_Content, self::VALUE_ContentIdThirdLocalized, self::VALUE_LanguageIdSecond);
$this->recordIds['localizedContentId'] = $localizedTableIds[self::TABLE_Content][self::VALUE_ContentIdThirdLocalized];
}
/**
* @see DataSet/Assertion/changeContentRecordSorting.csv
*/
......
......@@ -144,6 +144,21 @@ class ActionTest extends \TYPO3\CMS\Workspaces\Tests\Functional\DataHandling\Reg
->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', '[Translate to Dansk:] Regular Element #2'));
}
/**
* @test
* @see DataSet/localizeContentFromNonDefaultLanguage.csv
*/
public function localizeContentFromNonDefaultLanguage()
{
parent::localizeContentFromNonDefaultLanguage();
$this->assertAssertionDataSet('localizeContentFromNonDefaultLanguage');
$responseSections = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageIdSecond, self::VALUE_BackendUserId, self::VALUE_WorkspaceId)->getResponseSections();
$this->assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #3'));
}
/**
* @test
* @see DataSet/Assertion/changeContentRecordSorting.csv
......
"tt_content",,,,,,,,,,,,,
,"uid","pid","sorting","deleted","sys_language_uid","l18n_parent","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","header"
,296,88,256,0,0,0,0,0,0,0,0,0,"Regular Element #0"
,297,89,256,0,0,0,0,0,0,0,0,0,"Regular Element #1"
,298,89,512,0,0,0,0,0,0,0,0,0,"Regular Element #2"
,299,89,768,0,0,0,0,0,0,0,0,0,"Regular Element #3"
,300,89,1024,0,1,299,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
,301,-1,512,0,0,0,298,2,2,0,298,0,"Regular Element #2"
,302,89,1280,0,2,299,300,1,1,0,0,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #3"
,303,-1,1280,0,2,299,300,1,-1,0,302,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #3"
......@@ -163,6 +163,21 @@ class ActionTest extends \TYPO3\CMS\Workspaces\Tests\Functional\DataHandling\Reg
->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', '[Translate to Dansk:] Regular Element #2'));
}
/**
* @test
* @see DataSet/localizeContentFromNonDefaultLanguage.csv
*/
public function localizeContentFromNonDefaultLanguage()
{
parent::localizeContentFromNonDefaultLanguage();
$this->actionService->publishRecord(self::TABLE_Content, $this->recordIds['localizedContentId']);
$this->assertAssertionDataSet('localizeContentFromNonDefaultLanguage');
$responseSections = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageIdSecond)->getResponseSections();
$this->assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #3'));
}
/**
* @test
* @see DataSet/Assertion/changeContentRecordSorting.csv
......
"tt_content",,,,,,,,,,,,,
,"uid","pid","sorting","deleted","sys_language_uid","l18n_parent","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","header"
,296,88,256,0,0,0,0,0,0,0,0,0,"Regular Element #0"
,297,89,256,0,0,0,0,0,0,0,0,0,"Regular Element #1"
,298,89,512,0,0,0,0,0,0,0,0,0,"Regular Element #2"
,299,89,768,0,0,0,0,0,0,0,0,0,"Regular Element #3"
,300,89,1024,0,1,299,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
,301,-1,512,0,0,0,298,2,2,0,298,0,"Regular Element #2"
,302,89,1280,0,2,299,300,0,0,0,0,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #3"
......@@ -152,6 +152,21 @@ class ActionTest extends \TYPO3\CMS\Workspaces\Tests\Functional\DataHandling\Reg
->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', '[Translate to Dansk:] Regular Element #2'));
}
/**
* @test
* @see DataSet/localizeContentFromNonDefaultLanguage.csv
*/
public function localizeContentFromNonDefaultLanguage()
{
parent::localizeContentFromNonDefaultLanguage();
$this->actionService->publishWorkspace(self::VALUE_WorkspaceId);
$this->assertAssertionDataSet('localizeContentFromNonDefaultLanguage');
$responseSections = $this->getFrontendResponse(self::VALUE_PageId, self::VALUE_LanguageIdSecond)->getResponseSections();
$this->assertThat($responseSections, $this->getRequestSectionHasRecordConstraint()
->setTable(self::TABLE_Content)->setField('header')->setValues('Regular Element #1', '[Translate to Deutsch:] [Translate to Dansk:] Regular Element #3'));
}
/**
* @test
* @see DataSet/Assertion/changeContentRecordSorting.csv
......
"tt_content",,,,,,,,,,,,,
,"uid","pid","sorting","deleted","sys_language_uid","l18n_parent","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","header"
,296,88,256,0,0,0,0,0,0,0,0,0,"Regular Element #0"
,297,89,256,0,0,0,0,0,0,0,0,0,"Regular Element #1"
,298,89,512,0,0,0,0,0,0,0,0,0,"Regular Element #2"
,299,89,768,0,0,0,0,0,0,0,0,0,"Regular Element #3"
,300,89,1024,0,1,299,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
,301,-1,512,0,0,0,298,2,2,0,298,0,"Regular Element #2"
,302,89,1280,0,2,299,300,0,0,0,0,0,"[Translate to Deutsch:] [Translate to Dansk:] Regular Element #3"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment