[TASK] Remove leftover page/branch versioning code 62/50462/8
authorBenni Mack <benni@typo3.org>
Mon, 31 Oct 2016 20:09:01 +0000 (21:09 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 1 Nov 2016 12:50:53 +0000 (13:50 +0100)
There are several places within EXT:version and DataHandler
which try to do "pageVersionizing" but it's not possible
anymore (see removed code in "new" section of DataHandlerHook)
since TYPO3 v7.

This also means that the `versioning_followPages` option is removed
completely from the Core.

Resolves: #78524
Releases: master
Change-Id: I6166e198fc74922aa34e2ae49440e4c0fe4354a6
Reviewed-on: https://review.typo3.org/50462
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
15 files changed:
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Migrations/TcaMigration.php
typo3/sysext/core/Configuration/TCA/sys_category.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-78524-TCAOptionVersioning_followPagesRemoved.rst [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php
typo3/sysext/core/Tests/Unit/Migrations/TcaMigrationTest.php
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/tx_blogexample_domain_model_blog.php
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/tx_blogexample_domain_model_person.php
typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example/Configuration/TCA/tx_blogexample_domain_model_post.php
typo3/sysext/frontend/Classes/Page/PageRepository.php
typo3/sysext/frontend/Configuration/TCA/pages_language_overlay.php
typo3/sysext/frontend/Configuration/TCA/tt_content.php
typo3/sysext/impexp/Tests/Functional/Fixtures/Extensions/impexp_group_files/Configuration/TCA/tx_impexpgroupfiles_item.php
typo3/sysext/lowlevel/Classes/CleanerCommand.php
typo3/sysext/version/Classes/Hook/DataHandlerHook.php

index 98d9f54..8697f6a 100644 (file)
@@ -1158,7 +1158,6 @@ class DataHandler
                                 $cmd = [];
                                 $cmd[$table][$id]['version'] = [
                                     'action' => 'new',
-                                    'treeLevels' => -1,
                                     // Default is to create a version of the individual records... element versioning that is.
                                     'label' => 'Auto-created for WS #' . $this->BE_USER->workspace
                                 ];
index 776f0b2..d304539 100644 (file)
@@ -57,6 +57,7 @@ class TcaMigration
         $tca = $this->migrateSelectTreeOptions($tca);
         $tca = $this->migrateTSconfigSoftReferences($tca);
         $tca = $this->migrateShowIfRteOption($tca);
+        $tca = $this->migrateWorkspacesOptions($tca);
         // @todo: if showitem/defaultExtras wizards[xy] is migrated to columnsOverrides here, enableByTypeConfig could be dropped
         return $tca;
     }
@@ -849,4 +850,27 @@ class TcaMigration
         }
         return $tca;
     }
+
+    /**
+     * Casts "versioningWS" to bool, and removes "versioning_followPages"
+     *
+     * @param array $tca Incoming TCA
+     * @return array Migrated TCA
+     */
+    protected function migrateWorkspacesOptions(array $tca)
+    {
+        foreach ($tca as $table => &$tableDefinition) {
+            if (isset($tableDefinition['ctrl']['versioningWS']) && !is_bool($tableDefinition['ctrl']['versioningWS'])) {
+                $tableDefinition['ctrl']['versioningWS'] = (bool)$tableDefinition['ctrl']['versioningWS'];
+                $this->messages[] = 'The TCA setting \'versioningWS\' was set to a boolean value '
+                    . 'in TCA ' . $table . '[\'ctrl\'][\'versioningWS\']';
+            }
+            if (isset($tableDefinition['ctrl']['versioning_followPages']) && !empty($tableDefinition['ctrl']['versioning_followPages'])) {
+                unset($tableDefinition['ctrl']['versioning_followPages']);
+                $this->messages[] = 'The TCA setting \'versioning_followPages\' was removed as it is unused '
+                    . 'in TCA ' . $table . '[\'ctrl\'][\'versioning_followPages\']';
+            }
+        }
+        return $tca;
+    }
 }
index 5629e89..30ee2d3 100644 (file)
@@ -11,7 +11,6 @@ return [
         'sortby' => 'sorting',
         'versioningWS' => true,
         'rootLevel' => -1,
-        'versioning_followPages' => true,
         'origUid' => 't3_origuid',
         'languageField' => 'sys_language_uid',
         'transOrigPointerField' => 'l10n_parent',
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-78524-TCAOptionVersioning_followPagesRemoved.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-78524-TCAOptionVersioning_followPagesRemoved.rst
new file mode 100644 (file)
index 0000000..a2c67c0
--- /dev/null
@@ -0,0 +1,39 @@
+.. include:: ../../Includes.txt
+
+===============================================================
+Deprecation: #78524 - TCA option versioning_followPages removed
+===============================================================
+
+See :issue:`78524`
+
+Description
+===========
+
+The option `$TCA[$table][ctrl][versioning_followPages]` which was used for branch versioning has been removed.
+
+Additionally the option `$TCA[$table][ctrl][versioningWS]` is now cast to boolean.
+
+The branch / page versioning functionality was removed in TYPO3 v7, but the leftover functionality code has been
+completely removed as well.
+
+
+Impact
+======
+
+A deprecation message is thrown when scanning the TCA tree for these options not properly set or removed.
+
+
+Affected Installations
+======================
+
+Any TYPO3 installation with a TCA definition as mentioned above.
+
+
+Migration
+=========
+
+Remove the setting `$TCA[$table][ctrl][versioning_followPages]` from any TCA definition.
+
+If a TCA table has workspaces enabled, set the option `$TCA[$table][ctrl][versioningWS]` to a boolean (true/false) directly.
+
+.. index:: TCA, ext:workspaces
index 599ecbf..387d73b 100644 (file)
@@ -377,7 +377,6 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                 1 => [
                     'version' => [
                         'action' => 'new',
-                        'treeLevels' => -1,
                         'label' => 'Auto-created for WS #1'
                     ]
                 ]
index 0906102..44ac224 100644 (file)
@@ -1750,4 +1750,119 @@ class TcaMigrationTest extends UnitTestCase
         $subject = new TcaMigration();
         $this->assertEquals($expectedConfig, $subject->migrate($givenConfig));
     }
+
+    public function migrateWorkspaceSettingsDataProvider()
+    {
+        return [
+            'no workspaces enabled' => [
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => false
+                        ],
+                    ],
+                ],
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => false
+                        ],
+                    ],
+                ]
+            ],
+            'nothing activated' => [
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'label' => 'blabla'
+                        ],
+                    ],
+                ],
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'label' => 'blabla'
+                        ],
+                    ],
+                ]
+            ],
+            'nothing changed, workspaces enabled' => [
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => true
+                        ],
+                    ],
+                ],
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => true
+                        ],
+                    ],
+                ]
+            ],
+            'cast workspaces to bool' => [
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => 1
+                        ],
+                    ],
+                ],
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => true
+                        ],
+                    ],
+                ]
+            ],
+            'cast workspaces v2 to bool' => [
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => 2
+                        ],
+                    ],
+                ],
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => true
+                        ],
+                    ],
+                ]
+            ],
+            'cast workspaces v2 to bool and remove followpages' => [
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => 2,
+                            'versioning_followPages' => true
+                        ],
+                    ],
+                ],
+                [
+                    'aTable' => [
+                        'ctrl' => [
+                            'versioningWS' => true
+                        ],
+                    ],
+                ]
+            ],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider migrateWorkspaceSettingsDataProvider
+     * @param array $givenConfig
+     * @param array $expectedConfig
+     */
+    public function migrateWorkspaceSettings(array $givenConfig, array $expectedConfig)
+    {
+        $subject = new TcaMigration();
+        $this->assertEquals($expectedConfig, $subject->migrate($givenConfig));
+    }
 }
index ddb24c4..d4a5966 100644 (file)
@@ -6,7 +6,6 @@ return [
         'tstamp' => 'tstamp',
         'crdate' => 'crdate',
         'versioningWS' => true,
-        'versioning_followPages' => true,
         'origUid' => 't3_origuid',
         'languageField' => 'sys_language_uid',
         'transOrigPointerField' => 'l18n_parent',
index ccfd15d..17b0556 100644 (file)
@@ -8,7 +8,6 @@ return [
         'tstamp' => 'tstamp',
         'crdate' => 'crdate',
         'versioningWS' => true,
-        'versioning_followPages' => true,
         'origUid' => 't3_origuid',
         'prependAtCopy' => 'LLL:EXT:lang/locallang_general.xml:LGL.prependAtCopy',
         'delete' => 'deleted',
index 6cb0051..6ebaf3e 100644 (file)
@@ -8,7 +8,6 @@ return [
         'tstamp'   => 'tstamp',
         'crdate'   => 'crdate',
         'versioningWS' => true,
-        'versioning_followPages' => true,
         'origUid' => 't3_origuid',
         'languageField' => 'sys_language_uid',
         'transOrigPointerField' => 'l18n_parent',
index 8f77457..3b3bad0 100644 (file)
@@ -1569,8 +1569,7 @@ class PageRepository
                     $wsAlt['pid'] = $row['pid'];
                     // For versions of single elements or page+content, preserve online UID and PID
                     // (this will produce true "overlay" of element _content_, not any references)
-                    // For page+content the "_ORIG_uid" should actually be used as PID for selection
-                    // of tables with "versioning_followPages" enabled.
+                    // For page+content the "_ORIG_uid" should actually be used as PID for selection.
                     $wsAlt['_ORIG_uid'] = $wsAlt['uid'];
                     $wsAlt['uid'] = $row['uid'];
                     // Translate page alias as well so links are pointing to the _online_ page:
index 9dbeabc..9db4558 100644 (file)
@@ -5,7 +5,6 @@ return [
         'tstamp' => 'tstamp',
         'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:pages_language_overlay',
         'versioningWS' => true,
-        'versioning_followPages' => true,
         'origUid' => 't3_origuid',
         'crdate' => 'crdate',
         'hideAtCopy' => 1,
index 106ec62..2572584 100644 (file)
@@ -12,7 +12,6 @@ return [
         'title' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_tca.xlf:tt_content',
         'delete' => 'deleted',
         'versioningWS' => true,
-        'versioning_followPages' => true,
         'origUid' => 't3_origuid',
         'type' => 'CType',
         'hideAtCopy' => true,
index 8eedda2..6f95610 100644 (file)
@@ -476,8 +476,8 @@ NOW Running --AUTOFIX on result. OK?' . ($this->cli_isArg('--dryrun') ? ' (--dry
                     if ($echoLevel == 3) {
                         echo LF . '    \\-' . $tableName . ':' . $rowSub['uid'];
                     }
-                    // If the rootID represents an "element" or "page" version type, we must check if the record from this table is allowed to belong to this:
-                    if ($versionSwapmode === 'SWAPMODE:-1' || ($versionSwapmode === 'SWAPMODE:0' && !$GLOBALS['TCA'][$tableName]['ctrl']['versioning_followPages'])) {
+                    // If the rootID represents a version, we must check if the record from this table is allowed to belong to this:
+                    if ($versionSwapmode === 'SWAPMODE:-1') {
                         // This is illegal records under a versioned page - therefore not registered in $this->recStats['all'] so they should be orphaned:
                         $this->recStats['illegal_record_under_versioned_page'][$tableName][$rowSub['uid']] = $rowSub['uid'];
                         if ($echoLevel > 1) {
index 62656bb..e3d8012 100644 (file)
@@ -86,17 +86,7 @@ class DataHandlerHook
             $notificationAlternativeRecipients = (isset($value['notificationAlternativeRecipients'])) && is_array($value['notificationAlternativeRecipients']) ? $value['notificationAlternativeRecipients'] : [];
             switch ($action) {
                 case 'new':
-                    // check if page / branch versioning is needed,
-                    // or if "element" version can be used
-                    $versionizeTree = -1;
-                    if (isset($value['treeLevels'])) {
-                        $versionizeTree = \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($value['treeLevels'], -1, 100);
-                    }
-                    if ($table == 'pages' && $versionizeTree >= 0) {
-                        $this->versionizePages($id, $value['label'], $versionizeTree, $tcemainObj);
-                    } else {
-                        $tcemainObj->versionizeRecord($table, $id, $value['label']);
-                    }
+                    $tcemainObj->versionizeRecord($table, $id, $value['label']);
                     break;
                 case 'swap':
                     $this->version_swap($table, $id, $value['swapWith'], $value['swapIntoWS'],
@@ -755,65 +745,6 @@ class DataHandlerHook
     /*****************************
      *****  CMD versioning  ******
      *****************************/
-    /**
-     * Creates a new version of a page including content and possible subpages.
-     *
-     * @param int $uid Page uid to create new version of.
-     * @param string $label Version label
-     * @param int $versionizeTree Indicating "treeLevel" - "page" (0) or "branch" (>=1) ["element" type must call versionizeRecord() directly]
-     * @param DataHandler $tcemainObj TCEmain object
-     * @return void
-     * @see copyPages()
-     */
-    protected function versionizePages($uid, $label, $versionizeTree, DataHandler $tcemainObj)
-    {
-        $uid = (int)$uid;
-        // returns the branch
-        $brExist = $tcemainObj->doesBranchExist('', $uid, $tcemainObj->pMap['show'], 1);
-        // Checks if we had permissions
-        if ((int)$brExist === -1) {
-            $tcemainObj->newlog('Could not read all subpages to versionize.', 1);
-            return;
-        }
-        // Make list of tables that should come along with a new version of the page:
-        $verTablesArray = [];
-        $allTables = array_keys($GLOBALS['TCA']);
-        foreach ($allTables as $tableName) {
-            if ($tableName != 'pages' && ($versionizeTree > 0 || $GLOBALS['TCA'][$tableName]['ctrl']['versioning_followPages'])) {
-                $verTablesArray[] = $tableName;
-            }
-        }
-        // Remove the possible inline child tables from the tables to be versioniozed automatically:
-        $verTablesArray = array_diff($verTablesArray, $this->getPossibleInlineChildTablesOfParentTable('pages'));
-        // Begin to copy pages if we're allowed to:
-        if ($versionizeTree !== -1) {
-            $tcemainObj->newlog('Versioning type "' . $versionizeTree . '" was not allowed in workspace', 1);
-            return;
-        }
-        // Versionize this page:
-        $theNewRootID = $tcemainObj->versionizeRecord('pages', $uid, $label, false, $versionizeTree);
-        if (!$theNewRootID) {
-            $tcemainObj->newlog('The root version could not be created!', 1);
-            return;
-        }
-        $this->rawCopyPageContent($uid, $theNewRootID, $verTablesArray, $tcemainObj);
-        // If we're going to copy recursively...:
-        if ($versionizeTree > 0) {
-            // Get ALL subpages to copy (read permissions respected - they should NOT be...):
-            $CPtable = $tcemainObj->int_pageTreeInfo([], $uid, (int)$versionizeTree, $theNewRootID);
-            // Now copying the subpages
-            foreach ($CPtable as $thePageUid => $thePagePid) {
-                $newPid = $tcemainObj->copyMappingArray['pages'][$thePagePid];
-                if (isset($newPid)) {
-                    $theNewRootID = $tcemainObj->copyRecord_raw('pages', $thePageUid, $newPid);
-                    $this->rawCopyPageContent($thePageUid, $theNewRootID, $verTablesArray, $tcemainObj);
-                } else {
-                    $tcemainObj->newlog('Something went wrong during copying branch (for versioning)', 1);
-                    break;
-                }
-            }
-        }
-    }
 
     /**
      * Swapping versions of a record
@@ -1253,52 +1184,6 @@ class DataHandlerHook
     /*******************************
      *****  helper functions  ******
      *******************************/
-    /**
-     * Copies all records from tables in $copyTablesArray from page with $old_pid to page with $new_pid
-     * Uses raw-copy for the operation (meant for versioning!)
-     *
-     * @param int $oldPageId Current page id.
-     * @param int $newPageId New page id
-     * @param array $copyTablesArray Array of tables from which to copy
-     * @param DataHandler $tcemainObj TCEmain object
-     * @return void
-     * @see versionizePages()
-     */
-    protected function rawCopyPageContent($oldPageId, $newPageId, array $copyTablesArray, DataHandler $tcemainObj)
-    {
-        if (!$newPageId) {
-            return;
-        }
-        foreach ($copyTablesArray as $table) {
-            // all records under the page is copied.
-            if ($table && is_array($GLOBALS['TCA'][$table]) && $table !== 'pages') {
-                $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
-                    ->getQueryBuilderForTable($table);
-                $queryBuilder->getRestrictions()
-                    ->removeAll()
-                    ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
-
-                $statement = $queryBuilder
-                    ->select('uid')
-                    ->from($table)
-                    ->where(
-                        $queryBuilder->expr()->eq(
-                            'pid',
-                            $queryBuilder->createNamedParameter($oldPageId, \PDO::PARAM_INT)
-                        )
-                    )
-                    ->execute();
-
-                while ($row = $statement->fetch()) {
-                    // Check, if this record has already been copied by a parent record as relation:
-                    if (!$tcemainObj->copyMappingArray[$table][$row['uid']]) {
-                        // Copying each of the underlying records (method RAW)
-                        $tcemainObj->copyRecord_raw($table, $row['uid'], $newPageId);
-                    }
-                }
-            }
-        }
-    }
 
     /**
      * Finds all elements for swapping versions in workspace
@@ -1617,28 +1502,6 @@ class DataHandlerHook
     }
 
     /**
-     * Gets all possible child tables that are used on each parent table as field.
-     *
-     * @param string $parentTable Name of the parent table
-     * @param array $possibleInlineChildren Collected possible inline children
-     * @return array
-     */
-    protected function getPossibleInlineChildTablesOfParentTable($parentTable, array $possibleInlineChildren = [])
-    {
-        foreach ($GLOBALS['TCA'][$parentTable]['columns'] as $parentField => $parentFieldDefinition) {
-            if (isset($parentFieldDefinition['config']['type'])) {
-                $parentFieldConfiguration = $parentFieldDefinition['config'];
-                if ($parentFieldConfiguration['type'] == 'inline' && isset($parentFieldConfiguration['foreign_table'])) {
-                    if (!in_array($parentFieldConfiguration['foreign_table'], $possibleInlineChildren)) {
-                        $possibleInlineChildren = $this->getPossibleInlineChildTablesOfParentTable($parentFieldConfiguration['foreign_table'], array_merge($possibleInlineChildren, $parentFieldConfiguration['foreign_table']));
-                    }
-                }
-            }
-        }
-        return $possibleInlineChildren;
-    }
-
-    /**
      * Gets an instance of the command map helper.
      *
      * @param DataHandler $tceMain TCEmain object