TYPO3 CMS  TYPO3_6-2
TYPO3\CMS\Core\Database\ReferenceIndex Class Reference
Inheritance diagram for TYPO3\CMS\Core\Database\ReferenceIndex:
t3lib_refindex

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, $pObj)
 
 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 = array()
 
 $errorLog = array()
 
 $WSOL = FALSE
 
 $relations = array()
 
 $words_strings = array()
 
 $words = array()
 
 $hashVersion = 1
 

Protected Member Functions

 isDbReferenceField (array $configuration)
 
 fetchTableRelationFields ($tableName)
 
 getRelationHandler ()
 

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.

Author
Kasper Skårhøj kaspe.nosp@m.rYYY.nosp@m.Y@typ.nosp@m.o3.c.nosp@m.om

Definition at line 32 of file ReferenceIndex.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructor

Definition at line 133 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)
integer$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]
integer$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.
integer$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.
integer$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.
Todo:
Define visibility

Definition at line 364 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)
integer$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]
integer$deletedWhether record is deleted-flagged or not
array$itemsData array with databaes relations (table/id)
Returns
void
Todo:
Define visibility

Definition at line 401 of file ReferenceIndex.php.

References 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)
integer$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]
integer$deletedWhether record is deleted-flagged or not
array$itemsData array with file relations
Returns
void
Todo:
Define visibility

Definition at line 419 of file ReferenceIndex.php.

References 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)
integer$uidUID of source record (where reference is located)
string$fieldnameFieldname of source record (where reference is located)
string$flexpointerPointer to location inside flexform struc
integer$deleted
array$keysData array with soft reference keys
Returns
void
Todo:
Define visibility

Definition at line 441 of file ReferenceIndex.php.

References 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.
Todo:
Define visibility

Definition at line 1084 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
Todo:
Define visibility

Definition at line 1098 of file ReferenceIndex.php.

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

◆ 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 1052 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
Todo:
Define visibility

Definition at line 255 of file ReferenceIndex.php.

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

◆ getRelationHandler()

TYPO3\CMS\Core\Database\ReferenceIndex::getRelationHandler ( )
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()
Todo:
Define visibility

Definition at line 485 of file ReferenceIndex.php.

References $GLOBALS, 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,
  $pObj 
)

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$pObjObject reference to caller
Returns
void
See also
::checkValue_flex_procInData_travDS()
Todo:
Define visibility

Definition at line 596 of file ReferenceIndex.php.

References 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
integer$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
Todo:
Define visibility

Definition at line 735 of file ReferenceIndex.php.

References $GLOBALS, TYPO3\CMS\Core\Database\ReferenceIndex\getRelationHandler(), 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
integer$uidField uid
Returns
bool|array If field type is OK it will return an array with the files inside. Else FALSE
Todo:
Define visibility

Definition at line 672 of file ReferenceIndex.php.

References 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 ( )

Gets the current workspace id.

Returns
int

Definition at line 151 of file ReferenceIndex.php.

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

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

◆ 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 1009 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
Todo:
Define visibility

Definition at line 1026 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 targetted at clean-up operations. Please use TCEmain in the usual ways if you wish to manipulate references. Since this interface allows updates to soft reference values (which TCEmain 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
boolean$returnDataArrayReturn $dataArray only, do not submit it to database.
boolean$bypassWorkspaceAdminCheckIf set, it will bypass check for workspace-zero and admin user
Returns
string If a return string, that carries an error message, otherwise FALSE (=OK) (except if $returnDataArray is set!)
Todo:
Define visibility

Definition at line 787 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
Todo:
Define visibility

Definition at line 893 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
Todo:
Define visibility

Definition at line 931 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
Todo:
Define visibility

Definition at line 970 of file ReferenceIndex.php.

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

◆ setWorkspaceId()

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

Sets the current workspace id.

Parameters
int$workspaceId

Definition at line 142 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 tcemain I think... Anyway, thats 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.
Todo:
Define visibility

Definition at line 165 of file ReferenceIndex.php.

References $GLOBALS, TYPO3\CMS\Core\Database\ReferenceIndex\$relations, $result, $uid, TYPO3\CMS\Core\Database\ReferenceIndex\fetchTableRelationFields(), TYPO3\CMS\Core\Database\ReferenceIndex\generateRefIndexData(), 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 81 of file ReferenceIndex.php.

◆ $errorLog

TYPO3\CMS\Core\Database\ReferenceIndex::$errorLog = array()
Todo:
Define visibility

Definition at line 92 of file ReferenceIndex.php.

◆ $hashVersion

TYPO3\CMS\Core\Database\ReferenceIndex::$hashVersion = 1
Todo:
Define visibility

Definition at line 118 of file ReferenceIndex.php.

◆ $nonRelationFields

TYPO3\CMS\Core\Database\ReferenceIndex::$nonRelationFields
staticprotected
Initial value:
= array(
'uid' => TRUE,
'perms_userid' => TRUE,
'perms_groupid' => TRUE,
'perms_user' => TRUE,
'perms_group' => TRUE,
'perms_everybody' => TRUE,
'pid' => TRUE
)

Definition at line 65 of file ReferenceIndex.php.

◆ $nonRelationTables

TYPO3\CMS\Core\Database\ReferenceIndex::$nonRelationTables
staticprotected
Initial value:
= array(
'sys_log' => TRUE,
'sys_history' => TRUE,
'tx_extensionmanager_domain_model_extension' => TRUE
)

Definition at line 48 of file ReferenceIndex.php.

◆ $relations

TYPO3\CMS\Core\Database\ReferenceIndex::$relations = array()
Todo:
Define visibility

Definition at line 102 of file ReferenceIndex.php.

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

◆ $runtimeCache

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

Definition at line 128 of file ReferenceIndex.php.

◆ $temp_flexRelations

TYPO3\CMS\Core\Database\ReferenceIndex::$temp_flexRelations = array()

Definition at line 87 of file ReferenceIndex.php.

◆ $words

TYPO3\CMS\Core\Database\ReferenceIndex::$words = array()
Todo:
Define visibility

Definition at line 112 of file ReferenceIndex.php.

◆ $words_strings

TYPO3\CMS\Core\Database\ReferenceIndex::$words_strings = array()
Todo:
Define visibility

Definition at line 107 of file ReferenceIndex.php.

◆ $workspaceId

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

◆ $WSOL

TYPO3\CMS\Core\Database\ReferenceIndex::$WSOL = FALSE
Todo:
Define visibility

Definition at line 97 of file ReferenceIndex.php.