/** * Removes unused ImageVariants after a Node property changes to a different ImageVariant. * This is triggered via the nodePropertyChanged event. * * Note: This method it triggered by the "nodePropertyChanged" signal, @see \Neos\ContentRepository\Domain\Model\Node::emitNodePropertyChanged() * * @param NodeInterface $node the affected node * @param string $propertyName name of the property that has been changed/added * @param mixed $oldValue the property value before it was changed or NULL if the property is new * @param mixed $value the new property value * @return void */ public function removeUnusedImageVariant(NodeInterface $node, $propertyName, $oldValue, $value) { if ($oldValue === $value || !$oldValue instanceof ImageVariant) { return; } $identifier = $this->persistenceManager->getIdentifierByObject($oldValue); $results = $this->nodeDataRepository->findNodesByRelatedEntities(array(ImageVariant::class => [$identifier])); // This case shouldn't happen as the query will usually find at least the node that triggered this call, still if there is no relation we can remove the ImageVariant. if ($results === []) { $this->assetRepository->remove($oldValue); return; } // If the result contains exactly the node that got a new ImageVariant assigned then we are safe to remove the asset here. if ($results === [$node->getNodeData()]) { $this->assetRepository->remove($oldValue); } }
/** * Removes all routing cache entries for the given $nodeData * * @param NodeInterface $node * @return void */ protected function flushRoutingCacheForNode(NodeInterface $node) { $nodeData = $node->getNodeData(); $nodeDataIdentifier = $this->persistenceManager->getIdentifierByObject($nodeData); if ($nodeDataIdentifier === null) { return; } $this->routerCachingService->flushCachesByTag($nodeDataIdentifier); }
/** * Move the given node instance to the target workspace * * If no target node variant (having the same dimension values) exists in the target workspace, the node that * is published will be used as a new node variant in the target workspace. * * @param NodeInterface $node The node to publish * @param Workspace $targetWorkspace The workspace to publish to * @return void */ protected function moveNodeVariantToTargetWorkspace(NodeInterface $node, Workspace $targetWorkspace) { $nodeData = $node->getNodeData(); $this->handleShadowNodeData($nodeData, $targetWorkspace, $nodeData); // Technically this shouldn't be needed but due to doctrines behavior we need it. if ($nodeData->isRemoved() && $targetWorkspace->getBaseWorkspace() === null) { $this->nodeDataRepository->remove($nodeData); return; } $nodeData->setMovedTo(null); $nodeData->setWorkspace($targetWorkspace); $nodeData->setLastPublicationDateTime($this->now); $node->setNodeDataIsMatchingContext(null); $this->nodeService->cleanUpProperties($node); }
/** * Method which does the actual work of discarding, includes a protection against endless recursions and * multiple discarding of the same node. * * @param NodeInterface $node The node to discard * @param array &$alreadyDiscardedNodeIdentifiers List of node identifiers which already have been discarded during one discardNode() run * @return void * @throws \Neos\ContentRepository\Exception\WorkspaceException */ protected function doDiscardNode(NodeInterface $node, array &$alreadyDiscardedNodeIdentifiers = []) { if ($node->getWorkspace()->getBaseWorkspace() === null) { throw new WorkspaceException('Nodes in a in a workspace without a base workspace cannot be discarded.', 1395841899); } if ($node->getPath() === '/') { return; } if (array_search($node->getIdentifier(), $alreadyDiscardedNodeIdentifiers) !== false) { return; } $alreadyDiscardedNodeIdentifiers[] = $node->getIdentifier(); $possibleShadowNodeData = $this->nodeDataRepository->findOneByMovedTo($node->getNodeData()); if ($possibleShadowNodeData instanceof NodeData) { if ($possibleShadowNodeData->getMovedTo() !== null) { $parentBasePath = $node->getPath(); $affectedChildNodeDataInSameWorkspace = $this->nodeDataRepository->findByParentAndNodeType($parentBasePath, null, $node->getWorkspace(), null, false, true); foreach ($affectedChildNodeDataInSameWorkspace as $affectedChildNodeData) { /** @var NodeData $affectedChildNodeData */ $affectedChildNode = $this->nodeFactory->createFromNodeData($affectedChildNodeData, $node->getContext()); $this->doDiscardNode($affectedChildNode, $alreadyDiscardedNodeIdentifiers); } } $this->nodeDataRepository->remove($possibleShadowNodeData); } $this->nodeDataRepository->remove($node); $this->emitNodeDiscarded($node); }
/** * For internal use in createRecursiveCopy. * * @param NodeInterface $sourceNode * @param boolean $isCopy * @return void */ public function similarize(NodeInterface $sourceNode, $isCopy = false) { $this->nodeData->similarize($sourceNode->getNodeData(), $isCopy); }