‪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, private readonly TcaSchemaFactory $tcaSchemaFactory,)
 
 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)
 
 enrichInlineRelations (string $tableName, array $itemArray)
 
 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 (FieldTypeInterface $field)
 
 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 47 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,
private readonly TcaSchemaFactory  $tcaSchemaFactory 
)

Definition at line 72 of file ReferenceIndex.php.

Member Function Documentation

◆ compileReferenceIndexRowsForRecord()

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

◆ enrichInlineRelations()

TYPO3\CMS\Core\Database\ReferenceIndex::enrichInlineRelations ( string  $tableName,
array  $itemArray 
)
private

RelationHandler does not return relation record details when dealing with inline foreign_table relations. We need fields like hidden and starrtime, though. Fetch them now.

Definition at line 794 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\ReferenceIndex\$queryBuilder, TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxBindParameters(), and TYPO3\CMS\Core\Database\Connection\PARAM_INT_ARRAY.

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

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

References TYPO3\CMS\Core\Database\ReferenceIndex\$queryBuilder, and 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 84 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 1094 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\ReferenceIndex\$queryBuilder, and 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 1060 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\ReferenceIndex\$queryBuilder, and 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 
)

◆ 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

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

References TYPO3\CMS\Core\Database\ReferenceIndex\isReferenceField().

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\getRelations(), 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 990 of file ReferenceIndex.php.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\getRelationsFromRelationField(), and TYPO3\CMS\Core\Database\ReferenceIndex\isReferenceField().

◆ isReferenceField()

TYPO3\CMS\Core\Database\ReferenceIndex::isReferenceField ( FieldTypeInterface  $field)
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 1004 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Schema\Field\FieldTypeInterface\getConfiguration(), TYPO3\CMS\Core\Database\ReferenceIndex\isDbReferenceField(), and TYPO3\CMS\Core\Schema\Field\FieldTypeInterface\isType().

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

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

References TYPO3\CMS\Core\Database\ReferenceIndex\$queryBuilder, and 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

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

References TYPO3\CMS\Core\Database\ReferenceIndex\$queryBuilder, and 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 1128 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 383 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 524 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 64 of file ReferenceIndex.php.

◆ $queryBuilder

◆ $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 515 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 70 of file ReferenceIndex.php.

◆ HASH_VERSION

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

Definition at line 55 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:513