addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Max queue items to index in this run', '20'); $this->addOption('root', 'r', InputOption::VALUE_REQUIRED, 'Root page uid of the site', '1'); $this->addOption('debug', 'd', InputOption::VALUE_NONE, 'Single-step the first queue item verbosely'); } protected function execute(InputInterface $input, OutputInterface $output): int { Bootstrap::initializeBackendAuthentication(); $rootPageId = (int)$input->getOption('root'); $limit = (int)$input->getOption('limit'); $siteRepository = GeneralUtility::makeInstance(SiteRepository::class); $site = $siteRepository->getSiteByRootPageId($rootPageId); $configs = $site->getAllSolrConnectionConfigurations(); $output->writeln('Connection configurations: ' . count($configs)); foreach ($configs as $languageId => $config) { $read = $config['read']; $output->writeln(sprintf( ' lang %d: %s://%s:%d%s core=%s auth=%s', $languageId, $read['scheme'], $read['host'], $read['port'], $read['path'], $read['core'], $read['username'] !== '' ? 'yes' : 'no', )); } if ($configs === []) { $output->writeln('No connection configuration resolved - check site config.'); return Command::FAILURE; } if ($input->getOption('debug')) { $queue = GeneralUtility::makeInstance(Queue::class); $items = $queue->getItemsToIndex($site, 5); $output->writeln('getItemsToIndex(5): ' . count($items) . ' items'); if ($items !== []) { $first = $items[0]; $output->writeln(' first: type=' . $first->getType() . ' uid=' . $first->getRecordUid()); $svc = GeneralUtility::getContainer()->get(IndexingService::class); $ref = new \ReflectionObject($svc); $call = static function (string $method, array $args) use ($svc, $ref) { $m = $ref->getMethod($method); return $m->invokeArgs($svc, $args); }; $conns = $call('getPageSolrConnections', [$first]); $output->writeln(' getPageSolrConnections: ' . count($conns) . ' connections (langs: ' . implode(',', array_keys($conns)) . ')'); if ($conns === []) { return Command::SUCCESS; } $groups = $call('findUserGroupsForPage', [$first, 0]); $output->writeln(' findUserGroupsForPage(lang 0): ' . json_encode($groups)); $accessRootline = $call('buildAccessRootline', [$first, 0, $groups[0] ?? 0]); $params = $call('buildPageParameters', [$first]); $instructions = new \ApacheSolrForTypo3\Solr\IndexQueue\IndexingInstructions( items: [$first], action: \ApacheSolrForTypo3\Solr\IndexQueue\IndexingInstructions::ACTION_INDEX_PAGE, language: 0, userGroup: (int)($groups[0] ?? 0), accessRootline: $accessRootline, parameters: $params, ); $response = $call('executeSubRequest', [$first, 0, $instructions]); if ($response === null) { $output->writeln(' executeSubRequest => NULL (siehe Log)'); } else { $output->writeln(' executeSubRequest => HTTP ' . $response->getStatusCode() . ' content-type=' . $response->getHeaderLine('Content-Type')); $body = (string)$response->getBody(); $output->writeln(' body (600 Zeichen): ' . substr($body, 0, 600)); } } return Command::SUCCESS; } $indexService = GeneralUtility::makeInstance(IndexService::class, $site); try { $success = $indexService->indexItems($limit); } catch (Throwable $e) { $output->writeln('indexItems threw: ' . $e->getMessage() . ''); $output->writeln($e->getTraceAsString()); return Command::FAILURE; } $output->writeln('indexItems(' . $limit . ') returned: ' . ($success ? 'success' : 'with errors')); return Command::SUCCESS; } }