Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: Fusion eel neos deprecation tracer #5262

Open
wants to merge 2 commits into
base: 8.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions Neos.Fusion/Classes/Core/EelNeosDeprecationTracer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

declare(strict_types=1);

namespace Neos\Fusion\Core;

use Neos\Eel\EelInvocationTracerInterface;
use Neos\Flow\Annotations as Flow;
use Psr\Log\LoggerInterface;

final class EelNeosDeprecationTracer implements EelInvocationTracerInterface
{
/** @Flow\Inject */
protected LoggerInterface $logger;

/**
* These are the lowercase names of the Neos 9 Node fields that were removed in 9.0.
* Only the fields name, nodeTypeName and properties will continue to exist.
*/
private const LEGACY_NODE_FIELDS = [
'accessrestrictions' => true,
'accessroles' => true,
'accessible' => true,
'autocreated' => true,
'cacheentryidentifier' => true,
'childnodes' => true,
'contentobject' => true,
'context' => true,
'contextpath' => true,
'creationdatetime' => true,
'depth' => true,
'dimensions' => true,
'hidden' => true,
'hiddenafterdatetime' => true,
'hiddenbeforedatetime' => true,
'hiddeninindex' => true,
'identifier' => true,
'index' => true,
'label' => true,
'lastmodificationdatetime' => true,
'lastpublicationdatetime' => true,
'nodeaggregateidentifier' => true,
'nodedata' => true,
'nodename' => true,
'nodetype' => true,
'numberofchildnodes' => true,
'othernodevariants' => true,
'parent' => true,
'parentpath' => true,
'path' => true,
'primarychildnode' => true,
'propertynames' => true,
'removed' => true,
'root' => true,
'tethered' => true,
'visible' => true,
'workspace' => true,
];

public function __construct(
private readonly string $eelExpression,
private readonly bool $throwExceptions,
) {
}

public function recordPropertyAccess(object $object, string $propertyName): void
{
if (
// deliberate cross package reference from Neos.Fusion to simplify the wiring of this temporary migration helper
$object instanceof \Neos\ContentRepository\Domain\Model\Node
&& array_key_exists(strtolower($propertyName), self::LEGACY_NODE_FIELDS)
) {
$this->logDeprecationOrThrowException(
sprintf('The node field "%s" is deprecated in "%s"', $propertyName, $this->eelExpression)
);
}
}

public function recordMethodCall(object $object, string $methodName, array $arguments): void
{
}

public function recordFunctionCall(callable $function, string $functionName, array $arguments): void
{
}

private function logDeprecationOrThrowException(string $message): void
{
if ($this->throwExceptions) {
throw new \RuntimeException($message);
} else {
$this->logger->debug($message);
}
}
}
8 changes: 7 additions & 1 deletion Neos.Fusion/Classes/Core/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,13 @@ protected function evaluateEelExpression($expression, AbstractFusionObject $cont
$this->eelEvaluator->_activateDependency();
}

return EelUtility::evaluateEelExpression($expression, $this->eelEvaluator, $contextVariables);
$tracer = match ($this->settings['deprecationTracer'] ?? null) {
'LOG' => new EelNeosDeprecationTracer($expression, false),
'EXCEPTION' => new EelNeosDeprecationTracer($expression, true),
default => null
};

return EelUtility::evaluateEelExpression($expression, $this->eelEvaluator, $contextVariables, [], $tracer);
}

/**
Expand Down
1 change: 1 addition & 0 deletions Neos.Fusion/Configuration/Development/Settings.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Neos:
Fusion:
deprecationTracer: "LOG"
rendering:
exceptionHandler: Neos\Fusion\Core\ExceptionHandlers\HtmlMessageHandler
5 changes: 5 additions & 0 deletions Neos.Fusion/Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Neos:
# This option is suited only for development and enabled there by default.
enableParsePartialsCache: true

# Experimental logging for deprecated fusion code at runtime.
# Either disabled or "LOG" or "EXCEPTION" to let the exception handler step in ensuring no deprecated syntax is used.
# Should only be used during development
deprecationTracer: false

# Default context objects that are available in Eel expressions
#
# New variables should be added with a package key prefix. Example:
Expand Down
Loading