Bug #98988
openMissing functionality - Database Records indexing on save in indexed_search 11.5
0%
Description
Hello,
I have been mitgrating an extension I made in 8.7 to 11.5 and it’s using indexed_search to index the records. In 8.7, the Index Records immediately when saved works but in 11.5 with the same configuration it doesn’t work.
This is my hypothesis, I’ve been digging a bit in the code and I beleive this part of the code that was in TYPO3\CMS\IndexedSearch\Hook\CrawlerHook from 8.7 should have been added somewhere else in the code with the removal of interdependance between crawler and indexed search for 11.5.
/*************************
*
* Hook functions for DataHandler (indexing of records)
*
*************************/
/**
* DataHandler hook function for on-the-fly indexing of database records
*
* @param string $command DataHandler command
* @param string $table Table name
* @param string $id Record ID. If new record its a string pointing to index inside \TYPO3\CMS\Core\DataHandling\DataHandler::substNEWwithIDs
* @param mixed $value Target value (ignored)
* @param DataHandler $pObj DataHandler calling object
*/
public function processCmdmap_preProcess($command, $table, $id, $value, $pObj)
{
// Clean up the index
if ($command === 'delete' && $table === 'pages') {
$this->deleteFromIndex($id);
}
}
/**
* DataHandler hook function for on-the-fly indexing of database records
*
* @param string $status Status "new" or "update
* @param string $table Table name
* @param string $id Record ID. If new record its a string pointing to index inside \TYPO3\CMS\Core\DataHandling\DataHandler::substNEWwithIDs
* @param array $fieldArray Field array of updated fields in the operation
* @param DataHandler $pObj DataHandler calling object
*/
public function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, $pObj)
{
// Check if any fields are actually updated:
if (empty($fieldArray)) {
return;
}
// 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:
$currentRecord = BackendUtility::getRecord($table, $id);
if (is_array($currentRecord)) {
// Select all (not running) indexing configurations of type "record" (1) and
// which points to this table and is located on the same page as the record
// or pointing to the right source PID
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('index_config');
$result = $queryBuilder->select('*')
->from('index_config')
->where(
$queryBuilder->expr()->eq('set_id', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq('type', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)),
$queryBuilder->expr()->eq(
'table2index',
$queryBuilder->createNamedParameter($table, \PDO::PARAM_STR)
),
$queryBuilder->expr()->orX(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq(
'alternative_source_pid',
$queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
),
$queryBuilder->expr()->eq(
'pid',
$queryBuilder->createNamedParameter($currentRecord['pid'], \PDO::PARAM_INT)
)
),
$queryBuilder->expr()->eq(
'alternative_source_pid',
$queryBuilder->createNamedParameter($currentRecord['pid'], \PDO::PARAM_INT)
)
),
$queryBuilder->expr()->eq(
'records_indexonchange',
$queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)
)
)
->execute();
while ($cfgRec = $result->fetch()) {
$this->indexSingleRecord($currentRecord, $cfgRec);
}
}
}
Updated by Tomas Norre Mikkelsen about 2 years ago
I think you are right, this is missing. One can still select "database records" in the Indexed Search configuration.
The questions are:
1. Where does this code belong?
2. Will it need refactoring? before adding it back. (refactoring in respect for PSR-14)
Updated by Christian Kuhn about 2 years ago
- Related to Task #93110: Drop dependency to EXT:crawler added