Fixed bug #6992: t3ib_refindex requires t3lib_BEfunc but does not include it
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_refindex.php
index 83247be..ec4f67c 100755 (executable)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
-/**
- * Reference index processing
- *
- * $Id$
- *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
- */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
  *
  *
  */
 
+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');
+//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.
 
 
 
@@ -96,7 +90,7 @@ class t3lib_refindex {
 
        var $words_strings = array();
        var $words = array();
-       
+
        var $hashVersion = 1;   // Number which we can increase if a change in the code means we will have to force a re-generation of the index.
 
 
@@ -157,7 +151,7 @@ class t3lib_refindex {
 
                                $result['relations'] = $relations;
                        } else return FALSE;    // Weird mistake I would say...
-                       
+
                                // Words:
                        if (!$testOnly) $this->wordIndexing($table,$uid);
                }
@@ -191,7 +185,7 @@ class t3lib_refindex {
                        list($record) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*',$table,'uid='.intval($uid));
 
                        if (is_array($record))  {
-                               
+
                                        // Initialize:
                                $this->words_strings = array();
                                $this->words = array();
@@ -418,7 +412,7 @@ class t3lib_refindex {
                                }
 
                                        // Add DB:
-                               if ($result = $this->getRelations_procDB($value, $conf, $uid))  {
+                               if ($result = $this->getRelations_procDB($value, $conf, $uid, $table))  {
                                                // Create an entry for the field with all DB relations:
                                        $outRow[$field] = array(
                                                'type' => 'db',
@@ -430,7 +424,7 @@ class t3lib_refindex {
                                if ($conf['type']=='flex')      {
 
                                                // Get current value array:
-                                               // NOTICE: failure to resolve Data Structures can lead to integrity problems with the reference index. Please look up the note in the JavaDoc documentation for the function t3lib_BEfunc::getFlexFormDS() 
+                                               // NOTICE: failure to resolve Data Structures can lead to integrity problems with the reference index. Please look up the note in the JavaDoc documentation for the function t3lib_BEfunc::getFlexFormDS()
                                        $dataStructArray = t3lib_BEfunc::getFlexFormDS($conf, $row, $table,'',$this->WSOL);
                                        $currentValueArray = t3lib_div::xml2array($value);
 
@@ -589,9 +583,10 @@ class t3lib_refindex {
         * @param       string          Field value
         * @param       array           Field configuration array of type "TCA/columns"
         * @param       integer         Field uid
+        * @param       string          Table name
         * @return      array           If field type is OK it will return an array with the database relations. Else false
         */
-       function getRelations_procDB($value, $conf, $uid)       {
+       function getRelations_procDB($value, $conf, $uid, $table = '')  {
 
                        // DB record lists:
                if ($this->isReferenceField($conf))     {
@@ -603,7 +598,7 @@ class t3lib_refindex {
                        }
 
                        $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
-                       $dbAnalysis->start($value,$allowedTables,$conf['MM'],$uid);
+                       $dbAnalysis->start($value,$allowedTables,$conf['MM'],$uid,$table,$conf);
 
                        return $dbAnalysis->itemArray;
                }
@@ -637,11 +632,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     {
-               
-               if ($GLOBALS['BE_USER']->workspace===0 && $GLOBALS['BE_USER']->isAdmin())       {
+       function setReferenceValue($hash,$newValue,$returnDataArray=FALSE,$bypassWorkspaceAdminCheck=FALSE)     {
+
+               if (($GLOBALS['BE_USER']->workspace===0 && $GLOBALS['BE_USER']->isAdmin()) || $bypassWorkspaceAdminCheck)       {
 
                                // Get current index from Database:
                        list($refRec) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
@@ -706,6 +702,7 @@ class t3lib_refindex {
                                                        if ($returnDataArray)   {
                                                                return $dataArray;
                                                        } else {
+
                                                                        // Execute CMD array:
                                                                $tce = t3lib_div::makeInstance('t3lib_TCEmain');
                                                                $tce->stripslashes_values = FALSE;
@@ -713,10 +710,10 @@ class t3lib_refindex {
                                                                $tce->bypassWorkspaceRestrictions = TRUE;
                                                                $tce->bypassFileHandling = TRUE;
                                                                $tce->bypassAccessCheckForRecords = TRUE;       // Otherwise this cannot update things in deleted records...
-                                                       
+
                                                                $tce->start($dataArray,array());        // check has been done previously that there is a backend user which is Admin and also in live workspace
                                                                $tce->process_datamap();
-       
+
                                                                        // Return errors if any:
                                                                if (count($tce->errorLog))      {
                                                                        return chr(10).'TCEmain:'.implode(chr(10).'TCEmain:',$tce->errorLog);
@@ -855,12 +852,17 @@ class t3lib_refindex {
         * Indexing words
         *
         *******************************/
-       
+
        /**
-        *
+        * 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. 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) {
@@ -880,9 +882,9 @@ class t3lib_refindex {
         */
        function updateWordIndex($words,$table,$uid) {
 
-                       // Submit words to 
+                       // Submit words to
                $this->submitWords($words);
-               
+
                        // Result id and remove relations:
                $rid = t3lib_div::md5int($table.':'.$uid);
                $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_refindex_rel', 'rid='.intval($rid));
@@ -917,7 +919,7 @@ class t3lib_refindex {
 
                $hashArr = array();
                foreach($wl as $w)      {
-                       $hashArr[] = t3lib_div::md5int($w);     
+                       $hashArr[] = t3lib_div::md5int($w);
                }
                $wl = array_flip($wl);
 
@@ -963,7 +965,7 @@ class t3lib_refindex {
         * @return      boolean         True if DB reference field (group/db or select with foreign-table)
         */
        function isReferenceField($conf)        {
-               return ($conf['type']=='group' && $conf['internal_type']=='db') ||      ($conf['type']=='select' && $conf['foreign_table']);
+               return ($conf['type']=='group' && $conf['internal_type']=='db') || (($conf['type']=='select' || $conf['type']=='inline') && $conf['foreign_table']);
        }
 
        /**
@@ -1001,7 +1003,7 @@ class t3lib_refindex {
                $recCount=0;
                $tableCount=0;
 
-               $headerContent = $testOnly ? 'Reference Index being TESTED (nothing written)' : 'Reference Index being Updated';
+               $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).