‪TYPO3CMS  10.4
TYPO3\CMS\Core\Database\RelationHandler Class Reference

Public Member Functions

 setWorkspaceId ($workspaceId)
 
 setReferenceIndexUpdater (ReferenceIndexUpdater $updater)
 
bool isPurged ()
 
 start ($itemlist, $tablelist, $MMtable='', $MMuid=0, $currentTable='', $conf=[])
 
 setFetchAllFields ($allFields)
 
 setUpdateReferenceIndex ($updateReferenceIndex)
 
 setUseLiveParentIds ($useLiveParentIds)
 
 setUseLiveReferenceIds ($useLiveReferenceIds)
 
 readList ($itemlist, array $configuration)
 
 sortList ($sortby)
 
 readMM ($tableName, $uid)
 
 writeMM ($MM_tableName, $uid, $prependTableName=false)
 
 remapMM ($MM_tableName, $uid, $newUid, $prependTableName=false)
 
 readForeignField ($uid, $conf)
 
 writeForeignField ($conf, $parentUid, $updateToUid=0, $skipSorting=false)
 
array getValueArray ($prependTableName=false)
 
array getFromDB ()
 
array getResolvedItemArray ()
 
mixed countItems ($returnAsArray=true)
 
array updateRefIndex ($table, $uid)
 
bool convertItemArray ()
 
bool purgeItemArray ($workspaceId=null)
 
bool processDeletePlaceholder ()
 

Static Public Member Functions

static bool isOnSymmetricSide ($parentUid, $parentConf, $childRec)
 

Public Attributes

bool $registerNonTableValues = false
 
array $tableArray = array( )
 
array< int, $itemArray=array();public array $nonTableArray=array();public array $additionalWhere=array();public bool $checkIfDeleted=true;public string $firstTable='';public string $secondTable='';public bool $MM_is_foreign=false;public string $MM_oppositeField='';public string $MM_oppositeTable='';public array $MM_oppositeFieldConf=array();public string $MM_isMultiTableRelationship='';public string $currentTable;public bool $undeleteRecord;public array $MM_match_fields=array();public bool $MM_hasUidField;public array $MM_insert_fields=array();public string $MM_table_where='';protected array $MM_oppositeUsage;protected bool $updateReferenceIndex=true;protected ReferenceIndexUpdater|null $referenceIndexUpdater;protected bool $useLiveParentIds=true;protected bool $useLiveReferenceIds=true;protected int|null $workspaceId;protected bool $purged=false;public array $results=array();public int function getWorkspaceId():int { if(!isset( $this->workspaceId)) { $this-> workspaceId = (int)$GLOBALS['BE_USER']->workspace
 
return $this workspaceId
 

Protected Member Functions

bool purgeItemArrayHandler ($purgeCallback)
 
array purgeVersionedIds ($tableName, array $ids)
 
array purgeLiveVersionedIds ($tableName, array $ids)
 
array purgeDeletePlaceholder ($tableName, array $ids)
 
 removeFromItemArray ($tableName, $id)
 
array completeOppositeUsageValues ($tableName, array $referenceValues)
 
int getLiveDefaultId ($tableName, $id)
 
array sanitizeIds (array $ids)
 
PlainDataResolver getResolver ($tableName, array $ids, array $sortingStatement=null)
 
Connection getConnectionForTableName (string $tableName)
 

Protected Attributes

bool $fetchAllFields = false
 

Detailed Description

Load database groups (relations) Used to process the relations created by the TCA element types "group" and "select" for database records. Manages MM-relations as well.

Definition at line 34 of file RelationHandler.php.

Member Function Documentation

◆ completeOppositeUsageValues()

array TYPO3\CMS\Core\Database\RelationHandler::completeOppositeUsageValues (   $tableName,
array  $referenceValues 
)
protected

Completes MM values to be written by values from the opposite relation. This method used MM insert field or MM match fields if defined.

Parameters
string$tableName‪Name of the opposite table
array$referenceValues‪Values to be written
Returns
‪array Values to be written, possibly modified

Definition at line 1610 of file RelationHandler.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Database\RelationHandler\writeMM().

◆ convertItemArray()

bool TYPO3\CMS\Core\Database\RelationHandler::convertItemArray ( )

Converts elements in the local item array to use version ids instead of live ids, if possible. The most common use case is, to call that prior to processing with MM relations in a workspace context. For tha special case, ids on both side of the MM relation must use version ids if available.

Returns
‪bool Whether items have been converted

Definition at line 1321 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\getResolver(), TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled(), TYPO3\CMS\Core\DataHandling\PlainDataResolver\processVersionOverlays(), TYPO3\CMS\Core\DataHandling\PlainDataResolver\setKeepDeletePlaceholder(), and TYPO3\CMS\Core\DataHandling\PlainDataResolver\setKeepMovePlaceholder().

◆ countItems()

mixed TYPO3\CMS\Core\Database\RelationHandler::countItems (   $returnAsArray = true)

Counts the items in $this->itemArray and puts this value in an array by default.

Parameters
bool$returnAsArray‪Whether to put the count value in an array
Returns
‪mixed The plain count as integer or the same inside an array

Definition at line 1272 of file RelationHandler.php.

◆ getConnectionForTableName()

◆ getFromDB()

array TYPO3\CMS\Core\Database\RelationHandler::getFromDB ( )

Reads all records from internal tableArray into the internal ->results array where keys are table names and for each table, records are stored with uids as their keys. If $this->fetchAllFields is false you can save a little memory since only uid,pid and a few other fields are selected.

Returns
‪array

Definition at line 1190 of file RelationHandler.php.

References $fields, $GLOBALS, TYPO3\CMS\Core\Database\RelationHandler\getConnectionForTableName(), TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxBindParameters(), TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

◆ getLiveDefaultId()

int TYPO3\CMS\Core\Database\RelationHandler::getLiveDefaultId (   $tableName,
  $id 
)
protected

Gets the record uid of the live default record. If already pointing to the live record, the submitted record uid is returned.

Parameters
string$tableName
int$id
Returns
‪int

Definition at line 1639 of file RelationHandler.php.

References TYPO3\CMS\Backend\Utility\BackendUtility\getLiveVersionIdOfRecord().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\readForeignField(), TYPO3\CMS\Core\Database\RelationHandler\readList(), and TYPO3\CMS\Core\Database\RelationHandler\writeForeignField().

◆ getResolvedItemArray()

array TYPO3\CMS\Core\Database\RelationHandler::getResolvedItemArray ( )

This method is typically called after getFromDB(). $this->results holds a list of resolved and valid relations, $this->itemArray hold a list of "selected" relations from the incoming selection array. The difference is that "itemArray" may hold a single table/uid combination multiple times, for instance in a type=group relation having multiple=true, while "results" hold each resolved relation only once. The methods creates a sanitized "itemArray" from resolved "results" list, normalized the return array to always contain both table name and uid, and keep incoming "itemArray" sort order and keeps "multiple" selections.

Returns
‪array

Definition at line 1252 of file RelationHandler.php.

◆ getResolver()

PlainDataResolver TYPO3\CMS\Core\Database\RelationHandler::getResolver (   $tableName,
array  $ids,
array  $sortingStatement = null 
)
protected
Parameters
string$tableName
int[]$ids
array$sortingStatement
Returns
‪PlainDataResolver

Definition at line 1665 of file RelationHandler.php.

Referenced by TYPO3\CMS\Core\Database\RelationHandler\convertItemArray(), TYPO3\CMS\Core\Database\RelationHandler\readForeignField(), and TYPO3\CMS\Core\Database\RelationHandler\readList().

◆ getValueArray()

array TYPO3\CMS\Core\Database\RelationHandler::getValueArray (   $prependTableName = false)

After initialization you can extract an array of the elements from the object. Use this function for that.

Parameters
bool$prependTableName‪If set, then table names will ALWAYS be prepended (unless its a _NO_TABLE value)
Returns
‪array A numeric array.

Definition at line 1164 of file RelationHandler.php.

◆ isOnSymmetricSide()

static bool TYPO3\CMS\Core\Database\RelationHandler::isOnSymmetricSide (   $parentUid,
  $parentConf,
  $childRec 
)
static

Checks, if we're looking from the "other" side, the symmetric side, to a symmetric relation.

Parameters
string$parentUid‪The uid of the parent record
array$parentConf‪The TCA configuration of the parent field embedding the child records
array$childRec‪The record row of the child record
Returns
‪bool Returns TRUE if looking from the symmetric ("other") side to the relation.

Definition at line 1595 of file RelationHandler.php.

References TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\writeForeignField().

◆ isPurged()

bool TYPO3\CMS\Core\Database\RelationHandler::isPurged ( )

Whether item array has been purged in this instance.

Returns
‪bool

Definition at line 235 of file RelationHandler.php.

◆ processDeletePlaceholder()

bool TYPO3\CMS\Core\Database\RelationHandler::processDeletePlaceholder ( )

Removes items having a delete placeholder from $this->itemArray

Returns
‪bool Whether items have been purged

Definition at line 1394 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\purgeItemArrayHandler().

◆ purgeDeletePlaceholder()

array TYPO3\CMS\Core\Database\RelationHandler::purgeDeletePlaceholder (   $tableName,
array  $ids 
)
protected

◆ purgeItemArray()

bool TYPO3\CMS\Core\Database\RelationHandler::purgeItemArray (   $workspaceId = null)
Parameters
int | null$workspaceId
Returns
‪bool Whether items have been purged

Definition at line 1368 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\purgeItemArrayHandler().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\start().

◆ purgeItemArrayHandler()

bool TYPO3\CMS\Core\Database\RelationHandler::purgeItemArrayHandler (   $purgeCallback)
protected

Handles a purge callback on $this->itemArray

Parameters
string$purgeCallback
Returns
‪bool Whether items have been purged

Definition at line 1409 of file RelationHandler.php.

References TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled(), and TYPO3\CMS\Core\Database\RelationHandler\removeFromItemArray().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\processDeletePlaceholder(), and TYPO3\CMS\Core\Database\RelationHandler\purgeItemArray().

◆ purgeLiveVersionedIds()

array TYPO3\CMS\Core\Database\RelationHandler::purgeLiveVersionedIds (   $tableName,
array  $ids 
)
protected

Purges ids that are live but have an accordant version.

Parameters
string$tableName
array$ids
Returns
‪array

Definition at line 1487 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\getConnectionForTableName(), TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxBindParameters(), and TYPO3\CMS\Core\Database\RelationHandler\sanitizeIds().

◆ purgeVersionedIds()

array TYPO3\CMS\Core\Database\RelationHandler::purgeVersionedIds (   $tableName,
array  $ids 
)
protected

◆ readForeignField()

TYPO3\CMS\Core\Database\RelationHandler::readForeignField (   $uid,
  $conf 
)

◆ readList()

TYPO3\CMS\Core\Database\RelationHandler::readList (   $itemlist,
array  $configuration 
)

◆ readMM()

TYPO3\CMS\Core\Database\RelationHandler::readMM (   $tableName,
  $uid 
)

Reads the record tablename/id into the internal arrays itemArray and tableArray from MM records. You can call this function after start if you supply no list to start()

Parameters
string$tableName‪MM Tablename
int$uid‪Local UID

Definition at line 509 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\Connection\createQueryBuilder(), TYPO3\CMS\Core\Database\RelationHandler\getConnectionForTableName(), TYPO3\CMS\Core\Database\Query\QueryBuilder\getRestrictions(), TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface\removeAll(), and TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\start().

◆ remapMM()

TYPO3\CMS\Core\Database\RelationHandler::remapMM (   $MM_tableName,
  $uid,
  $newUid,
  $prependTableName = false 
)

Remaps MM table elements from one local uid to another Does NOT update the reference index for you, must be called subsequently to do that!

Parameters
string$MM_tableName‪MM table name
int$uid‪Local, current UID
int$newUid‪Local, new UID
bool$prependTableName‪If set, then table names will always be written.

Definition at line 839 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\andWhere(), TYPO3\CMS\Core\Database\Connection\createQueryBuilder(), TYPO3\CMS\Core\Database\Query\QueryBuilder\execute(), TYPO3\CMS\Core\Database\RelationHandler\getConnectionForTableName(), TYPO3\CMS\Core\Database\Query\QueryBuilder\set(), TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix(), TYPO3\CMS\Core\Database\Query\QueryBuilder\update(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\where().

◆ removeFromItemArray()

TYPO3\CMS\Core\Database\RelationHandler::removeFromItemArray (   $tableName,
  $id 
)
protected

◆ sanitizeIds()

array TYPO3\CMS\Core\Database\RelationHandler::sanitizeIds ( array  $ids)
protected

◆ setFetchAllFields()

TYPO3\CMS\Core\Database\RelationHandler::setFetchAllFields (   $allFields)

Sets $fetchAllFields

Parameters
bool$allFields‪enables fetching of all fields in getFromDB()

Definition at line 338 of file RelationHandler.php.

◆ setReferenceIndexUpdater()

TYPO3\CMS\Core\Database\RelationHandler::setReferenceIndexUpdater ( ReferenceIndexUpdater  $updater)

Setter to carry the 'deferred' reference index updater registry around.

Parameters
ReferenceIndexUpdater$updater

Used internally within DataHandler only

Definition at line 225 of file RelationHandler.php.

◆ setUpdateReferenceIndex()

TYPO3\CMS\Core\Database\RelationHandler::setUpdateReferenceIndex (   $updateReferenceIndex)

Sets whether the reference index shall be updated.

Parameters
bool$updateReferenceIndex‪Whether the reference index shall be updated
Todo:
‪: Unused in core, should be removed, use ReferenceIndexUpdater instead

Definition at line 349 of file RelationHandler.php.

◆ setUseLiveParentIds()

TYPO3\CMS\Core\Database\RelationHandler::setUseLiveParentIds (   $useLiveParentIds)
Parameters
bool$useLiveParentIds

Definition at line 357 of file RelationHandler.php.

◆ setUseLiveReferenceIds()

TYPO3\CMS\Core\Database\RelationHandler::setUseLiveReferenceIds (   $useLiveReferenceIds)
Parameters
bool$useLiveReferenceIds

Definition at line 365 of file RelationHandler.php.

◆ setWorkspaceId()

TYPO3\CMS\Core\Database\RelationHandler::setWorkspaceId (   $workspaceId)

Sets the current workspace id.

Parameters
int$workspaceId

Definition at line 214 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\workspaceId.

◆ sortList()

TYPO3\CMS\Core\Database\RelationHandler::sortList (   $sortby)

Does a sorting on $this->itemArray depending on a default sortby field. This is only used for automatic sorting of comma separated lists. This function is only relevant for data that is stored in comma separated lists!

Parameters
string$sortby‪The default_sortby field/command (e.g. 'price DESC')

Definition at line 457 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\getConnectionForTableName(), TYPO3\CMS\Core\Database\Platform\PlatformInformation\getMaxBindParameters(), and TYPO3\CMS\Core\Database\Query\QueryHelper\parseOrderBy().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\start().

◆ start()

TYPO3\CMS\Core\Database\RelationHandler::start (   $itemlist,
  $tablelist,
  $MMtable = '',
  $MMuid = 0,
  $currentTable = '',
  $conf = [] 
)

Initialization of the class.

Parameters
string$itemlist‪List of group/select items
string$tablelist‪Comma list of tables, first table takes priority if no table is set for an entry in the list.
string$MMtable‪Name of a MM table.
int$MMuid‪Local UID for MM lookup
string$currentTable‪Current table name
array$conf‪TCA configuration for current field

Definition at line 250 of file RelationHandler.php.

References $GLOBALS, TYPO3\CMS\Core\Database\RelationHandler\purgeItemArray(), TYPO3\CMS\Core\Database\RelationHandler\readForeignField(), TYPO3\CMS\Core\Database\RelationHandler\readList(), TYPO3\CMS\Core\Database\RelationHandler\readMM(), TYPO3\CMS\Core\Database\RelationHandler\sortList(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

◆ updateRefIndex()

array TYPO3\CMS\Core\Database\RelationHandler::updateRefIndex (   $table,
  $uid 
)

Update Reference Index (sys_refindex) for a record. Should be called any almost any update to a record which could affect references inside the record. If used from within DataHandler, only registers a row for update for later processing.

Parameters
string$table‪Table name
int$uid‪Record uid
Returns
‪array Result from ReferenceIndex->updateRefIndexTable() updated directly, else empty array

Should be protected

Definition at line 1291 of file RelationHandler.php.

References TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\writeForeignField(), and TYPO3\CMS\Core\Database\RelationHandler\writeMM().

◆ writeForeignField()

TYPO3\CMS\Core\Database\RelationHandler::writeForeignField (   $conf,
  $parentUid,
  $updateToUid = 0,
  $skipSorting = false 
)

Write the sorting values to a foreign_table, that has a foreign_field (uid of the parent record)

Parameters
array$conf‪TCA configuration for current field
int$parentUid‪The uid of the parent record
int$updateToUid‪If this is larger than zero it will be used as foreign UID instead of the given $parentUid (on Copy)
bool$skipSorting‪Do not update the sorting columns, this could happen for imported values

Definition at line 1029 of file RelationHandler.php.

References $fields, $GLOBALS, TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger(), TYPO3\CMS\Core\Type\Enumeration\cast(), TYPO3\CMS\Core\Database\RelationHandler\getConnectionForTableName(), TYPO3\CMS\Core\Database\RelationHandler\getLiveDefaultId(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecord(), TYPO3\CMS\Core\Database\RelationHandler\isOnSymmetricSide(), TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled(), TYPO3\CMS\Core\Versioning\VersionState\NEW_PLACEHOLDER_VERSION, TYPO3\CMS\Core\Database\Query\QueryHelper\parseOrderBy(), TYPO3\CMS\Core\Database\Connection\update(), and TYPO3\CMS\Core\Database\RelationHandler\updateRefIndex().

◆ writeMM()

TYPO3\CMS\Core\Database\RelationHandler::writeMM (   $MM_tableName,
  $uid,
  $prependTableName = false 
)

Writes the internal itemArray to MM table:

Parameters
string$MM_tableName‪MM table name
int$uid‪Local UID
bool$prependTableName‪If set, then table names will always be written.

Definition at line 596 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\completeOppositeUsageValues(), TYPO3\CMS\Core\Database\RelationHandler\getConnectionForTableName(), TYPO3\CMS\Core\Database\Query\QueryHelper\stripLogicalOperatorPrefix(), and TYPO3\CMS\Core\Database\RelationHandler\updateRefIndex().

Member Data Documentation

◆ $fetchAllFields

bool TYPO3\CMS\Core\Database\RelationHandler::$fetchAllFields = false
protected

$fetchAllFields if false getFromDB() fetches only uid, pid, thumbnail and label fields (as defined in TCA)

Definition at line 40 of file RelationHandler.php.

◆ $registerNonTableValues

bool TYPO3\CMS\Core\Database\RelationHandler::$registerNonTableValues = false

If set, values that are not ids in tables are normally discarded. By this options they will be preserved.

Definition at line 46 of file RelationHandler.php.

◆ $tableArray

array TYPO3\CMS\Core\Database\RelationHandler::$tableArray = array( )

Contains the table names as keys. The values are the id-values for each table. Should ONLY contain proper table names.

Definition at line 53 of file RelationHandler.php.

◆ workspaceId [1/2]

array<int, $itemArray = array( ); public array $nonTableArray = array( ); public array $additionalWhere = array( ); public bool $checkIfDeleted = true; public string $firstTable = ''; public string $secondTable = ''; public bool $MM_is_foreign = false; public string $MM_oppositeField = ''; public string $MM_oppositeTable = ''; public array $MM_oppositeFieldConf = array( ); public string $MM_isMultiTableRelationship = ''; public string $currentTable; public bool $undeleteRecord; public array $MM_match_fields = array( ); public bool $MM_hasUidField; public array $MM_insert_fields = array( ); public string $MM_table_where = ''; protected array $MM_oppositeUsage; protected bool $updateReferenceIndex = true; protected ReferenceIndexUpdater|null $referenceIndexUpdater; protected bool $useLiveParentIds = true; protected bool $useLiveReferenceIds = true; protected int|null $workspaceId; protected bool $purged = false; public array $results = array( ); public int function getWorkspaceId(): int { if (!isset($this->workspaceId)) { $this-> TYPO3\CMS\Core\Database\RelationHandler::workspaceId = (int)$GLOBALS['BE_USER']->workspace

Contains items in a numeric array (table/id for each). Tablenames here might be "_NO_TABLE"

array<string, mixed>>

Definition at line 204 of file RelationHandler.php.

Referenced by TYPO3\CMS\Core\Database\RelationHandler\setWorkspaceId().

◆ workspaceId [2/2]

return $this TYPO3\CMS\Core\Database\RelationHandler::workspaceId

Definition at line 206 of file RelationHandler.php.