Skip to content

Commit

Permalink
[TASK] Remove getIsSiteManagedSite as all site are managed now
Browse files Browse the repository at this point in the history
* Remove getIsSiteManagedSite as all site are managed now
* Remove unused imports
  • Loading branch information
sfroemkenjw authored Jun 6, 2024
1 parent 7871a68 commit fe42a48
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 57 deletions.
10 changes: 2 additions & 8 deletions Classes/IndexQueue/PageIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use ApacheSolrForTypo3\Solr\Domain\Index\PageIndexer\PageUriBuilder;
use ApacheSolrForTypo3\Solr\NoSolrConnectionFoundException;
use ApacheSolrForTypo3\Solr\System\Solr\SolrConnection;
use ApacheSolrForTypo3\Solr\System\Util\SiteUtility;
use Doctrine\DBAL\Exception as DBALException;
use Exception;
use Psr\Log\LogLevel;
Expand Down Expand Up @@ -228,8 +227,7 @@ protected function getPageIndexerRequest(): PageIndexerRequest
*/
protected function getDataUrl(Item $item, int $language = 0): string
{
$pageId = $item->getRecordUid();
$uriBuilder = $this->getUriBuilder($pageId);
$uriBuilder = $this->getUriBuilder();
$mountPointParameter = $this->getMountPageDataUrlParameter($item);
return $uriBuilder->getPageIndexingUriFromPageItemAndLanguageId($item, $language, $mountPointParameter, $this->options);
}
Expand All @@ -239,12 +237,8 @@ protected function getDataUrl(Item $item, int $language = 0): string
*
* @throws \Exception
*/
protected function getUriBuilder(int $pageId): PageUriBuilder
protected function getUriBuilder(): PageUriBuilder
{
if (!SiteUtility::getIsSiteManagedSite($pageId)) {
throw new \Exception('Site of page with uid ' . $pageId . ' is not a TYPO3 managed site');
}

return GeneralUtility::makeInstance(PageUriBuilder::class);
}

Expand Down
17 changes: 0 additions & 17 deletions Classes/System/Util/SiteUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
namespace ApacheSolrForTypo3\Solr\System\Util;

use ApacheSolrForTypo3\Solr\Domain\Site\Site as ExtSolrSite;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Site\Entity\Site as CoreSite;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* This class contains related functions for the new site management that was introduced with TYPO3 9.
Expand All @@ -39,20 +36,6 @@ public static function reset(): void
self::$languages = [];
}

/**
* Determines if the site where the page belongs to is managed with the TYPO3 site management.
*/
public static function getIsSiteManagedSite(int $pageId): bool
{
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
try {
/** @var SiteFinder $siteFinder */
return $siteFinder->getSiteByPageId($pageId) instanceof CoreSite;
} catch (SiteNotFoundException) {
}
return false;
}

/**
* This method is used to retrieve the connection configuration from the TYPO3 site configuration.
*
Expand Down
25 changes: 0 additions & 25 deletions Classes/ViewHelpers/SearchFormViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace ApacheSolrForTypo3\Solr\ViewHelpers;

use ApacheSolrForTypo3\Solr\System\Url\UrlHelper;
use ApacheSolrForTypo3\Solr\System\Util\SiteUtility;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand Down Expand Up @@ -106,26 +105,12 @@ public function render()
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add('q', $this->getQueryString());
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add('pageUid', $pageUid);
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add(
'languageUid',
($this->renderingContext->getRequest()->getAttribute('language')?->getLanguageId() ?? 0)
);
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add('existingParameters', $this->getExistingSearchParameters());
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add('addPageAndLanguageId', !$this->getIsSiteManagedSite($pageUid));
$formContent = $this->renderChildren();
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('addPageAndLanguageId');
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('q');
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('pageUid');
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('languageUid');
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('existingParameters');

$this->tag->setContent($formContent);
Expand Down Expand Up @@ -174,16 +159,6 @@ protected function translateSearchParametersToInputTagAttributes(
return $attributes;
}

/**
* When a site is managed with site management the language and the id are encoded in the path segment of the url.
* When no speaking urls are active (e.g. with TYPO3 8 and no realurl) this information is passed as query parameter
* and would get lost when it is only part of the query arguments in the action parameter of the form.
*/
protected function getIsSiteManagedSite(int $pageId): bool
{
return SiteUtility::getIsSiteManagedSite($pageId);
}

protected function getTemplateVariableContainer(): ?VariableProviderInterface
{
return $this->templateVariableContainer;
Expand Down
5 changes: 0 additions & 5 deletions Resources/Private/Partials/Search/Form.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
<f:form.hidden name="{pluginNamespace}{name}" value="{value}" />
</f:for>

<f:if condition="{addPageAndLanguageId}">
<input type="hidden" name="L" value="{languageUid}" />
<input type="hidden" name="id" value="{pageUid}" />
</f:if>

<div class="input-group">
<input type="text" class="tx-solr-q js-solr-q tx-solr-suggest tx-solr-suggest-focus form-control" name="{pluginNamespace}[q]" value="{q}" />
<button class="btn btn-primary tx-solr-submit" type="submit">
Expand Down
2 changes: 0 additions & 2 deletions Tests/Unit/ViewHelpers/SearchFormViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ protected function setUp(): void
'getTemplateVariableContainer',
'getSearchResultSet',
'renderChildren',
'getIsSiteManagedSite',
])
->getMock();
$renderingContext = new RenderingContext(
Expand All @@ -69,7 +68,6 @@ protected function setUp(): void
$this->viewHelper->expects(self::any())->method('getTypoScriptConfiguration')->willReturn($this->typoScriptConfigurationMock);
$this->viewHelper->expects(self::any())->method('getTemplateVariableContainer')->willReturn($this->createMock(VariableProviderInterface::class));
$this->viewHelper->expects(self::once())->method('renderChildren')->willReturn('');
$this->viewHelper->expects(self::once())->method('getIsSiteManagedSite')->willReturn(false);
parent::setUp();
}

Expand Down

0 comments on commit fe42a48

Please sign in to comment.