From 48e1af02b7a0d6ad10af09c7895b148f81db71df Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Fri, 30 Mar 2012 11:14:14 +0200 Subject: [PATCH] Unset default Solr core --- dlf/common/class.tx_dlf_document.php | 11 +++- dlf/common/class.tx_dlf_helper.php | 4 +- dlf/common/class.tx_dlf_indexing.php | 8 +-- dlf/common/class.tx_dlf_solr.php | 4 +- dlf/ext_tables.php | 3 +- dlf/hooks/class.tx_dlf_tceforms.php | 55 +++++++++++++++++++ dlf/locallang.xml | 16 +++--- dlf/modules/indexing/index.php | 4 +- dlf/modules/indexing/locallang.xml | 2 + .../collection/class.tx_dlf_collection.php | 4 +- dlf/plugins/oai/flexform.xml | 2 +- dlf/plugins/search/class.tx_dlf_search.php | 16 ++++-- dlf/plugins/search/flexform.xml | 9 +-- .../statistics/class.tx_dlf_statistics.php | 4 +- dlf/plugins/toc/class.tx_dlf_toc.php | 2 +- 15 files changed, 110 insertions(+), 34 deletions(-) diff --git a/dlf/common/class.tx_dlf_document.php b/dlf/common/class.tx_dlf_document.php index 3cf8e7b1..056af8c0 100644 --- a/dlf/common/class.tx_dlf_document.php +++ b/dlf/common/class.tx_dlf_document.php @@ -1031,7 +1031,7 @@ class tx_dlf_document { * * @return boolean TRUE on success or FALSE on failure */ - public function save($pid = 0, $core = 1) { + public function save($pid = 0, $core = 0) { if (TYPO3_MODE !== 'BE') { @@ -1044,6 +1044,9 @@ class tx_dlf_document { // Make sure $pid is a non-negative integer. $pid = max(intval($pid), 0); + // Make sure $core is a non-negative integer. + $core = max(intval($core), 0); + // If $pid is not given, try to get it elsewhere. if (!$pid && $this->pid) { @@ -1263,7 +1266,7 @@ class tx_dlf_document { if ($superior->pid != $pid) { - $superior->save($pid); + $superior->save($pid, $core); } @@ -1348,6 +1351,10 @@ class tx_dlf_document { tx_dlf_indexing::add($this, $core); + } else { + + trigger_error('Invalid UID for Solr core ('.$core.') given to index document', E_USER_NOTICE); + } return TRUE; diff --git a/dlf/common/class.tx_dlf_helper.php b/dlf/common/class.tx_dlf_helper.php index a23e9313..05e9f315 100644 --- a/dlf/common/class.tx_dlf_helper.php +++ b/dlf/common/class.tx_dlf_helper.php @@ -771,8 +771,8 @@ class tx_dlf_helper { if (TYPO3_MODE === 'FE') { - // Tables "tx_dlf_solrcores" and "tx_dlf_formats" always have PID 0. - if (in_array($table, array ('tx_dlf_solrcores', 'tx_dlf_formats'))) { + // Table "tx_dlf_formats" always has PID 0. + if ($table == 'tx_dlf_formats') { return t3lib_BEfunc::deleteClause($table); diff --git a/dlf/common/class.tx_dlf_indexing.php b/dlf/common/class.tx_dlf_indexing.php index d3711fef..d37cf19b 100644 --- a/dlf/common/class.tx_dlf_indexing.php +++ b/dlf/common/class.tx_dlf_indexing.php @@ -134,7 +134,7 @@ class tx_dlf_indexing { * * @return integer 0 on success or 1 on failure */ - public static function add(tx_dlf_document &$doc, $core = 1) { + public static function add(tx_dlf_document &$doc, $core = 0) { if (in_array($doc->uid, self::$processedDocs)) { @@ -242,8 +242,8 @@ class tx_dlf_indexing { $_message = t3lib_div::makeInstance( 't3lib_FlashMessage', $GLOBALS['LANG']->getLL('flash.solrNoConnection', TRUE), - $GLOBALS['LANG']->getLL('flash.error', TRUE), - t3lib_FlashMessage::ERROR, + $GLOBALS['LANG']->getLL('flash.warning', TRUE), + t3lib_FlashMessage::WARNING, TRUE ); @@ -251,7 +251,7 @@ class tx_dlf_indexing { } - trigger_error('Could not connect to Apache Solr server', E_USER_ERROR); + trigger_error('Could not connect to Apache Solr server', E_USER_WARNING); return 1; diff --git a/dlf/common/class.tx_dlf_solr.php b/dlf/common/class.tx_dlf_solr.php index f3b11725..d43fb44f 100644 --- a/dlf/common/class.tx_dlf_solr.php +++ b/dlf/common/class.tx_dlf_solr.php @@ -55,7 +55,7 @@ class tx_dlf_solr { * * @return mixed Instance of Apache_Solr_Service or NULL on failure */ - public static function solrConnect($core = 1) { + public static function solrConnect($core = 0) { // Load class. if (!class_exists('Apache_Solr_Service')) { @@ -97,7 +97,7 @@ class tx_dlf_solr { } else { - trigger_error('Could not find Solr core with UID '.$core, E_USER_ERROR); + trigger_error('Could not find Solr core with UID '.$core, E_USER_NOTICE); return; diff --git a/dlf/ext_tables.php b/dlf/ext_tables.php index 5f357678..7600b795 100644 --- a/dlf/ext_tables.php +++ b/dlf/ext_tables.php @@ -129,7 +129,8 @@ $TCA['tx_dlf_solrcores'] = array ( 'delete' => 'deleted', 'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php', 'iconfile' => t3lib_extMgm::extRelPath($_EXTKEY).'res/icon_txdlfsolrcores.png', - 'rootLevel' => 1, + 'rootLevel' => 0, + 'adminOnly' => 1, 'dividers2tabs' => 2, ), 'feInterface' => array ( diff --git a/dlf/hooks/class.tx_dlf_tceforms.php b/dlf/hooks/class.tx_dlf_tceforms.php index 50631525..67cd137d 100644 --- a/dlf/hooks/class.tx_dlf_tceforms.php +++ b/dlf/hooks/class.tx_dlf_tceforms.php @@ -147,6 +147,61 @@ class tx_dlf_tceforms { } + /** + * Helper to get flexform's items array for plugin "tx_dlf_search" + * + * @access public + * + * @param array &$params: An array with parameters + * @param t3lib_TCEforms &$pObj: The parent object + * + * @return void + */ + public function itemsProcFunc_solrList(&$params, &$pObj) { + + if ($params['row']['pi_flexform']) { + + $pi_flexform = t3lib_div::xml2array($params['row']['pi_flexform']); + + $pages = $pi_flexform['data']['sDEF']['lDEF']['pages']['vDEF']; + + // There is a strange behavior where the uid from the flexform is prepended by the table's name and appended by its title. + // i.e. instead of "18" it reads "pages_18|Title" + if (!t3lib_div::testInt($pages)) { + + $_parts = explode('|', $pages); + + $pages = array_pop(explode('_', $_parts[0])); + + } + + if ($pages > 0) { + + $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery( + 'label,uid', + 'tx_dlf_solrcores', + 'pid IN ('.intval($pages).',0)'.tx_dlf_helper::whereClause('tx_dlf_solrcores'), + '', + 'label', + '' + ); + + if ($GLOBALS['TYPO3_DB']->sql_num_rows($result) > 0) { + + while ($resArray = $GLOBALS['TYPO3_DB']->sql_fetch_row($result)) { + + $params['items'][] = $resArray; + + } + + } + + } + + } + + } + /** * Helper to get flexform's items array for plugin "tx_dlf_toolbox" * diff --git a/dlf/locallang.xml b/dlf/locallang.xml index fb774f27..3619af0e 100644 --- a/dlf/locallang.xml +++ b/dlf/locallang.xml @@ -138,7 +138,7 @@ - + @@ -146,10 +146,10 @@ - + - + @@ -157,7 +157,7 @@ - + @@ -297,7 +297,7 @@ - + @@ -305,10 +305,10 @@ - + - + @@ -316,7 +316,7 @@ - + diff --git a/dlf/modules/indexing/index.php b/dlf/modules/indexing/index.php index 6cdc3989..914617e2 100644 --- a/dlf/modules/indexing/index.php +++ b/dlf/modules/indexing/index.php @@ -70,7 +70,7 @@ class tx_dlf_modIndexing extends tx_dlf_module { $_cores = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 'tx_dlf_solrcores.label AS label,tx_dlf_solrcores.uid AS uid', 'tx_dlf_solrcores', - 'tx_dlf_solrcores.pid=0'.tx_dlf_helper::whereClause('tx_dlf_solrcores'), + '1=1'.tx_dlf_helper::whereClause('tx_dlf_solrcores'), '', '', '' @@ -134,7 +134,7 @@ class tx_dlf_modIndexing extends tx_dlf_module { $_cores = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 'tx_dlf_solrcores.label AS label,tx_dlf_solrcores.uid AS uid', 'tx_dlf_solrcores', - 'tx_dlf_solrcores.pid=0'.tx_dlf_helper::whereClause('tx_dlf_solrcores'), + '1=1'.tx_dlf_helper::whereClause('tx_dlf_solrcores'), '', '', '' diff --git a/dlf/modules/indexing/locallang.xml b/dlf/modules/indexing/locallang.xml index aba9528a..7a3b1f32 100644 --- a/dlf/modules/indexing/locallang.xml +++ b/dlf/modules/indexing/locallang.xml @@ -13,6 +13,7 @@ + @@ -33,6 +34,7 @@ + diff --git a/dlf/plugins/collection/class.tx_dlf_collection.php b/dlf/plugins/collection/class.tx_dlf_collection.php index 34be4698..dea5cfad 100644 --- a/dlf/plugins/collection/class.tx_dlf_collection.php +++ b/dlf/plugins/collection/class.tx_dlf_collection.php @@ -54,7 +54,9 @@ class tx_dlf_collection extends tx_dlf_plugin { $this->init($conf); // Quit without doing anything if required configuration variables are not set. - if (!$this->conf['pages']) { + if (empty($this->conf['pages'])) { + + trigger_error('Incomplete configuration for plugin '.get_class($this), E_USER_NOTICE); return $content; diff --git a/dlf/plugins/oai/flexform.xml b/dlf/plugins/oai/flexform.xml index 91b47507..bf8ee722 100644 --- a/dlf/plugins/oai/flexform.xml +++ b/dlf/plugins/oai/flexform.xml @@ -13,9 +13,9 @@ - reload 1 + reload group db diff --git a/dlf/plugins/search/class.tx_dlf_search.php b/dlf/plugins/search/class.tx_dlf_search.php index 2579a39a..3eb36313 100644 --- a/dlf/plugins/search/class.tx_dlf_search.php +++ b/dlf/plugins/search/class.tx_dlf_search.php @@ -56,6 +56,15 @@ class tx_dlf_search extends tx_dlf_plugin { // Disable caching for this plugin. $this->setCache(FALSE); + // Quit without doing anything if required variables are not set. + if (empty($this->conf['solrcore'])) { + + trigger_error('Incomplete configuration for plugin '.get_class($this), E_USER_NOTICE); + + return $content; + + } + if (empty($this->piVars['query'])) { // Load template file. @@ -83,12 +92,9 @@ class tx_dlf_search extends tx_dlf_plugin { return $this->pi_wrapInBaseClass($content); - } else { + } elseif (($solr = tx_dlf_solr::solrConnect($this->conf['solrcore'])) !== NULL) { - // Get Solr instance... - $solr = tx_dlf_solr::solrConnect($this->conf['solrcore']); - - // ...and perform search. + // Perform search. $query = $solr->search($this->piVars['query'], 0, $this->conf['limit'], array ()); $numHits = count($query->response->docs); diff --git a/dlf/plugins/search/flexform.xml b/dlf/plugins/search/flexform.xml index 07020f71..55bf9e5e 100644 --- a/dlf/plugins/search/flexform.xml +++ b/dlf/plugins/search/flexform.xml @@ -15,6 +15,7 @@ 1 + reload group db @@ -28,15 +29,15 @@ 1 + FIELD:pages:REQ:true select - tx_dlf_solrcores - AND tx_dlf_solrcores.pid=0 ORDER BY tx_dlf_solrcores.label - 1 + + tx_dlf_tceforms->itemsProcFunc_solrList 1 1 - 1 + 0 diff --git a/dlf/plugins/statistics/class.tx_dlf_statistics.php b/dlf/plugins/statistics/class.tx_dlf_statistics.php index c7a4516b..5ba76d4a 100644 --- a/dlf/plugins/statistics/class.tx_dlf_statistics.php +++ b/dlf/plugins/statistics/class.tx_dlf_statistics.php @@ -54,7 +54,9 @@ class tx_dlf_statistics extends tx_dlf_plugin { $this->init($conf); // Quit without doing anything if required configuration variables are not set. - if (!$this->conf['pages']) { + if (empty($this->conf['pages'])) { + + trigger_error('Incomplete configuration for plugin '.get_class($this), E_USER_NOTICE); return $content; diff --git a/dlf/plugins/toc/class.tx_dlf_toc.php b/dlf/plugins/toc/class.tx_dlf_toc.php index 3f843adc..ac281306 100644 --- a/dlf/plugins/toc/class.tx_dlf_toc.php +++ b/dlf/plugins/toc/class.tx_dlf_toc.php @@ -163,7 +163,7 @@ class tx_dlf_toc extends tx_dlf_plugin { // Check for typoscript configuration to prevent fatal error. if (empty($this->conf['menuConf.'])) { - trigger_error('No typoscript configuration for table of contents available', E_USER_ERROR); + trigger_error('No typoscript configuration for table of contents available', E_USER_NOTICE); return $content;