From dfbee191302b26bf31d819b20f536cf17d4ffd0c Mon Sep 17 00:00:00 2001
From: Benni Mack <benni@typo3.org>
Date: Thu, 27 Jun 2019 14:43:29 +0200
Subject: [PATCH] [!!!][TASK] Remove "sys_template.nextLevel"

The special handling "nextLevel" in TypoScript templates
to only load a specific sys_template on the next level (subpages and
further down the rootline) but not on the current level,
is removed.

It is recommended to use proper inclusions and TypoScript
conditions instead.

This reduces complexity within the TemplateService parser,
and for newcomers a very confusing option after gathering
some feedback on this topic.

The database field "sys_template.nextLevel" is therefore
removed.

Resolves: #88640
Releases: master
Change-Id: I06e14d6dfbde82eb36f2ffc30b61bd9870906246
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61158
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Benjamin Kott <benjamin.kott@outlook.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
---
 .../TypoScript/ExtendedTemplateService.php    |  1 -
 .../Classes/TypoScript/TemplateService.php    | 37 --------------
 ...dTypoScriptSublevel-InheritanceRemoved.rst | 49 +++++++++++++++++++
 .../Configuration/TCA/sys_template.php        | 16 +-----
 .../Private/Language/locallang_tca.xlf        |  3 --
 .../Tca/TemplateVisibleFieldsTest.php         |  1 -
 typo3/sysext/frontend/ext_tables.sql          |  1 -
 .../Private/Language/locallang_analyzer.xlf   |  3 --
 .../TemplateAnalyzerModuleFunction.html       |  1 -
 9 files changed, 51 insertions(+), 61 deletions(-)
 create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Breaking-88640-DatabaseFieldSys_templatenextLevelAndTypoScriptSublevel-InheritanceRemoved.rst

diff --git a/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php b/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php
index a75be9086dd7..b5a7f20dba1e 100644
--- a/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php
+++ b/typo3/sysext/core/Classes/TypoScript/ExtendedTemplateService.php
@@ -679,7 +679,6 @@ class ExtendedTemplateService extends TemplateService
 							<td align="center">' . ($row['clConst'] ? $statusCheckedIcon : '') . '</td>
 							<td align="center">' . ($row['pid'] ?: '') . '</td>
 							<td align="center">' . ($RL >= 0 ? $RL : '') . '</td>
-							<td>' . ($row['next'] ? $row['next'] : '') . '</td>
 						</tr>';
             if ($deeper) {
                 $keyArray = $this->ext_getTemplateHierarchyArr($arr[$key . '.'], $depthData . ($first ? '' : '<span class="treeline-icon treeline-icon-' . $LN . '"></span>'), $keyArray);
diff --git a/typo3/sysext/core/Classes/TypoScript/TemplateService.php b/typo3/sysext/core/Classes/TypoScript/TemplateService.php
index 84f9e8441414..fc61166e5f3f 100644
--- a/typo3/sysext/core/Classes/TypoScript/TemplateService.php
+++ b/typo3/sysext/core/Classes/TypoScript/TemplateService.php
@@ -159,13 +159,6 @@ class TemplateService
      */
     protected $hierarchyInfoToRoot = [];
 
-    /**
-     * Next-level flag (see runThroughTemplates())
-     *
-     * @var int
-     */
-    protected $nextLevel = 0;
-
     /**
      * The Page UID of the root page
      *
@@ -535,28 +528,6 @@ class TemplateService
         $c = count($this->absoluteRootLine);
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_template');
         for ($a = 0; $a < $c; $a++) {
-            // If some template loaded before has set a template-id for the next level, then load this template first!
-            if ($this->nextLevel) {
-                $queryBuilder->setRestrictions($this->queryBuilderRestrictions);
-                $queryResult = $queryBuilder
-                    ->select('*')
-                    ->from('sys_template')
-                    ->where(
-                        $queryBuilder->expr()->eq(
-                            'uid',
-                            $queryBuilder->createNamedParameter($this->nextLevel, \PDO::PARAM_INT)
-                        )
-                    )
-                    ->execute();
-                $this->nextLevel = 0;
-                if ($row = $queryResult->fetch()) {
-                    $this->versionOL($row);
-                    if (is_array($row)) {
-                        $this->processTemplate($row, 'sys_' . $row['uid'], $this->absoluteRootLine[$a]['uid'], 'sys_' . $row['uid']);
-                    }
-                }
-            }
-
             $where = [
                 $queryBuilder->expr()->eq(
                     'pid',
@@ -702,7 +673,6 @@ class TemplateService
         // Creating hierarchy information; Used by backend analysis tools
         $this->hierarchyInfo[] = ($this->hierarchyInfoToRoot[] = [
             'root' => trim($row['root'] ?? ''),
-            'next' => $row['nextLevel'] ?? null,
             'clConst' => $clConst,
             'clConf' => $clConf,
             'templateID' => $templateID,
@@ -727,12 +697,6 @@ class TemplateService
             $this->rootId = $pid;
             $this->rootLine = [];
         }
-        // If a template is set to be active on the next level set this internal value to point to this UID. (See runThroughTemplates())
-        if ($row['nextLevel'] ?? null) {
-            $this->nextLevel = $row['nextLevel'];
-        } else {
-            $this->nextLevel = 0;
-        }
     }
 
     /**
@@ -1240,7 +1204,6 @@ class TemplateService
             $rootTemplateId = $this->hierarchyInfo[count($this->hierarchyInfo) - 1]['templateID'] ?? null;
             $defaultTemplateInfo = [
                 'root' => '',
-                'next' => '',
                 'clConst' => '',
                 'clConf' => '',
                 'templateID' => '_defaultTypoScript_',
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Breaking-88640-DatabaseFieldSys_templatenextLevelAndTypoScriptSublevel-InheritanceRemoved.rst b/typo3/sysext/core/Documentation/Changelog/master/Breaking-88640-DatabaseFieldSys_templatenextLevelAndTypoScriptSublevel-InheritanceRemoved.rst
new file mode 100644
index 000000000000..f5e8f0c620fd
--- /dev/null
+++ b/typo3/sysext/core/Documentation/Changelog/master/Breaking-88640-DatabaseFieldSys_templatenextLevelAndTypoScriptSublevel-InheritanceRemoved.rst
@@ -0,0 +1,49 @@
+.. include:: ../../Includes.txt
+
+========================================================================================================
+Breaking: #88640 - Database field "sys_template.nextLevel" and TypoScript sublevel - inheritance removed
+========================================================================================================
+
+See :issue:`88640`
+
+Description
+===========
+
+The database field `nextLevel` of the database table `sys_template` where TypoScript configuration
+is stored, has been removed.
+
+The field `nextLevel` was introduced in TYPO3 v3.x before TypoScript could be imported from
+external files.
+
+Nowadays, TypoScript conditions should be used much more instead of this `nextLevel` feature,
+which is kind of a pseudo-condition.
+
+
+Impact
+======
+
+The database field is removed, and not evaluated anymore in TypoScript compilation.
+
+Requesting the database field in custom database queries will result in an SQL error.
+
+
+Affected Installations
+======================
+
+TYPO3 installations that have `sys_template` records with this flag activated,
+or querying this database field in third-party extensions.
+
+
+Migration
+=========
+
+Check for existing `sys_template` records having this flag activated by executing
+this SQL command:
+
+:sql:`SELECT * FROM sys_template WHERE nextLevel>0 AND deleted=0;`
+
+before updating TYPO3 Core.
+
+Replace the sys_template record (the uid of the record is stored in the "nextLevel" field) with a condition e.g. :ts:`[tree.level > 1]` to add TypoScript for subpages.
+
+.. index:: Database, NotScanned
\ No newline at end of file
diff --git a/typo3/sysext/frontend/Configuration/TCA/sys_template.php b/typo3/sysext/frontend/Configuration/TCA/sys_template.php
index d8e786f68b26..034958538a76 100644
--- a/typo3/sysext/frontend/Configuration/TCA/sys_template.php
+++ b/typo3/sysext/frontend/Configuration/TCA/sys_template.php
@@ -27,7 +27,7 @@ return [
         'searchFields' => 'title,constants,config'
     ],
     'interface' => [
-        'showRecordFieldList' => 'title,clear,root,basedOn,nextLevel,sitetitle,description,hidden,starttime,endtime'
+        'showRecordFieldList' => 'title,clear,root,basedOn,sitetitle,description,hidden,starttime,endtime'
     ],
     'columns' => [
         'title' => [
@@ -123,18 +123,6 @@ return [
                 'softref' => 'email[subst],url[subst]'
             ],
         ],
-        'nextLevel' => [
-            'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:sys_template.nextLevel',
-            'config' => [
-                'type' => 'group',
-                'internal_type' => 'db',
-                'allowed' => 'sys_template',
-                'size' => 1,
-                'maxitems' => 1,
-                'minitems' => 0,
-                'default' => '',
-            ]
-        ],
         'include_static_file' => [
             'label' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:sys_template.include_static_file',
             'config' => [
@@ -229,7 +217,7 @@ return [
             --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
                 title, sitetitle, constants, config,
             --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:sys_template.tabs.options,
-                clear, root, nextLevel,
+                clear, root,
             --div--;LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:sys_template.tabs.include,
                 includeStaticAfterBasedOn, include_static_file, basedOn, static_file_mode,
             --div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:access,
diff --git a/typo3/sysext/frontend/Resources/Private/Language/locallang_tca.xlf b/typo3/sysext/frontend/Resources/Private/Language/locallang_tca.xlf
index 27f561df0dbd..60d3d5d93fd6 100644
--- a/typo3/sysext/frontend/Resources/Private/Language/locallang_tca.xlf
+++ b/typo3/sysext/frontend/Resources/Private/Language/locallang_tca.xlf
@@ -489,9 +489,6 @@
 			<trans-unit id="sys_template.resources">
 				<source>Resources</source>
 			</trans-unit>
-			<trans-unit id="sys_template.nextLevel">
-				<source>Template on Next Level</source>
-			</trans-unit>
 			<trans-unit id="sys_template.include_static_file">
 				<source>Include static (from extensions)</source>
 			</trans-unit>
diff --git a/typo3/sysext/frontend/Tests/Functional/Tca/TemplateVisibleFieldsTest.php b/typo3/sysext/frontend/Tests/Functional/Tca/TemplateVisibleFieldsTest.php
index e95e89771395..bdccaa473e11 100644
--- a/typo3/sysext/frontend/Tests/Functional/Tca/TemplateVisibleFieldsTest.php
+++ b/typo3/sysext/frontend/Tests/Functional/Tca/TemplateVisibleFieldsTest.php
@@ -29,7 +29,6 @@ class TemplateVisibleFieldsTest extends \TYPO3\TestingFramework\Core\Functional\
         'description',
         'clear',
         'root',
-        'nextLevel',
         'includeStaticAfterBasedOn',
         'include_static_file',
         'basedOn',
diff --git a/typo3/sysext/frontend/ext_tables.sql b/typo3/sysext/frontend/ext_tables.sql
index e139e2125f37..c9e6cc768c01 100644
--- a/typo3/sysext/frontend/ext_tables.sql
+++ b/typo3/sysext/frontend/ext_tables.sql
@@ -82,7 +82,6 @@ CREATE TABLE sys_template (
 	include_static_file text,
 	constants text,
 	config text,
-	nextLevel varchar(5) DEFAULT '' NOT NULL,
 	basedOn tinytext,
 	includeStaticAfterBasedOn tinyint(4) unsigned DEFAULT '0' NOT NULL,
 	static_file_mode tinyint(4) unsigned DEFAULT '0' NOT NULL,
diff --git a/typo3/sysext/tstemplate/Resources/Private/Language/locallang_analyzer.xlf b/typo3/sysext/tstemplate/Resources/Private/Language/locallang_analyzer.xlf
index eae30d95d8d8..e054bd143165 100644
--- a/typo3/sysext/tstemplate/Resources/Private/Language/locallang_analyzer.xlf
+++ b/typo3/sysext/tstemplate/Resources/Private/Language/locallang_analyzer.xlf
@@ -24,9 +24,6 @@
 			<trans-unit id="rootline">
 				<source>Rootline</source>
 			</trans-unit>
-			<trans-unit id="nextLevel">
-				<source>Next Level</source>
-			</trans-unit>
 			<trans-unit id="templateHierarchy">
 				<source>Template hierarchy</source>
 			</trans-unit>
diff --git a/typo3/sysext/tstemplate/Resources/Private/Templates/TemplateAnalyzerModuleFunction.html b/typo3/sysext/tstemplate/Resources/Private/Templates/TemplateAnalyzerModuleFunction.html
index 8d18843a8833..ac2712afcad9 100644
--- a/typo3/sysext/tstemplate/Resources/Private/Templates/TemplateAnalyzerModuleFunction.html
+++ b/typo3/sysext/tstemplate/Resources/Private/Templates/TemplateAnalyzerModuleFunction.html
@@ -23,7 +23,6 @@
                 <th><f:translate key="{LLPrefix}clearConstants"/></th>
                 <th><f:translate key="{LLPrefix}pid"/></th>
                 <th><f:translate key="{LLPrefix}rootline"/></th>
-                <th><f:translate key="{LLPrefix}nextLevel"/></th>
             </tr>
         </thead>
         <f:format.raw>{hierarchy}</f:format.raw>
-- 
GitLab