From b27e5ad7016ab7e3ff0c0cd0caac0fbb61a2165f Mon Sep 17 00:00:00 2001 From: Oliver Eglseder Date: Thu, 19 Oct 2023 10:43:04 +0200 Subject: [PATCH 1/4] [BUGFIX] Do not enhance records with sys_redirects if they are excluded from publishing Resolves: https://projekte.in2code.de/issues/59783 --- .../RedirectsSupport/PageRecordRedirectEnhancer.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Classes/Features/RedirectsSupport/PageRecordRedirectEnhancer.php b/Classes/Features/RedirectsSupport/PageRecordRedirectEnhancer.php index 270dc4b2a..b4b285e19 100644 --- a/Classes/Features/RedirectsSupport/PageRecordRedirectEnhancer.php +++ b/Classes/Features/RedirectsSupport/PageRecordRedirectEnhancer.php @@ -30,6 +30,7 @@ */ use In2code\In2publishCore\Component\RecordHandling\RecordFinder; +use In2code\In2publishCore\Config\ConfigContainer; use In2code\In2publishCore\Domain\Model\Record; use In2code\In2publishCore\Domain\Model\RecordInterface; use In2code\In2publishCore\Event\AllRelatedRecordsWereAddedToOneRecord; @@ -44,6 +45,7 @@ use function array_key_exists; use function array_keys; +use function in_array; class PageRecordRedirectEnhancer { @@ -57,6 +59,8 @@ class PageRecordRedirectEnhancer protected LinkService $linkService; + protected ConfigContainer $configContainer; + /** @var array> */ protected array $looseRedirects = []; @@ -65,17 +69,23 @@ public function __construct( Connection $localDatabase, Connection $foreignDatabase, SysRedirectRepository $repo, - LinkService $linkService + LinkService $linkService, + ConfigContainer $configContainer ) { $this->recordFinder = $recordFinder; $this->localDatabase = $localDatabase; $this->foreignDatabase = $foreignDatabase; $this->repo = $repo; $this->linkService = $linkService; + $this->configContainer = $configContainer; } public function addRedirectsToPageRecord(AllRelatedRecordsWereAddedToOneRecord $event): void { + $excludedTables = $this->configContainer->get('excludeRelatedTables'); + if (in_array('sys_redirects', $excludedTables)) { + return; + } $record = $event->getRecord(); $pid = $record->getIdentifier(); From 26a69b0065a8fd8e4de6b79c2b219dbf601242f3 Mon Sep 17 00:00:00 2001 From: Oliver Eglseder Date: Fri, 22 Dec 2023 12:38:20 +0100 Subject: [PATCH 2/4] [BUGFIX] Search for file links only in href attributes Resolves: #111 Resolves: https://projekte.in2code.de/issues/60981 --- .../RecordHandling/DefaultRecordFinder.php | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/Classes/Component/RecordHandling/DefaultRecordFinder.php b/Classes/Component/RecordHandling/DefaultRecordFinder.php index 9d228f5fa..df1548e28 100644 --- a/Classes/Component/RecordHandling/DefaultRecordFinder.php +++ b/Classes/Component/RecordHandling/DefaultRecordFinder.php @@ -64,6 +64,7 @@ use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\Query\QueryHelper; use TYPO3\CMS\Core\EventDispatcher\EventDispatcher; +use TYPO3\CMS\Core\Html\HtmlParser; use TYPO3\CMS\Core\Resource\ResourceFactory; use TYPO3\CMS\Core\Service\FlexFormService; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -91,7 +92,9 @@ use function parse_url; use function preg_match; use function preg_match_all; +use function preg_split; use function reset; +use function str_starts_with; use function stripos; use function strlen; use function strpos; @@ -648,18 +651,39 @@ protected function fetchRelatedRecordsByRte(string $bodyText, array $excludedTab } } } - if (strpos($bodyText, 'file:') !== false) { - preg_match_all('~file:(\d+)~', $bodyText, $matches); - if (!empty($matches[1])) { - $matches = $matches[1]; - } - $matches = array_filter($matches); - if ( - count($matches) > 0 - && !in_array('sys_file', $excludedTableNames, true) - ) { - foreach ($matches as $match) { - $relatedRecords[] = $this->findByIdentifier((int)$match, 'sys_file'); + if ( + !in_array('sys_file', $excludedTableNames, true) + && 0 < preg_match_all('~href="file:(\d+)"~', $bodyText) + ) { + /** @var HtmlParser $htmlParser */ + $htmlParser = GeneralUtility::makeInstance(HtmlParser::class); + $tags = explode('<', $bodyText); + foreach ($tags as $tag) { + if (!str_starts_with($tag, 'a ')) { + continue; + } + $tagEnd = strpos($tag, '>'); + if (false === $tagEnd || $tagEnd < 5) { + continue; + } + $tagContent = substr($tag, 0, $tagEnd); + $tagParts = preg_split('/\\s+/', $tagContent, 2); + if (!isset($tagParts[1])) { + continue; + } + $tagAttributes = $htmlParser->get_tag_attributes($tagParts[1]); + if (isset($tagAttributes[0]['href']) && str_starts_with($tagAttributes[0]['href'], 'file:')) { + $href = substr($tagAttributes[0]['href'], 5); + if (MathUtility::canBeInterpretedAsInteger($href)) { + $record = $this->findByIdentifier((int)$href, 'sys_file'); + if ( + null !== $record + && [] !== $record->getLocalProperties() + && [] !== $record->getForeignProperties() + ) { + $relatedRecords[] = $record; + } + } } } } From 01fb93e1a373b17c5aed2d3bdcfd00684acdc01e Mon Sep 17 00:00:00 2001 From: Oliver Eglseder Date: Fri, 22 Dec 2023 12:39:41 +0100 Subject: [PATCH 3/4] [META] Set the EM conf version number to 11.0.9 --- ext_emconf.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext_emconf.php b/ext_emconf.php index 91e2bf3ef..3f655e194 100755 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,7 +9,7 @@ 'title' => 'in2publish Core', 'description' => 'Content publishing extension to connect stage and production server', 'category' => 'plugin', - 'version' => '11.0.8', + 'version' => '11.0.9', 'state' => 'stable', 'clearCacheOnLoad' => true, 'author' => 'Alex Kellner, Oliver Eglseder, Thomas Scheibitz, Stefan Busemann', From 7c1854e123852963568334006a23813a95d1e3b7 Mon Sep 17 00:00:00 2001 From: Oliver Eglseder Date: Fri, 22 Dec 2023 12:40:40 +0100 Subject: [PATCH 4/4] [DOCS] Update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a78ce041e..5893e4742 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # In2publish Core Change Log +1.0.9: +- [META] Set the EM conf version number to 11.0.9 +- [BUGFIX] Search for file links only in href attributes +- [BUGFIX] Do not enhance records with sys_redirects if they are excluded from publishing +- [RELEASE] Version 11.0.8 with correct performance test + 11.0.8 - [META] Set the EM conf version number to 11.0.8 - [BUGFIX] Sort query results by language