Browse Source

Fix Bug #768247: Hiding a document does not affect the Solr index

tags/v1.2.0
Sebastian Meyer 11 years ago
parent
commit
855a3ae763
  1. 2
      dlf/common/class.tx_dlf_document.php
  2. 120
      dlf/common/class.tx_dlf_indexing.php
  3. 73
      dlf/hooks/class.tx_dlf_tcemain.php
  4. 8
      dlf/locallang_db.xml

2
dlf/common/class.tx_dlf_document.php

@ -1100,7 +1100,7 @@ class tx_dlf_document {
// Add document to index.
if ($core) {
tx_dlf_indexing::addToIndex($this, $core);
tx_dlf_indexing::add($this, $core);
}

120
dlf/common/class.tx_dlf_indexing.php

@ -129,12 +129,12 @@ class tx_dlf_indexing {
*
* @access public
*
* @param tx_dlf_document &$doc: The document to index
* @param tx_dlf_document &$doc: The document to add
* @param integer $core: UID of the Solr core to use
*
* @return void
* @return integer 0 on success or 1 on failure
*/
public static function addToIndex(tx_dlf_document &$doc, $core = 1) {
public static function add(tx_dlf_document &$doc, $core = 1) {
if (in_array($doc->uid, self::$processedDocs)) {
@ -147,7 +147,7 @@ class tx_dlf_indexing {
// Handle multi-volume documents.
if ($doc->parentid) {
$errors = self::addToIndex(tx_dlf_document::getInstance($doc->parentid, 0, TRUE), $core);
$errors = self::add(tx_dlf_document::getInstance($doc->parentid, 0, TRUE), $core);
}
@ -248,6 +248,106 @@ class tx_dlf_indexing {
}
/**
* Delete document from Solr index
*
* @access public
*
* @param integer $uid: UID of the document to delete
*
* @return integer 0 on success or 1 on failure
*/
public static function delete($uid) {
// Sanitize input.
$uid = max(intval($uid), 0);
// Get Solr core for document.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_solrcores.uid AS uid,tx_dlf_documents.title AS title',
'tx_dlf_solrcores,tx_dlf_documents',
'tx_dlf_solrcores.uid=tx_dlf_documents.solrcore AND tx_dlf_documents.uid='.$uid.tx_dlf_helper::whereClause('tx_dlf_solrcores'),
'',
'',
'1'
);
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
list ($core, $title) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
// Establish Solr connection.
if (self::solrConnect($core)) {
try {
// Delete Solr document.
self::$solr->deleteByQuery('uid:'.$uid);
self::$solr->commit();
} catch (Exception $e) {
if (!defined('TYPO3_cliMode')) {
$_message = t3lib_div::makeInstance(
't3lib_FlashMessage',
$GLOBALS['LANG']->getLL('flash.solrException', TRUE).'<br />'.htmlspecialchars($e->getMessage()),
$GLOBALS['LANG']->getLL('flash.error', TRUE),
t3lib_FlashMessage::ERROR,
TRUE
);
t3lib_FlashMessageQueue::addMessage($_message);
}
trigger_error('Apache Solr exception thrown: '.$e->getMessage(), E_USER_ERROR);
return 1;
}
} else {
if (!defined('TYPO3_cliMode')) {
$_message = t3lib_div::makeInstance(
't3lib_FlashMessage',
$GLOBALS['LANG']->getLL('flash.solrNoConnection', TRUE),
$GLOBALS['LANG']->getLL('flash.error', TRUE),
t3lib_FlashMessage::ERROR,
TRUE
);
t3lib_FlashMessageQueue::addMessage($_message);
}
trigger_error('Could not connect to Apache Solr server', E_USER_ERROR);
return 1;
}
if (!defined('TYPO3_cliMode')) {
$_message = t3lib_div::makeInstance(
't3lib_FlashMessage',
htmlspecialchars(sprintf($GLOBALS['LANG']->getLL('flash.documentDeleted'), $title, $uid)),
$GLOBALS['LANG']->getLL('flash.done', TRUE),
t3lib_FlashMessage::OK,
TRUE
);
t3lib_FlashMessageQueue::addMessage($_message);
}
}
}
/**
* Load indexing configuration
*
* @access protected
@ -326,7 +426,7 @@ class tx_dlf_indexing {
* @param tx_dlf_document &$doc: The METS document
* @param array $logicalUnit: Array of the logical unit to process
*
* @return void
* @return integer 0 on success or 1 on failure
*/
protected static function process(tx_dlf_document &$doc, array $logicalUnit) {
@ -498,15 +598,19 @@ class tx_dlf_indexing {
*
* @return boolean TRUE on success or FALSE on failure
*/
protected static function solrConnect($core, $pid) {
protected static function solrConnect($core, $pid = 0) {
if (!self::$solr) {
// Connect to Solr server.
if (self::$solr = tx_dlf_solr::solrConnect($core)) {
// Load indexing configuration.
self::loadIndexConf($pid);
// Load indexing configuration if needed.
if ($pid) {
self::loadIndexConf($pid);
}
} else {

73
dlf/hooks/class.tx_dlf_tcemain.php

@ -38,7 +38,7 @@
class tx_dlf_tcemain {
/**
* Post-processing hook for the process_datamap() method.
* Field post-processing hook for the process_datamap() method.
*
* @access public
*
@ -188,6 +188,77 @@ class tx_dlf_tcemain {
}
/**
* After database operations hook for the process_datamap() method.
*
* @access public
*
* @param string $status: 'new' or 'update'
* @param string $table: The destination table
* @param integer $id: The uid of the record
* @param array &$fieldArray: Array of field values
* @param t3lib_TCEmain $pObj: The parent object
*
* @return void
*/
public function processDatamap_afterDatabaseOperations($status, $table, $id, &$fieldArray, $pObj) {
if ($status == "update") {
switch ($table) {
// After database operations for table "tx_dlf_documents".
case 'tx_dlf_documents':
// Delete/re-index document in Solr according to "hidden" status in database.
if (isset($fieldArray['hidden'])) {
// Get Solr core.
$result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'tx_dlf_solrcores.index_name AS index_name',
'tx_dlf_solrcores,tx_dlf_documents',
'tx_dlf_solrcores.uid=tx_dlf_documents.solrcore AND tx_dlf_documents.uid='.intval($id).tx_dlf_helper::whereClause('tx_dlf_solrcores'),
'',
'',
'1'
);
if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
list ($core) = $GLOBALS['TYPO3_DB']->sql_fetch_row($result);
// Establish Solr connection.
if ($solr = tx_dlf_solr::solrConnect($core)) {
if ($fieldArray['hidden']) {
// Delete Solr document.
$solr->deleteByQuery('uid:'.$id);
$solr->commit();
} else {
// Reindex document.
$doc = tx_dlf_document::getInstance($id);
$doc->save($doc->pid, $core);
}
}
}
}
break;
}
}
}
/**
* Post-processing hook for the process_cmdmap() method.
*
* @access public

8
dlf/locallang_db.xml

@ -107,6 +107,8 @@
<label index="tx_dlf_libraries.tab1">General</label>
<label index="tx_dlf_libraries.tab2">Translation</label>
<label index="tx_dlf_libraries.tab3">Catalogs</label>
<label index="tx_dlf_toolbox.toolsDfgviewer">Link to DFG Viewer</label>
<label index="tx_dlf_toolbox.toolsPdf">PDF Download</label>
<label index="tt_content.dlf_collection">DLF: Collection</label>
<label index="tt_content.dlf_listview">DLF: List View</label>
<label index="tt_content.dlf_metadata">DLF: Metadata</label>
@ -116,8 +118,6 @@
<label index="tt_content.dlf_search">DLF: Search</label>
<label index="tt_content.dlf_toc">DLF: Table of Contents</label>
<label index="tt_content.dlf_toolbox">DLF: Toolbox</label>
<label index="tx_dlf_toolbox.toolsDfgviewer">Link to DFG Viewer</label>
<label index="tx_dlf_toolbox.toolsPdf">PDF Download</label>
</languageKey>
<languageKey index="de" type="array">
<label index="tx_dlf_documents">Dokumente</label>
@ -221,6 +221,8 @@
<label index="tx_dlf_libraries.tab1">Allgemein</label>
<label index="tx_dlf_libraries.tab2">Übersetzung</label>
<label index="tx_dlf_libraries.tab3">Kataloge</label>
<label index="tx_dlf_toolbox.toolsDfgviewer">Link zum DFG-Viewer</label>
<label index="tx_dlf_toolbox.toolsPdf">PDF-Download</label>
<label index="tt_content.dlf_collection">DLF: Kollektion</label>
<label index="tt_content.dlf_listview">DLF: Listenansicht</label>
<label index="tt_content.dlf_metadata">DLF: Metadaten</label>
@ -230,8 +232,6 @@
<label index="tt_content.dlf_search">DLF: Suche</label>
<label index="tt_content.dlf_toc">DLF: Inhaltsverzeichnis</label>
<label index="tt_content.dlf_toolbox">DLF: Werkzeugkasten</label>
<label index="tx_dlf_toolbox.toolsDfgviewer">Link zum DFG-Viewer</label>
<label index="tx_dlf_toolbox.toolsPdf">PDF-Download</label>
</languageKey>
</data>
</T3locallang>
Loading…
Cancel
Save