Deprecation: #102793 - PageRepository->enableFields

See forge#102793

Description

One of the common PHP APIs used in TYPO3 Core for fetching records is \TYPO3\CMS\Core\Domain\Repository\PageRepository. The method enableFields() is used to enhance a database query with additional restrictions such as filtering out versioned records from workspaces, hidden database entries or scheduled database entries.

This method has been marked as deprecated in favor of a new method getDefaultConstraints().

Impact

Calling the method will trigger a PHP deprecation warning.

Affected installations

TYPO3 installations with custom extensions using the method enableFields() of the PageRepository class.

Migration

A new method called getDefaultConstraints() has been introduced which supersedes the old method. The new method returns an array of CompositeExpression objects, which can be used instead.

Before (TYPO3 v12)

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
    ->getQueryBuilderForTable($tableName);

$constraints = GeneralUtility::makeInstance(PageRepository::class)
    ->enableFields($tableName);

$queryBuilder
    ->select('*')
    ->from($tableName);
    ->where(QueryHelper::stripLogicalOperatorPrefix($constraints);

$queryBuilder->execute();
Copied!

After (TYPO3 v13)

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
    ->getQueryBuilderForTable($tableName);

$constraints = GeneralUtility::makeInstance(PageRepository::class)
    ->getDefaultConstraints($tableName);

$queryBuilder
    ->select('*')
    ->from($tableName);

if ($constraints !== []) {
    $queryBuilder->where(...$constraints);
}

$queryBuilder->execute();
Copied!