TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Database\ReferenceIndex Class Reference

Public Member Functions

 __construct ()
 
 setWorkspaceId ($workspaceId)
 
 getWorkspaceId ()
 
 updateRefIndexTable ($tableName, $uid, $testOnly=false)
 
 generateRefIndexData ($tableName, $uid)
 
 createEntryData ($table, $uid, $field, $flexPointer, $deleted, $ref_table, $ref_uid, $ref_string='', $sort=-1, $softref_key='', $softref_id='')
 
 createEntryData_dbRels ($table, $uid, $fieldName, $flexPointer, $deleted, $items)
 
 createEntryData_fileRels ($table, $uid, $fieldName, $flexPointer, $deleted, $items)
 
 createEntryData_softreferences ($table, $uid, $fieldName, $flexPointer, $deleted, $keys)
 
 getRelations ($table, $row, $onlyField='')
 
 getRelations_flexFormCallBack ($dsArr, $dataValue, $PA, $structurePath, $parentObject)
 
 getRelations_procFiles ($value, $conf, $uid)
 
 getRelations_procDB ($value, $conf, $uid, $table='', $field='')
 
 setReferenceValue ($hash, $newValue, $returnDataArray=false, $bypassWorkspaceAdminCheck=false)
 
 setReferenceValue_dbRels ($refRec, $itemArray, $newValue, &$dataArray, $flexPointer='')
 
 setReferenceValue_fileRels ($refRec, $itemArray, $newValue, &$dataArray, $flexPointer='')
 
 setReferenceValue_softreferences ($refRec, $softref, $newValue, &$dataArray, $flexPointer='')
 
 isReferenceField (array $configuration)
 
 destPathFromUploadFolder ($folder)
 
 error ($msg)
 

Public Attributes

 $temp_flexRelations = []
 
 $errorLog = []
 
 $WSOL = false
 
 $relations = []
 
 $hashVersion = 1
 

Protected Member Functions

 isDbReferenceField (array $configuration)
 
 fetchTableRelationFields ($tableName)
 
 getDatabaseConnection ()
 
 getBackendUser ()
 

Protected Attributes

 $workspaceId = 0
 
 $runtimeCache = null
 

Static Protected Attributes

static $nonRelationTables
 
static $nonRelationFields
 
static $cachePrefixTableRelationFields = 'core-refidx-tblRelFields-'
 

Detailed Description

Reference index processing and relation extraction

NOTICE: When the reference index is updated for an offline version the results may not be correct. First, lets assumed that the reference update happens in LIVE workspace (ALWAYS update from Live workspace if you analyse whole database!) Secondly, lets assume that in a Draft workspace you have changed the data structure of a parent page record - this is (in TemplaVoila) inherited by subpages. When in the LIVE workspace the data structure for the records/pages in the offline workspace will not be evaluated to the right one simply because the data structure is taken from a rootline traversal and in the Live workspace that will NOT include the changed DataStructure! Thus the evaluation will be based on the Data Structure set in the Live workspace! Somehow this scenario is rarely going to happen. Yet, it is an inconsistency and I see now practical way to handle it - other than simply ignoring maintaining the index for workspace records. Or we can say that the index is precise for all Live elements while glitches might happen in an offline workspace? Anyway, I just wanted to document this finding - I don't think we can find a solution for it. And its very TemplaVoila specific.

Definition at line 43 of file ReferenceIndex.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Database\ReferenceIndex::__construct ( )

Constructor

Definition at line 153 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance().

Member Function Documentation

◆ createEntryData()

TYPO3\CMS\Core\Database\ReferenceIndex::createEntryData (   $table,
  $uid,
  $field,
  $flexPointer,
  $deleted,
  $ref_table,
  $ref_uid,
  $ref_string = '',
  $sort = -1,
  $softref_key = '',
  $softref_id = '' 
)

Create array with field/value pairs ready to insert in database. The "hash" field is a fingerprint value across this table.

Parameters
string$tableTablename of source record (where reference is located)
int$uidUID of source record (where reference is located)
string$fieldFieldname of source record (where reference is located)
string$flexPointerPointer to location inside FlexForm structure where reference is located in [field]
int$deletedWhether record is deleted-flagged or not
string$ref_tableFor database references; the tablename the reference points to. Special keyword "_FILE" indicates that "ref_string" is a file reference either absolute or relative to PATH_site. Special keyword "_STRING" indicates some special usage (typ. softreference) where "ref_string" is used for the value.
int$ref_uidFor database references; The UID of the record (zero "ref_table" is "_FILE" or "_STRING")
string$ref_stringFor "_FILE" or "_STRING" references: The filepath (relative to PATH_site or absolute) or other string.
int$sortThe sorting order of references if many (the "group" or "select" TCA types). -1 if no sorting order is specified.
string$softref_keyIf the reference is a soft reference, this is the soft reference parser key. Otherwise empty.
string$softref_idSoft reference ID for key. Might be useful for replace operations.
Returns
array Array record to insert into table.

Definition at line 390 of file ReferenceIndex.php.

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\createEntryData_dbRels(), TYPO3\CMS\Core\Database\ReferenceIndex\createEntryData_fileRels(), and TYPO3\CMS\Core\Database\ReferenceIndex\createEntryData_softreferences().

◆ createEntryData_dbRels()

TYPO3\CMS\Core\Database\ReferenceIndex::createEntryData_dbRels (   $table,
  $uid,
  $fieldName,
  $flexPointer,
  $deleted,
  $items 
)

Enter database references to ->relations array

Parameters
string$tableTablename of source record (where reference is located)
int$uidUID of source record (where reference is located)
string$fieldNameFieldname of source record (where reference is located)
string$flexPointerPointer to location inside FlexForm structure where reference is located in [field]
int$deletedWhether record is deleted-flagged or not
array$itemsData array with database relations (table/id)
Returns
void

Definition at line 427 of file ReferenceIndex.php.

References $uid, and TYPO3\CMS\Core\Database\ReferenceIndex\createEntryData().

◆ createEntryData_fileRels()

TYPO3\CMS\Core\Database\ReferenceIndex::createEntryData_fileRels (   $table,
  $uid,
  $fieldName,
  $flexPointer,
  $deleted,
  $items 
)

Enter file references to ->relations array

Parameters
string$tableTablename of source record (where reference is located)
int$uidUID of source record (where reference is located)
string$fieldNameFieldname of source record (where reference is located)
string$flexPointerPointer to location inside FlexForm structure where reference is located in [field]
int$deletedWhether record is deleted-flagged or not
array$itemsData array with file relations
Returns
void

Definition at line 445 of file ReferenceIndex.php.

References $uid, TYPO3\CMS\Core\Database\ReferenceIndex\createEntryData(), TYPO3\CMS\Core\Utility\GeneralUtility\isFirstPartOfStr(), and TYPO3\CMS\Core\Utility\PathUtility\stripPathSitePrefix().

◆ createEntryData_softreferences()

TYPO3\CMS\Core\Database\ReferenceIndex::createEntryData_softreferences (   $table,
  $uid,
  $fieldName,
  $flexPointer,
  $deleted,
  $keys 
)

Enter softref references to ->relations array

Parameters
string$tableTablename of source record (where reference is located)
int$uidUID of source record (where reference is located)
string$fieldNameFieldname of source record (where reference is located)
string$flexPointerPointer to location inside FlexForm structure
int$deleted
array$keysData array with soft reference keys
Returns
void

Definition at line 467 of file ReferenceIndex.php.

References $uid, and TYPO3\CMS\Core\Database\ReferenceIndex\createEntryData().

◆ destPathFromUploadFolder()

TYPO3\CMS\Core\Database\ReferenceIndex::destPathFromUploadFolder (   $folder)

Returns destination path to an upload folder given by $folder

Parameters
string$folderFolder relative to PATH_site
Returns
string Input folder prefixed with PATH_site. No checking for existence is done. Output must be a folder without trailing slash.

Definition at line 1136 of file ReferenceIndex.php.

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

◆ error()

TYPO3\CMS\Core\Database\ReferenceIndex::error (   $msg)

Sets error message in the internal error log

Parameters
string$msgError message
Returns
void
Deprecated:
since TYPO3 CMS 7, will be removed in TYPO3 CMS 8

Definition at line 1151 of file ReferenceIndex.php.

◆ fetchTableRelationFields()

TYPO3\CMS\Core\Database\ReferenceIndex::fetchTableRelationFields (   $tableName)
protected

Returns all fields of a table which could contain a relation

Parameters
string$tableNameName of the table
Returns
string Fields which could contain a relation

Definition at line 1104 of file ReferenceIndex.php.

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

◆ generateRefIndexData()

TYPO3\CMS\Core\Database\ReferenceIndex::generateRefIndexData (   $tableName,
  $uid 
)

Returns array of arrays with an index of all references found in record from table/uid If the result is used to update the sys_refindex table then ->WSOL must NOT be TRUE (no workspace overlay anywhere!)

Parameters
string$tableNameTable name from $GLOBALS['TCA']
int$uidRecord UID
Returns
array|NULL Index Rows

Definition at line 286 of file ReferenceIndex.php.

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

◆ getBackendUser()

TYPO3\CMS\Core\Database\ReferenceIndex::getBackendUser ( )
protected

Returns the current BE user.

Returns

Definition at line 1278 of file ReferenceIndex.php.

◆ getDatabaseConnection()

TYPO3\CMS\Core\Database\ReferenceIndex::getDatabaseConnection ( )
protected

◆ getRelations()

TYPO3\CMS\Core\Database\ReferenceIndex::getRelations (   $table,
  $row,
  $onlyField = '' 
)

Returns relation information for a $table/$row-array Traverses all fields in input row which are configured in TCA/columns It looks for hard relations to files and records in the TCA types "select" and "group"

Parameters
string$tableTable name
array$rowRow from table
string$onlyFieldSpecific field to fetch for.
Returns
array Array with information about relations
See also
export_addRecord()

Definition at line 512 of file ReferenceIndex.php.

References $GLOBALS, TYPO3\CMS\Core\Database\ReferenceIndex\$temp_flexRelations, $uid, TYPO3\CMS\Backend\Utility\BackendUtility\explodeSoftRefParserList(), TYPO3\CMS\Core\Database\ReferenceIndex\getRelations_procDB(), TYPO3\CMS\Core\Database\ReferenceIndex\getRelations_procFiles(), TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance(), TYPO3\CMS\Backend\Utility\BackendUtility\softRefParserObj(), and TYPO3\CMS\Core\Utility\GeneralUtility\xml2array().

◆ getRelations_flexFormCallBack()

TYPO3\CMS\Core\Database\ReferenceIndex::getRelations_flexFormCallBack (   $dsArr,
  $dataValue,
  $PA,
  $structurePath,
  $parentObject 
)

Callback function for traversing the FlexForm structure in relation to finding file and DB references!

Parameters
array$dsArrData structure for the current value
mixed$dataValueCurrent value
array$PAAdditional configuration used in calling function
string$structurePathPath of value in DS structure
object$parentObjectObject reference to caller (unused)
Returns
void
See also
DataHandler::checkValue_flex_procInData_travDS(),FlexFormTools::traverseFlexFormXMLData()

Definition at line 623 of file ReferenceIndex.php.

References $uid, TYPO3\CMS\Backend\Utility\BackendUtility\explodeSoftRefParserList(), TYPO3\CMS\Core\Database\ReferenceIndex\getRelations_procDB(), TYPO3\CMS\Core\Database\ReferenceIndex\getRelations_procFiles(), and TYPO3\CMS\Backend\Utility\BackendUtility\softRefParserObj().

◆ getRelations_procDB()

TYPO3\CMS\Core\Database\ReferenceIndex::getRelations_procDB (   $value,
  $conf,
  $uid,
  $table = '',
  $field = '' 
)

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

Parameters
string$valueField value
array$confField configuration array of type "TCA/columns
int$uidField uid
string$tableTable name
string$fieldField name
Returns
array If field type is OK it will return an array with the database relations. Else FALSE

Definition at line 761 of file ReferenceIndex.php.

References $uid, TYPO3\CMS\Core\Database\ReferenceIndex\getDatabaseConnection(), TYPO3\CMS\Core\Database\ReferenceIndex\isDbReferenceField(), and TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance().

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\getRelations(), and TYPO3\CMS\Core\Database\ReferenceIndex\getRelations_flexFormCallBack().

◆ getRelations_procFiles()

TYPO3\CMS\Core\Database\ReferenceIndex::getRelations_procFiles (   $value,
  $conf,
  $uid 
)

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

Parameters
string$valueField value
array$confField configuration array of type "TCA/columns
int$uidField uid
Returns
bool|array If field type is OK it will return an array with the files inside. Else FALSE

Definition at line 699 of file ReferenceIndex.php.

References $uid, TYPO3\CMS\Core\Database\ReferenceIndex\destPathFromUploadFolder(), TYPO3\CMS\Core\Resource\ResourceFactory\getInstance(), and TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance().

Referenced by TYPO3\CMS\Core\Database\ReferenceIndex\getRelations(), and TYPO3\CMS\Core\Database\ReferenceIndex\getRelations_flexFormCallBack().

◆ getWorkspaceId()

TYPO3\CMS\Core\Database\ReferenceIndex::getWorkspaceId ( )

◆ isDbReferenceField()

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

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

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

Definition at line 1060 of file ReferenceIndex.php.

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

◆ isReferenceField()

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

Returns TRUE if the TCA/columns field type is a reference field

Parameters
array$configurationConfig array for TCA/columns field
Returns
bool TRUE if reference field

Definition at line 1077 of file ReferenceIndex.php.

◆ setReferenceValue()

TYPO3\CMS\Core\Database\ReferenceIndex::setReferenceValue (   $hash,
  $newValue,
  $returnDataArray = false,
  $bypassWorkspaceAdminCheck = false 
)

Setting the value of a reference or removing it completely. Usage: For lowlevel clean up operations! WARNING: With this you can set values that are not allowed in the database since it will bypass all checks for validity! Hence it is targeted at clean-up operations. Please use DataHandler in the usual ways if you wish to manipulate references. Since this interface allows updates to soft reference values (which DataHandler does not directly) you may like to use it for that as an exception to the warning above. Notice; If you want to remove multiple references from the same field, you MUST start with the one having the highest sorting number. If you don't the removal of a reference with a lower number will recreate an index in which the remaining references in that field has new hash-keys due to new sorting numbers - and you will get errors for the remaining operations which cannot find the hash you feed it! To ensure proper working only admin-BE_USERS in live workspace should use this function

Parameters
string$hash32-byte hash string identifying the record from sys_refindex which you wish to change the value for
mixed$newValueValue you wish to set for reference. If NULL, the reference is removed (unless a soft-reference in which case it can only be set to a blank string). If you wish to set a database reference, use the format "[table]:[uid]". Any other case, the input value is set as-is
bool$returnDataArrayReturn $dataArray only, do not submit it to database.
bool$bypassWorkspaceAdminCheckIf set, it will bypass check for workspace-zero and admin user
Returns
string|bool|array FALSE (=OK), error message string or array (if $returnDataArray is set!)

Definition at line 826 of file ReferenceIndex.php.

◆ setReferenceValue_dbRels()

TYPO3\CMS\Core\Database\ReferenceIndex::setReferenceValue_dbRels (   $refRec,
  $itemArray,
  $newValue,
$dataArray,
  $flexPointer = '' 
)

Setting a value for a reference for a DB field:

Parameters
array$refRecsys_refindex record
array$itemArrayArray of references from that field
string$newValueValue to substitute current value with (or NULL to unset it)
array$dataArrayData array in which the new value is set (passed by reference)
string$flexPointerFlexform pointer, if in a flex form field.
Returns
string Error message if any, otherwise FALSE = OK

Definition at line 937 of file ReferenceIndex.php.

◆ setReferenceValue_fileRels()

TYPO3\CMS\Core\Database\ReferenceIndex::setReferenceValue_fileRels (   $refRec,
  $itemArray,
  $newValue,
$dataArray,
  $flexPointer = '' 
)

Setting a value for a reference for a FILE field:

Parameters
array$refRecsys_refindex record
array$itemArrayArray of references from that field
string$newValueValue to substitute current value with (or NULL to unset it)
array$dataArrayData array in which the new value is set (passed by reference)
string$flexPointerFlexform pointer, if in a flex form field.
Returns
string Error message if any, otherwise FALSE = OK

Definition at line 977 of file ReferenceIndex.php.

◆ setReferenceValue_softreferences()

TYPO3\CMS\Core\Database\ReferenceIndex::setReferenceValue_softreferences (   $refRec,
  $softref,
  $newValue,
$dataArray,
  $flexPointer = '' 
)

Setting a value for a soft reference token

Parameters
array$refRecsys_refindex record
array$softrefArray of soft reference occurencies
string$newValueValue to substitute current value with
array$dataArrayData array in which the new value is set (passed by reference)
string$flexPointerFlexform pointer, if in a flex form field.
Returns
string Error message if any, otherwise FALSE = OK

Definition at line 1018 of file ReferenceIndex.php.

◆ setWorkspaceId()

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

Sets the current workspace id

Parameters
int$workspaceId
See also
updateIndex()

Definition at line 164 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\ReferenceIndex\$workspaceId.

◆ updateRefIndexTable()

TYPO3\CMS\Core\Database\ReferenceIndex::updateRefIndexTable (   $tableName,
  $uid,
  $testOnly = false 
)

Call this function to update the sys_refindex table for a record (even one just deleted) NOTICE: Currently, references updated for a deleted-flagged record will not include those from within FlexForm fields in some cases where the data structure is defined by another record since the resolving process ignores deleted records! This will also result in bad cleaning up in DataHandler I think... Anyway, that's the story of FlexForms; as long as the DS can change, lots of references can get lost in no time.

Parameters
string$tableNameTable name
int$uidUID of record
bool$testOnlyIf set, nothing will be written to the index but the result value will still report statistics on what is added, deleted and kept. Can be used for mere analysis.
Returns
array Array with statistics about how many index records were added, deleted and not altered plus the complete reference set for the record.

Definition at line 192 of file ReferenceIndex.php.

References TYPO3\CMS\Core\Database\ReferenceIndex\$relations, $uid, TYPO3\CMS\Core\Database\ReferenceIndex\fetchTableRelationFields(), TYPO3\CMS\Core\Database\ReferenceIndex\generateRefIndexData(), TYPO3\CMS\Core\Database\ReferenceIndex\getDatabaseConnection(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecordRaw(), and TYPO3\CMS\Core\Database\ReferenceIndex\getWorkspaceId().

Member Data Documentation

◆ $cachePrefixTableRelationFields

TYPO3\CMS\Core\Database\ReferenceIndex::$cachePrefixTableRelationFields = 'core-refidx-tblRelFields-'
staticprotected

Definition at line 92 of file ReferenceIndex.php.

◆ $errorLog

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

Definition at line 109 of file ReferenceIndex.php.

◆ $hashVersion

TYPO3\CMS\Core\Database\ReferenceIndex::$hashVersion = 1

Definition at line 134 of file ReferenceIndex.php.

◆ $nonRelationFields

TYPO3\CMS\Core\Database\ReferenceIndex::$nonRelationFields
staticprotected
Initial value:
= [
'uid' => true

Definition at line 76 of file ReferenceIndex.php.

◆ $nonRelationTables

TYPO3\CMS\Core\Database\ReferenceIndex::$nonRelationTables
staticprotected
Initial value:
= [
'sys_log' => true

Definition at line 59 of file ReferenceIndex.php.

◆ $relations

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

◆ $runtimeCache

TYPO3\CMS\Core\Database\ReferenceIndex::$runtimeCache = null
protected

Definition at line 148 of file ReferenceIndex.php.

◆ $temp_flexRelations

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

◆ $workspaceId

TYPO3\CMS\Core\Database\ReferenceIndex::$workspaceId = 0
protected

◆ $WSOL

TYPO3\CMS\Core\Database\ReferenceIndex::$WSOL = false

Definition at line 118 of file ReferenceIndex.php.