Fixed bug #15383: [Unit tests] Add tests for t3lib_div::validEmail
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_refindex.php
old mode 100755 (executable)
new mode 100644 (file)
index 1a920c3..9a458e9
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2010 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  *
  */
 
-require_once(PATH_t3lib.'class.t3lib_befunc.php');
-require_once(PATH_t3lib.'class.t3lib_tcemain.php');
-require_once(PATH_t3lib.'class.t3lib_flexformtools.php');
-//require_once(PATH_typo3.'sysext/indexed_search/class.lexer.php'); // Disabled until Kasper finishes this feature. Apart from that, t3lib classes should never require stuff from extensions.
 
 
 
@@ -205,6 +201,7 @@ class t3lib_refindex {
                                                case 'db':
                                                        $this->createEntryData_dbRels($table,$uid,$fieldname,'',$deleted,$dat['itemArray']);
                                                break;
+                                               case 'file_reference':
                                                case 'file':
                                                        $this->createEntryData_fileRels($table,$uid,$fieldname,'',$deleted,$dat['newValueFiles']);
                                                break;
@@ -342,6 +339,7 @@ class t3lib_refindex {
                                                                        list($tableName,$recordId) = explode(':',$el['subst']['recordRef']);
                                                                        $this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,$tableName,$recordId,'',-1,$spKey,$subKey);
                                                                 break;
+                                                                case 'file_reference':
                                                                 case 'file':
                                                                        $this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,'_FILE',0,$el['subst']['relFileName'],-1,$spKey,$subKey);
                                                                 break;
@@ -452,7 +450,7 @@ class t3lib_refindex {
                                if (strlen($value) && $softRefs = t3lib_BEfunc::explodeSoftRefParserList($conf['softref']))     {
                                        $softRefValue = $value;
                                        foreach($softRefs as $spKey => $spParams)       {
-                                               $softRefObj = &t3lib_BEfunc::softRefParserObj($spKey);
+                                               $softRefObj = t3lib_BEfunc::softRefParserObj($spKey);
                                                if (is_object($softRefObj))     {
                                                        $resultArray = $softRefObj->findRef($table, $field, $uid, $softRefValue, $spKey, $spParams);
                                                        if (is_array($resultArray))     {
@@ -485,7 +483,7 @@ class t3lib_refindex {
         * @return      void
         * @see t3lib_TCEmain::checkValue_flex_procInData_travDS()
         */
-       function getRelations_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, &$pObj) {
+       function getRelations_flexFormCallBack($dsArr, $dataValue, $PA, $structurePath, $pObj) {
                $structurePath = substr($structurePath,5).'/';  // removing "data/" in the beginning of path (which points to location in data array)
 
                $dsConf = $dsArr['TCEforms']['config'];
@@ -511,7 +509,7 @@ class t3lib_refindex {
                if (strlen($dataValue) && $softRefs = t3lib_BEfunc::explodeSoftRefParserList($dsConf['softref']))       {
                        $softRefValue = $dataValue;
                        foreach($softRefs as $spKey => $spParams)       {
-                               $softRefObj = &t3lib_BEfunc::softRefParserObj($spKey);
+                               $softRefObj = t3lib_BEfunc::softRefParserObj($spKey);
                                if (is_object($softRefObj))     {
                                        $resultArray = $softRefObj->findRef($table, $field, $uid, $softRefValue, $spKey, $spParams, $structurePath);
                                        if (is_array($resultArray) && is_array($resultArray['elements']))       {
@@ -537,7 +535,7 @@ class t3lib_refindex {
         */
        function getRelations_procFiles($value, $conf, $uid)    {
                        // Take care of files...
-               if ($conf['type']=='group' && $conf['internal_type']=='file')   {
+               if ($conf['type'] == 'group' && ($conf['internal_type'] == 'file' || $conf['internal_type'] == 'file_reference')) {
 
                                // Collect file values in array:
                        if ($conf['MM'])        {
@@ -555,7 +553,7 @@ class t3lib_refindex {
                        }
 
                                // Traverse the files and add them:
-                       $uploadFolder = $conf['uploadfolder'];
+                       $uploadFolder = $conf['internal_type'] == 'file' ? $conf['uploadfolder'] : '';
                        $dest = $this->destPathFromUploadFolder($uploadFolder);
                        $newValue = array();
                        $newValueFiles = array();
@@ -565,7 +563,7 @@ class t3lib_refindex {
                                        $realFile = $dest.'/'.trim($file);
 #                                      if (@is_file($realFile))        {               // Now, the refernece index should NOT look if files exist - just faithfully include them if they are in the records!
                                                $newValueFiles[] = array(
-                                                       'filename' => $file,
+                                                       'filename' => basename($file),
                                                        'ID' => md5($realFile),
                                                        'ID_absFile' => $realFile
                                                );      // the order should be preserved here because.. (?)
@@ -668,6 +666,7 @@ class t3lib_refindex {
                                                                        $error = $this->setReferenceValue_dbRels($refRec,$dat['itemArray'],$newValue,$dataArray);
                                                                        if ($error)     return $error;
                                                                break;
+                                                               case 'file_reference':
                                                                case 'file':
                                                                        $this->setReferenceValue_fileRels($refRec,$dat['newValueFiles'],$newValue,$dataArray);
                                                                        if ($error)     return $error;
@@ -716,7 +715,7 @@ class t3lib_refindex {
 
                                                                        // Return errors if any:
                                                                if (count($tce->errorLog))      {
-                                                                       return chr(10).'TCEmain:'.implode(chr(10).'TCEmain:',$tce->errorLog);
+                                                                       return LF.'TCEmain:'.implode(LF.'TCEmain:',$tce->errorLog);
                                                                }
                                                        }
                                                }
@@ -932,8 +931,7 @@ class t3lib_refindex {
                                        unset($wl[$row['baseword']]);
                                }
 
-                               reset($wl);
-                               while(list($key,$val)=each($wl)) {
+                               foreach ($wl as $key => $val) {
                                        $insertFields = array(
                                                'wid' => t3lib_div::md5int($key),
                                                'baseword' => $key
@@ -975,6 +973,9 @@ class t3lib_refindex {
         * @return      string          Input folder prefixed with PATH_site. No checking for existence is done. Output must be a folder without trailing slash.
         */
        function destPathFromUploadFolder($folder)      {
+               if (!$folder) {
+                       return substr(PATH_site, 0, -1);
+               }
                return PATH_site.$folder;
        }
 
@@ -1005,9 +1006,9 @@ class t3lib_refindex {
 
                $headerContent = $testOnly ? 'Reference Index being TESTED (nothing written, use "-e" to update)' : 'Reference Index being Updated';
                if ($cli_echo) echo
-                                               '*******************************************'.chr(10).
-                                               $headerContent.chr(10).
-                                               '*******************************************'.chr(10);
+                                               '*******************************************'.LF.
+                                               $headerContent.LF.
+                                               '*******************************************'.LF;
 
                        // Traverse all tables:
                foreach ($TCA as $tableName => $cfg)    {
@@ -1026,7 +1027,7 @@ class t3lib_refindex {
                                if ($result['addedNodes'] || $result['deletedNodes'])   {
                                        $Err = 'Record '.$tableName.':'.$recdat['uid'].' had '.$result['addedNodes'].' added indexes and '.$result['deletedNodes'].' deleted indexes';
                                        $errors[]= $Err;
-                                       if ($cli_echo) echo $Err.chr(10);
+                                       if ($cli_echo) echo $Err.LF;
                                        #$errors[] = t3lib_div::view_array($result);
                                }
                        }
@@ -1037,7 +1038,7 @@ class t3lib_refindex {
                        if (count($lostIndexes))        {
                                $Err = 'Table '.$tableName.' has '.count($lostIndexes).' lost indexes which are now deleted';
                                $errors[]= $Err;
-                               if ($cli_echo) echo $Err.chr(10);
+                               if ($cli_echo) echo $Err.LF;
                                if (!$testOnly) $TYPO3_DB->exec_DELETEquery('sys_refindex',$where);
                        }
                }
@@ -1048,14 +1049,19 @@ class t3lib_refindex {
                if (count($lostTables)) {
                        $Err = 'Index table hosted '.count($lostTables).' indexes for non-existing tables, now removed';
                        $errors[]= $Err;
-                       if ($cli_echo) echo $Err.chr(10);
+                       if ($cli_echo) echo $Err.LF;
                        if (!$testOnly) $TYPO3_DB->exec_DELETEquery('sys_refindex',$where);
                }
 
-               $testedHowMuch = $recCount.' records from '.$tableCount.' tables were checked/updated.'.chr(10);
+               $testedHowMuch = $recCount.' records from '.$tableCount.' tables were checked/updated.'.LF;
+
+               $bodyContent = $testedHowMuch.(count($errors)?implode(LF,$errors):'Index Integrity was perfect!');
+               if ($cli_echo) echo $testedHowMuch.(count($errors)?'Updates: '.count($errors):'Index Integrity was perfect!').LF;
 
-               $bodyContent = $testedHowMuch.(count($errors)?implode(chr(10),$errors):'Index Integrity was perfect!');
-               if ($cli_echo) echo $testedHowMuch.(count($errors)?'Updates: '.count($errors):'Index Integrity was perfect!').chr(10);
+               if(!$testOnly) {
+                       $registry = t3lib_div::makeInstance('t3lib_Registry');
+                       $registry->set('core', 'sys_refindex_lastUpdate', $GLOBALS['EXEC_TIME']);
+               }
 
                return array($headerContent,$bodyContent,count($errors));
        }