Skip to content

Commit

Permalink
TASK: Add rule RemoveTableLocalPropertyRector (#3430)
Browse files Browse the repository at this point in the history
Resolves: #3414
  • Loading branch information
sabbelasichon authored Jun 14, 2023
1 parent 0ef6593 commit e98c42d
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/v12/tca-120.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
$rectorConfig->rule(MigrateRequiredFlagRector::class);
$rectorConfig->rule(RemoveTCAInterfaceAlwaysDescriptionRector::class);
$rectorConfig->rule(RemoveCruserIdRector::class);
$rectorConfig->rule(\Ssch\TYPO3Rector\Rector\v12\v0\tca\RemoveTableLocalPropertyRector::class);
};
86 changes: 86 additions & 0 deletions src/Rector/v12/v0/tca/RemoveTableLocalPropertyRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Rector\v12\v0\tca;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Breaking-98479-RemovedFileReferenceRelatedFunctionality.html
* @see \Ssch\TYPO3Rector\Tests\Rector\v12\v0\tca\RemoveTableLocalPropertyRector\RemoveTableLocalPropertyRectorTest
*/
final class RemoveTableLocalPropertyRector extends AbstractRector
{
public function getNodeTypes(): array
{
return [Expr\ArrayItem::class];
}

/**
* @param ArrayItem $node
*/
public function refactor(Node $node): ?Node
{
if (null === $node->key) {
return null;
}

if (! $this->valueResolver->isValue($node->key, 'foreign_match_fields')) {
return null;
}

if (! $node->value instanceof Array_) {
return null;
}

foreach ($node->value->items as $item) {
if (null === $item) {
continue;
}

if (null === $item->key) {
continue;
}

if ($this->valueResolver->isValue($item->key, 'table_local')) {
$this->removeNode($item);
}
}

return null;
}

/**
* @codeCoverageIgnore
*/
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Remove TCA property table_local in foreign_match_fields', [new CodeSample(
<<<'CODE_SAMPLE'
'foreign_match_fields' => [
'fieldname' => 'media',
'tablenames' => 'tx_site_domain_model_mediacollection',
'table_local' => 'sys_file',
],
'maxitems' => 1,
'minitems' => 1,
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
'foreign_match_fields' => [
'fieldname' => 'media',
'tablenames' => 'tx_site_domain_model_mediacollection',
],
'maxitems' => 1,
'minitems' => 1,
CODE_SAMPLE
)]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\tca\RemoveTableLocalPropertyRector\Fixture;

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

return [
'ctrl' => [],
'columns' => [
'images' => [
'exclude' => 1,
'label' => 'Bilder',
'config' => ExtensionManagementUtility::getFileFieldTCAConfig(
'images',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference',
'showPossibleLocalizationRecords' => true,
'showRemovedLocalizationRecords' => true,
'showAllLocalizationLink' => true,
'showSynchronizationLink' => true,
],
'foreign_match_fields' => [
'fieldname' => 'images',
'tablenames' => 'tx_aknwevents_domain_model_event',
'table_local' => 'sys_file',
],
'minitems' => 0,
'maxitems' => 999,
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
'images2' => [
'exclude' => 1,
'label' => 'Bilder',
'config' => ExtensionManagementUtility::getFileFieldTCAConfig(
'images',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference',
'showPossibleLocalizationRecords' => true,
'showRemovedLocalizationRecords' => true,
'showAllLocalizationLink' => true,
'showSynchronizationLink' => true,
],
'foreign_match_fields' => [
'fieldname' => 'images',
'tablenames' => 'tx_aknwevents_domain_model_event',
],
'minitems' => 0,
'maxitems' => 999,
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
],
];

?>
-----
<?php

namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\tca\RemoveTableLocalPropertyRector\Fixture;

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;

return [
'ctrl' => [],
'columns' => [
'images' => [
'exclude' => 1,
'label' => 'Bilder',
'config' => ExtensionManagementUtility::getFileFieldTCAConfig(
'images',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference',
'showPossibleLocalizationRecords' => true,
'showRemovedLocalizationRecords' => true,
'showAllLocalizationLink' => true,
'showSynchronizationLink' => true,
],
'foreign_match_fields' => [
'fieldname' => 'images',
'tablenames' => 'tx_aknwevents_domain_model_event',
],
'minitems' => 0,
'maxitems' => 999,
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
'images2' => [
'exclude' => 1,
'label' => 'Bilder',
'config' => ExtensionManagementUtility::getFileFieldTCAConfig(
'images',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xlf:images.addFileReference',
'showPossibleLocalizationRecords' => true,
'showRemovedLocalizationRecords' => true,
'showAllLocalizationLink' => true,
'showSynchronizationLink' => true,
],
'foreign_match_fields' => [
'fieldname' => 'images',
'tablenames' => 'tx_aknwevents_domain_model_event',
],
'minitems' => 0,
'maxitems' => 999,
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
],
];

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Ssch\TYPO3Rector\Tests\Rector\v12\v0\tca\RemoveTableLocalPropertyRector;

use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

final class RemoveTableLocalPropertyRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

/**
* @return Iterator<array<string>>
*/
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Ssch\TYPO3Rector\Rector\v12\v0\tca\RemoveTableLocalPropertyRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../../../config/config_test.php');
$rectorConfig->rule(RemoveTableLocalPropertyRector::class);
};

0 comments on commit e98c42d

Please sign in to comment.