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

BUGFIX: Update of usage of previous asset when an asset property is updated #11

Merged
merged 2 commits into from
Apr 5, 2023
Merged
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
3 changes: 2 additions & 1 deletion Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Flowpack\Neos\AssetUsage\Service\AssetIntegrationService;
use Neos\ContentRepository\Domain\Model\Node;
use Neos\ContentRepository\Domain\Model\Workspace;
use Neos\Neos\Service\PublishingService;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\Package as BasePackage;
use Neos\Media\Domain\Service\AssetService;
Expand All @@ -31,7 +32,7 @@ public function boot(Bootstrap $bootstrap): void
$dispatcher->connect(Node::class, 'nodePropertyChanged', AssetIntegrationService::class, 'nodePropertyChanged');
$dispatcher->connect(Node::class, 'nodeRemoved', AssetIntegrationService::class, 'nodeRemoved');
$dispatcher->connect(Node::class, 'nodeAdded', AssetIntegrationService::class, 'nodeAdded');
$dispatcher->connect(Node::class, 'nodeDiscarded', AssetIntegrationService::class, 'nodeDiscarded');
$dispatcher->connect(PublishingService::class, 'nodeDiscarded', AssetIntegrationService::class, 'nodeDiscarded');
$dispatcher->connect(Workspace::class, 'beforeNodePublishing', AssetIntegrationService::class, 'beforeNodePublishing');
$dispatcher->connect(Workspace::class, 'afterNodePublishing', AssetIntegrationService::class, 'afterNodePublishing');

Expand Down
15 changes: 8 additions & 7 deletions Classes/Service/AssetIntegrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,21 @@ public function beforeNodePublishing(NodeInterface $node, Workspace $targetWorks
$targetNode = $contentContext->getNodeByIdentifier($node->getIdentifier());

foreach ($this->getAssetPropertyNamesForNodeType($node->getNodeType()) as $propertyName) {
if (!$node->hasProperty($propertyName)) {
return;
}
$propertyValue = $node->getProperty($propertyName);
if (!$propertyValue) {
return;
}
// Unregister the asset stored in the target node, the assets will be registered again after publishing
if ($targetNode && $targetNode->hasProperty($propertyName)) {
$targetPropertyValue = $targetNode->getProperty($propertyName);
if ($targetPropertyValue) {
$this->unregisterUsageInNode($targetNode, $targetPropertyValue, false);
}
}

if (!$node->hasProperty($propertyName)) {
return;
}
$propertyValue = $node->getProperty($propertyName);
if (empty($propertyValue)) {
return;
}
$this->unregisterUsageInNode($node, $propertyValue, false);
}
}
Expand Down