TYPO3  7.6
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
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 = array()
 
 $errorLog = array()
 
 $WSOL = false
 
 $relations = array()
 
 $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 42 of file ReferenceIndex.php.

Constructor & Destructor Documentation

__construct ( )

Constructor

Definition at line 152 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 389 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 426 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 444 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 466 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 1135 of file ReferenceIndex.php.

Referenced by ReferenceIndex\getRelations_procFiles().

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

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

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

Referenced by ReferenceIndex\updateRefIndexTable().

getBackendUser ( )
protected

Returns the current BE user.

Returns

Definition at line 1272 of file ReferenceIndex.php.

getDatabaseConnection ( )
protected
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 511 of file ReferenceIndex.php.

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

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

References elseif, ReferenceIndex\getDatabaseConnection(), 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 698 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 174 of file ReferenceIndex.php.

References ReferenceIndex\$workspaceId.

Referenced by ReferenceIndex\updateRefIndexTable().

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

Referenced by ReferenceIndex\getRelations_procDB().

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

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

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

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

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

setWorkspaceId (   $workspaceId)

Sets the current workspace id

Parameters
int$workspaceId
See Also
updateIndex()

Definition at line 163 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 191 of file ReferenceIndex.php.

References ReferenceIndex\$relations, ReferenceIndex\fetchTableRelationFields(), ReferenceIndex\generateRefIndexData(), ReferenceIndex\getDatabaseConnection(), BackendUtility\getRecordRaw(), and ReferenceIndex\getWorkspaceId().

Member Data Documentation

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

Definition at line 91 of file ReferenceIndex.php.

$errorLog = array()

Definition at line 108 of file ReferenceIndex.php.

$hashVersion = 1

Definition at line 133 of file ReferenceIndex.php.

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

$nonRelationTables
staticprotected
Initial value:
= array(
'sys_log' => true,
'sys_history' => true,
'tx_extensionmanager_domain_model_extension' => true
)

Definition at line 58 of file ReferenceIndex.php.

$relations = array()

Definition at line 125 of file ReferenceIndex.php.

Referenced by ReferenceIndex\updateRefIndexTable().

$runtimeCache = null
protected

Definition at line 147 of file ReferenceIndex.php.

$temp_flexRelations = array()

Definition at line 99 of file ReferenceIndex.php.

$workspaceId = 0
protected
$WSOL = false

Definition at line 117 of file ReferenceIndex.php.