Skip to content

Commit

Permalink
[BUGFIX] Fixes Databender for Redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoffmann1979 committed May 7, 2024
1 parent 63cf257 commit ffacf64
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
use In2code\In2publishCore\Utility\BackendUtility;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\LinkHandling\LinkService;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

use function in_array;

Expand All @@ -50,6 +52,10 @@ class RedirectSourceHostReplacement implements SingletonInterface, LoggerAwareIn
Record::S_MOVED,
];

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function replaceLocalWithForeignSourceHost(RecordWasSelectedForPublishing $event): void
{
$record = $event->getRecord();
Expand Down Expand Up @@ -101,6 +107,24 @@ public function replaceLocalWithForeignSourceHost(RecordWasSelectedForPublishing
return;
}

// 4. Check Target
$target = $properties['target'];
if (null !== $target && str_contains($target, 't3://')) {
$coreLinkService = GeneralUtility::makeInstance(LinkService::class);
$linkAttributes = $coreLinkService->resolveByStringRepresentation($target);
if (!empty($linkAttributes['pageuid'])) {
$url = BackendUtility::buildPreviewUri('pages', $linkAttributes['pageuid'], 'foreign');
if (null === $url) {
return;
}
$newHost = $url->getHost();

$properties['source_host'] = $newHost;
$record->setLocalProps($properties);
return;
}
}

$this->logger->alert(
'A redirect without an associated page or site is going to be published',
['uid' => $record->getId()],
Expand Down

0 comments on commit ffacf64

Please sign in to comment.