-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Add rule RemoveTableLocalPropertyRector (#3430)
Resolves: #3414
- Loading branch information
1 parent
0ef6593
commit e98c42d
Showing
5 changed files
with
250 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
)]); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/Fixture/fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | ||
), | ||
], | ||
], | ||
]; | ||
|
||
?> |
32 changes: 32 additions & 0 deletions
32
...s/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/RemoveTableLocalPropertyRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Rector/v12/v0/tca/RemoveTableLocalPropertyRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |