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 08be36a..9a458e9
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2006 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
@@ -60,9 +60,6 @@
  *
  */
 
-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.
 
 
 
@@ -204,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;
@@ -341,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;
@@ -451,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))     {
@@ -484,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'];
@@ -510,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']))       {
@@ -536,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'])        {
@@ -554,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();
@@ -564,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.. (?)
@@ -631,11 +630,12 @@ class t3lib_refindex {
         * @param       string          32-byte hash string identifying the record from sys_refindex which you wish to change the value for
         * @param       mixed           Value 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
         * @param       boolean         Return $dataArray only, do not submit it to database.
+        * @param       boolean         If set, it will bypass check for workspace-zero and admin user
         * @return      string          If a return string, that carries an error message, otherwise false (=OK) (except if $returnDataArray is set!)
         */
-       function setReferenceValue($hash,$newValue,$returnDataArray=FALSE     {
+       function setReferenceValue($hash,$newValue,$returnDataArray=FALSE,$bypassWorkspaceAdminCheck=FALSE)     {
 
-               if ($GLOBALS['BE_USER']->workspace===0 && $GLOBALS['BE_USER']->isAdmin())       {
+               if (($GLOBALS['BE_USER']->workspace===0 && $GLOBALS['BE_USER']->isAdmin()) || $bypassWorkspaceAdminCheck)       {
 
                                // Get current index from Database:
                        list($refRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
@@ -666,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;
@@ -700,6 +701,7 @@ class t3lib_refindex {
                                                        if ($returnDataArray)   {
                                                                return $dataArray;
                                                        } else {
+
                                                                        // Execute CMD array:
                                                                $tce = t3lib_div::makeInstance('t3lib_TCEmain');
                                                                $tce->stripslashes_values = FALSE;
@@ -713,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);
                                                                }
                                                        }
                                                }
@@ -851,11 +853,15 @@ class t3lib_refindex {
         *******************************/
 
        /**
-        *
+        * Indexing words from table records. Can be useful for quick backend look ups in records across the system.
         */
        function wordIndexing($table,$uid)      {
-               return; // Disabled until Kasper finishes this feature.
+               return; // Disabled until Kasper finishes this feature. If someone else needs it in the meantime you are welcome to complete it. Below my todo list.
 
+               // TODO:
+               // - Flag to disable indexing
+               // - Clean-up to remove words not used anymore  and indexes for records not in the system anymore.
+               // - UTF-8 compliant substr()
                $lexer = t3lib_div::makeInstance('tx_indexedsearch_lexer');
                $words = $lexer->split2Words(implode(' ',$this->words_strings));
                foreach($words as $w) {
@@ -925,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
@@ -968,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;
        }
 
@@ -998,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)    {
@@ -1019,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);
                                }
                        }
@@ -1030,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);
                        }
                }
@@ -1041,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(chr(10),$errors):'Index Integrity was perfect!');
-               if ($cli_echo) echo $testedHowMuch.(count($errors)?'Updates: '.count($errors):'Index Integrity was perfect!').chr(10);
+               $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;
+
+               if(!$testOnly) {
+                       $registry = t3lib_div::makeInstance('t3lib_Registry');
+                       $registry->set('core', 'sys_refindex_lastUpdate', $GLOBALS['EXEC_TIME']);
+               }
 
                return array($headerContent,$bodyContent,count($errors));
        }
@@ -1058,4 +1071,5 @@ class t3lib_refindex {
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_refindex.php']) {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_refindex.php']);
 }
-?>
+
+?>
\ No newline at end of file