Added feature #4592: Keep indexed_search tables consistent when deleting/hiding pages...
authorMichael Stucki <michael.stucki@typo3.org>
Tue, 6 Feb 2007 07:10:36 +0000 (07:10 +0000)
committerMichael Stucki <michael.stucki@typo3.org>
Tue, 6 Feb 2007 07:10:36 +0000 (07:10 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1999 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/indexed_search/class.crawler.php
typo3/sysext/indexed_search/ext_localconf.php

index 9080084..59f7fe6 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-02-06  Michael Stucki  <michael@typo3.org>
+
+       * Added feature #4592: Keep indexed_search tables consistent when deleting/hiding pages (Thanks to Michael Fritz)
+
 2007-02-05  Ingmar Schlecht  <ingmar@typo3.org>
 
        * Lots of <label> tags added to checkbox labels throughout the core (Thanks to Ingo Renner for this big patch!)
index 5705a47..38da67c 100755 (executable)
@@ -805,6 +805,29 @@ class tx_indexedsearch_crawler {
                $this->pObj->addQueueEntry_callBack($cfgRec['set_id'],$nparams,$this->callBack,$cfgRec['pid']);
        }
 
+       /**
+        * Deletes all data stored by indexed search for a given page
+        *
+        * @param       integer         Uid of the page to delete all pHash
+        * @return      void
+        */
+       function deleteFromIndex($id)   {
+
+                       // Lookup old phash rows:
+               $oldPhashRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('phash','index_section', 'page_id='.intval($id));
+
+               $pHashesToDelete = array();
+               foreach ($oldPhashRows as $pHashRow)    {
+                       $pHashesToDelete[] = $pHashRow['phash'];
+               }
+
+               $where_clause = 'phash IN ('.implode(',',$GLOBALS['TYPO3_DB']->cleanIntArray($pHashesToDelete)).')';
+               $tables = explode(',', 'index_debug,index_fulltext,index_grlist,index_phash,index_rel,index_section');
+               foreach ($tables as $table)     {
+                       $GLOBALS['TYPO3_DB']->exec_DELETEquery($table, $where_clause);
+               }
+       }
+
 
 
 
@@ -820,6 +843,24 @@ class tx_indexedsearch_crawler {
        /**
         * TCEmain hook function for on-the-fly indexing of database records
         *
+        * @param       string          TCEmain command
+        * @param       string          Table name
+        * @param       string          Record ID. If new record its a string pointing to index inside t3lib_tcemain::substNEWwithIDs
+        * @param       mixed           Target value (ignored)
+        * @param       object          Reference to tcemain calling object
+        * @return      void
+        */
+       function processCmdmap_preProcess($command, $table, $id, $value, &$pObj)        {
+
+                       // Clean up the index
+               if ($command=='delete' && $table == 'pages')    {
+                       $this->deleteFromIndex($id);
+               }
+       }
+
+       /**
+        * TCEmain hook function for on-the-fly indexing of database records
+        *
         * @param       string          Status "new" or "update"
         * @param       string          Table name
         * @param       string          Record ID. If new record its a string pointing to index inside t3lib_tcemain::substNEWwithIDs
@@ -835,6 +876,11 @@ class tx_indexedsearch_crawler {
                                // Translate new ids.
                        if ($status=='new')     {
                                $id = $pObj->substNEWwithIDs[$id];
+
+                       } elseif ($table=='pages' && $status=='update' && ((array_key_exists('hidden',$fieldArray) && $fieldArray['hidden']==1) || (array_key_exists('no_search',$fieldArray) && $fieldArray['no_search']==1))) {
+
+                                       // If the page should be hidden or not indexed after update, delete index for this page
+                               $this->deleteFromIndex($id);
                        }
 
                                // Get full record and if exists, search for indexing configurations:
index ccd325f..2b0f500 100755 (executable)
@@ -16,6 +16,7 @@ $TYPO3_CONF_VARS['EXTCONF']['crawler']['procInstructions']['tx_indexedsearch_rei
 $TYPO3_CONF_VARS['EXTCONF']['crawler']['cli_hooks']['tx_indexedsearch_crawl'] = 'EXT:indexed_search/class.crawler.php:&tx_indexedsearch_crawler';
 
        // Register with TCEmain:
+$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['tx_indexedsearch'] = 'EXT:indexed_search/class.crawler.php:&tx_indexedsearch_crawler';
 $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['tx_indexedsearch'] = 'EXT:indexed_search/class.crawler.php:&tx_indexedsearch_crawler';
 
        // Configure default document parsers: