Closed netengine-at closed 3 years ago
The field is a comma separated list auf root pages, not a switch for on, off. You can look for a Hook in the file upload process and save the list of desired root pages. If you want to find all documents you can write a simple scheduler task, which set automatically all root page lists. Also you can check the sys_file entry for mime types, if you want to index only PDF documents for examle. Or to check the identifier to get only documents from specified folders.
It could be done with an EventListener
<?php
namespace Your\Namespace\EventListener;
use HMMH\SolrFileIndexer\IndexQueue\Queue;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\Event\AfterFileMetaDataCreatedEvent;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
/**
* Enable indexing of new files
*/
class AfterFileMetaDataCreated
{
/**
* @var Queue
*/
protected $queue;
/**
* @var ConfigurationManagerInterface
*/
protected $configurationManager;
/**
* @var ResourceFactory
*/
protected $resourceFactory;
public function __invoke(AfterFileMetaDataCreatedEvent $event): void
{
$typoScript = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
preg_match_all(
'/\w+/',
$typoScript['plugin.']['tx_solr.']['index.']['queue.']['sys_file_metadata.']['allowedFileTypes'],
$matches
);
$allowedFileTypes = $matches[0];
$file = BackendUtility::getRecord('sys_file', $event->getFileUid());
if (in_array(strtolower($file['extension']), $allowedFileTypes))
{
$table = 'sys_file_metadata';
/** @var Connection $connection */
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
$connection->update(
$table,
[
// List of root pages
'enable_indexing' => 1
],
[
'uid' => $event->getMetaDataUid()
]
);
$this->queue->saveItemForRootpage($table, $event->getMetaDataUid(), '1', 'sys_file_metadata', []);
}
}
public function injectQueue(Queue $queue)
{
$this->queue = $queue;
}
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager)
{
$this->configurationManager = $configurationManager;
}
public function injectResourceFactory(ResourceFactory $resourceFactory)
{
$this->resourceFactory = $resourceFactory;
}
}
Thanks for the help guy!
Hi,
is it possible to set enable_indexing=1 as default?
I was thinking I could extend your extension (just the SQL) but I'm not sure if this is even possible. I found multiple examples of adding a column to a table but no examples of extending a certain column.
CREATE TABLE sys_file_metadata ( enable_indexing tinytext NULL DEFAULT '1' );
I would be very thankful for any ideas ;)