diff --git a/Classes/EventListener/PageIndexer/FrontendGroupsModifier.php b/Classes/EventListener/PageIndexer/FrontendGroupsModifier.php index da9391d3ec..e4dd283a0e 100644 --- a/Classes/EventListener/PageIndexer/FrontendGroupsModifier.php +++ b/Classes/EventListener/PageIndexer/FrontendGroupsModifier.php @@ -19,6 +19,7 @@ use ApacheSolrForTypo3\Solr\Access\Rootline; use ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\AuthorizationService; +use ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\PageIndexer; use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest; use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager; use TYPO3\CMS\Core\Http\JsonResponse; @@ -29,6 +30,8 @@ /** * Class FrontendGroupsModifier is responsible to fake the fe_groups to make * the indexing of access restricted pages and content elements. + * + * This class is involved only on {@link PageIndexer} processing. */ class FrontendGroupsModifier { @@ -40,7 +43,9 @@ class FrontendGroupsModifier public function __invoke(ModifyResolvedFrontendGroupsEvent $event): void { $pageIndexerRequest = $event->getRequest()->getAttribute('solr.pageIndexingInstructions'); - if (!$pageIndexerRequest instanceof PageIndexerRequest) { + if ( + !$pageIndexerRequest instanceof PageIndexerRequest + || !in_array(PageIndexer::ACTION_NAME, $pageIndexerRequest->getActions())) { return; } diff --git a/Classes/IndexQueue/FrontendHelper/PageIndexer.php b/Classes/IndexQueue/FrontendHelper/PageIndexer.php index be8578452e..8ff018aa09 100644 --- a/Classes/IndexQueue/FrontendHelper/PageIndexer.php +++ b/Classes/IndexQueue/FrontendHelper/PageIndexer.php @@ -59,12 +59,14 @@ */ class PageIndexer implements FrontendHelper, SingletonInterface { + public const ACTION_NAME = 'indexPage'; + protected bool $activated = false; /** * This frontend helper's executed action. */ - protected string $action = 'indexPage'; + protected string $action = self::ACTION_NAME; /** * Index Queue page indexer request. diff --git a/Classes/IndexQueue/FrontendHelper/UserGroupDetector.php b/Classes/IndexQueue/FrontendHelper/UserGroupDetector.php index 6869155da2..b095fb3b1e 100644 --- a/Classes/IndexQueue/FrontendHelper/UserGroupDetector.php +++ b/Classes/IndexQueue/FrontendHelper/UserGroupDetector.php @@ -34,6 +34,8 @@ */ class UserGroupDetector implements FrontendHelper, SingletonInterface { + public const ACTION_NAME = 'findUserGroups'; + /** * Index Queue page indexer request. */ @@ -42,7 +44,7 @@ class UserGroupDetector implements FrontendHelper, SingletonInterface /** * This frontend helper's executed action. */ - protected string $action = 'findUserGroups'; + protected string $action = self::ACTION_NAME; /** * Holds the original, unmodified TCA during user group detection @@ -96,9 +98,8 @@ public function deactivateTcaFrontendGroupEnableFields(ModifyTypoScriptConfigEve return; } if (empty($this->originalTca)) { - return; + $this->originalTca = $GLOBALS['TCA']; } - $this->originalTca = $GLOBALS['TCA']; foreach ($GLOBALS['TCA'] as $tableName => $tableConfiguration) { if (isset($GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns']['fe_group'])) { @@ -117,8 +118,7 @@ public function deactivateTcaFrontendGroupEnableFields(ModifyTypoScriptConfigEve public function getPage_preProcess(BeforePageIsRetrievedEvent $event): void { if ($this->activated) { - //$event->skipGroupAccessCheck(); - $disableGroupAccessCheck = true; + $event->skipGroupAccessCheck(); } } @@ -227,6 +227,7 @@ protected function getFrontendGroups(): array public function deactivate(PageIndexerResponse $response): void { $this->activated = false; + $GLOBALS['TCA'] = $this->originalTca; $response->addActionResult($this->action, $this->getFrontendGroups()); } } diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index af7f93ee1e..9a9b8f2824 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -295,6 +295,10 @@ services: - name: event.listener identifier: 'solr.index.PageFieldMappingIndexer' + ApacheSolrForTypo3\Solr\IndexQueue\FrontendHelper\UserGroupDetector: + autowire: true + autoconfigure: true + ApacheSolrForTypo3\Solr\EventListener\Extbase\PersistenceEventListener: autowire: true tags: diff --git a/Tests/Integration/IndexQueue/PageIndexerTest.php b/Tests/Integration/IndexQueue/PageIndexerTest.php index 2905556b18..bde52e85d9 100644 --- a/Tests/Integration/IndexQueue/PageIndexerTest.php +++ b/Tests/Integration/IndexQueue/PageIndexerTest.php @@ -24,6 +24,8 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\Test; use Traversable; +use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest; @@ -50,14 +52,14 @@ protected function setUp(): void page.10.stdWrap.dataWrap = | ' ); + $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); } /** - * Executed after each test. Emptys solr and checks if the index is empty + * Executed after each test. Empties solr and checks if the index is empty */ protected function tearDown(): void { - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); parent::tearDown(); } @@ -73,9 +75,6 @@ public function canIndexPageWithAccessProtectedContentIntoSolr( int $expectedNumFoundLoggedInUser, string $core = 'core_en' ): void { - self::markTestSkipped('@todo: Fix it. See: https://github.com/TYPO3-Solr/ext-solr/issues/4161'); - - $this->cleanUpAllCoresOnSolrServerAndAssertEmpty(); $this->importCSVDataSet(__DIR__ . '/Fixtures/' . $fixture . '.csv'); $createPageIndexerMock = function(): PageIndexerRequest { @@ -279,6 +278,9 @@ protected function sendPageIndexerRequest(string $url, PageIndexerRequest $reque $indexerResponse->addActionResult($action, $actionResult); } + /** @var VariableFrontend $runtimeCache */ + $runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime'); + $runtimeCache->flush(); return $indexerResponse; } } diff --git a/Tests/Integration/IntegrationTestBase.php b/Tests/Integration/IntegrationTestBase.php index 89a7ff6e70..0b31fed4cf 100644 --- a/Tests/Integration/IntegrationTestBase.php +++ b/Tests/Integration/IntegrationTestBase.php @@ -24,6 +24,8 @@ use ReflectionClass; use ReflectionException; use ReflectionObject; +use TYPO3\CMS\Core\Cache\CacheManager; +use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Exception\SiteNotFoundException; @@ -461,6 +463,10 @@ protected function executePageIndexer(string $url, Item $item, int $frontendUser $requestContext = (new InternalRequestContext())->withFrontendUserId($frontendUserId); } $response = $this->executeFrontendSubRequest($request, $requestContext); + /** @var VariableFrontend $runtimeCache */ + $runtimeCache = GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime'); + $runtimeCache->flush(); + $response->getBody()->rewind(); return $response; }