[TASK] Add feature switch "unifiedPageTranslationHandling" 46/55446/8
authorBenni Mack <benni@typo3.org>
Wed, 24 Jan 2018 13:21:17 +0000 (14:21 +0100)
committerFrank Naegler <frank.naegler@typo3.org>
Fri, 2 Mar 2018 10:55:07 +0000 (11:55 +0100)
The feature switch "unifiedPageTranslationHandling" is active for all new
installations, but not active for existing installations.

It does the following when active:
- All DB schema migrations decide to drop "pages_language_overlay"
- TCA migration no longer throws a deprecation info (but still unsets "pages_language_overlay")

Once the Update Wizard for migrating pages_language_overlay records is done,
the feature is enabled.

Resolves: #83711
Releases: master
Change-Id: I478c8d5d745309889fa38b44b5eaab7226afdfc4
Reviewed-on: https://review.typo3.org/55446
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/core/Classes/Database/Schema/SchemaMigrator.php
typo3/sysext/core/Classes/Migrations/TcaMigration.php
typo3/sysext/core/Configuration/DefaultConfiguration.php
typo3/sysext/core/Configuration/DefaultConfigurationDescription.yaml
typo3/sysext/core/Configuration/FactoryConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Feature-83711-FeatureFlagUnifiedPageTranslationHandling.rst [new file with mode: 0644]
typo3/sysext/install/Classes/Updates/MigratePagesLanguageOverlayUpdate.php

index 2e82166..f505042 100644 (file)
@@ -19,6 +19,7 @@ use Doctrine\DBAL\DBALException;
 use Doctrine\DBAL\Schema\Schema;
 use Doctrine\DBAL\Schema\SchemaDiff;
 use Doctrine\DBAL\Schema\Table;
+use TYPO3\CMS\Core\Configuration\Features;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Schema\Exception\StatementException;
 use TYPO3\CMS\Core\Database\Schema\Parser\Parser;
@@ -268,6 +269,18 @@ class SchemaMigrator
         }
 
         // Flatten the array of arrays by one level
-        return array_merge(...$tables);
+        $tables = array_merge(...$tables);
+
+        // Drop any definition of pages_language_overlay in SQL
+        // will be removed in TYPO3 v10.0 once the feature is enabled by default
+        if (GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('unifiedPageTranslationHandling')) {
+            foreach ($tables as $k => $table) {
+                if ($table->getName() === 'pages_language_overlay') {
+                    unset($tables[$k]);
+                }
+            }
+        }
+
+        return $tables;
     }
 }
index bd6d5d0..7157e79 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Migrations;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Configuration\Features;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -2566,9 +2567,12 @@ class TcaMigration
     protected function migratePagesLanguageOverlayRemoval(array $tca)
     {
         if (isset($tca['pages_language_overlay'])) {
-            $this->messages[] = 'The TCA table \'pages_language_overlay\' is'
-                . ' not used anymore and has been removed automatically in'
-                . ' order to avoid negative side-effects.';
+            // If the feature is not enabled, a deprecation log entry is thrown
+            if (!GeneralUtility::makeInstance(Features::class)->isFeatureEnabled('unifiedPageTranslationHandling')) {
+                $this->messages[] = 'The TCA table \'pages_language_overlay\' is'
+                    . ' not used anymore and has been removed automatically in'
+                    . ' order to avoid negative side-effects.';
+            }
             unset($tca['pages_language_overlay']);
         }
         return $tca;
index 4f2e1ab..b9142a6 100644 (file)
@@ -69,7 +69,8 @@ return [
         'fileCreateMask' => '0664',
         'folderCreateMask' => '2775',
         'features' => [
-            'redirects.hitCount' => false
+            'redirects.hitCount' => false,
+            'unifiedPageTranslationHandling' => false
         ],
         'createGroup' => '',
         'sitename' => 'TYPO3',
index afda9c7..b8901b3 100644 (file)
@@ -202,6 +202,13 @@ SYS:
         systemMaintainers:
             type: array
             description: 'A list of backend user IDs allowed to access the Install Tool'
+        features:
+            type: container
+            description: 'New features of TYPO3 that are activated on new installations but upgrading installations can still use the old behaviour'
+            items:
+              unifiedPageTranslationHandling:
+                type: bool
+                description: 'If activated, TCA configuration for pages_language_overlay will never be loaded, and the database table "pages_language_overlay" will not be created.'
 EXT:
     type: container
     items:
index 78264e1..23d6ad5 100644 (file)
@@ -23,5 +23,8 @@ return [
     ],
     'SYS' => [
         'sitename' => 'New TYPO3 site',
+        'features' => [
+            'unifiedPageTranslationHandling' => true
+        ],
     ],
 ];
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-83711-FeatureFlagUnifiedPageTranslationHandling.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-83711-FeatureFlagUnifiedPageTranslationHandling.rst
new file mode 100644 (file)
index 0000000..f243a71
--- /dev/null
@@ -0,0 +1,22 @@
+.. include:: ../../Includes.txt
+
+=============================================================
+Feature: #83711 - FeatureFlag: unifiedPageTranslationHandling
+=============================================================
+
+See :issue:`83711`
+
+Description
+===========
+
+The feature switch `unifiedPageTranslationHandling` is active for all new
+installations, but not active for existing installations.
+
+It does the following when active:
+- All DB schema migrations decide to drop `pages_language_overlay`
+- TCA migration no longer throws a deprecation info (but still unsets `pages_language_overlay`)
+
+Once the Update Wizard for migrating `pages_language_overlay` records is done,
+the feature is enabled.
+
+.. index:: Backend, Frontend
\ No newline at end of file
index 16764f6..8b5c760 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Install\Updates;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Configuration\ConfigurationManager;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Install\Service\LoadTcaService;
@@ -46,7 +47,8 @@ class MigratePagesLanguageOverlayUpdate extends AbstractUpdate
 
         $updateNeeded = false;
 
-        if (!$this->isWizardDone()) {
+        // Check if the database table even exists
+        if ($this->checkIfWizardIsRequired() && !$this->isWizardDone()) {
             $updateNeeded = true;
         }
 
@@ -92,6 +94,7 @@ class MigratePagesLanguageOverlayUpdate extends AbstractUpdate
         $this->updateInlineRelations();
         $this->updateSysHistoryRelations();
         $this->markWizardAsDone();
+        $this->enableFeatureFlag();
         return true;
     }
 
@@ -293,4 +296,40 @@ class MigratePagesLanguageOverlayUpdate extends AbstractUpdate
             ->fetch();
         return !empty($migratedRecord);
     }
+
+    /**
+     * Check if the database table "pages_language_overlay" exists and if so, if there are entries in the DB table.
+     *
+     * @return bool
+     * @throws \InvalidArgumentException
+     */
+    protected function checkIfWizardIsRequired(): bool
+    {
+        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
+        $connection = $connectionPool->getConnectionByName('Default');
+        $tableNames = $connection->getSchemaManager()->listTableNames();
+        if (in_array('pages_language_overlay', $tableNames, true)) {
+            // table is available, now check if there are entries in it
+            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
+                ->getQueryBuilderForTable('pages_language_overlay');
+            $numberOfEntries = $queryBuilder->count('*')
+                ->from('pages_language_overlay')
+                ->execute()
+                ->fetchColumn();
+            return (bool)$numberOfEntries;
+        }
+
+        return false;
+    }
+
+    /**
+     * Once the update wizard is run through, the feature to not load any pages_language_overlay data can
+     * be activated.
+     *
+     * Basically writes 'SYS/features/unifiedPageTranslationHandling' to LocalConfiguration.php
+     */
+    protected function enableFeatureFlag()
+    {
+        GeneralUtility::makeInstance(ConfigurationManager::class)->enableFeature('unifiedPageTranslationHandling');
+    }
 }