From d437a6dc0e7cc169e044c361fb6c5690ea90e1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anke=20H=C3=A4slich?= Date: Wed, 15 Feb 2023 13:40:24 +0100 Subject: [PATCH] FEATURE: Exclude node types from usage count Add optional configuration for exclusion of node types. Useful in combination with the usage of the package `neos/metadata-contentrepositoryadapter`. Fixes: #8 --- Classes/Service/AssetIntegrationService.php | 13 ++++++++++++ Configuration/Settings.yaml | 4 ++++ Readme.md | 23 +++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 Configuration/Settings.yaml diff --git a/Classes/Service/AssetIntegrationService.php b/Classes/Service/AssetIntegrationService.php index 06eae09..2d90434 100644 --- a/Classes/Service/AssetIntegrationService.php +++ b/Classes/Service/AssetIntegrationService.php @@ -53,6 +53,12 @@ final class AssetIntegrationService */ protected $assetUsageLogger; + /** + * @Flow\InjectConfiguration(path="excludedNodeTypes") + * @var array + */ + protected $excludedNodeTypes; + private $assetPropertiesByNodeType = []; public function assetRemoved(AssetInterface $asset): void @@ -104,6 +110,13 @@ public function getAssetPropertyNamesForNodeType(NodeType $nodeType): array return $this->assetPropertiesByNodeType[$nodeType->getName()]; } + foreach ($this->excludedNodeTypes as $excludedNodeType) { + if ($nodeType->isOfType($excludedNodeType)) { + $this->assetPropertiesByNodeType[$nodeType->getName()] = []; + return []; + } + } + $propertyNames = array_reduce(array_keys($nodeType->getProperties()), function ($carry, $propertyName) use ($nodeType) { if ($this->propertyTypeCanBeRegistered($nodeType->getPropertyType($propertyName))) { diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml new file mode 100644 index 0000000..3588351 --- /dev/null +++ b/Configuration/Settings.yaml @@ -0,0 +1,4 @@ +Flowpack: + Neos: + AssetUsage: + excludedNodeTypes: [] diff --git a/Readme.md b/Readme.md index 994584f..f54fab1 100644 --- a/Readme.md +++ b/Readme.md @@ -46,6 +46,29 @@ When that happens, it is important that you try to find out where they come from If you think this happened due to an error in this package, please open an issue with as much information as you can give. +## Feature: Exclude node types from usage count + +Possible use case: If you are using this package in combination with [neos/metadata-contentrepositoryadapter](https://github.com/neos/metadata-contentrepositoryadapter), the metadata entries will be recognized as usage count. You can adjust this behaviour with the following settings. + +Example to exclude all metadata node types from usage count: +``` +Flowpack: + Neos: + AssetUsage: + excludedNodeTypes: + - 'Neos.MetaData:AbstractMetaData' +``` + +Example to exclude multiple custom metadata node types: +``` +Flowpack: + Neos: + AssetUsage: + excludedNodeTypes: + - 'Vendor.PackageName:Custom.MetaData.NodeType1' + - 'Vendor.PackageName:Custom.MetaData.NodeType2' +``` + ## Related packages * [Flowpack.EntityUsage](https://github.com/Flowpack/Flowpack.EntityUsage) the generic usage implementation