TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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)
 

Public Attributes

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

Protected Member Functions

 isDbReferenceField (array $configuration)
 
 fetchTableRelationFields ($tableName)
 
 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 44 of file ReferenceIndex.php.

Constructor & Destructor Documentation

__construct ( )

Constructor

Definition at line 145 of file ReferenceIndex.php.

References GeneralUtility\makeInstance().

Member Function Documentation

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

Referenced by ReferenceIndex\createEntryData_dbRels(), ReferenceIndex\createEntryData_fileRels(), and ReferenceIndex\createEntryData_softreferences().

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

References ReferenceIndex\createEntryData().

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

References ReferenceIndex\createEntryData(), GeneralUtility\isFirstPartOfStr(), and PathUtility\stripPathSitePrefix().

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

References ReferenceIndex\createEntryData().

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

Referenced by ReferenceIndex\getRelations_procFiles().

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

References $fields, $GLOBALS, and ReferenceIndex\isReferenceField().

Referenced by ReferenceIndex\updateRefIndexTable().

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

Referenced by ReferenceIndex\updateRefIndexTable().

getBackendUser ( )
protected

Returns the current BE user.

Returns

Definition at line 1318 of file ReferenceIndex.php.

References $GLOBALS.

Referenced by ReferenceIndex\setReferenceValue().

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

References $GLOBALS, ReferenceIndex\$temp_flexRelations, BackendUtility\explodeSoftRefParserList(), ReferenceIndex\getRelations_procDB(), ReferenceIndex\getRelations_procFiles(), GeneralUtility\makeInstance(), BackendUtility\softRefParserObj(), and GeneralUtility\xml2array().

Referenced by ReferenceIndex\setReferenceValue().

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

References BackendUtility\explodeSoftRefParserList(), ReferenceIndex\getRelations_procDB(), ReferenceIndex\getRelations_procFiles(), and BackendUtility\softRefParserObj().

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

References ReferenceIndex\isDbReferenceField(), and GeneralUtility\makeInstance().

Referenced by ReferenceIndex\getRelations(), and ReferenceIndex\getRelations_flexFormCallBack().

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

References ReferenceIndex\destPathFromUploadFolder(), ResourceFactory\getInstance(), and GeneralUtility\makeInstance().

Referenced by ReferenceIndex\getRelations(), and ReferenceIndex\getRelations_flexFormCallBack().

getWorkspaceId ( )

Gets the current workspace id

Returns
int
See also
updateRefIndexTable(),createEntryData()

Definition at line 167 of file ReferenceIndex.php.

References ReferenceIndex\$workspaceId.

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

Referenced by ReferenceIndex\getRelations_procDB(), and ReferenceIndex\isReferenceField().

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

References ReferenceIndex\isDbReferenceField().

Referenced by ReferenceIndex\fetchTableRelationFields().

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

References $GLOBALS, ReferenceIndex\getBackendUser(), ReferenceIndex\getRelations(), GeneralUtility\makeInstance(), ReferenceIndex\setReferenceValue_dbRels(), ReferenceIndex\setReferenceValue_fileRels(), and ReferenceIndex\setReferenceValue_softreferences().

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

References GeneralUtility\makeInstance().

Referenced by ReferenceIndex\setReferenceValue().

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

References GeneralUtility\makeInstance(), and PathUtility\stripPathSitePrefix().

Referenced by ReferenceIndex\setReferenceValue().

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

References GeneralUtility\makeInstance().

Referenced by ReferenceIndex\setReferenceValue().

setWorkspaceId (   $workspaceId)

Sets the current workspace id

Parameters
int$workspaceId
See also
updateIndex()

Definition at line 156 of file ReferenceIndex.php.

References ReferenceIndex\$workspaceId.

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

References ReferenceIndex\$relations, ReferenceIndex\fetchTableRelationFields(), ReferenceIndex\generateRefIndexData(), BackendUtility\getRecordRaw(), and GeneralUtility\makeInstance().

Member Data Documentation

$cachePrefixTableRelationFields = 'core-refidx-tblRelFields-'
staticprotected

Definition at line 93 of file ReferenceIndex.php.

$hashVersion = 1

Definition at line 126 of file ReferenceIndex.php.

$nonRelationFields
staticprotected
Initial value:
= [
'uid' => true

Definition at line 77 of file ReferenceIndex.php.

$nonRelationTables
staticprotected
Initial value:
= [
'sys_log' => true

Definition at line 60 of file ReferenceIndex.php.

$relations = []

Definition at line 118 of file ReferenceIndex.php.

Referenced by ReferenceIndex\updateRefIndexTable().

$runtimeCache = null
protected

Definition at line 140 of file ReferenceIndex.php.

$temp_flexRelations = []

Definition at line 101 of file ReferenceIndex.php.

Referenced by ReferenceIndex\getRelations().

$workspaceId = 0
protected
$WSOL = false

Definition at line 110 of file ReferenceIndex.php.