[BUGFIX] Make checks in localize compatible with new Localization Wizard 67/50467/4
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Sat, 29 Oct 2016 20:51:05 +0000 (22:51 +0200)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Mon, 31 Oct 2016 23:28:31 +0000 (00:28 +0100)
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/50467
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
14 files changed:
typo3/sysext/backend/Classes/Controller/Page/LocalizationController.php
typo3/sysext/backend/Tests/Functional/Controller/Page/LocalizationControllerTest.php
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Tests/Functional/DataHandling/Regular/AbstractActionTestCase.php
typo3/sysext/core/Tests/Functional/DataHandling/Regular/Modify/ActionTest.php
typo3/sysext/core/Tests/Functional/DataHandling/Regular/Modify/DataSet/localizeContentFromNonDefaultLanguage.csv [new file with mode: 0644]
typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.ts
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/AbstractActionTestCase.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Modify/ActionTest.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Modify/DataSet/localizeContentFromNonDefaultLanguage.csv [new file with mode: 0644]
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Publish/ActionTest.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Publish/DataSet/localizeContentFromNonDefaultLanguage.csv [new file with mode: 0644]
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/PublishAll/ActionTest.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/PublishAll/DataSet/localizeContentFromNonDefaultLanguage.csv [new file with mode: 0644]

index 551e2aa..6df2ffa 100644 (file)
@@ -217,28 +217,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',
index 50b4127..7346fc8 100644 (file)
@@ -107,19 +107,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',
             ],
         ];
         $results = $this->getDatabaseConnection()->exec_SELECTgetRows('pid, sys_language_uid, l18n_parent, header', 'tt_content', 'pid = 1 AND sys_language_uid = 2');
index 83e88e3..898056a 100644 (file)
@@ -4595,16 +4595,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;
         }
@@ -4629,7 +4641,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 ((int)$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']];
index 1eaf6f2..c7c20ce 100644 (file)
@@ -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';
@@ -118,6 +119,15 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
 
     /**
      * @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
      */
     public function changeContentSorting()
index c5b4708..fdd2549 100644 (file)
@@ -130,6 +130,21 @@ class ActionTest extends \TYPO3\CMS\Core\Tests\Functional\DataHandling\Regular\A
 
     /**
      * @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
      */
     public function changeContentSorting()
diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/Regular/Modify/DataSet/localizeContentFromNonDefaultLanguage.csv b/typo3/sysext/core/Tests/Functional/DataHandling/Regular/Modify/DataSet/localizeContentFromNonDefaultLanguage.csv
new file mode 100644 (file)
index 0000000..e1058c5
--- /dev/null
@@ -0,0 +1,7 @@
+"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
index 29c9559..848f712 100644 (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
index 8ad8a66..801d98e 100644 (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';
@@ -145,6 +146,15 @@ abstract class AbstractActionTestCase extends \TYPO3\CMS\Core\Tests\Functional\D
     }
 
     /**
+     * @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
      */
     public function changeContentSorting()
index 00e9514..c9ed478 100644 (file)
@@ -146,6 +146,21 @@ class ActionTest extends \TYPO3\CMS\Workspaces\Tests\Functional\DataHandling\Reg
 
     /**
      * @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
      */
     public function changeContentSorting()
diff --git a/typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Modify/DataSet/localizeContentFromNonDefaultLanguage.csv b/typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Modify/DataSet/localizeContentFromNonDefaultLanguage.csv
new file mode 100644 (file)
index 0000000..4b67fe2
--- /dev/null
@@ -0,0 +1,10 @@
+"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"
index 783d822..ba656ec 100644 (file)
@@ -165,6 +165,21 @@ class ActionTest extends \TYPO3\CMS\Workspaces\Tests\Functional\DataHandling\Reg
 
     /**
      * @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
      */
     public function changeContentSorting()
diff --git a/typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Publish/DataSet/localizeContentFromNonDefaultLanguage.csv b/typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Publish/DataSet/localizeContentFromNonDefaultLanguage.csv
new file mode 100644 (file)
index 0000000..253279a
--- /dev/null
@@ -0,0 +1,9 @@
+"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"
index 8e7dcd7..6a4b0c1 100644 (file)
@@ -154,6 +154,21 @@ class ActionTest extends \TYPO3\CMS\Workspaces\Tests\Functional\DataHandling\Reg
 
     /**
      * @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
      */
     public function changeContentSorting()
diff --git a/typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/PublishAll/DataSet/localizeContentFromNonDefaultLanguage.csv b/typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/PublishAll/DataSet/localizeContentFromNonDefaultLanguage.csv
new file mode 100644 (file)
index 0000000..253279a
--- /dev/null
@@ -0,0 +1,9 @@
+"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"