Skip to content

Commit

Permalink
[BUGFIX] Do not resolve relations to pages from TCA
Browse files Browse the repository at this point in the history
  • Loading branch information
vertexvaar committed May 2, 2024
2 parents 3003b9c + 75638b6 commit 9fd3523
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
use In2code\In2publishCore\Component\Core\PreProcessing\ProcessingResult;
use In2code\In2publishCore\Component\Core\PreProcessing\TcaPreProcessor;
use In2code\In2publishCore\Component\Core\Resolver\Resolver;
use In2code\In2publishCore\Component\Core\Service\Config\ExcludedTablesServiceInjection;
use Psr\Container\ContainerInterface;

use function array_key_exists;
use function array_keys;
use function array_merge;
use function count;

abstract class AbstractProcessor implements TcaPreProcessor
{
use ExcludedTablesServiceInjection;

public const ADDITIONAL_ORDER_BY_PATTERN = '/(?P<where>.*)ORDER[\s\n]+BY[\s\n]+(?P<col>\w+(\.\w+)?)(?P<dir>\s(DESC|ASC))?/is';
protected ContainerInterface $container;

Expand Down Expand Up @@ -91,6 +95,9 @@ public function process(string $table, string $column, array $tca): ProcessingRe
$reasons[] = $reason;
}
if (!empty($reasons)) {
if (1 === count($reasons)) {
[$reasons] = $reasons;
}
return new ProcessingResult(ProcessingResult::INCOMPATIBLE, $reasons);
}
$processedTca = [];
Expand All @@ -103,7 +110,7 @@ public function process(string $table, string $column, array $tca): ProcessingRe
if (null === $resolver) {
return new ProcessingResult(
ProcessingResult::INCOMPATIBLE,
['The processor did not return a valid resolver. The target table might be excluded or empty.'],
'The processor did not return a valid resolver. The target table might be excluded or empty.',
);
}
return new ProcessingResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class CategoryProcessor extends AbstractProcessor
'relationship',
];

protected function additionalPreProcess(string $table, string $column, array $tca): array
{
if ($this->excludedTablesService->isExcludedTable('sys_category')) {
return ['The table sys_category is excluded from publishing'];
}
return [];
}

protected function buildResolver(string $table, string $column, array $processedTca): Resolver
{
$relationship = 'manyToMany';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public function getColumn(): string
return 'related';
}

protected function additionalPreProcess(string $table, string $column, array $tca): array
{
if ($this->excludedTablesService->isExcludedTable('tx_news_domain_model_news')) {
return ['The table tx_news_domain_model_news is excluded from publishing'];
}
return [];
}

protected function buildResolver(string $table, string $column, array $processedTca): Resolver
{
$resolver = $this->container->get(StaticJoinResolver::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class FilePreprocessor extends AbstractProcessor
{
protected string $type = 'file';

protected function additionalPreProcess(string $table, string $column, array $tca): array
{
if ($this->excludedTablesService->isExcludedTable('sys_file_reference')) {
return ['The table sys_file_reference is excluded from publishing'];
}
return [];
}

protected function buildResolver(string $table, string $column, array $processedTca): ?Resolver
{
$foreignTable = 'sys_file_reference';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ public function getColumn(): string
return 'settings.persistenceIdentifier';
}

protected function additionalPreProcess(string $table, string $column, array $tca): array
{
if ($this->excludedTablesService->isExcludedTable('tt_content')) {
return ['The table tt_content is excluded from publishing'];
}
return [];
}

protected function buildResolver(string $table, string $column, array $processedTca): ?Resolver
{
return new FormFrameworkResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
use In2code\In2publishCore\Utility\DatabaseUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

use function array_diff;
use function array_key_exists;
use function array_keys;
use function implode;
use function preg_match;
use function strpos;
Expand Down Expand Up @@ -55,8 +57,17 @@ protected function additionalPreProcess(string $table, string $column, array $tc
return [];
}

$reasons = [];
$allowedTables = GeneralUtility::trimExplode(',', $allowed);
if (['pages'] === $allowedTables) {
return ['TCA relations to pages are not resolved.'];
}

$allowedTables = $this->excludedTablesService->removeExcludedTables($allowedTables);
if (empty($allowedTables)) {
return ['All tables of this relation (' . $allowed . ') are excluded.'];
}

$reasons = [];
foreach ($allowedTables as $allowedTable) {
if (!array_key_exists($allowedTable, $GLOBALS['TCA'])) {
$reasons[] = 'Can not reference the table "' . $allowedTable
Expand All @@ -69,7 +80,15 @@ protected function additionalPreProcess(string $table, string $column, array $tc
protected function buildResolver(string $table, string $column, array $processedTca): ?Resolver
{
$foreignTable = $processedTca['allowed'];
$tables = GeneralUtility::trimExplode(',', $foreignTable);
if ('*' === $foreignTable) {
$tables = $this->excludedTablesService->getAllNonExcludedTcaTables();
} else {
$tables = GeneralUtility::trimExplode(',', $foreignTable);
$tables = $this->excludedTablesService->removeExcludedTables($tables);
}

$tables = array_diff($tables, ['pages']);

$isSingleTable = $this->isSingleTable($foreignTable);

if (isset($processedTca['MM'])) {
Expand All @@ -78,7 +97,7 @@ protected function buildResolver(string $table, string $column, array $processed

$foreignMatchFields = [];
foreach ($processedTca['MM_match_fields'] ?? [] as $matchField => $matchValue) {
if ((string)(int)$matchValue === (string)$matchValue) {
if ((string) (int) $matchValue === (string) $matchValue) {
$foreignMatchFields[] = $matchField . ' = ' . $matchValue;
} else {
$foreignMatchFields[] = $matchField . ' = "' . $matchValue . '"';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ class InlineProcessor extends AbstractProcessor
'MM_opposite_field',
];

protected function additionalPreProcess(string $table, string $column, array $tca): array
{
$foreignTable = $tca['foreign_table'] ?? null;
if (null !== $foreignTable && $this->excludedTablesService->isExcludedTable($foreignTable)) {
return ['The table ' . $foreignTable . ' is excluded from publishing'];
}
return [];
}

protected function buildResolver(string $table, string $column, array $processedTca): Resolver
{
$foreignTable = $processedTca['foreign_table'];
Expand Down Expand Up @@ -80,7 +89,7 @@ public function processMmMatchFields(array $processedTca): string
{
$foreignMatchFields = [];
foreach ($processedTca['MM_match_fields'] ?? [] as $matchField => $matchValue) {
if ((string)(int)$matchValue === (string)$matchValue) {
if ((string) (int) $matchValue === (string) $matchValue) {
$foreignMatchFields[] = $matchField . ' = ' . $matchValue;
} else {
$foreignMatchFields[] = $matchField . ' = "' . $matchValue . '"';
Expand All @@ -99,7 +108,7 @@ protected function processForeignMatchFields(array $processedTca): string
{
$foreignMatchFields = [];
foreach ($processedTca['foreign_match_fields'] ?? [] as $matchField => $matchValue) {
if ((string)(int)$matchValue === (string)$matchValue) {
if ((string) (int) $matchValue === (string) $matchValue) {
$foreignMatchFields[] = $matchField . ' = ' . $matchValue;
} else {
$foreignMatchFields[] = $matchField . ' = "' . $matchValue . '"';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ protected function additionalPreProcess(string $table, string $column, array $tc
'Multiple is broken in the TYPO3 Core, https://forge.typo3.org/issues/103604',
];
}

// Skip relations to table "pages", except if it's the page's transOrigPointerField
$foreignTable = $tca['foreign_table'] ?? null;
$transOrigPointerField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] ?? null;
if ('pages' === $foreignTable && ('pages' !== $table || $column !== $transOrigPointerField)) {
return ['TCA relations to pages are not resolved.'];
}

if (null !== $foreignTable && $this->excludedTablesService->isExcludedTable($foreignTable)) {
return ['The table ' . $foreignTable . ' is excluded from publishing'];
}

return [];
}

Expand All @@ -65,7 +77,7 @@ protected function buildResolver(string $table, string $column, array $processed

$foreignMatchFields = [];
foreach ($processedTca['MM_match_fields'] ?? [] as $matchField => $matchValue) {
if ((string)(int)$matchValue === (string)$matchValue) {
if ((string) (int) $matchValue === (string) $matchValue) {
$foreignMatchFields[] = $matchField . ' = ' . $matchValue;
} else {
$foreignMatchFields[] = $matchField . ' = "' . $matchValue . '"';
Expand Down
7 changes: 2 additions & 5 deletions Classes/Component/Core/Resolver/TextResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TextResolver extends AbstractResolver
{
use EventDispatcherInjection;

private const REGEX_T3URN = '~(?P<URN>t3\://(?:file|page)\?uid=\d+)(?:#[\w\d\-\_\!]+)?~';
private const REGEX_T3URN = '~(?P<URN>t3\://(?:file)\?uid=\d+)(?:#[\w\d\-\_\!]+)?~';
protected string $column;

public function configure(string $column): void
Expand All @@ -32,7 +32,7 @@ public function configure(string $column): void

public function getTargetTables(): array
{
return ['sys_file', 'pages'];
return ['sys_file'];
}

public function resolve(Demands $demands, Record $record): void
Expand Down Expand Up @@ -64,9 +64,6 @@ protected function findRelationsInText(Demands $demands, string $text, Record $r
if ('file' === $urnParsed['host'] && isset($data['uid'])) {
$demands->addDemand(new SelectDemand('sys_file', '', 'uid', $data['uid'], $record));
}
if ('page' === $urnParsed['host'] && isset($data['uid'])) {
$demands->addDemand(new SelectDemand('pages', '', 'uid', $data['uid'], $record));
}
}

$this->eventDispatcher->dispatch(new DemandsForTextWereCollected($demands, $record, $text));
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"extra": {
"branch-alias": {
"dev-develop": "12.4.x-dev",
"dev-master": "12.4.x-dev"
"dev-master": "12.4.x-dev",
"dev-feature/ignore-pages-relation": "12.4.x-dev"
},
"typo3/cms": {
"extension-key": "in2publish_core"
Expand Down

0 comments on commit 9fd3523

Please sign in to comment.