Skip to content

Commit 10507b7

Browse files
committed
[RELEASE] Version 11.0.9 with a bugfix for legacy file references in rich text
Releases: #111 Releases: https://projekte.in2code.de/issues/60981
2 parents 3072411 + 7c1854e commit 10507b7

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# In2publish Core Change Log
22

3+
1.0.9:
4+
- [META] Set the EM conf version number to 11.0.9
5+
- [BUGFIX] Search for file links only in href attributes
6+
- [BUGFIX] Do not enhance records with sys_redirects if they are excluded from publishing
7+
- [RELEASE] Version 11.0.8 with correct performance test
8+
39
11.0.8
410
- [META] Set the EM conf version number to 11.0.8
511
- [BUGFIX] Sort query results by language

Classes/Component/RecordHandling/DefaultRecordFinder.php

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
use TYPO3\CMS\Core\Database\Connection;
6565
use TYPO3\CMS\Core\Database\Query\QueryHelper;
6666
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
67+
use TYPO3\CMS\Core\Html\HtmlParser;
6768
use TYPO3\CMS\Core\Resource\ResourceFactory;
6869
use TYPO3\CMS\Core\Service\FlexFormService;
6970
use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -91,7 +92,9 @@
9192
use function parse_url;
9293
use function preg_match;
9394
use function preg_match_all;
95+
use function preg_split;
9496
use function reset;
97+
use function str_starts_with;
9598
use function stripos;
9699
use function strlen;
97100
use function strpos;
@@ -648,18 +651,39 @@ protected function fetchRelatedRecordsByRte(string $bodyText, array $excludedTab
648651
}
649652
}
650653
}
651-
if (strpos($bodyText, 'file:') !== false) {
652-
preg_match_all('~file:(\d+)~', $bodyText, $matches);
653-
if (!empty($matches[1])) {
654-
$matches = $matches[1];
655-
}
656-
$matches = array_filter($matches);
657-
if (
658-
count($matches) > 0
659-
&& !in_array('sys_file', $excludedTableNames, true)
660-
) {
661-
foreach ($matches as $match) {
662-
$relatedRecords[] = $this->findByIdentifier((int)$match, 'sys_file');
654+
if (
655+
!in_array('sys_file', $excludedTableNames, true)
656+
&& 0 < preg_match_all('~href="file:(\d+)"~', $bodyText)
657+
) {
658+
/** @var HtmlParser $htmlParser */
659+
$htmlParser = GeneralUtility::makeInstance(HtmlParser::class);
660+
$tags = explode('<', $bodyText);
661+
foreach ($tags as $tag) {
662+
if (!str_starts_with($tag, 'a ')) {
663+
continue;
664+
}
665+
$tagEnd = strpos($tag, '>');
666+
if (false === $tagEnd || $tagEnd < 5) {
667+
continue;
668+
}
669+
$tagContent = substr($tag, 0, $tagEnd);
670+
$tagParts = preg_split('/\\s+/', $tagContent, 2);
671+
if (!isset($tagParts[1])) {
672+
continue;
673+
}
674+
$tagAttributes = $htmlParser->get_tag_attributes($tagParts[1]);
675+
if (isset($tagAttributes[0]['href']) && str_starts_with($tagAttributes[0]['href'], 'file:')) {
676+
$href = substr($tagAttributes[0]['href'], 5);
677+
if (MathUtility::canBeInterpretedAsInteger($href)) {
678+
$record = $this->findByIdentifier((int)$href, 'sys_file');
679+
if (
680+
null !== $record
681+
&& [] !== $record->getLocalProperties()
682+
&& [] !== $record->getForeignProperties()
683+
) {
684+
$relatedRecords[] = $record;
685+
}
686+
}
663687
}
664688
}
665689
}

Classes/Features/RedirectsSupport/PageRecordRedirectEnhancer.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131

3232
use In2code\In2publishCore\Component\RecordHandling\RecordFinder;
33+
use In2code\In2publishCore\Config\ConfigContainer;
3334
use In2code\In2publishCore\Domain\Model\Record;
3435
use In2code\In2publishCore\Domain\Model\RecordInterface;
3536
use In2code\In2publishCore\Event\AllRelatedRecordsWereAddedToOneRecord;
@@ -44,6 +45,7 @@
4445

4546
use function array_key_exists;
4647
use function array_keys;
48+
use function in_array;
4749

4850
class PageRecordRedirectEnhancer
4951
{
@@ -57,6 +59,8 @@ class PageRecordRedirectEnhancer
5759

5860
protected LinkService $linkService;
5961

62+
protected ConfigContainer $configContainer;
63+
6064
/** @var array<string, array<int>> */
6165
protected array $looseRedirects = [];
6266

@@ -65,17 +69,23 @@ public function __construct(
6569
Connection $localDatabase,
6670
Connection $foreignDatabase,
6771
SysRedirectRepository $repo,
68-
LinkService $linkService
72+
LinkService $linkService,
73+
ConfigContainer $configContainer
6974
) {
7075
$this->recordFinder = $recordFinder;
7176
$this->localDatabase = $localDatabase;
7277
$this->foreignDatabase = $foreignDatabase;
7378
$this->repo = $repo;
7479
$this->linkService = $linkService;
80+
$this->configContainer = $configContainer;
7581
}
7682

7783
public function addRedirectsToPageRecord(AllRelatedRecordsWereAddedToOneRecord $event): void
7884
{
85+
$excludedTables = $this->configContainer->get('excludeRelatedTables');
86+
if (in_array('sys_redirects', $excludedTables)) {
87+
return;
88+
}
7989
$record = $event->getRecord();
8090
$pid = $record->getIdentifier();
8191

ext_emconf.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'title' => 'in2publish Core',
1010
'description' => 'Content publishing extension to connect stage and production server',
1111
'category' => 'plugin',
12-
'version' => '11.0.8',
12+
'version' => '11.0.9',
1313
'state' => 'stable',
1414
'clearCacheOnLoad' => true,
1515
'author' => 'Alex Kellner, Oliver Eglseder, Thomas Scheibitz, Stefan Busemann',

0 commit comments

Comments
 (0)