‪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()
 
 $queryResult
 
 $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 59 of file ReferenceIndex.php.

Member Function Documentation

◆ compileReferenceIndexRowsForRecord()

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

◆ getConnectionForTable()

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

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

Returns
‪array<string, true>

◆ getListOfActiveWorkspaces()

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

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

Returns
‪int[]

Definition at line 893 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 70 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)
private

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 947 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\Connection\PARAM_STR_ARRAY.

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

◆ getNumberOfUnusedWorkspaceRowsInReferenceIndex()

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

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 913 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\Connection\PARAM_INT_ARRAY.

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.

Returns
‪array Array with information about relations

Definition at line 444 of file ReferenceIndex.php.

◆ getRelationsFromFlexData()

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

◆ getRelationsFromRelationField()

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

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

Definition at line 782 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)
private

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 866 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)
private

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

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

Definition at line 835 of file ReferenceIndex.php.

◆ isReferenceField()

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

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 849 of file ReferenceIndex.php.

◆ removeReferenceIndexDataFromUnusedDatabaseTables()

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

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 966 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\Connection\PARAM_STR_ARRAY.

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

◆ removeRelationHashes()

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

Remove sys_refindex rows by hash.

Parameters
array<string,true>‪$currentRelationHashes

Definition at line 528 of file ReferenceIndex.php.

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

◆ removeUnusedWorkspaceRowsFromReferenceIndex()

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

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

Definition at line 931 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\Connection\PARAM_INT_ARRAY.

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

◆ shouldExcludeTableFromReferenceIndex()

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

Checks if a given table should be excluded from ReferenceIndex

Definition at line 981 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.

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

Definition at line 376 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 520 of file ReferenceIndex.php.

◆ $excludedTables

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

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. 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

TYPO3\CMS\Core\Database\ReferenceIndex::$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))
)->executeQuery()

Definition at line 511 of file ReferenceIndex.php.

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

◆ $tableRelationFieldCache

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

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 57 of file ReferenceIndex.php.

◆ HASH_VERSION

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

Definition at line 42 of file ReferenceIndex.php.

‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Core\Database\ReferenceIndex\$queryBuilder
‪$queryBuilder
Definition: ReferenceIndex.php:509