Skip to content

Commit

Permalink
Merge pull request #113 from neos/feature/comment-cache-lifetime
Browse files Browse the repository at this point in the history
FEATURE: Add comment on usage of cacheLifetime in Fusion
  • Loading branch information
ahaeslich authored Dec 18, 2024
2 parents 59fd1fc + 6f14ba2 commit d400249
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Neos\Rector\ContentRepository90\Rules\ContextGetRootNodeRector;
use Neos\Rector\ContentRepository90\Rules\ContextIsInBackendRector;
use Neos\Rector\ContentRepository90\Rules\ContextIsLiveRector;
use Neos\Rector\ContentRepository90\Rules\FusionCacheLifetimeRector;
use Neos\Rector\ContentRepository90\Rules\FusionCachingNodeInEntryIdentifierRector;
use Neos\Rector\ContentRepository90\Rules\FusionContextCurrentRenderingModeRector;
use Neos\Rector\ContentRepository90\Rules\FusionContextCurrentSiteRector;
Expand Down Expand Up @@ -397,6 +398,11 @@
$rectorConfig->rule(ContextGetCurrentRenderingModeRector::class);
$rectorConfig->rule(FusionContextCurrentRenderingModeRector::class);

/**
* CacheLifetimeOperation
*/
$rectorConfig->rule(FusionCacheLifetimeRector::class);


/**
* ContentDimensionCombinator
Expand Down
28 changes: 28 additions & 0 deletions src/ContentRepository90/Rules/FusionCacheLifetimeRector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Neos\Rector\ContentRepository90\Rules;

use Neos\Rector\Core\FusionProcessing\EelExpressionTransformer;
use Neos\Rector\Core\FusionProcessing\FusionRectorInterface;
use Neos\Rector\Utility\CodeSampleLoader;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

class FusionCacheLifetimeRector implements FusionRectorInterface
{

public function getRuleDefinition(): RuleDefinition
{
return CodeSampleLoader::fromFile('Fusion: Add comment if .cacheLifetime() is used.', __CLASS__);
}

public function refactorFileContent(string $fileContent): string
{
return EelExpressionTransformer::parse($fileContent)
->addCommentsIfRegexMatches(
'/\.cacheLifetime()/',
'// TODO 9.0 migration: Line %LINE: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility'
)->getProcessedContent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
prototype(My.Namespace:Value) < prototype(Neos.Fusion:Value) {

lifetime = ${q(node).cacheLifetime()}

@cache.maximumLifetime = ${q(node).context({'invisibleContentShown': true}).find('[instanceof Neos.Neos:Content]').cacheLifetime()}

}
-----
// TODO 9.0 migration: Line 5: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility
// TODO 9.0 migration: Line 7: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility
prototype(My.Namespace:Value) < prototype(Neos.Fusion:Value) {

lifetime = ${q(node).cacheLifetime()}

@cache.maximumLifetime = ${q(node).context({'invisibleContentShown': true}).find('[instanceof Neos.Neos:Content]').cacheLifetime()}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Neos\Rector\Tests\ContentRepository90\Rules\FusionNodeDepthRector;

use Rector\Testing\PHPUnit\AbstractRectorTestCase;

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

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

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

declare (strict_types=1);

use Neos\Rector\ContentRepository90\Rules\FusionCacheLifetimeRector;
use Neos\Rector\Core\FusionProcessing\FusionFileProcessor;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig) : void {
$services = $rectorConfig->services();
$services->defaults()
->public()
->autowire()
->autoconfigure();
$services->set(FusionFileProcessor::class);
$rectorConfig->disableParallel(); // does not work for fusion files - see https://github.com/rectorphp/rector-src/pull/2597#issuecomment-1190120688

$rectorConfig->rule(FusionCacheLifetimeRector::class);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
prototype(My.Namespace:Value) < prototype(Neos.Fusion:Value) {

lifetime = ${q(node).cacheLifetime()}

@cache.maximumLifetime = ${q(node).context({'invisibleContentShown': true}).find('[instanceof Neos.Neos:Content]').cacheLifetime()}

}
-----
// TODO 9.0 migration: Line 5: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility
// TODO 9.0 migration: Line 7: You may need to remove ".cacheLifetime()" as this FlowQuery Operation has been removed. This is not needed anymore as the concept of timeable node visibility has changed. See https://github.com/neos/timeable-node-visibility
prototype(My.Namespace:Value) < prototype(Neos.Fusion:Value) {

lifetime = ${q(node).cacheLifetime()}

@cache.maximumLifetime = ${q(node).context({'invisibleContentShown': true}).find('[instanceof Neos.Neos:Content]').cacheLifetime()}

}

0 comments on commit d400249

Please sign in to comment.