[TASK] Upgrade migrated allowLanguageSynchronization field names 92/51692/8
authorOliver Hader <oliver@typo3.org>
Wed, 15 Feb 2017 08:33:45 +0000 (09:33 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 23 Feb 2017 08:09:31 +0000 (09:09 +0100)
In case TCA field values have not been migrated yet, but their TCA at the
same time already being updated to allowLanguageSynchronization, then the
field values are not considered in the upgrade wizard.

This change now includes manually updated TCA settings as well.

Resolves: #79950
Related: #79658
Releases: master
Change-Id: Id239c569e3731691a54015642e56a6450c09badc
Reviewed-on: https://review.typo3.org/51692
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Classes/Updates/RowUpdater/L10nModeUpdater.php
typo3/sysext/install/Tests/Unit/Updates/RowUpdater/L10nModeUpdaterTest.php [new file with mode: 0644]

index e01e9c2..d6817cc 100644 (file)
@@ -22,7 +22,6 @@ use TYPO3\CMS\Core\DataHandling\Localization\DataMapProcessor;
 use TYPO3\CMS\Core\DataHandling\Localization\State;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Versioning\VersionState;
-use TYPO3\CMS\Install\Service\LoadTcaService;
 use TYPO3\CMS\Lang\LanguageService;
 
 /**
@@ -32,16 +31,6 @@ use TYPO3\CMS\Lang\LanguageService;
 class L10nModeUpdater implements RowUpdaterInterface
 {
     /**
-     * @var array Full, migrated TCA as prepared by upgrade wizard controller
-     */
-    protected $migratedTca;
-
-    /**
-     * @var array Full, but NOT migrated TCA
-     */
-    protected $notMigratedTca;
-
-    /**
      * List of tables with information about to migrate fields.
      * Created during hasPotentialUpdateForTable(), used in updateTableRow()
      *
@@ -50,18 +39,6 @@ class L10nModeUpdater implements RowUpdaterInterface
     protected $payload = [];
 
     /**
-     * Prepare non-migrated TCA to be used in 'hasPotentialUpdateForTable' step
-     */
-    public function __construct()
-    {
-        $this->migratedTca = $GLOBALS['TCA'];
-        $loadTcaService = GeneralUtility::makeInstance(LoadTcaService::class);
-        $loadTcaService->loadExtensionTablesWithoutMigration();
-        $this->notMigratedTca = $GLOBALS['TCA'];
-        $GLOBALS['TCA'] = $this->migratedTca;
-    }
-
-    /**
      * Get title
      *
      * @return string
@@ -80,9 +57,7 @@ class L10nModeUpdater implements RowUpdaterInterface
      */
     public function hasPotentialUpdateForTable(string $tableName): bool
     {
-        $GLOBALS['TCA'] = $this->notMigratedTca;
         $this->payload[$tableName] = $this->getL10nModePayloadForTable($tableName);
-        $GLOBALS['TCA'] = $this->migratedTca;
         return !empty($this->payload[$tableName]['localizations']);
     }
 
@@ -239,17 +214,13 @@ class L10nModeUpdater implements RowUpdaterInterface
 
         $fieldModes = [];
         foreach ($tableDefinition['columns'] as $fieldName => $fieldConfiguration) {
-            if (
-                empty($fieldConfiguration['l10n_mode'])
-                || empty($fieldConfiguration['config']['type'])
-            ) {
-                continue;
-            }
-            if (
-                $fieldConfiguration['l10n_mode'] === 'exclude'
-                || $fieldConfiguration['l10n_mode'] === 'mergeIfNotBlank'
-            ) {
-                $fieldModes[$fieldName] = $fieldConfiguration['l10n_mode'];
+            $l10nMode = ($fieldConfiguration['l10n_mode'] ?? null);
+            $allowLanguageSynchronization = ($fieldConfiguration['config']['behaviour']['allowLanguageSynchronization'] ?? null);
+
+            if ($l10nMode === 'exclude') {
+                $fieldModes[$fieldName] = $l10nMode;
+            } elseif ($allowLanguageSynchronization) {
+                $fieldModes[$fieldName] = 'mergeIfNotBlank';
             }
         }
 
diff --git a/typo3/sysext/install/Tests/Unit/Updates/RowUpdater/L10nModeUpdaterTest.php b/typo3/sysext/install/Tests/Unit/Updates/RowUpdater/L10nModeUpdaterTest.php
new file mode 100644 (file)
index 0000000..fc6b01a
--- /dev/null
@@ -0,0 +1,165 @@
+<?php
+namespace TYPO3\CMS\Install\Tests\Unit\Updates\RowUpdater;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use Prophecy\Argument;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
+use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface;
+use TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Install\Updates\RowUpdater\L10nModeUpdater;
+
+/**
+ * Test Class for ContentTypesToTextMediaUpdate
+ */
+class L10nModeUpdaterTest extends BaseTestCase
+{
+    /**
+     * @test
+     */
+    public function hasPotentialUpdateForTableThrowsExceptionIfGlobalsTcaIsNoArray()
+    {
+        $this->expectException(\RuntimeException::class);
+        $this->expectExceptionCode(1484176136);
+        (new L10nModeUpdater())->hasPotentialUpdateForTable('someTable');
+    }
+
+    /**
+     * @test
+     */
+    public function hasPotentialUpdateForTableReturnFalseForTableWithoutL10nMode()
+    {
+        $GLOBALS['TCA'] = [
+            'testTable' => [
+                'ctrl' => [
+                    'languageField' => 'sys_language_uid',
+                    'transOrigPointerField' => 'l10n_parent',
+                ],
+                'columns' => [
+                    'testField' => [
+                        'label' => 'someLabel',
+                        'config' => [
+                            'type' => 'input',
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $subject = new L10nModeUpdater();
+        $this->assertFalse($subject->hasPotentialUpdateForTable('testTable'));
+    }
+
+    /**
+     * @test
+     */
+    public function hasPotentialUpdateForTableReturnTrueForTableWithL10nModeExclude()
+    {
+        $GLOBALS['TCA'] = [
+            'testTable' => [
+                'ctrl' => [
+                    'languageField' => 'sys_language_uid',
+                    'transOrigPointerField' => 'l10n_parent',
+                ],
+                'columns' => [
+                    'testField' => [
+                        'label' => 'someLabel',
+                        'l10n_mode' => 'exclude',
+                        'config' => [
+                            'type' => 'input',
+                        ],
+                    ],
+                ],
+            ],
+        ];
+
+        $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
+        $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
+        $connectionPoolProphecy->getQueryBuilderForTable('testTable')->willReturn($queryBuilderProphecy->reveal());
+        $restrictionBuilderProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
+        $queryBuilderProphecy->getRestrictions()->willReturn($restrictionBuilderProphecy->reveal());
+        $queryBuilderProphecy->from('testTable');
+        $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
+        $queryBuilderProphecy->expr()->willReturn($expressionBuilderProphecy->reveal());
+        $queryBuilderProphecy->createNamedParameter(Argument::cetera())->willReturnArgument(0);
+        $expressionBuilderProphecy->gt('sys_language_uid', 0);
+        $expressionBuilderProphecy->gt('l10n_parent', 0);
+        $queryBuilderProphecy->select('uid', 'l10n_parent')->willReturn($queryBuilderProphecy->reveal());
+        $queryBuilderProphecy->andWhere(Argument::cetera())->willReturn($queryBuilderProphecy->reveal());
+        $queryBuilderProphecy->execute()->willReturn([
+            [
+                'uid' => 23,
+                'l10n_parent' => 42,
+            ]
+        ]);
+
+        $subject = new L10nModeUpdater();
+        $this->assertTrue($subject->hasPotentialUpdateForTable('testTable'));
+    }
+
+    /**
+     * @test
+     */
+    public function hasPotentialUpdateForTableReturnTrueForTableWithBehaviourAllowLanguageSynchronization()
+    {
+        $GLOBALS['TCA'] = [
+            'testTable' => [
+                'ctrl' => [
+                    'languageField' => 'sys_language_uid',
+                    'transOrigPointerField' => 'l10n_parent',
+                ],
+                'columns' => [
+                    'testField' => [
+                        'label' => 'someLabel',
+                        'config' => [
+                            'type' => 'input',
+                            'behaviour' => [
+                                'allowLanguageSynchronization' => true,
+                            ]
+                        ],
+                    ],
+                ],
+            ],
+        ];
+
+        $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
+        GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
+        $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
+        $connectionPoolProphecy->getQueryBuilderForTable('testTable')->willReturn($queryBuilderProphecy->reveal());
+        $restrictionBuilderProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
+        $queryBuilderProphecy->getRestrictions()->willReturn($restrictionBuilderProphecy->reveal());
+        $queryBuilderProphecy->from('testTable');
+        $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
+        $queryBuilderProphecy->expr()->willReturn($expressionBuilderProphecy->reveal());
+        $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
+        $queryBuilderProphecy->expr()->willReturn($expressionBuilderProphecy->reveal());
+        $queryBuilderProphecy->createNamedParameter(Argument::cetera())->willReturnArgument(0);
+        $expressionBuilderProphecy->gt('sys_language_uid', 0);
+        $expressionBuilderProphecy->gt('l10n_parent', 0);
+        $queryBuilderProphecy->select('uid', 'l10n_parent')->willReturn($queryBuilderProphecy->reveal());
+        $queryBuilderProphecy->andWhere(Argument::cetera())->willReturn($queryBuilderProphecy->reveal());
+        $queryBuilderProphecy->execute()->willReturn([
+            [
+                'uid' => 23,
+                'l10n_parent' => 42,
+            ]
+        ]);
+
+        $subject = new L10nModeUpdater();
+        $this->assertTrue($subject->hasPotentialUpdateForTable('testTable'));
+    }
+}