/**
* Prefix url of document with current resourcelocator prefix.
*
* @param IndexRebuildEvent $event
*/
public function onIndexRebuild(IndexRebuildEvent $event)
{
$output = $event->getOutput();
$filter = $event->getFilter();
$output->writeln('<info>Rebuilding content index</info>');
$typeMap = $this->baseMetadataFactory->getPhpcrTypeMap();
$phpcrTypes = [];
foreach ($typeMap as $type) {
$phpcrType = $type['phpcr_type'];
if ($phpcrType !== 'sulu:path') {
$phpcrTypes[] = sprintf('[jcr:mixinTypes] = "%s"', $phpcrType);
}
}
$condition = implode(' or ', $phpcrTypes);
// TODO: We cannot select all contents via. the parent type, see: https://github.com/jackalope/jackalope-doctrine-dbal/issues/217
$query = $this->documentManager->createQuery('SELECT * FROM [nt:unstructured] AS a WHERE ' . $condition);
$count = [];
$documents = $query->execute();
$progress = new ProgressHelper();
$progress->start($output, count($documents));
foreach ($documents as $document) {
if ($document instanceof SecurityBehavior && !empty($document->getPermissions())) {
$progress->advance();
continue;
}
$locales = $this->inspector->getLocales($document);
foreach ($locales as $locale) {
try {
$this->documentManager->find($document->getUuid(), $locale);
$documentClass = get_class($document);
if ($filter && !preg_match('{' . $filter . '}', $documentClass)) {
continue;
}
$this->searchManager->index($document, $locale);
if (!isset($count[$documentClass])) {
$count[$documentClass] = 0;
}
++$count[$documentClass];
} catch (\Exception $e) {
$output->writeln(sprintf('<error>Error indexing or de-indexing page (path: %s locale: %s)</error>: %s', $this->inspector->getPath($document), $locale, $e->getMessage()));
}
}
$progress->advance();
}
$output->writeln('');
foreach ($count as $className => $count) {
if ($count == 0) {
continue;
}
$output->writeln(sprintf('<comment>Content</comment>: %s <info>%s</info> indexed', $className, $count));
}
}