Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Solr Plugins within mount points uses the wrong site hash #4317

Open
websi opened this issue Feb 7, 2025 · 0 comments
Open

[BUG] Solr Plugins within mount points uses the wrong site hash #4317

websi opened this issue Feb 7, 2025 · 0 comments
Assignees

Comments

@websi
Copy link

websi commented Feb 7, 2025

Describe the bug
Solr Plugins within mount points uses the wrong site hash.
The site hash from the page where the element is saved is used instead of the page where the content is mounted.

This was not an Problem with TYPO3 10. With TYPO3 12 the problem exist.

The source of the problem is that \ApacheSolrForTypo3\Solr\Domain\Search\Query\QueryBuilder::useSiteHashFromTypoScript only use the page id to get the current context.
That is not correct if the page is mounted on an other page tree.
This method need to use the detected page from TYPO3, like within \ApacheSolrForTypo3\Solr\Controller\AbstractBaseController:initializeSearch

To Reproduce

  • Need two page trees
  • Solr plugin is configured on first page tree
  • The page with the solr plugin is mounted on second page tree
  • Open the mounted page. No results are displayed

Expected behavior

Solr use the site hash from the current page within the frontend context and show the results for the second page tree.

Used versions (please complete the following information):

  • TYPO3 Version: 12.4.26
  • Browser: Chrome
  • EXT:solr Version: 12.0.5
  • Used Apache Solr Version: 9.8.0
  • PHP Version: 8.3
  • MariaDB Version: 10.11

Additional context

Current workaround need to execute before ApacheSolrForTypo3\Solr\Search\AccessComponent

use ApacheSolrForTypo3\Solr\Domain\Search\Query\QueryBuilder;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Site\Entity\Site;

class AfterSearchQueryHasBeenPreparedEvent
{
    public function __construct(protected QueryBuilder $queryBuilder)
    {
    }

    /**
     * Use site hash from correct page within mount points.
     */
    public function __invoke(\ApacheSolrForTypo3\Solr\Event\Search\AfterSearchQueryHasBeenPreparedEvent $event): void
    {
        /** @var ServerRequestInterface|null $request */
        $request = $GLOBALS['TYPO3_REQUEST'] ?? null;
        $site = $request?->getAttribute('site');
        if (
            !($site instanceof Site) ||
            !($request instanceof ServerRequestInterface) ||
            !ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()
        ) {
            return;
        }

        $configuration = $event->getTypoScriptConfiguration();
        $queryConfiguration = $configuration->getObjectByPathOrDefault('plugin.tx_solr.search.query.');
        $allowSiteConfig = $queryConfiguration['allowedSites'] ?? '__solr_current_site';
        if (!in_array($allowSiteConfig, ['__solr_current_site', '__current_site'], true)) {
            return;
        }

        $query = $this->queryBuilder
            ->startFrom($event->getQuery())
            ->useSiteHashFromAllowedSites($site->getBase()->getHost())
            ->getQuery();
        $event->setQuery($query);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants