‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Database\ReferenceIndex Class Reference

Public Member Functions

 __construct (private readonly EventDispatcherInterface $eventDispatcher, private readonly SoftReferenceParserFactory $softReferenceParserFactory, private readonly ConnectionPool $connectionPool, private readonly Registry $registry, private readonly FlexFormTools $flexFormTools,)
 getNumberOfReferencedRecords (string $tableName, int $uid)
array updateIndex (bool $testOnly, ?ProgressListenerInterface $progressListener=null)
array updateRefIndexTable (string $tableName, int $uid, bool $testOnly=false, int $workspaceUid=0, array $currentRecord=null)
array getRelations (string $tableName, array $record, int $workspaceUid)

Public Attributes

 $queryBuilder = $connection->createQueryBuilder()
 $currentRelationHashes = []
while($relation=$queryResult->fetchAssociative()) return $currentRelationHashes

Private Member Functions

array< string, getCurrentRelationHashes(string $tableName, int $uid, int $workspaceUid):array { $connection=$this-> connectionPool getConnectionForTable ('sys_refindex')
 removeRelationHashes (array $currentRelationHashes)
 compileReferenceIndexRowsForRecord (string $tableName, array $record, int $workspaceUid)
 getRelationsFromFlexData (string $tableName, string $fieldName, array $row, int $workspaceUid)
 getRelationsFromRelationField (string $tableName, mixed $fieldValue, array $conf, int $uid, int $workspaceUid, array $row=[])
bool isDbReferenceField (array $configuration)
 isReferenceField (array $configuration)
 getTableRelationFields (string $tableName)
int[] getListOfActiveWorkspaces ()
 getNumberOfUnusedWorkspaceRowsInReferenceIndex (array $activeWorkspaces)
 removeUnusedWorkspaceRowsFromReferenceIndex (array $activeWorkspaces)
 getNumberOfUnusedTablesInReferenceIndex (array $tableNames)
 removeReferenceIndexDataFromUnusedDatabaseTables (array $tableNames)
 shouldExcludeTableFromReferenceIndex (string $tableName)

Private Attributes

const HASH_VERSION = 1
array $excludedTables
array $tableRelationFieldCache = []

Detailed Description

Reference index processing and relation extraction.

Extensions shouldn't fiddle with the reference index themselves, it's task of DataHandler to do this.

Definition at line 39 of file ReferenceIndex.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Database\ReferenceIndex::__construct ( private readonly EventDispatcherInterface  $eventDispatcher,
private readonly SoftReferenceParserFactory  $softReferenceParserFactory,
private readonly ConnectionPool  $connectionPool,
private readonly Registry  $registry,
private readonly FlexFormTools  $flexFormTools 

Definition at line 62 of file ReferenceIndex.php.

Member Function Documentation

◆ compileReferenceIndexRowsForRecord()

TYPO3\CMS\Core\Database\ReferenceIndex::compileReferenceIndexRowsForRecord ( string  $tableName,
array  $record,
int  $workspaceUid 

◆ getConnectionForTable()

array<string, getCurrentRelationHashes(string $tableName, int $uid, int $workspaceUid): array { $connection = $this-> connectionPool TYPO3\CMS\Core\Database\ReferenceIndex::getConnectionForTable ( 'sys_refindex'  )

Get current sys_refindex rows of table:uid from database with hash as index.

‪array<string, true>

◆ getListOfActiveWorkspaces()

int [] TYPO3\CMS\Core\Database\ReferenceIndex::getListOfActiveWorkspaces ( )

Create list of non-deleted "active" workspace uids. This contains at least 0 "live workspace".


Definition at line 896 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded().

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateIndex().

◆ getNumberOfReferencedRecords()

TYPO3\CMS\Core\Database\ReferenceIndex::getNumberOfReferencedRecords ( string  $tableName,
int  $uid 

Returns the amount of references for the given record.

Definition at line 73 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\ReferenceIndex\$queryBuilder, TYPO3\CMS\Webhooks\Message\$uid, and TYPO3\CMS\Core\Database\Connection\PARAM_INT.

◆ getNumberOfUnusedTablesInReferenceIndex()

TYPO3\CMS\Core\Database\ReferenceIndex::getNumberOfUnusedTablesInReferenceIndex ( array  $tableNames)

When a TCA table with references has been removed, there may be old sys_refindex rows for it. The query finds the number of affected rows.

Definition at line 954 of file ReferenceIndex.php.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateIndex().

◆ getNumberOfUnusedWorkspaceRowsInReferenceIndex()

TYPO3\CMS\Core\Database\ReferenceIndex::getNumberOfUnusedWorkspaceRowsInReferenceIndex ( array  $activeWorkspaces)

Helper method of updateIndex() to find number of rows in sys_refindex that relate to a non-existing or deleted workspace record, even if workspaces is not loaded at all, but has been loaded somewhere in the past and sys_refindex rows have been created.

Definition at line 920 of file ReferenceIndex.php.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateIndex().

◆ getRelations()

array TYPO3\CMS\Core\Database\ReferenceIndex::getRelations ( string  $tableName,
array  $record,
int  $workspaceUid 

Returns relation information for a record from a TCA table.

‪array Array with information about relations

Definition at line 447 of file ReferenceIndex.php.

◆ getRelationsFromFlexData()

TYPO3\CMS\Core\Database\ReferenceIndex::getRelationsFromFlexData ( string  $tableName,
string  $fieldName,
array  $row,
int  $workspaceUid 

◆ getRelationsFromRelationField()

TYPO3\CMS\Core\Database\ReferenceIndex::getRelationsFromRelationField ( string  $tableName,
mixed  $fieldValue,
array  $conf,
int  $uid,
int  $workspaceUid,
array  $row = [] 

Check field configuration if it is a DB relation field and extract DB relations if any

Definition at line 785 of file ReferenceIndex.php.

References TYPO3\CMS\Webhooks\Message\$uid, and TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded().

◆ getTableRelationFields()

TYPO3\CMS\Core\Database\ReferenceIndex::getTableRelationFields ( string  $tableName)

List of TCA columns that can have relations. Typically inline, group and friends, as well as flex fields and fields with 'softref' config. If empty, the table can not have relations. Uses a class cache to be quick for multiple calls on same table.

Definition at line 869 of file ReferenceIndex.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateIndex(), and TYPO3\CMS\Core\Database\ReferenceIndex\updateRefIndexTable().

◆ isDbReferenceField()

bool TYPO3\CMS\Core\Database\ReferenceIndex::isDbReferenceField ( array  $configuration)

Returns true if the TCA/columns field type is a DB reference field

array$configuration‪Config array for TCA/columns field
‪bool TRUE if DB reference field (group/db or select with foreign-table)

Definition at line 838 of file ReferenceIndex.php.

◆ isReferenceField()

TYPO3\CMS\Core\Database\ReferenceIndex::isReferenceField ( array  $configuration)

Returns true if the TCA/columns field may carry references. True for group, inline and friends, for flex, and if there is a 'softref' definition.

Definition at line 852 of file ReferenceIndex.php.

◆ removeReferenceIndexDataFromUnusedDatabaseTables()

TYPO3\CMS\Core\Database\ReferenceIndex::removeReferenceIndexDataFromUnusedDatabaseTables ( array  $tableNames)

When a TCA table with references has been removed, there may be old sys_refindex rows for it. The query deletes those.

Definition at line 973 of file ReferenceIndex.php.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateIndex().

◆ removeRelationHashes()

TYPO3\CMS\Core\Database\ReferenceIndex::removeRelationHashes ( array  $currentRelationHashes)

Remove sys_refindex rows by hash.


Definition at line 531 of file ReferenceIndex.php.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateRefIndexTable().

◆ removeUnusedWorkspaceRowsFromReferenceIndex()

TYPO3\CMS\Core\Database\ReferenceIndex::removeUnusedWorkspaceRowsFromReferenceIndex ( array  $activeWorkspaces)

Delete sys_refindex rows of deleted / not existing workspace records, or all if ext:workspace is not loaded.

Definition at line 938 of file ReferenceIndex.php.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateIndex().

◆ shouldExcludeTableFromReferenceIndex()

TYPO3\CMS\Core\Database\ReferenceIndex::shouldExcludeTableFromReferenceIndex ( string  $tableName)

Checks if a given table should be excluded from ReferenceIndex

Definition at line 988 of file ReferenceIndex.php.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateIndex(), and TYPO3\CMS\Core\Database\ReferenceIndex\updateRefIndexTable().

◆ updateIndex()

◆ updateRefIndexTable()

array TYPO3\CMS\Core\Database\ReferenceIndex::updateRefIndexTable ( string  $tableName,
int  $uid,
bool  $testOnly = false,
int  $workspaceUid = 0,
array  $currentRecord = null 

Update the sys_refindex table for a record, even one just deleted. This is used by DataHandler ReferenceIndexUpdater as entry method to take care of single records. It is also used internally via updateIndex() by CLI "referenceindex:update" and lowlevel BE module.

array | null$currentRecord‪Current full (select *) record from DB. Optimization for updateIndex().
‪array Statistics about how many index records were added, deleted and not altered.

Definition at line 379 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\ReferenceIndex\$currentRelationHashes, TYPO3\CMS\Webhooks\Message\$uid, TYPO3\CMS\Core\Database\ReferenceIndex\compileReferenceIndexRowsForRecord(), TYPO3\CMS\Core\Database\ReferenceIndex\getTableRelationFields(), TYPO3\CMS\Core\Database\ReferenceIndex\removeRelationHashes(), and TYPO3\CMS\Core\Database\ReferenceIndex\shouldExcludeTableFromReferenceIndex().

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateIndex().

Member Data Documentation

◆ $currentRelationHashes [1/2]

TYPO3\CMS\Core\Database\ReferenceIndex::$currentRelationHashes = []

◆ $currentRelationHashes [2/2]

while ( $relation=$queryResult->fetchAssociative()) return TYPO3\CMS\Core\Database\ReferenceIndex::$currentRelationHashes

Definition at line 523 of file ReferenceIndex.php.

◆ $excludedTables

array TYPO3\CMS\Core\Database\ReferenceIndex::$excludedTables
Initial value:
= [
'sys_log' => true,
'tx_extensionmanager_domain_model_extension' => true,

Key list of tables to exclude from ReferenceIndex. Only $GLOBALS['TCA'] need to be listed here, if at all. This is a performance improvement to skip tables "irrelevant" in refindex scope, for instance sys_log. An event may alter this. The list depends on TCA and an event, entries are managed once per class instance. Array with fields as keys and booleans as values for fast isset() lookup instead of slower in_array().

Definition at line 51 of file ReferenceIndex.php.

◆ $queryBuilder

TYPO3\CMS\Core\Database\ReferenceIndex::$queryBuilder = $connection->createQueryBuilder()

◆ $queryResult

Initial value:
= ‪$queryBuilder->select('hash')->from('sys_refindex')->where(
‪$queryBuilder->expr()->eq('tablename', ‪$queryBuilder->createNamedParameter($tableName)),
‪$queryBuilder->expr()->eq('recuid', ‪$queryBuilder->createNamedParameter(‪$uid, ‪Connection::PARAM_INT)),
‪$queryBuilder->expr()->eq('workspace', ‪$queryBuilder->createNamedParameter($workspaceUid, ‪Connection::PARAM_INT))

Definition at line 514 of file ReferenceIndex.php.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\updateIndex().

◆ $tableRelationFieldCache

array TYPO3\CMS\Core\Database\ReferenceIndex::$tableRelationFieldCache = []

A list of fields that may contain relations per TCA table. The list depends on TCA, entries are created once per table, per class instance.

Definition at line 60 of file ReferenceIndex.php.


const TYPO3\CMS\Core\Database\ReferenceIndex::HASH_VERSION = 1

Definition at line 42 of file ReferenceIndex.php.

‪const PARAM_INT
Definition: Connection.php:50
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
Definition: ReferenceIndex.php:512