Skip to content

Commit

Permalink
Merge pull request #11 from punktDeForks/task/adjust-asset-usage-updates
Browse files Browse the repository at this point in the history
BUGFIX: Update of usage of previous asset when an asset property is updated
  • Loading branch information
Sebobo authored Apr 5, 2023
2 parents 0a22288 + a3387bc commit 3f7b733
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
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

0 comments on commit 3f7b733

Please sign in to comment.