Commit 779b5bf8 authored by Oliver Bartsch's avatar Oliver Bartsch Committed by Benni Mack
Browse files

[TASK] Deprecate CategoryRegistry and API method

In #94622 the TCA type `category` was introduced as
replacement for the CategoryRegistry.

Therefore, the CategoryRegistry as well as the API method
ExtensionManagementUtility::makeCategorizable() are now
deprecated.

Resolves: #85613
Related: #94622
Releases: master
Change-Id: Ie12a643b97e2149981aec3fb1599bf8c8b4a8d64
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/70202

Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent 868e616f
......@@ -24,6 +24,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class to register category configurations.
* @deprecated since v11, will be removed in v12
*/
class CategoryRegistry implements SingletonInterface
{
......@@ -248,6 +249,12 @@ class CategoryRegistry implements SingletonInterface
$GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables'],
true
);
if ($defaultCategorizedTables !== []) {
trigger_error(
'$GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'defaultCategorizedTables\'] is deprecated and will be removed in v12. Register category fields with the TCA type "category" instead.',
E_USER_DEPRECATED
);
}
foreach ($defaultCategorizedTables as $defaultCategorizedTable) {
if (!$this->isRegistered($defaultCategorizedTable)) {
$this->add('core', $defaultCategorizedTable, 'categories');
......
......@@ -1582,6 +1582,7 @@ tt_content.' . $key . $suffix . ' {
$cacheData = $codeCache->require($cacheIdentifier);
if ($cacheData) {
$GLOBALS['TCA'] = $cacheData['tca'];
// @deprecated remove categoryRegistry in v12
GeneralUtility::setSingletonInstance(
CategoryRegistry::class,
unserialize(
......@@ -1629,6 +1630,7 @@ tt_content.' . $key . $suffix . ' {
}
// Apply category stuff
// @deprecated since v11, can be removed in v12
CategoryRegistry::getInstance()->applyTcaForPreRegisteredTables();
// Execute override files from Configuration/TCA/Overrides
......@@ -1681,6 +1683,7 @@ tt_content.' . $key . $suffix . ' {
*/
protected static function createBaseTcaCacheFile(FrontendInterface $codeCache)
{
// @deprecated Remove 'categoryRegistry' in v12
$codeCache->set(
static::getBaseTcaCacheIdentifier(),
'return '
......@@ -1842,6 +1845,11 @@ tt_content.' . $key . $suffix . ' {
*/
public static function makeCategorizable($extensionKey, $tableName, $fieldName = 'categories', array $options = [], $override = false)
{
trigger_error(
__CLASS__ . '::makeCategorizable() is deprecated and will be removed in v12. Use the TCA type "category" instead.',
E_USER_DEPRECATED
);
// Update the category registry
$result = CategoryRegistry::getInstance()->add($extensionKey, $tableName, $fieldName, $options, $override);
if ($result === false) {
......
.. include:: ../../Includes.txt
=======================================
Deprecation: #85613 - Category Registry
=======================================
See :issue:`85613`
Description
===========
With :issue:`94622` the new TCA type `category` has been introduced
as a replacement for the :php:`CategoryRegistry`. Therefore, the
:php:`CategoryRegistry` as well as the
:php:`ExtensionManagementUtility::makeCategorizable()` method
have been deprecated and will be removed in TYPO3 v12.
The main reasons for this replacement are:
* Using a dedicated type is more intuitive and consistent
* No more `TCA/Overrides` are necessary for defining category fields
* The new implementation is state of the art (e.g. directly usage of
the doctrine API for automatically adding the database columns)
Impact
======
Defining category fields for tables with
:php:`$GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables']` or
by calling :php:`ExtensionManagementUtility::makeCategorizable()` will
trigger a PHP :php:`E_USER_DEPRECATED` error.
The extension scanner will furthermore detect any call to
:php:`ExtensionManagementUtility::makeCategorizable()` and
:php:`CategoryRegistry` as strong match and any usage of
:php:`$GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables']`
as weak match.
Affected Installations
======================
All installations registering category fields using
:php:`ExtensionManagementUtility::makeCategorizable()` or defining
:php:`$GLOBALS['TYPO3_CONF_VARS']['SYS']['defaultCategorizedTables']`.
Furthermore, all installations, which directly access the :php:`CategoryRegistry`.
Migration
=========
Directly define category fields in the corresponding TCA, using the `category`
TCA type. Have a look at the corresponding
:doc:`changelog <../11.4/Feature-94622-NewTCATypeCategory>`, for code
examples.
.. index:: PHP-API, TCA, PartiallyScanned, ext:core
......@@ -13,8 +13,8 @@ When using :php:`TCA` keys that contain SQL fragments like `foreign_table_where`
`MM_table_where` and `search.andWhere`, it is important to use a special syntax
for SQL field names to stay DBAL compatible.
See :doc:`Important-81751-DbalCompatibleQuotingInTca` for details. It
boils down to: Use :sql:`{#colPos}=0` instead of :sql:`colPos=0` to stay DBAL
See :doc:`#81751 <../8.7.x/Important-81751-DbalCompatibleQuotingInTca>` for details.
It boils down to: Use :sql:`{#colPos}=0` instead of :sql:`colPos=0` to stay DBAL
compatible. The core then takes care field names are properly quoted for the
specific DMBS that is used.
......
......@@ -1787,40 +1787,6 @@ class ExtensionManagementUtilityTest extends UnitTestCase
ExtensionManagementUtility::unloadExtension($packageName);
}
/////////////////////////////////////////
// Tests concerning makeCategorizable
/////////////////////////////////////////
/**
* @test
*/
public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName()
{
$extensionKey = StringUtility::getUniqueId('extension');
$tableName = StringUtility::getUniqueId('table');
/** @var CategoryRegistry|\PHPUnit\Framework\MockObject\MockObject $registryMock */
$registryMock = $this->getMockBuilder(CategoryRegistry::class)->getMock();
$registryMock->expects(self::once())->method('add')->with($extensionKey, $tableName, 'categories', []);
GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName);
}
/**
* @test
*/
public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName()
{
$extensionKey = StringUtility::getUniqueId('extension');
$tableName = StringUtility::getUniqueId('table');
$fieldName = StringUtility::getUniqueId('field');
/** @var CategoryRegistry|\PHPUnit\Framework\MockObject\MockObject $registryMock */
$registryMock = $this->getMockBuilder(CategoryRegistry::class)->getMock();
$registryMock->expects(self::once())->method('add')->with($extensionKey, $tableName, $fieldName, []);
GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName, $fieldName);
}
///////////////////////////////
// Tests concerning addPlugin
///////////////////////////////
......
......@@ -15,7 +15,7 @@ declare(strict_types=1);
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Core\Tests\Unit\Category;
namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Category;
use TYPO3\CMS\Core\Category\CategoryRegistry;
use TYPO3\CMS\Core\Utility\StringUtility;
......
<?php
declare(strict_types=1);
/*
* 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!
*/
namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Utility;
use TYPO3\CMS\Core\Category\CategoryRegistry;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
class ExtensionManagementUtilityTest extends UnitTestCase
{
/**
* @var bool Reset singletons created by subject
*/
protected $resetSingletonInstances = true;
/**
* @test
*/
public function doesMakeCategorizableCallsTheCategoryRegistryWithDefaultFieldName(): void
{
$extensionKey = StringUtility::getUniqueId('extension');
$tableName = StringUtility::getUniqueId('table');
$registryMock = $this->getMockBuilder(CategoryRegistry::class)->getMock();
$registryMock->expects(self::once())->method('add')->with($extensionKey, $tableName, 'categories', []);
GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName);
}
/**
* @test
*/
public function doesMakeCategorizableCallsTheCategoryRegistryWithFieldName(): void
{
$extensionKey = StringUtility::getUniqueId('extension');
$tableName = StringUtility::getUniqueId('table');
$fieldName = StringUtility::getUniqueId('field');
$registryMock = $this->getMockBuilder(CategoryRegistry::class)->getMock();
$registryMock->expects(self::once())->method('add')->with($extensionKey, $tableName, $fieldName, []);
GeneralUtility::setSingletonInstance(CategoryRegistry::class, $registryMock);
ExtensionManagementUtility::makeCategorizable($extensionKey, $tableName, $fieldName);
}
}
......@@ -76,6 +76,7 @@ class LoadTcaService
}
// Apply category stuff
// @deprecated since v11, can be removed in v12
CategoryRegistry::getInstance()->applyTcaForPreRegisteredTables();
// Execute override files from Configuration/TCA/Overrides
......
......@@ -487,4 +487,9 @@ return [
'Important-94312-RemovedBEloginSecurityLevelAndFEloginSecurityLevelOptions.rst',
],
],
'$GLOBALS[\'TYPO3_CONF_VARS\'][\'SYS\'][\'defaultCategorizedTables\']' => [
'restFiles' => [
'Deprecation-85613-CategoryRegistry.rst',
],
],
];
......@@ -1759,4 +1759,9 @@ return [
'Deprecation-94654-GenericExtbaseDomainClasses.rst',
],
],
'TYPO3\CMS\Core\Category\CategoryRegistry' => [
'restFiles' => [
'Deprecation-85613-CategoryRegistry.rst',
],
],
];
......@@ -1135,4 +1135,11 @@ return [
'Deprecation-94414-DeprecateLanguageServiceContainerEntry.rst'
],
],
'TYPO3\CMS\Core\Utility\ExtensionManagementUtility::makeCategorizable' => [
'numberOfMandatoryArguments' => 2,
'maximumNumberOfArguments' => 5,
'restFiles' => [
'Deprecation-85613-CategoryRegistry.rst'
],
],
];
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment