00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00063 require_once(PATH_t3lib.'class.t3lib_tcemain.php');
00064 require_once(PATH_t3lib.'class.t3lib_flexformtools.php');
00065
00066
00067
00068
00083 class t3lib_refindex {
00084
00085 var $temp_flexRelations = array();
00086 var $errorLog = array();
00087 var $WSOL = FALSE;
00088 var $relations = array();
00089
00090 var $words_strings = array();
00091 var $words = array();
00092
00093 var $hashVersion = 1;
00094
00095
00105 function updateRefIndexTable($table,$uid,$testOnly=FALSE) {
00106
00107
00108 $this->WSOL = FALSE;
00109
00110
00111 $result = array(
00112 'keptNodes' => 0,
00113 'deletedNodes' => 0,
00114 'addedNodes' => 0
00115 );
00116
00117
00118 $currentRels = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00119 '*',
00120 'sys_refindex',
00121 'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
00122 ' AND recuid='.intval($uid),
00123 '','','','hash'
00124 );
00125
00126
00127 if (t3lib_BEfunc::getRecordRaw($table,'uid='.intval($uid),'uid')) {
00128
00129
00130 $relations = $this->generateRefIndexData($table,$uid);
00131
00132 if (is_array($relations)) {
00133
00134
00135 foreach($relations as $k => $datRec) {
00136 $relations[$k]['hash'] = md5(implode('
00137
00138
00139 if (isset($currentRels[$relations[$k]['hash']])) {
00140 unset($currentRels[$relations[$k]['hash']]);
00141 $result['keptNodes']++;
00142 $relations[$k]['_ACTION'] = 'KEPT';
00143 } else {
00144
00145 if (!$testOnly) $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_refindex',$relations[$k]);
00146 $result['addedNodes']++;
00147 $relations[$k]['_ACTION'] = 'ADDED';
00148 }
00149 }
00150
00151 $result['relations'] = $relations;
00152 } else return FALSE;
00153
00154
00155 if (!$testOnly) $this->wordIndexing($table,$uid);
00156 }
00157
00158
00159 if (count($currentRels)) {
00160 $hashList = array_keys($currentRels);
00161 if (count($hashList)) {
00162 $result['deletedNodes'] = count($hashList);
00163 $result['deletedNodes_hashList'] = implode(',',$hashList);
00164 if (!$testOnly) $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_refindex','hash IN ('.implode(',',$GLOBALS['TYPO3_DB']->fullQuoteArray($hashList,'sys_refindex')).')');
00165 }
00166 }
00167
00168 return $result;
00169 }
00170
00179 function generateRefIndexData($table,$uid) {
00180 global $TCA;
00181
00182 if (isset($TCA[$table])) {
00183
00184 list($record) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*',$table,'uid='.intval($uid));
00185
00186 if (is_array($record)) {
00187
00188
00189 $this->words_strings = array();
00190 $this->words = array();
00191
00192
00193 $deleted = $TCA[$table]['ctrl']['delete'] ? ($record[$TCA[$table]['ctrl']['delete']]?1:0) : 0;
00194
00195
00196 $dbrels = $this->getRelations($table,$record);
00197
00198
00199 $this->relations = array();
00200 foreach($dbrels as $fieldname => $dat) {
00201
00202
00203 switch((string)$dat['type']) {
00204 case 'db':
00205 $this->createEntryData_dbRels($table,$uid,$fieldname,'',$deleted,$dat['itemArray']);
00206 break;
00207 case 'file':
00208 $this->createEntryData_fileRels($table,$uid,$fieldname,'',$deleted,$dat['newValueFiles']);
00209 break;
00210 case 'flex':
00211
00212 if (is_array($dat['flexFormRels']['db'])) {
00213 foreach($dat['flexFormRels']['db'] as $flexpointer => $subList) {
00214 $this->createEntryData_dbRels($table,$uid,$fieldname,$flexpointer,$deleted,$subList);
00215 }
00216 }
00217
00218 if (is_array($dat['flexFormRels']['file'])) {
00219 foreach($dat['flexFormRels']['file'] as $flexpointer => $subList) {
00220 $this->createEntryData_fileRels($table,$uid,$fieldname,$flexpointer,$deleted,$subList);
00221 }
00222 }
00223
00224 if (is_array($dat['flexFormRels']['softrefs'])) {
00225 foreach($dat['flexFormRels']['softrefs'] as $flexpointer => $subList) {
00226 $this->createEntryData_softreferences($table,$uid,$fieldname,$flexpointer,$deleted,$subList['keys']);
00227 }
00228 }
00229 break;
00230 }
00231
00232
00233 if (is_array($dat['softrefs'])) {
00234 $this->createEntryData_softreferences($table,$uid,$fieldname,'',$deleted,$dat['softrefs']['keys']);
00235 }
00236 }
00237
00238
00239 t3lib_div::loadTCA($table);
00240 foreach($TCA[$table]['columns'] as $field => $conf) {
00241 if (t3lib_div::inList('input,text',$conf['config']['type']) && strcmp($record[$field],'') && !t3lib_div::testInt($record[$field])) {
00242 $this->words_strings[$field] = $record[$field];
00243 }
00244 }
00245
00246 return $this->relations;
00247 }
00248 }
00249 }
00250
00268 function createEntryData($table,$uid,$field,$flexpointer,$deleted,$ref_table,$ref_uid,$ref_string='',$sort=-1,$softref_key='',$softref_id='') {
00269 return array(
00270 'tablename' => $table,
00271 'recuid' => $uid,
00272 'field' => $field,
00273 'flexpointer' => $flexpointer,
00274 'softref_key' => $softref_key,
00275 'softref_id' => $softref_id,
00276 'sorting' => $sort,
00277 'deleted' => $deleted,
00278 'ref_table' => $ref_table,
00279 'ref_uid' => $ref_uid,
00280 'ref_string' => $ref_string,
00281 );
00282 }
00283
00295 function createEntryData_dbRels($table,$uid,$fieldname,$flexpointer,$deleted,$items) {
00296 foreach($items as $sort => $i) {
00297 $this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,$i['table'],$i['id'],'',$sort);
00298 }
00299 }
00300
00312 function createEntryData_fileRels($table,$uid,$fieldname,$flexpointer,$deleted,$items) {
00313 foreach($items as $sort => $i) {
00314 $filePath = $i['ID_absFile'];
00315 if (t3lib_div::isFirstPartOfStr($filePath,PATH_site)) {
00316 $filePath = substr($filePath,strlen(PATH_site));
00317 }
00318 $this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,'_FILE',0,$filePath,$sort);
00319 }
00320 }
00321
00333 function createEntryData_softreferences($table,$uid,$fieldname,$flexpointer,$deleted,$keys) {
00334 if (is_array($keys)) {
00335 foreach($keys as $spKey => $elements) {
00336 if (is_array($elements)) {
00337 foreach($elements as $subKey => $el) {
00338 if (is_array($el['subst'])) {
00339 switch((string)$el['subst']['type']) {
00340 case 'db':
00341 list($tableName,$recordId) = explode(':',$el['subst']['recordRef']);
00342 $this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,$tableName,$recordId,'',-1,$spKey,$subKey);
00343 break;
00344 case 'file':
00345 $this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,'_FILE',0,$el['subst']['relFileName'],-1,$spKey,$subKey);
00346 break;
00347 case 'string':
00348 $this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,'_STRING',0,$el['subst']['tokenValue'],-1,$spKey,$subKey);
00349 break;
00350 }
00351 }
00352 }
00353 }
00354 }
00355 }
00356 }
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00389 function getRelations($table,$row,$onlyField='') {
00390 global $TCA;
00391
00392
00393 t3lib_div::loadTCA($table);
00394
00395
00396 $uid = $row['uid'];
00397 $nonFields = explode(',','uid,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,pid');
00398
00399 $outRow = array();
00400 foreach($row as $field => $value) {
00401 if (!in_array($field,$nonFields) && is_array($TCA[$table]['columns'][$field]) && (!$onlyField || $onlyField===$field)) {
00402 $conf = $TCA[$table]['columns'][$field]['config'];
00403
00404
00405 if ($result = $this->getRelations_procFiles($value, $conf, $uid)) {
00406
00407 $outRow[$field] = array(
00408 'type' => 'file',
00409 'newValueFiles' => $result,
00410 );
00411 }
00412
00413
00414 if ($result = $this->getRelations_procDB($value, $conf, $uid, $table)) {
00415
00416 $outRow[$field] = array(
00417 'type' => 'db',
00418 'itemArray' => $result,
00419 );
00420 }
00421
00422
00423 if ($conf['type']=='flex') {
00424
00425
00426
00427 $dataStructArray = t3lib_BEfunc::getFlexFormDS($conf, $row, $table,'',$this->WSOL);
00428 $currentValueArray = t3lib_div::xml2array($value);
00429
00430
00431 if (is_array($currentValueArray)) {
00432 $this->temp_flexRelations = array(
00433 'db' => array(),
00434 'file' => array(),
00435 'softrefs' => array()
00436 );
00437
00438
00439 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
00440 $flexObj->traverseFlexFormXMLData($table,$field,$row,$this,'getRelations_flexFormCallBack');
00441
00442
00443 $outRow[$field] = array(
00444 'type' => 'flex',
00445 'flexFormRels' => $this->temp_flexRelations,
00446 );
00447 }
00448 }
00449
00450
00451 if (strlen($value) && $softRefs = t3lib_BEfunc::explodeSoftRefParserList($conf['softref'])) {
00452 $softRefValue = $value;
00453 foreach($softRefs as $spKey => $spParams) {
00454 $softRefObj = &t3lib_BEfunc::softRefParserObj($spKey);
00455 if (is_object($softRefObj)) {
00456 $resultArray = $softRefObj->findRef($table, $field, $uid, $softRefValue, $spKey, $spParams);
00457 if (is_array($resultArray)) {
00458 $outRow[$field]['softrefs']['keys'][$spKey] = $resultArray['elements'];
00459 if (strlen($resultArray['content'])) {
00460 $softRefValue = $resultArray['content'];
00461 }
00462 }
00463 }
00464 }
00465
00466 if (is_array($outRow[$field]['softrefs']) && count($outRow[$field]['softrefs']) && strcmp($value,$softRefValue) && strstr($softRefValue,'{softref:')) {
00467 $outRow[$field]['softrefs']['tokenizedContent'] = $softRefValue;
00468 }
00469 }
00470 }
00471 }
00472
00473 return $outRow;
00474 }
00475
00487 function getRelations_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, &$pObj) {
00488 $structurePath = substr($structurePath,5).'/';
00489
00490 $dsConf = $dsArr['TCEforms']['config'];
00491
00492
00493 list($table, $uid, $field) = array($PA['table'],$PA['uid'],$PA['field']);
00494
00495
00496 if ($result = $this->getRelations_procFiles($dataValue, $dsConf, $uid)) {
00497
00498
00499 $this->temp_flexRelations['file'][$structurePath] = $result;
00500 }
00501
00502
00503 if ($result = $this->getRelations_procDB($dataValue, $dsConf, $uid)) {
00504
00505
00506 $this->temp_flexRelations['db'][$structurePath] = $result;
00507 }
00508
00509
00510 if (strlen($dataValue) && $softRefs = t3lib_BEfunc::explodeSoftRefParserList($dsConf['softref'])) {
00511 $softRefValue = $dataValue;
00512 foreach($softRefs as $spKey => $spParams) {
00513 $softRefObj = &t3lib_BEfunc::softRefParserObj($spKey);
00514 if (is_object($softRefObj)) {
00515 $resultArray = $softRefObj->findRef($table, $field, $uid, $softRefValue, $spKey, $spParams, $structurePath);
00516 if (is_array($resultArray) && is_array($resultArray['elements'])) {
00517 $this->temp_flexRelations['softrefs'][$structurePath]['keys'][$spKey] = $resultArray['elements'];
00518 if (strlen($resultArray['content'])) $softRefValue = $resultArray['content'];
00519 }
00520 }
00521 }
00522
00523 if (count($this->temp_flexRelations['softrefs']) && strcmp($dataValue,$softRefValue)) {
00524 $this->temp_flexRelations['softrefs'][$structurePath]['tokenizedContent'] = $softRefValue;
00525 }
00526 }
00527 }
00528
00537 function getRelations_procFiles($value, $conf, $uid) {
00538
00539 if ($conf['type']=='group' && $conf['internal_type']=='file') {
00540
00541
00542 if ($conf['MM']) {
00543 $theFileValues = array();
00544 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00545 $dbAnalysis->start('', 'files', $conf['MM'], $uid);
00546
00547 foreach($dbAnalysis->itemArray as $somekey => $someval) {
00548 if ($someval['id']) {
00549 $theFileValues[] = $someval['id'];
00550 }
00551 }
00552 } else {
00553 $theFileValues = explode(',',$value);
00554 }
00555
00556
00557 $uploadFolder = $conf['uploadfolder'];
00558 $dest = $this->destPathFromUploadFolder($uploadFolder);
00559 $newValue = array();
00560 $newValueFiles = array();
00561
00562 foreach($theFileValues as $file) {
00563 if (trim($file)) {
00564 $realFile = $dest.'/'.trim($file);
00565 # if (@is_file($realFile)) { // Now, the refernece index should NOT look if files exist - just faithfully include them if they are in the records!
00566 $newValueFiles[] = array(
00567 'filename' => $file,
00568 'ID' => md5($realFile),
00569 'ID_absFile' => $realFile
00570 );
00571 # } else $this->error('Missing file: '.$realFile);
00572 }
00573 }
00574
00575 return $newValueFiles;
00576 }
00577 }
00578
00588 function getRelations_procDB($value, $conf, $uid, $table = '') {
00589
00590
00591 if ($this->isReferenceField($conf)) {
00592 $allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table'];
00593 $prependName = $conf['type']=='group' ? $conf['prepend_tname'] : $conf['neg_foreign_table'];
00594
00595 if($conf['MM_opposite_field']) {
00596 return array();
00597 }
00598
00599 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00600 $dbAnalysis->start($value,$allowedTables,$conf['MM'],$uid,$table,$conf);
00601
00602 return $dbAnalysis->itemArray;
00603 }
00604 }
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00637 function setReferenceValue($hash,$newValue,$returnDataArray=FALSE,$bypassWorkspaceAdminCheck=FALSE) {
00638
00639 if (($GLOBALS['BE_USER']->workspace===0 && $GLOBALS['BE_USER']->isAdmin()) || $bypassWorkspaceAdminCheck) {
00640
00641
00642 list($refRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00643 '*',
00644 'sys_refindex',
00645 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash,'sys_refindex')
00646 );
00647
00648
00649 if (is_array($refRec)) {
00650 if ($GLOBALS['TCA'][$refRec['tablename']]) {
00651
00652
00653 list($record) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*',$refRec['tablename'],'uid='.intval($refRec['recuid']));
00654
00655 if (is_array($record)) {
00656
00657
00658 $dbrels = $this->getRelations($refRec['tablename'],$record,$refRec['field']);
00659 if ($dat = $dbrels[$refRec['field']]) {
00660
00661
00662 $dataArray = array();
00663
00664
00665 switch((string)$dat['type']) {
00666 case 'db':
00667 $error = $this->setReferenceValue_dbRels($refRec,$dat['itemArray'],$newValue,$dataArray);
00668 if ($error) return $error;
00669 break;
00670 case 'file':
00671 $this->setReferenceValue_fileRels($refRec,$dat['newValueFiles'],$newValue,$dataArray);
00672 if ($error) return $error;
00673 break;
00674 case 'flex':
00675
00676 if (is_array($dat['flexFormRels']['db'][$refRec['flexpointer']])) {
00677 $error = $this->setReferenceValue_dbRels($refRec,$dat['flexFormRels']['db'][$refRec['flexpointer']],$newValue,$dataArray,$refRec['flexpointer']);
00678 if ($error) return $error;
00679 }
00680
00681 if (is_array($dat['flexFormRels']['file'][$refRec['flexpointer']])) {
00682 $this->setReferenceValue_fileRels($refRec,$dat['flexFormRels']['file'][$refRec['flexpointer']],$newValue,$dataArray,$refRec['flexpointer']);
00683 if ($error) return $error;
00684 }
00685
00686 if ($refRec['softref_key'] && is_array($dat['flexFormRels']['softrefs'][$refRec['flexpointer']]['keys'][$refRec['softref_key']])) {
00687 $error = $this->setReferenceValue_softreferences($refRec,$dat['flexFormRels']['softrefs'][$refRec['flexpointer']],$newValue,$dataArray,$refRec['flexpointer']);
00688 if ($error) return $error;
00689 }
00690 break;
00691 }
00692
00693
00694 if ($refRec['softref_key'] && is_array($dat['softrefs']['keys'][$refRec['softref_key']])) {
00695 $error = $this->setReferenceValue_softreferences($refRec,$dat['softrefs'],$newValue,$dataArray);
00696 if ($error) return $error;
00697
00698 }
00699
00700
00701 if ($returnDataArray) {
00702 return $dataArray;
00703 } else {
00704
00705
00706 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00707 $tce->stripslashes_values = FALSE;
00708 $tce->dontProcessTransformations = TRUE;
00709 $tce->bypassWorkspaceRestrictions = TRUE;
00710 $tce->bypassFileHandling = TRUE;
00711 $tce->bypassAccessCheckForRecords = TRUE;
00712
00713 $tce->start($dataArray,array());
00714 $tce->process_datamap();
00715
00716
00717 if (count($tce->errorLog)) {
00718 return chr(10).'TCEmain:'.implode(chr(10).'TCEmain:',$tce->errorLog);
00719 }
00720 }
00721 }
00722 }
00723 } else return 'ERROR: Tablename "'.$refRec['tablename'].'" was not in TCA!';
00724 } else return 'ERROR: No reference record with hash="'.$hash.'" was found!';
00725 } else return 'ERROR: BE_USER object is not admin OR not in workspace 0 (Live)';
00726 }
00727
00738 function setReferenceValue_dbRels($refRec,$itemArray,$newValue,&$dataArray,$flexpointer='') {
00739 if (!strcmp($itemArray[$refRec['sorting']]['id'],$refRec['ref_uid']) && !strcmp($itemArray[$refRec['sorting']]['table'],$refRec['ref_table'])) {
00740
00741
00742 if ($newValue===NULL) {
00743 unset($itemArray[$refRec['sorting']]);
00744 } else {
00745 list($itemArray[$refRec['sorting']]['table'],$itemArray[$refRec['sorting']]['id']) = explode(':',$newValue);
00746 }
00747
00748
00749 $saveValue = array();
00750 foreach($itemArray as $pair) {
00751 $saveValue[] = $pair['table'].'_'.$pair['id'];
00752 }
00753
00754
00755 if ($flexpointer) {
00756 $flexToolObj = t3lib_div::makeInstance('t3lib_flexformtools');
00757 $dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']]['data'] = array();
00758 $flexToolObj->setArrayValueByPath(substr($flexpointer,0,-1),$dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']]['data'],implode(',',$saveValue));
00759 } else {
00760 $dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']] = implode(',',$saveValue);
00761 }
00762
00763 } else return 'ERROR: table:id pair "'.$refRec['ref_table'].':'.$refRec['ref_uid'].'" did not match that of the record ("'.$itemArray[$refRec['sorting']]['table'].':'.$itemArray[$refRec['sorting']]['id'].'") in sorting index "'.$refRec['sorting'].'"';
00764 }
00765
00776 function setReferenceValue_fileRels($refRec,$itemArray,$newValue,&$dataArray,$flexpointer='') {
00777 if (!strcmp(substr($itemArray[$refRec['sorting']]['ID_absFile'],strlen(PATH_site)),$refRec['ref_string']) && !strcmp('_FILE',$refRec['ref_table'])) {
00778
00779
00780 if ($newValue===NULL) {
00781 unset($itemArray[$refRec['sorting']]);
00782 } else {
00783 $itemArray[$refRec['sorting']]['filename'] = $newValue;
00784 }
00785
00786
00787 $saveValue = array();
00788 foreach($itemArray as $fileInfo) {
00789 $saveValue[] = $fileInfo['filename'];
00790 }
00791
00792
00793 if ($flexpointer) {
00794 $flexToolObj = t3lib_div::makeInstance('t3lib_flexformtools');
00795 $dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']]['data'] = array();
00796 $flexToolObj->setArrayValueByPath(substr($flexpointer,0,-1),$dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']]['data'],implode(',',$saveValue));
00797 } else {
00798 $dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']] = implode(',',$saveValue);
00799 }
00800
00801 } else return 'ERROR: either "'.$refRec['ref_table'].'" was not "_FILE" or file PATH_site+"'.$refRec['ref_string'].'" did not match that of the record ("'.$itemArray[$refRec['sorting']]['ID_absFile'].'") in sorting index "'.$refRec['sorting'].'"';
00802 }
00803
00814 function setReferenceValue_softreferences($refRec,$softref,$newValue,&$dataArray,$flexpointer='') {
00815 if (is_array($softref['keys'][$refRec['softref_key']][$refRec['softref_id']])) {
00816
00817
00818 $softref['keys'][$refRec['softref_key']][$refRec['softref_id']]['subst']['tokenValue'] = ''.$newValue;
00819
00820
00821 foreach($softref['keys'] as $sfIndexes) {
00822 foreach($sfIndexes as $data) {
00823 $softref['tokenizedContent'] = str_replace('{softref:'.$data['subst']['tokenID'].'}', $data['subst']['tokenValue'], $softref['tokenizedContent']);
00824 }
00825 }
00826
00827
00828 if (!strstr($softref['tokenizedContent'],'{softref:')) {
00829 if ($flexpointer) {
00830 $flexToolObj = t3lib_div::makeInstance('t3lib_flexformtools');
00831 $dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']]['data'] = array();
00832 $flexToolObj->setArrayValueByPath(substr($flexpointer,0,-1),$dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']]['data'],$softref['tokenizedContent']);
00833 } else {
00834 $dataArray[$refRec['tablename']][$refRec['recuid']][$refRec['field']] = $softref['tokenizedContent'];
00835 }
00836 } else return 'ERROR: After substituting all found soft references there were still soft reference tokens in the text. (theoretically this does not have to be an error if the string "{softref:" happens to be in the field for another reason.)';
00837 } else return 'ERROR: Soft reference parser key "'.$refRec['softref_key'].'" or the index "'.$refRec['softref_id'].'" was not found.';
00838 }
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00858 function wordIndexing($table,$uid) {
00859 return;
00860
00861
00862
00863
00864
00865 $lexer = t3lib_div::makeInstance('tx_indexedsearch_lexer');
00866 $words = $lexer->split2Words(implode(' ',$this->words_strings));
00867 foreach($words as $w) {
00868 $words[]=substr($w,0,3);
00869 }
00870 $words = array_unique($words);
00871 $this->updateWordIndex($words,$table,$uid);
00872 }
00873
00882 function updateWordIndex($words,$table,$uid) {
00883
00884
00885 $this->submitWords($words);
00886
00887
00888 $rid = t3lib_div::md5int($table.':'.$uid);
00889 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_refindex_rel', 'rid='.intval($rid));
00890
00891
00892 foreach($words as $w) {
00893 $insertFields = array(
00894 'rid' => $rid,
00895 'wid' => t3lib_div::md5int($w)
00896 );
00897
00898 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_refindex_rel', $insertFields);
00899 }
00900
00901
00902 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_refindex_res', 'rid='.intval($rid));
00903 $insertFields = array(
00904 'rid' => $rid,
00905 'tablename' => $table,
00906 'recuid' => $uid
00907 );
00908 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_refindex_res', $insertFields);
00909 }
00910
00917 function submitWords($wl) {
00918
00919 $hashArr = array();
00920 foreach($wl as $w) {
00921 $hashArr[] = t3lib_div::md5int($w);
00922 }
00923 $wl = array_flip($wl);
00924
00925 if (count($hashArr)) {
00926 $cwl = implode(',',$hashArr);
00927 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('baseword', 'sys_refindex_words', 'wid IN ('.$cwl.')');
00928
00929 if($GLOBALS['TYPO3_DB']->sql_num_rows($res)!=count($wl)) {
00930 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00931 unset($wl[$row['baseword']]);
00932 }
00933
00934 reset($wl);
00935 while(list($key,$val)=each($wl)) {
00936 $insertFields = array(
00937 'wid' => t3lib_div::md5int($key),
00938 'baseword' => $key
00939 );
00940
00941
00942 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_refindex_words', $insertFields);
00943 }
00944 }
00945 }
00946 }
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00966 function isReferenceField($conf) {
00967 return ($conf['type']=='group' && $conf['internal_type']=='db') || (($conf['type']=='select' || $conf['type']=='inline') && $conf['foreign_table']);
00968 }
00969
00976 function destPathFromUploadFolder($folder) {
00977 return PATH_site.$folder;
00978 }
00979
00986 function error($msg) {
00987 $this->errorLog[]=$msg;
00988 }
00989
00997 function updateIndex($testOnly,$cli_echo=FALSE) {
00998 global $TCA, $TYPO3_DB;
00999
01000 $errors = array();
01001 $tableNames = array();
01002 $recCount=0;
01003 $tableCount=0;
01004
01005 $headerContent = $testOnly ? 'Reference Index being TESTED (nothing written, use "-e" to update)' : 'Reference Index being Updated';
01006 if ($cli_echo) echo
01007 '*******************************************'.chr(10).
01008 $headerContent.chr(10).
01009 '*******************************************'.chr(10);
01010
01011
01012 foreach ($TCA as $tableName => $cfg) {
01013 $tableNames[] = $tableName;
01014 $tableCount++;
01015
01016
01017 $allRecs = $TYPO3_DB->exec_SELECTgetRows('uid',$tableName,'1=1');
01018 $uidList = array(0);
01019 foreach ($allRecs as $recdat) {
01020 $refIndexObj = t3lib_div::makeInstance('t3lib_refindex');
01021 $result = $refIndexObj->updateRefIndexTable($tableName,$recdat['uid'],$testOnly);
01022 $uidList[]= $recdat['uid'];
01023 $recCount++;
01024
01025 if ($result['addedNodes'] || $result['deletedNodes']) {
01026 $Err = 'Record '.$tableName.':'.$recdat['uid'].' had '.$result['addedNodes'].' added indexes and '.$result['deletedNodes'].' deleted indexes';
01027 $errors[]= $Err;
01028 if ($cli_echo) echo $Err.chr(10);
01029 #$errors[] = t3lib_div::view_array($result);
01030 }
01031 }
01032
01033
01034 $where = 'tablename='.$TYPO3_DB->fullQuoteStr($tableName,'sys_refindex').' AND recuid NOT IN ('.implode(',',$uidList).')';
01035 $lostIndexes = $TYPO3_DB->exec_SELECTgetRows('hash','sys_refindex',$where);
01036 if (count($lostIndexes)) {
01037 $Err = 'Table '.$tableName.' has '.count($lostIndexes).' lost indexes which are now deleted';
01038 $errors[]= $Err;
01039 if ($cli_echo) echo $Err.chr(10);
01040 if (!$testOnly) $TYPO3_DB->exec_DELETEquery('sys_refindex',$where);
01041 }
01042 }
01043
01044
01045 $where = 'tablename NOT IN ('.implode(',',$TYPO3_DB->fullQuoteArray($tableNames,'sys_refindex')).')';
01046 $lostTables = $TYPO3_DB->exec_SELECTgetRows('hash','sys_refindex',$where);
01047 if (count($lostTables)) {
01048 $Err = 'Index table hosted '.count($lostTables).' indexes for non-existing tables, now removed';
01049 $errors[]= $Err;
01050 if ($cli_echo) echo $Err.chr(10);
01051 if (!$testOnly) $TYPO3_DB->exec_DELETEquery('sys_refindex',$where);
01052 }
01053
01054 $testedHowMuch = $recCount.' records from '.$tableCount.' tables were checked/updated.'.chr(10);
01055
01056 $bodyContent = $testedHowMuch.(count($errors)?implode(chr(10),$errors):'Index Integrity was perfect!');
01057 if ($cli_echo) echo $testedHowMuch.(count($errors)?'Updates: '.count($errors):'Index Integrity was perfect!').chr(10);
01058
01059 return array($headerContent,$bodyContent,count($errors));
01060 }
01061 }
01062
01063
01064 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_refindex.php']) {
01065 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_refindex.php']);
01066 }
01067 ?>