Skip to content

Commit

Permalink
[RELEASE] Version 11.0.9 with a bugfix for legacy file references in …
Browse files Browse the repository at this point in the history
…rich text

Releases: #111
Releases: https://projekte.in2code.de/issues/60981
  • Loading branch information
vertexvaar committed Dec 22, 2023
2 parents 3072411 + 7c1854e commit 10507b7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 36 additions & 12 deletions Classes/Component/RecordHandling/DefaultRecordFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion Classes/Features/RedirectsSupport/PageRecordRedirectEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -44,6 +45,7 @@

use function array_key_exists;
use function array_keys;
use function in_array;

class PageRecordRedirectEnhancer
{
Expand All @@ -57,6 +59,8 @@ class PageRecordRedirectEnhancer

protected LinkService $linkService;

protected ConfigContainer $configContainer;

/** @var array<string, array<int>> */
protected array $looseRedirects = [];

Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 10507b7

Please sign in to comment.